Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am trying to add approle assignments to existing user.This is the code I am using.The code looks fine[I have just modified the GraphApi console App].

C#
  IPagedCollection<IApplication> applications = null;
//Get the App where I want to add the functionality    
  applications = activeDirectoryClient.Applications.Where(e => e.AppId == "APPId").ExecuteAsync().Result;
//Get the appApplication 
appObject = (Application)applications.FirstOrDefault();
AppRole appRole = new AppRole();
//Assign the first Approle to the approle   
 
 appRole = appObject.AppRoles.FirstOrDefault();
//retrived a single user  
User user = (User)retrievedUsers.First();
//Assign the approleassignments to user
 AppRoleAssignment appRoles = new AppRoleAssignment();        
            appRoles.Id = appRole.Id;                
    appRoles.ResourceId = Guid.Parse(appObject.ObjectId);     
               appRoles.PrincipalDisplayName = appRole.DisplayName;        
            appRoles.ResourceDisplayName = appRole.DisplayName;            
        appRoles.PrincipalType = "User";               
     appRoles.PrincipalId = Guid.Parse(user.ObjectId); 
                   user.AppRoleAssignments.Add(appRoles);   
                 user.UpdateAsync().Wait();


But when I ran It is giving me the error "Request_ResourceNotFound": "Resource 'Some random string' does not exist or one of its queried reference-property objects are not present."

also I am able to update other details,it works fine.I just search for the issue it seems like if some of the parameter is not found, then we will get this error.But here I am not creating anything am just assigning the values like appID,ObjectID,PrincipalID.Please help me resolve the issue.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900