So the reason was becuase i wasnt setting the permissions in the right application... :(
Microsoft Graph API reqquest denied
Hello,
I am using the below code to create a GraphServiceClient, which I then try to use with: await client.Groups.Request().Top(999).GetAsync();
which gives me:
Status Code: Forbidden
Microsoft.Graph.ServiceException: Code: Authorization_RequestDenied
private static IAuthenticationProvider CreateAuthorizationProvider(IConfigurationRoot config)
{
var clientId = config["AzureAd:ClientID"];
var clientSecret = config["AzureAd:ClientSecret"];
var redirectUri = config["redirectUri"];
var authority = $"https://login.microsoftonline.com/{config["AzureAd:TenantID"]}/v2.0";
List<string> scopes = new List<string>();
scopes.Add("https://graph.microsoft.com/.default");
var cca = ConfidentialClientApplicationBuilder.Create(clientId)
.WithAuthority(authority)
.WithRedirectUri(redirectUri)
.WithClientSecret(clientSecret)
.Build();
return new MsalAuthenticationProvider(cca, scopes.ToArray());
}
private static GraphServiceClient GetAuthenticatedGraphClient(IConfigurationRoot config)
{
var authenticationProvider = CreateAuthorizationProvider(config);
_graphClient = new GraphServiceClient(authenticationProvider);
return _graphClient;
}