I am trying to fetch miscrosoft graph api user. For that I have generated token like this.
After getting token, I am using the token to fetch users using this api url
https://graph.microsoft.com/v1.0/users
I have given all the needed permission to the API. but still getting following error
{
"error": {
"code": "Authorization_RequestDenied",
"message": "Insufficient privileges to complete the operation.",
"innerError": {
"date": "2024-01-02T02:54:50",
"request-id": "******************",
"client-request-id": "******************"
}
}
}
Admin consent also has been assigned to the application as shown in below screenshot.
UPDATE
Note that: To fetch the users, the Microsoft Entra application must have
User.Read.All
Application API permission granted as you are making use of Client credential flow.
Make sure to grant User.Read.All
Application API permission to the application:
I generated the access token by using below parameters:
https://login.microsoftonline.com/TenantID/oauth2/token
client_id:ClientID
client_secret:ClientSecret
resource:https://graph.microsoft.com
grant_type:client_credentials
By using the above token, I am able to fetch the users successfully:
GET https://graph.microsoft.com/v1.0/users
Reference: