Skip to content

Allow returning claims or specific claim as a Map #146

Description

@hzalaz

We need to add to Payload interface a method like

Map<String, Object> jwt.getClaimsAsMap();

That will allow to get all claims as a simple map, useful for cases where the claim payload is way too complex to parse with Claim class.

JWTVerifier verifier = JWT.require(Algorithm.HMAC256("secret"))
        .withIssuer("auth0")
        .build(); //Reusable verifier instance
JWT jwt = verifier.verify(token);
Map<String, Object> claims = jwt.getClaimsAsMap();

Also additionally we can add the same feature to the Claim object like

JWT jwt = verifier.verify(token);
Claim claim = jwt.getClaim("user_metadata");
Map<String, Object> metadata = claim.getAsMap();

Considerations

  • Will always use the default JSON mapper config so if there is a structure that needs a custom mapping it will fail or have undefined behaviour
  • There will be no hook to register custom mappings
  • Only available to decode tokens not for signing

Metadata

Metadata

Assignees

Labels

enhancementAn enhancement or improvement to the SDK that could not be otherwise categorized as a new feature

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions