Serialize Non-Standard Claims On OidcIdToken To java.util Types Instead Of com.nimbusds.jose.shaded.json #12108
Labels
in: oauth2
An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)
status: declined
A suggestion or change that we don't feel we should currently apply
type: enhancement
A general enhancement
Expected Behavior
When converting the claims from the ID token in an
OAuth2AccessTokenResponse
it would be useful, for those that want to store the token in the session and use Jackson to serialize/deserialize the session, if any non-standard claims were converted to basejava.util
types, rather than left ascom.nimbusds.jose.shaded.json types
. I think this could be done in ClaimTypeConverter and MappedJwtClaimSetConverter by adjusting the loops in theconvert
methods.Current Behavior
Currently non-standard claims are ignored and passed on in a map of
Map<String, Object>
and therefore retain the type they were given when thegetJWTClaimsSet
method callspayload.toJSONObject()
.Context
This is similar to (or at least related to) #9210 but the current behavior is not a bug but rather is acting to the specification; however, I think this would be a useful way to treat non-standard claims which is why I'm proposing this as an enhancement.
Each of the implementations of
com.nimbusds.jwt.JWT
usegetPayload().toJSONObject();
to get thecom.nimbusds.jwt.JWTClaimsSet
and ClaimTypeConverter (or MappedJwtClaimSetConverter ) converts only standard claims non-standard claims are not modified.If/when the token is later serialized by Jackson, for example when using
GenericJackson2JsonRedisSerializer
withRedisIndexedSessionRepository
), non-standard claims that areArrayList
orHashMap
types retain theircom.nimbusds.jose.shaded.json
type (eitherJSONArray
orJSONObject
), this causes issues later with deserialization because they are not able to be deserialized by Jackson and SecurityJackson2Modules does not include a module for those types. I think this would be an easy change to make becauseJSONArray
andJSONObject
extendArrayList
andHashMap
respectively.Alternatively a module declaring serialization/deserialization strategies for the nimbusds types could be added to SecurityJackson2Modules.
The text was updated successfully, but these errors were encountered: