Hi all and thanks in advance for all feedback. It is much appreciated!
I use NuGet packages: Microsoft.Graph 3.27.0 Micfosoft.Graph.Auth 1.0.0
and OnBehalfOfProvider and basically just want to list users or filter to a specific one from Azure Active Directory, but I can't seem to figure out how to do the same as I am allowed to with Graph Explorer (https://developer.microsoft.com/en-us/graph/graph-explorer). With the online explorer I have no issues:
Everything fine with Graph Explorer and listing users
But in my C# .NET application when I try to do the same with scopes parameter: string[] graphScopes = { "User.Read","profile", "Sites.ReadWrite.All"}; or string[] graphScopes = { "https://graph.microsoft.com/user.read+offline_access"};
I get Status 500 Internal Server Error and these details:
"error": { "code": "generalException", "message": "Unexpected exception returned from MSAL." ... "innerException": { "classification": 4, "statusCode": 400, "claims": null, "responseBody": "{"error":"invalid_grant","error_description":"AADSTS65001: The user or administrator has not consented to use the application with ID 'c0fb187f-daa8-4566-a7fb-2decd05ef980' named 'platform-test-ad'. Send an interactive authorization request for this user and resource.
And with scopes parameter: string[] graphScopes = new string[] { "https://graph.microsoft.com/.default" };
I get 403:
"error": { "code": "Authorization_RequestDenied", "message": "Insufficient privileges to complete the operation.", ... "statusCode": 403, "rawResponseBody": "{\r\n "error": {\r\n "code": "Authorization_RequestDenied",\r\n "message": "Insufficient privileges to complete the operation."
Inside Azure, Enterprice applications | User settings looks like this: Enterprice applications User settings
and my C# code looks like this:
IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
.Create(authSettings.FunctionApplicationId)
.WithTenantId(authSettings.FunctionTenantId)
.WithAuthority(authSettings.Authority)
.WithClientSecret(authSettings.FunctionClientSecret)
.Build();
string[] graphScopes = new string[] { "https://graph.microsoft.com/user.read+offline_access" };
OnBehalfOfProvider authProvider = new OnBehalfOfProvider(confidentialClientApplication, graphScopes);
var userAssertion = new UserAssertion(token);
var usersRequest = confidentialClientApplication.Users
.Request()
.WithUserAssertion(userAssertion);
var usersResult = await usersRequest.GetAsync();
Any tips or explanation on this?
