I am having trouble accessing nested claims from a JWT using jose4j. I have a JWT whose claim set looks like this:
{
"iss": "awesome.issuer",
"iat": 1300819370,
"exp": 1300819380,
"clm": "string claim",
"sub": "batman",
"context": {
"username": "mpdavis",
"firstName": "Michael",
"lastName": "Davis
}
}
I am running into issues when I try to access and of the nested claims inside the context
claim. I can access top level claims easily with the getClaimValue
.
private String qsh;
qsh = jwtClaims.getClaimValue("qsh", String.class);
It seems like I have two options if I want to get a nested claim.
The first option is to find a way to return the context
claim as a Map<String,Object>
and pull each claim out of that object. The other option is to use flattenClaims
to flatten all of the claims into a Map<String,List<Object>>
and grab the first object off of the map for the nested claims.
Neither one of these options seem particularly resilient if the service granting these JWTs alters the schema very much.
Is there a better way?