Skip to content

OidcIdToken cannot be serialized to JSON if token contains claim of type JSONArray #9210

@mengelbrecht

Description

@mengelbrecht

Describe the bug
If an IdP sends an ID token with claim amr, the Jackson ObjectMapper with SecurityJackson2Modules cannot serialize the ID token to JSON (related: #4370).
The amr claim in the ID token has the type com.nimbusds.jose.shaded.json.JSONArray for which there is no default mixin.

Tested with Spring-Security 5.4.1.

To Reproduce
These steps resemble a normal oauth2Login configuration where additionally the ID token is serialized to JSON.

  1. Include an amr claim in the ID token
  2. Decode the string token value using an JwtDecoder created by OidcIdTokenDecoderFactory to a Jwt.
  3. Create an OidcIdToken from the Jwt.
  4. Serialize the OidcIdToken to a JSON string using an ObjectMapper with the SecurityJackson2Modules.

Expected behavior
The amr claim should be an ArrayList instead of JSONArray.

Workaround
Define a mixin for the JSONArray class.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: oauth2An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions