-
Notifications
You must be signed in to change notification settings - Fork 6k
OidcIdToken cannot be serialized to JSON if token contains claim of type JSONArray #9210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the report @mengelbrecht. The default converter for the Can you put together a test that reproduces the issue as I'm not seeing how the |
I could not create a test because the JWT has to be signed and the validator wants to fetch the jwks which fails in my test. After a little more digging I could reproduce it using this Kotlin snippet. The code outputs val jsonArray = com.nimbusds.jose.shaded.json.JSONArray().apply { add("test") }
val converted = ClaimConversionService.getSharedInstance().convert(
jsonArray,
TypeDescriptor.valueOf(Any::class.java),
TypeDescriptor.collection(Collection::class.java, TypeDescriptor.valueOf(String::class.java))
)
println(converted.javaClass.name) When Line 147 in 2abf59b
Just as you mentioned the Line 149 in 2abf59b
However, since |
Good catch @mengelbrecht ! So the issue is in Line 62 in 2abf59b
Instead of returning the Would you be interested in submitting this fix? |
@jgrandja unfortunately I don't have the time at the moment, sorry |
No worries @mengelbrecht. Thanks for reporting this! |
hi @jgrandja . I have some spare time and I can submit a PR for this today or tomorrow. |
That would be great @ovidiupopa91. Thank you! |
@ovidiupopa91 Looks like we could run into the same problem with Line 57 in 2abf59b
It returns the |
…ype JSONArray or JSONObject ObjectToListStringConverter and ObjectToMapStringObjectConverter were checking if the source object is of type List or Map and if the first element or key is a String. If we have a JSONArray containing Strings the above check will pass, meaning that a JSONArray will be returned which is not serializable (same applies to JSONObject) With this change, even if the check is passing a new List or Map will be returned. Closes spring-projectsgh-9210
…ype JSONArray or JSONObject ObjectToListStringConverter and ObjectToMapStringObjectConverter were checking if the source object is of type List or Map and if the first element or key is a String. If we have a JSONArray containing Strings the above check will pass, meaning that a JSONArray will be returned which is not serializable (same applies to JSONObject) With this change, even if the check is passing a new List or Map will be returned. Closes gh-9210
…ype JSONArray or JSONObject ObjectToListStringConverter and ObjectToMapStringObjectConverter were checking if the source object is of type List or Map and if the first element or key is a String. If we have a JSONArray containing Strings the above check will pass, meaning that a JSONArray will be returned which is not serializable (same applies to JSONObject) With this change, even if the check is passing a new List or Map will be returned. Closes gh-9210
…ype JSONArray or JSONObject ObjectToListStringConverter and ObjectToMapStringObjectConverter were checking if the source object is of type List or Map and if the first element or key is a String. If we have a JSONArray containing Strings the above check will pass, meaning that a JSONArray will be returned which is not serializable (same applies to JSONObject) With this change, even if the check is passing a new List or Map will be returned. Closes gh-9210
Describe the bug
If an IdP sends an ID token with claim
amr
, the JacksonObjectMapper
withSecurityJackson2Modules
cannot serialize the ID token to JSON (related: #4370).The
amr
claim in the ID token has the typecom.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.amr
claim in the ID tokenJwtDecoder
created byOidcIdTokenDecoderFactory
to aJwt
.OidcIdToken
from theJwt
.OidcIdToken
to a JSON string using anObjectMapper
with theSecurityJackson2Modules
.Expected behavior
The
amr
claim should be anArrayList
instead ofJSONArray
.Workaround
Define a mixin for the
JSONArray
class.The text was updated successfully, but these errors were encountered: