"NoPermissionsInAccessToken" when trying to get user profile photo using Microsoft Graph API + react-adal

Viewed 591

I'm trying to fetch the user's profile photo using https://graph.microsoft.com/v1.0/me/photo/$value endpoint and by following these instructions. In our React app we're using react-adal, so I first got an access token using adalGetToken(authContext, "https://graph.microsoft.com/") and then made the call with

axios.get("https://graph.microsoft.com/v1.0/me/photo/$value", {
  headers: {
    Authorization: `Bearer ${token}`,
  },
})

However, the response is

{
  "error": {
    "code": "NoPermissionsInAccessToken",
    "message": "The token contains no permissions, or permissions can not be understood.",
    "innerError": {
      "request-id": "d2ed76f0-7f35-4014-bc53-xxxxxxxxxxxx",
      "date": "2020-05-29T09:27:12"
    }
  }
}

When I make a call to https://graph.microsoft.com/v1.0/me using the same token, I get a proper response, eg

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity",
  "id": "<id>",
  ...
}

In Azure Portal I have delegated User.Read permissions for the application: Image of the permissions

What could be the problem?

1 Answers

You are validating the token by calling a different endpoint locally (v1.0/me) than your app is calling (v1.0/me/photo/$value).

You can manually validate access tokens using tools like https://jwt.io/ and https://jwt.ms/

Per the comment by @sruthi-j-msft-identity, v1.0/me/photo is not available for personal accounts. Try using beta/me/photo/$value in your React app if you are working with personal accounts. ref: https://docs.microsoft.com/en-us/graph/api/profilephoto-get?view=graph-rest-beta#permissions

The beta API contains preview features and should not be used for production systems.

Related