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

Option to use JsonWebTokenHandler in oidc handler #49333

Conversation

keegan-caruso
Copy link
Contributor

Option to use JsonWebTokenHandler in oidc handler

Description

Gives the option to use JsonWebTokenHandler instead of JwtSecurityTokenHandler in OIDC Handler. This gives an async model, last known good support for metadata, and better performance.

@keegan-caruso keegan-caruso requested review from a team, Tratcher and wtgodbe as code owners July 11, 2023 16:56
@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Jul 11, 2023
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-auth Includes: Authn, Authz, OAuth, OIDC, Bearer label Jul 11, 2023
@ghost
Copy link

ghost commented Jul 11, 2023

Thanks for your PR, @keegan-caruso. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

<MicrosoftIdentityModelLoggingVersion>6.15.1</MicrosoftIdentityModelLoggingVersion>
<MicrosoftIdentityModelProtocolsOpenIdConnectVersion>6.15.1</MicrosoftIdentityModelProtocolsOpenIdConnectVersion>
<MicrosoftIdentityModelProtocolsWsFederationVersion>6.15.1</MicrosoftIdentityModelProtocolsWsFederationVersion>
<MicrosoftIdentityModelLoggingVersion>7.0.0-preview</MicrosoftIdentityModelLoggingVersion>
Copy link
Member

Choose a reason for hiding this comment

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

Will 7.0.0 stable be released before .NET 8 ships?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, definitely. We can ship out of preview by end of August, at the latest. Depends on perf/stress testing and customer feedback.

public static partial void UnableToValidateIdTokenFromHandler(this ILogger logger, string idToken);

[LoggerMessage(57, LogLevel.Error, "The Validated Security Token must be of type JsonWebToken, but instead its type is: '{SecurityTokenType}'", EventName = "InvalidSecurityTokenTypeFromHandler")]
public static partial void InvalidSecurityTokenTypeFromHandler(this ILogger logger, string? securityTokenType);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public static partial void InvalidSecurityTokenTypeFromHandler(this ILogger logger, string? securityTokenType);
public static partial void InvalidSecurityTokenTypeFromHandler(this ILogger logger, string securityTokenType);

I don't think we'd want null to be passed here. If the object is null, we should probably say it is null somehow rather than have a message that says "but instead its type is: ".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the same approach as taken in InvalidSecurityTokenType earlier in the file

@@ -38,6 +40,10 @@ public OpenIdConnectOptions()
SignedOutCallbackPath = new PathString("/signout-callback-oidc");
RemoteSignOutPath = new PathString("/signout-oidc");
SecurityTokenValidator = _defaultHandler;
TokenHandler = _defaultTokenHandler;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should TokenHandler be plural, as in the WsFed and JwtBearer PRs? Or all singular? @keegan-caruso

Copy link
Contributor

Choose a reason for hiding this comment

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

we discussed off-line. resolved.

/// This will be used instead of <see cref="SecurityTokenValidator"/> if <see cref="UseTokenHandler"/> is <see langword="true"/>
/// </para>
/// </summary>
public TokenHandler TokenHandler { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

The other PR returns public IList<TokenHandler> TokenHandlers { get; private set; } should everything be aligned or does that matter?

Copy link
Contributor

Choose a reason for hiding this comment

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

resolved

@@ -266,7 +266,7 @@ await context.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme, new Authe
// Persist the new acess token
props.UpdateTokenValue("access_token", payload.RootElement.GetString("access_token"));
props.UpdateTokenValue("refresh_token", payload.RootElement.GetString("refresh_token"));
if (payload.RootElement.TryGetProperty("expires_in", out var property) && property.TryGetInt32(out var seconds))
if (payload.RootElement.TryGetProperty("expires_in", out var property) && int.TryParse(property.GetString(), out var seconds))
Copy link
Member

Choose a reason for hiding this comment

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

Why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

property.TryGetInt32 was throwing a InvalidOperationException on ValueKind not being a number

Copy link
Member

@eerhardt eerhardt Jul 17, 2023

Choose a reason for hiding this comment

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

https://github.com/dotnet/runtime/blob/0f56e166b16100c23dc81ae082f6155362b7c596/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.cs#L481

is the check that ensures it is a Number.

This seems like a bug. There should be no reason for a TryGet method to throw an exception.

Looks like this was designed this way according to dotnet/runtime#28132.

        // InvalidOperationException if Type is not Number
        // false if value does not fit.
        public bool TryGetDecimal(out decimal value);
        public bool TryGetDouble(out double value);
        public bool TryGetInt32(out int value);
        public bool TryGetInt64(out long value);
        public bool TryGetSingle(out float value);
        [CLSCompliantAttribute(false)]
        public bool TryGetUInt32(out uint value);
        [CLSCompliantAttribute(false)]
        public bool TryGetUInt64(out ulong value);

@captainsafia
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@BrennanConroy
Copy link
Member

/backport to release/8.0-preview7

@github-actions
Copy link
Contributor

Started backporting to release/8.0-preview7: https://github.com/dotnet/aspnetcore/actions/runs/5606681456

@github-actions
Copy link
Contributor

@BrennanConroy backporting to release/8.0-preview7 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: Option to use JsonWebTokenHandler in OpenIdConnectHandler
Applying: fix sample
Applying: split event tests
Applying: Use 7.0.0-preview for identity model libraries
Applying: use var for identitymodel versions
error: sha1 information is lacking or useless (eng/Versions.props).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0005 use var for identitymodel versions
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

@github-actions
Copy link
Contributor

@BrennanConroy an error occurred while backporting to release/8.0-preview7, please check the run log for details!

Error: git am failed, most likely due to a merge conflict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-auth Includes: Authn, Authz, OAuth, OIDC, Bearer community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants