Skip to content

Expose ID Token Claims on successful Authentication #294

@idg-sam

Description

@idg-sam

Some other implementations of MSAL (e.g. Python) make available the decoded ID Token claims for the user immediately upon receiving the token.
Currently, the Java implementation requires the user to import a JWT parsing library, such as this one from nimbusds:

<dependency>
  <groupId>com.nimbusds</groupId>
  <artifactId>nimbus-jose-jwt</artifactId>
  <version>9.0.1</version>
</dependency>

And extract them as follows:

import com.nimbusds.jwt.JWTClaimsSet;
import com.nimbusds.jwt.SignedJWT;
...

Future<IAuthenticationResult> future = client.acquireToken(authParams);
IAuthenticationResult result = future.get();

SignedJWT idToken = SignedJWT.parse(result.idToken());
JWTClaimsSet jcs = idToken.getJWTClaimsSet();
Map<String,Object> claimsObjectMap = jcs.getClaimsSet();
Map<String,String> claimsStringMap = new HashMap<>();

claimsObjectMap.forEach((String claim, Object value) -> {
   String val = value.toString();
   claimsStringMap.put(claim, val);
});

We could implement this and expose the claims to the user as a non-breaking change in the library. MSAL4J already includes nimbusds dependency.

Metadata

Metadata

Assignees

Labels

EnhancementA request or suggestion to improve some aspect of the library

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions