Change type of `idTokenClaims` for direct access
See original GitHub issueCore Library
MSAL.js v2 (@azure/msal-browser)
Wrapper Library
MSAL Angular (@azure/msal-angular)
Description
If the idTokenClaims
are set on an account, it’s recognized as an object
. This means you cannot access it’s members (roles doesn't exist on object
). With the following work-around I’m able to access the properties in the identity token.
// Doesn't work
const roles = account.idTokenClaims.roles;
// or
const roles2 = account.idTokenClaims['roles'];
// this does work
const claims = account.idTokenClaims as { [key: string]: any };
const roles3 = claims.roles;
// and this does also work:
const roles4 = claims['roles'];
The type { [key: string]: any }
is valid for each json document, and since the idTokenClaims are always represented as json, this would be a better description, and allow access to all the claims without manually changing the type. It would also support future claims that are not known yet.
An alternative would be to create something like this, but that requires more maintenance:
declare type IdentityToken {
aud?: string;
exp?: number;
iss?: string;
name?: string;
roles?: string[];
}
// Or supporting both methods
declare type IdentityTokenExtension = IdentityToken & { [key: string]: any; }
Source
External (Customer)
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Identity, Claims, & Tokens – An OpenID Connect Primer, Part ...
This blog series is a primer on OIDC. In this first post, we'll review some key concepts around OIDC and tokens, explained in...
Read more >@azure/msal-common | microsoft-authentication-libraries-for-js
idTokenClaims - Object contains claims from ID token; localAccountId - The user's account ID; nativeAccountId - The user's native account ID ...
Read more >Configure group claims for applications by using Azure Active ...
For each relevant token type, modify the group claim to use the optionalClaims ... Emit groups as group names in OAuth access tokens...
Read more >ID Tokens - Auth0
Describes how ID Tokens are used in token-based authentication to cache user profile information and provide it to a client application.
Read more >OpenID Connect Core 1.0 incorporating errata set 1
When using the Authorization Code Flow, these additional requirements for the following ID Token Claims apply: at_hash: OPTIONAL. Access ...
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
🎉This issue was addressed in #4680, which has now been successfully released as
@azure/msal-common@v6.3.0
.🎉We recommend upgrading to the latest version of
@azure/msal-browser
or@azure/msal-node
to take advantage of this change.Handy links:
@sameerag all tests are checked in the PR and are still green