Reputation: 2149
I am trying to add an AppRoleAssignment using this code:
AppRoleAssignment objAppRoleAssignment = new AppRoleAssignment();
objAppRoleAssignment.Id = Guid.Parse("00000000-0000-0000-0000-000000000000");
objAppRoleAssignment.ResourceId = Guid.Parse("ServicePrincipalID");
objAppRoleAssignment.PrincipalType = "User";
objAppRoleAssignment.PrincipalId = Guid.Parse(user.ObjectId);
user.AppRoleAssignments.Add(objAppRoleAssignment);
await user.UpdateAsync();
I don't have any roles so I am specifying the default 00000000-0000-0000-0000-000000000000
role
but I get this error:
{"odata.error":{"code":"Request_BadRequest","message":{"lang":"en","value":"One or more properties are invalid."},"values":null}}
Upvotes: 1
Views: 808
Reputation: 10662
The way you are doing it is correct. There seems to be two bugs in place that make it seem like your change isn't being saved.
A null value was found for the property named 'id', which has the expected type 'Edm.Guid[Nullable=False]'. The expected type 'Edm.Guid[Nullable=False]' does not allow null values.
https://graph.windows.net/[yourtenant]/servicePrincipals/[ResourceID]/appRoleAssignedTo
or
https://graph.windows.net/[yourtenant]/users/[PrincipalID]/appRoleAssignments
We're looking into correcting this issue, but in the interim your options are to either swallow the exception in #1 or not use the SDK and manually craft your post request to appRoleAssignments.
Upvotes: 1