Support loading OIDC options from configuration#42679
Conversation
src/Security/Authentication/OpenIdConnect/src/OpenIdConnectConfigureOptions.cs
Outdated
Show resolved
Hide resolved
49f6dc4 to
1374217
Compare
src/Security/Authentication/OpenIdConnect/src/OpenIdConnectConfigureOptions.cs
Outdated
Show resolved
Hide resolved
src/Security/Authentication/OpenIdConnect/src/OpenIdConnectConfigureOptions.cs
Outdated
Show resolved
Hide resolved
src/Security/Authentication/OpenIdConnect/src/OpenIdConnectConfigureOptions.cs
Outdated
Show resolved
Hide resolved
src/Security/Authentication/OpenIdConnect/src/OpenIdConnectConfigureOptions.cs
Outdated
Show resolved
Hide resolved
src/Security/Authentication/OpenIdConnect/src/OpenIdConnectConfigureOptions.cs
Show resolved
Hide resolved
src/Security/Authentication/OpenIdConnect/src/OpenIdConnectConfigureOptions.cs
Show resolved
Hide resolved
src/Security/Authentication/JwtBearer/src/JwtBearerConfigureOptions.cs
Outdated
Show resolved
Hide resolved
1374217 to
5e86e1b
Compare
src/Security/Authentication/JwtBearer/src/JwtBearerConfigureOptions.cs
Outdated
Show resolved
Hide resolved
src/Security/Authentication/JwtBearer/src/JwtBearerConfigureOptions.cs
Outdated
Show resolved
Hide resolved
src/Security/Authentication/JwtBearer/src/JwtBearerConfigureOptions.cs
Outdated
Show resolved
Hide resolved
src/Security/Authentication/OpenIdConnect/src/OpenIdConnectConfigureOptions.cs
Outdated
Show resolved
Hide resolved
src/Security/Authentication/OpenIdConnect/src/OpenIdConnectConfigureOptions.cs
Outdated
Show resolved
Hide resolved
src/Security/Authentication/OpenIdConnect/src/OpenIdConnectConfigureOptions.cs
Outdated
Show resolved
Hide resolved
src/Security/Authentication/OpenIdConnect/src/OpenIdConnectConfigureOptions.cs
Outdated
Show resolved
Hide resolved
| var scopes = configSection.GetSection(nameof(options.Scope)).GetChildren().Select(scope => scope.Value).OfType<string>(); | ||
| foreach (var scope in scopes) | ||
| { | ||
| options.Scope.Add(scope); |
There was a problem hiding this comment.
I'm not sure if it's needed, but there's no way to remove the default scopes right now.
There was a problem hiding this comment.
The openid scope is required in OIDC and I think scenarios where the user would not want a profile scope too are rare to justify supporting modification here.
There was a problem hiding this comment.
should Scope be cleared before adding new values? (if there are any)
5e86e1b to
4117466
Compare
src/Security/Authentication/JwtBearer/src/JwtBearerConfigureOptions.cs
Outdated
Show resolved
Hide resolved
src/Security/Authentication/OpenIdConnect/src/OpenIdConnectConfigureOptions.cs
Outdated
Show resolved
Hide resolved
src/Security/Authentication/OpenIdConnect/src/OpenIdConnectConfigureOptions.cs
Outdated
Show resolved
Hide resolved
src/Security/Authentication/OpenIdConnect/src/OpenIdConnectConfigureOptions.cs
Outdated
Show resolved
Hide resolved
src/Security/Authentication/OpenIdConnect/src/OpenIdConnectConfigureOptions.cs
Outdated
Show resolved
Hide resolved
src/Security/Authentication/OpenIdConnect/src/OpenIdConnectConfigureOptions.cs
Outdated
Show resolved
Hide resolved
src/Security/Authentication/OpenIdConnect/src/OpenIdConnectConfigureOptions.cs
Outdated
Show resolved
Hide resolved
| cookieBuilder.MaxAge = cookieBuilder.MaxAge is TimeSpan maxAge ? StringHelpers.ParseValueOrDefault(maxAge, cookieConfigSection[nameof(cookieBuilder.MaxAge)], _invariantTimeSpanParse) : cookieBuilder.MaxAge; | ||
| cookieBuilder.Name = cookieConfigSection[nameof(CookieBuilder.Name)] ?? cookieBuilder.Name; | ||
| cookieBuilder.Path = cookieConfigSection[nameof(CookieBuilder.Path)]; | ||
| cookieBuilder.SameSite = cookieConfigSection[nameof(CookieBuilder.SameSite)]?.ToLowerInvariant() switch |
There was a problem hiding this comment.
Is there a reason you didn't use Enum.Parse?
There was a problem hiding this comment.
It doesn't support case-insensitive parsing as far as I can tell.
There was a problem hiding this comment.
src/Security/Authentication/OpenIdConnect/src/OpenIdConnectConfigureOptions.cs
Outdated
Show resolved
Hide resolved
src/Security/Authentication/JwtBearer/src/JwtBearerConfigureOptions.cs
Outdated
Show resolved
Hide resolved
src/Security/Authentication/JwtBearer/src/JwtBearerConfigureOptions.cs
Outdated
Show resolved
Hide resolved
src/Security/Authentication/OpenIdConnect/src/OpenIdConnectConfigureOptions.cs
Outdated
Show resolved
Hide resolved
Tratcher
left a comment
There was a problem hiding this comment.
...after addressing the Enum.Parse comments.
src/Security/Authentication/OpenIdConnect/src/OpenIdConnectConfigureOptions.cs
Outdated
Show resolved
Hide resolved
|
|
||
| options.Authority = configSection[nameof(options.Authority)] ?? options.Authority; | ||
| options.BackchannelTimeout = StringHelpers.ParseValueOrDefault(configSection[nameof(options.BackchannelTimeout)], _invariantTimeSpanParse, options.BackchannelTimeout); | ||
| options.Challenge = configSection[nameof(options.Challenge)] ?? options.Challenge; |
There was a problem hiding this comment.
@captainsafia @Tratcher Could it be useful that EventsType be set from config too?
options.EventsType = StringHelpers.ParseValueOrDefault(configSection[nameof(options.EventsType)], Type.GetType, null);There was a problem hiding this comment.
Would you really switch out the events dynamically?
I think we've added more than we should have already and we're past the point of diminishing returns.
* Support loading OIDC options from configuration * Address feedback from review * Address review feedback * Support fallbacks for all options and override lists * Fix up Enum.Parse and default for Authority
Part of #42170 and fixes #42000.
OpenIdConnectOptionsandJwtBearerOptionsJwtBearerOptionsJwtBearerOptionsuser-jwtsto useValidIssuerandValidAudiencesnames to matchTokenValidationParametersThis does not add support for setting nested properties under
JwtBearerOptions.TokenValidationParameterssince I don't think that level of customization is necessary at the moment.