Skip to content
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

Handle case-insensitive JSON claim value types. #1769

Merged
merged 1 commit into from
Feb 6, 2025

Conversation

josephdecock
Copy link
Member

@josephdecock josephdecock commented Feb 5, 2025

This updates our serialization behavior so that we treat claims with either our json value type constant or the System.IdentityModel json value type constant the same. Prior to this change, we would serialize json with the System.IdentityModel as an escaped string instead of json, while our json value type constant would become json in the claims.

After this change, either constant will work to put JSON into your claims. For example, code like this in a profile service will now serialize the claims as JSON, instead of a string containing escaped quotes:

var payload = 
"""
{
  "nested": {
    "sample": "value"
  }
}
""";
context.IssuedClaims.Add(new Claim("json", payload, System.IdentityModel.Tokens.Jwt.JsonClaimValueTypes.Json))

Updated logic in ClaimsExtensions.cs and TokenExtensions.cs to handle JSON claim value types case-insensitively, ensuring compatibility with variations like "JSON", which is the value from System.IdentityModel.Tokens.Jwt.JsonClaimValueTypes.Json. Added corresponding unit tests to verify the behavior and ensure consistent parsing of JSON claims.
@josephdecock josephdecock requested a review from bhazen as a code owner February 5, 2025 22:26
@josephdecock josephdecock added the area/identity-server Related to Identity Server label Feb 5, 2025
@josephdecock josephdecock added this to the is-7.3.0 milestone Feb 5, 2025
@josephdecock josephdecock self-assigned this Feb 5, 2025
@josephdecock josephdecock merged commit 0ec7e38 into main Feb 6, 2025
9 of 14 checks passed
@josephdecock josephdecock deleted the jmdc/json-serialization branch February 6, 2025 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/identity-server Related to Identity Server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants