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
We need to add to
Payloadinterface a method likeThat will allow to get all claims as a simple map, useful for cases where the claim payload is way too complex to parse with
Claimclass.Also additionally we can add the same feature to the
Claimobject likeConsiderations