problem getting groups from graph api for a user

  • Thread starter Thread starter Richard Scannell
  • Start date Start date
R

Richard Scannell

Guest

Am working graph api

The following code works :

var graphClient = new GraphServiceClient( new DelegateAuthenticationProvider(
async (requestMessage) =>
{requestMessage.Headers.Authorization new AuthenticationHeaderValue("Bearer", accessToken);
}));

var user = await graphClient.Me.Request().Select(u => new {
u.DisplayName,


u.Mail,
u.UserPrincipalName,


u.Id }).GetAsync();

Based on the code at https://docs.microsoft.com/en-us/graph/api/user-list-approleassignments?view=graph-rest-1.0&tabs=csharp
I tried to get a list of my roles using the following code
var appRoleAssignments = await graphClient.Users["{id}"].AppRoleAssignments .Request() .GetAsync();
in my case, I tried the following permutations

var appRoleAssignments = await graphClient.Users[user.Id].AppRoleAssignments.Request().GetAsync();

var appRoleAssignments = await graphClient.Users[UserPrincipalName].AppRoleAssignments.Request().GetAsync();

var appRoleAssignments = await graphClient.Me.AppRoleAssignments.Request().GetAsync();

On Build it throws the following error
Error CS1061 'IUserRequestBuilder' does not contain a definition for 'AppRoleAssignments' and no accessible extension method 'AppRoleAssignments' accepting a first argument of type 'IUserRequestBuilder' could be found (are you missing a using directive or an assembly reference?) graph-tutorial... and yes, it does have a using microsoft.graph statement at the top.
and this is the path \packages\Microsoft.Graph.1.21.0\lib\net45\Microsoft.Graph.dll, which I installed from NuGet.

Is this the correct object and approach to get groups / roles. If not should I be looking at something else?







Richard

Continue reading...
 
Back
Top