Skip to content

Handle case-insensitive JSON claim value types.#1769

Merged
josephdecock merged 1 commit intomainfrom
jmdc/json-serialization
Feb 6, 2025
Merged

Handle case-insensitive JSON claim value types.#1769
josephdecock merged 1 commit intomainfrom
jmdc/json-serialization

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/products/is IdentityServer 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/products/is IdentityServer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants