reactjsazurenext.jsmsal-react

azure msal-brower with nextJs: passing only one scope to the API


I've got a SPA calling an API. The user authenticates using Azure AD and I'm exposing the API with a custom scope (access).

I report below the responses based on different scopes:

I don't think it's normal behaviour because I couldn't find any reference around it. What if I need, in the API, the info coming from the User.Read as well?

Dep version: "@azure/msal-browser": "^2.26.0"


Solution

  • I tried to reproduce the same in my environment and got the same results.

    When I passed ['access', 'user.read'] ,I got token for only access scope like below:

    enter image description here

    Please check the aud (audience) claim of the token you are generating.

    If you are giving 2 different scopes like ['access', 'user.read'], it will only consider first scope and generate token for that specific audience like below:

    enter image description here

    As mentioned by Juunas in this SO Thread, access token is valid for one API only based on the audience.

    If you want the info coming from the User.Read, you need to generate two tokens, one for your API scope (access) and another for Graph API scope (user.read).

    For more in detail, please refer below link:

    azure - Passing multiple scope values to Oauth token endpoint - by Hari Krishna