Repository navigation
Map non-string claims in the IdP user session note mapper - #55075
Open
baptistegh wants to merge 2 commits into
Open
baptistegh wants to merge 2 commits into
baptistegh wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Claim conversion drops non-text UserInfo array elements and null-valued token object properties, causing missing or incomplete session notes and incorrect configured-value matching.
2 open issues
What changed in this PR
Extends the OIDC identity-provider user session note mapper to support non-string claims, addressing the IdP-side portion of #45938 without changing token-side protocol mappers.
Changes:
- Matches array elements individually and stores values as comma-separated text.
- Adds JSON object and scalar conversion while retaining string-only regex matching.
- Documents the behavior and adds unit tests for matching and serialization.
| File | Description |
|---|---|
services/src/test/java/org/keycloak/broker/oidc/mappers/ClaimToUserSessionNoteMapperTest.java |
Adds tests for supported claim types, regex matching, and missing or unmatched claims. |
services/src/main/java/org/keycloak/broker/oidc/mappers/ClaimToUserSessionNoteMapper.java |
Implements non-string claim conversion and array matching; updates mapper documentation. |
Review effort: Balanced
baptistegh
force-pushed
the
idp-session-note-mapper-non-string-claims
branch
from
November 12, 2026 07:18
7655ce4 to
a831a83
Compare
baptistegh
force-pushed
the
idp-session-note-mapper-non-string-claims
branch
from
November 12, 2026 07:23
a831a83 to
eb3e78a
Compare
baptistegh
force-pushed
the
idp-session-note-mapper-non-string-claims
branch
from
November 12, 2026 08:39
eb3e78a to
5039fd0
Compare
Comment on lines
+260
to
+262
| if (keepArrays) { | ||
| // keep walking the path, so that an array is only returned if it is the claim itself | ||
| continue; |
The OIDC user session note IdP mapper skipped every claim that was not a string, so arrays, objects, numbers and booleans could not be propagated to the user session Store them as the OID4VP SD-JWT user session attribute mapper does: array elements are joined with a comma, objects are stored as their JSON representation and scalars as their text. An array claim matches when any of its elements equals the configured value Arrays found in the UserInfo claim set are kept with all their elements, as the shared lookup otherwise only returns their text elements, and null properties of object claims are kept in their JSON representation Regular expressions still only match string claims, so a pattern never matches the serialized form of an array or object An empty configured value stores the claim as is, whatever its type and whether regular expressions are enabled, so a claim such as amr can be propagated without knowing its values in advance. An empty value never matched before, except for an empty string claim, so existing configurations keep their behavior Assisted-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Baptiste Gouhoury <gouhoury.baptiste@gmail.com>
baptistegh
force-pushed
the
idp-session-note-mapper-non-string-claims
branch
from
November 12, 2026 08:49
5039fd0 to
d6115fa
Compare
Author
|
Hi @sschu, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Related to #45938
The OIDC "User Session Note" identity provider mapper currently ignores any claim that is not a string, so arrays, objects, numbers or booleans coming from an external IdP never make it into the user session.
I had a look at #45939 before opening this, since it targets the same issue. I ended up going a slightly different way on the IdP side, so I thought it would be easier to open a separate PR you can compare, rather than leave a long list of comments on someone else's work. Happy to close this one or help merge both approaches if that works better.
The idea was to behave the same way as the existing OID4VP SD-JWT user session attribute mapper (
OID4VPSdJwtUserSessionAttributeMapper), which already handles this case: array elements are joined with a comma, objects are stored as their JSON representation and other values as their text. Like the OID4VP mapper, there is no new configuration option.Main differences with #45939:
List.toString()and stripping spaces and brackets, so the content of each entry is kept as is (spaces, URLs, colons...)pwdmatches["pwd","mfa"]and the note is set topwd,mfaThe mapper only stores a claim when it matches a configured value, which does not work well for something like
amr, where you usually want to forward whatever the IdP sent. So if the value is left empty, the claim is now stored as is, whatever its type and whether "Regex Claim Values" is enabled. This is also closer to the OID4VP mapper, which always stores the claim. An empty value could never match before, except for a claim that is literally an empty string, so existing configurations should not be affected.For regular expressions I kept the current behavior on purpose: with "Regex Claim Values" enabled, only string claims are matched and other types are skipped with a warning, as today. Run 8000 ning a regex against the serialized form of an array or an object felt fragile and could easily match more than people expect. With the empty value option above, there is still a way to map arrays when you do not know their values in advance.
This PR does not change the token side. A mapped array ends up as the string
pwd,mfain the client token, not as a JSON array, while objects can be turned back into JSON with the JSON claim type. #45939 adds anArrayJSON type inOIDCAttributeMapperHelperfor this, but I think it deserves its own discussion since it applies to every OIDC protocol mapper exposing the claim JSON type. That is also why this PR only references the issue and does not close it.The new tests are unit tests in
ClaimToUserSessionNoteMapperTest, covering each claim type with and without regex, the empty value, and missing or empty claims. The existing integration test is unchanged, since string claims behave exactly as before.