I’m trying to use GraphServiceClient to get a set of users which have an AppRoleAssignment with a specific ResourceId. I’ve researched enough to know that this should be doable (second example here, also here the ResourceId is said to support the filter by eq option), so I don’t know what am I doing wrong.
I created this method to get the users that I want:
public async Task<IEnumerable<User>> GetAllUsersAsync(CancellationToken cancellationToken)
{
var clientSecret = options.ClientCredentials.First().ClientSecret;
var clientSecretCredential = new ClientSecretCredential(options.TenantId, options.ClientId, clientSecret);
var client = new GraphServiceClient(clientSecretCredential, options.Scopes);
List<User> users = new List<User>();
UserCollectionResponse? userCollectionResponse =
await client.Users.GetAsync(
requestConfiguration => {
requestConfiguration.Headers.Add("ConsistencyLevel", "eventual");
requestConfiguration.QueryParameters.Count = true;
requestConfiguration.QueryParameters.Select = ["id", "givenName", "surname", "mail", "userType"];
requestConfiguration.QueryParameters.Expand = ["appRoleAssignments"];
requestConfiguration.QueryParameters.Top = 100;
requestConfiguration.QueryParameters.Filter = string.Format("appRoleAssignments/any(a:a/ResourceId eq {0})", options.ServicePrincipal);
});
PageIterator<User, UserCollectionResponse> pageIterator =
PageIterator<User, UserCollectionResponse>.CreatePageIterator(
client,
userCollectionResponse,
(user) => {
var roles = user.AppRoleAssignments;
//if (roles != null && roles.Any(r => r.ResourceId.ToString() == options.ServicePrincipal))
users.Add(user);
return true;
}
);
await pageIterator.IterateAsync();
return users;
}
In theory this should work, but for some reason I’m getting this error:
Exception: Microsoft.Graph.Models.ODataErrors.ODataError: Property 'resourceId' does not exist as a declared property or extension property.
First thing I noticed is that the ResourceId property appears in lowercase on the error, while I specified it with a capital R on my code. Aside that, I see no other problems with it, nor understand why it is failing.
While I’m able to get the users that I want without this filter an uncommenting the line with the if in the Iterator, I want to get the exact users I need from the query itself instead of having to manually filter them, if possible.
Any suggestions?