This article discusses an issue in which you receive a NoPermissionsInAccessToken error message when you call the /me endpoint in Microsoft Graph. This article also explains why you can't call the /me endpoint by using a token that is acquired through the client credentials grant flow.
Symptoms
When you try to call the /me endpoint from your Microsoft Entra ID-based application that uses client credentials grant flow, you receive the following error message:
{
"error": {
"code": "NoPermissionsInAccessToken",
"message": "The token contains no permissions, or permissions can not be understood.",
"innerError": {
"oAuthEventOperationId": "48f66de9-xxx-xxxx1-xxxx-399ea6608ec0",
"oAuthEventcV": "MkVd0xxxxxvjGFVJkoA.1",
"errorUrl": "https://aka.ms/autherrors#error-InvalidGrant",
"requestId": "80f8a0e9-xxxx-xxxx-xxxx-88e5d4bb5bb2",
"date": "2021-07-30T04:04:38"
}
}
}
Cause
The /me endpoint is designed to enable signed-in users to retrieve their own information. To call the /me endpoint, you must provide some user context because the endpoint uses delegated permissions. That is, a token that's generated by using the client credentials grant flow can't use the /me endpoint because the user context information is absent.
Tokens that are obtained by using the client credentials grant flow represent application identities, not user identities. These tokens contain a roles claim for application permissions instead of a scp (scopes) claim for delegated permissions. The absence of user context makes it impossible for the /me endpoint to determine the user who is associated with the request.
Example tokens
Token with user context (delegated flow with a user signed in)
This token is granted by using delegated flow to which a user signed in. It contains user-specific information and a scp claim that contains the current user's permissions.
Token with application identity (client_credentials grant flow)
This token is generated by using the client credentials grant flow. It doesn't contain user-specific information. Instead, it contains a roles claim for application permissions.
Solution
When you use the client credentials grant flow in your application, you must use the /users endpoint instead of the /me endpoint. The /users endpoint enables you to retrieve user-specific information by using application tokens.
For example, if you want to call GET https://graph.microsoft.com/v1.0/me/memberOf to generate a list of groups that a user is a member of, use the following method:
- Obtain an application token by using the client credentials grant flow.
- Make sure that the application has the User.Read.All permission to query user information.
- Use the users endpoint to query specific user details. Replace {upn} with the User Principal Name (UPN) or User Object ID of the user.
GET https://graph.microsoft.com/v1.0/users/{upn or userID}/memberOf
Source: Microsoft Learn / IT Pro troubleshooting by Microsoft and contributors (upstream author metadata: bhvootla). Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.
