Code: Authorization_RequestDenied Message: Insufficient privileges to complete the operation.

Sandeep U S 21 Reputation points
2022-05-27T08:16:59.693+00:00

I am trying to access graph api using client credentials flow. But getting "Insufficient privileges to complete the operation." error.
All permissions are given to the registered application.

 1. AuthenticationContext authenticationContext = new AuthenticationContext(authority);  
 2. ClientCredential clientCred = new ClientCredential(clientId, clientSecret);  
 3. AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(graphResource, clientCred).Result;  
 4. var token = authenticationResult.AccessToken;  
 5. var delegateAuthProvider = new DelegateAuthenticationProvider((requestMessage) =>  
 6. {  
 7. requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", token.ToString());  
 8. return Task.FromResult(0);  
 9. });  
 10. // Initializing the GraphServiceClient  
 11. graphClient = new GraphServiceClient(graphAPIEndpoint, delegateAuthProvider);  
 12.   
 13. try  
 14. {  
 15.   
 16. var queryOptions = new List<QueryOption>()  
 17. { new QueryOption("$count", "true") };  
 18.   
 19. var members = graphClient.Groups  
 20. .Request(queryOptions)  
 21. .Header("ConsistencyLevel", "eventual")  
 22. .Top(5)  
 23. .GetAsync().Result;  
 24.   
 25.   
 26. }  
 27. catch (Exception ex)  
 28. {  
 29.   
 30. }  

206107-permissions.png

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Answer accepted by question author
  1. CarlZhao-MSFT 46,406 Reputation points
    2022-05-27T08:54:44.963+00:00

    Hi @Sandeep U S

    The client credentials flow only supports application permissions, you should grant Group.ReadWrite.All application permissions to your application and grant admin consent.

    206173-2022-05-27-165629.png


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.