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

Refactor: Add Serialization for JsonWebToken in OpenIdConnectConfiguration #2627

Open
wants to merge 14 commits into
base: dev
Choose a base branch
from

Conversation

nguyencuong2596
Copy link

@nguyencuong2596 nguyencuong2596 commented Jun 11, 2024

Refactor: Add Serialization for JsonWebToken in OpenIdConnectConfiguration

  • You've read the Contributor Guide and Code of Conduct.
  • You've included inline docs for your change, where applicable.
  • You've included unit or integration tests for your change, where applicable.
  • If any gains or losses in performance are possible, you've included benchmarks for your changes. More info
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Summary of the changes (Less than 80 chars)

Description

  • Implement (de)serialization for JsonWebKeySet in OpenIdConnectionConfiguration
  • Create new unit tests for the implementation

@nguyencuong2596 nguyencuong2596 requested a review from a team as a code owner June 11, 2024 18:03
@brentschmaltz
Copy link
Member

@nguyencuong2596 can you please add a description for what you are trying to do?

Copy link
Member

@brentschmaltz brentschmaltz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a description of what this PR is for.

@nguyencuong2596 nguyencuong2596 force-pushed the cuong/idenitity-model-serializer branch from 8f42e4a to cc1bc52 Compare June 17, 2024 17:17
@nguyencuong2596 nguyencuong2596 force-pushed the cuong/idenitity-model-serializer branch from cc1bc52 to 6aacac0 Compare June 17, 2024 17:53
@@ -156,6 +158,14 @@ public static OpenIdConnectConfiguration Read(ref Utf8JsonReader reader, OpenIdC
else if (reader.ValueTextEquals(Utf8Bytes.EndSessionEndpoint))
config.EndSessionEndpoint = JsonPrimitives.ReadString(ref reader, MetadataName.EndSessionEndpoint, ClassName, true);

else if (reader.ValueTextEquals(Encoding.UTF8.GetBytes(JsonWebKeySetParameterNames.Keys)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenIdConnectRetriever will reset the JsonWebKeySet here:

Is that accounted for?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. However, this shouldn't disrupt the flow that retrieves the configuration from an L2 cache. It might be best to fetch keys only if they are not already set.

Copy link
Member

@brentschmaltz brentschmaltz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the JsonWebKeySet set by the OpenIdConnectRetriever accounted for?

# Conflicts:
#	src/Microsoft.IdentityModel.Protocols.OpenIdConnect/Configuration/OpenIdConnectConfiguration.cs
#	src/Microsoft.IdentityModel.Protocols.OpenIdConnect/Json/OpenIdConnectConfigurationSerializer.cs
# Conflicts:
#	test/Microsoft.IdentityModel.Protocols.OpenIdConnect.Tests/OpenIdConnectConfigurationTests.cs
@nguyencuong2596 nguyencuong2596 force-pushed the cuong/idenitity-model-serializer branch from 50ee6d6 to 39c3ac2 Compare June 19, 2024 20:25
Copy link
Member

@brentschmaltz brentschmaltz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the boolean in WriteObject.

A method that writes: WriteObject and passes a boolean to Not write an object doesn't make sense to me.

@@ -220,6 +223,16 @@ public static OpenIdConnectConfiguration Read(ref Utf8JsonReader reader, OpenIdC
else if (reader.ValueTextEquals(Utf8Bytes.EndSessionEndpoint))
config.EndSessionEndpoint = JsonPrimitives.ReadString(ref reader, MetadataName.EndSessionEndpoint, ClassName, true);

else if (reader.ValueTextEquals(Encoding.UTF8.GetBytes(JsonWebKeySetParameterNames.Keys)))
{
config.ShouldSerializeJsonWebKeys = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this set to true?

@@ -575,6 +587,14 @@ public static OpenIdConnectConfiguration Read(ref Utf8JsonReader reader, OpenIdC

else if (propertyName.Equals(MetadataName.UserInfoSigningAlgValuesSupported, StringComparison.OrdinalIgnoreCase))
JsonPrimitives.ReadStrings(ref reader, config.UserInfoEndpointSigningAlgValuesSupported, propertyName, ClassName);

else if (propertyName.Equals(JsonWebKeySetParameterNames.Keys, StringComparison.OrdinalIgnoreCase))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking behavior for users.
Previously, users would have found an object in AdditionalData.

if (config.JsonWebKeySet == null)
config.JsonWebKeySet = new JsonWebKeySet();
// Skip key "Keys"
reader.Read();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is different than the case-insensitive below, reader.Read() is not called.


internal static void Append(ref Utf8JsonWriter writer, JsonWebKeySet jsonWebKeySet)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WriteKeys would be a better name than Append.

@@ -634,7 +634,7 @@ public static TheoryData<ConfigurationManagerTheoryData<OpenIdConnectConfigurati
ConfigurationValidator = openIdConnectConfigurationValidator2,
DocumentRetriever = new FileDocumentRetriever(),
ExpectedException = new ExpectedException(typeof(InvalidOperationException), "IDX21817:", typeof(InvalidConfigurationException)),
MetadataAddress = "JsonWebKeySetUnrecognizedKty.json",
MetadataAddress = "EmptyJsonWebKeySet.json",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why were these tests removed?
JsonWebKeySetUnrecognizedKty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants