Roles undefined in idTokenClaims but exist in token
See original GitHub issueCore Library
MSAL.js v2 (@azure/msal-browser)
Core Library Version
2.22.1
Wrapper Library
MSAL React (@azure/msal-react)
Wrapper Library Version
1.3.1
Description
idTokenClaims.roles
returns undefined.
The claims I get are: aud, exp, iat, iss, name, nbf, nonce, oid, preferred_username, rh, sub, tid, uti, ver … but no roles.
When I print the token from msalInstance.acquireTokenSilent
and decode it on https://jwt.ms/ I can see the roles I assigned to the account.
MSAL Configuration
export const msalConfig: Configuration = {
auth: {
clientId: process.env.REACT_APP_MSAL_CLIENT_ID || "",
authority: process.env.REACT_APP_MSAL_AUTHORITY,
redirectUri: process.env.REACT_APP_MSAL_REDIRECT_URL,
},
cache: {
cacheLocation: "sessionStorage",
storeAuthStateInCookie: false,
},
};
Relevant Code Snippets
const { accounts, inProgress } = useMsal();
let roles = accounts[0].idTokenClaims.roles; // <-- returns undefined
### Identity Provider
Azure AD / MSA
### Source
External (Customer)
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Node: AccountUserInfo.idTokenClaims is undefined ... - GitHub
currentAccount.idTokenClaims.roles ) but idTokenClaims is always undefined, even if I do have the object properly populated with the roles array ...
Read more >Cannot see role claims in access token when contacting my ...
As you can see, no claim relating to roles. But note that I can successfully get the role in the user token I...
Read more >Access-token is undefined after adding roles after post-login ...
accessToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles); } };. now if you try to access token it shows it is undefined.
Read more >Azure AD authentication & authorization error codes
Learn about the AADSTS error codes that are returned from the Azure AD security token service (STS).
Read more >OpenID Connect (OIDC) authorization code flow mechanism
OIDC Code Authentication Mechanism acquires three tokens during the authorization code flow: IDToken, Access Token and Refresh Token. ID Token is always a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@NidalGhonaim and if you don’t want to replicate the roles in the client app. You can use the client id of the api in the client app, but I’m not sure what the official policy on that is.
@NidalGhonaim the resource server (API) should decode and validate the access token, so that’s fine. If you need to adjust the UI based on user’s role then duplicating roles on the client app registration also makes sense (here’s an example doing that).