Azure-Samples / active-directory-dotnet-graphapi-console

A .NET console application that performs various queries against the Azure AD Graph API using both user identities and application identities.
79 stars 77 forks source link

Add user to app? #53

Open ivoloshin opened 6 years ago

ivoloshin commented 6 years ago

Is there a way, when logged in in app mode, to add a user to app? I tried the following and got an error:

var roleAssignment= new AppRoleAssignment() {
Id = Guid.Empty,
ObjectId = user.ObjectId,
ResourceId = Guid.Parse(AppModeConstants.ServicePrincipalObjectId),
PrincipalId = Guid.Parse(user.ObjectId),
PrincipalType = "User"
};

user.AppRoleAssignments.Add(roleAssignment);
await user.UpdateAsync();

Error:

{"odata.error":{"code":"Request_BadRequest","message":{"lang":"en","value":"One or more properties are invalid."},"date":"2017-12-19T18:57:45","requestId":"b2e61bc7-bbe1-4a7f-9f9d-3ce405b418a1","values":null}}