Hook auth options validation into validation feature (#8665)

This commit is contained in:
Hao Kung 2019-03-25 11:35:39 -07:00 committed by GitHub
parent 6641a02ff2
commit b7e122fbac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -25,9 +25,8 @@ namespace Microsoft.AspNetCore.Authentication
/// </summary> /// </summary>
public virtual IServiceCollection Services { get; } public virtual IServiceCollection Services { get; }
private AuthenticationBuilder AddSchemeHelper<TOptions, THandler>(string authenticationScheme, string displayName, Action<TOptions> configureOptions) private AuthenticationBuilder AddSchemeHelper<TOptions, THandler>(string authenticationScheme, string displayName, Action<TOptions> configureOptions)
where TOptions : class, new() where TOptions : AuthenticationSchemeOptions, new()
where THandler : class, IAuthenticationHandler where THandler : class, IAuthenticationHandler
{ {
Services.Configure<AuthenticationOptions>(o => Services.Configure<AuthenticationOptions>(o =>
@ -41,6 +40,10 @@ namespace Microsoft.AspNetCore.Authentication
{ {
Services.Configure(authenticationScheme, configureOptions); Services.Configure(authenticationScheme, configureOptions);
} }
Services.AddOptions<TOptions>(authenticationScheme).Validate(o => {
o.Validate(authenticationScheme);
return true;
});
Services.AddTransient<THandler>(); Services.AddTransient<THandler>();
return this; return this;
} }

View File

@ -82,8 +82,7 @@ namespace Microsoft.AspNetCore.Authentication
Scheme = scheme; Scheme = scheme;
Context = context; Context = context;
Options = OptionsMonitor.Get(Scheme.Name) ?? new TOptions(); Options = OptionsMonitor.Get(Scheme.Name);
Options.Validate(Scheme.Name);
await InitializeEventsAsync(); await InitializeEventsAsync();
await InitializeHandlerAsync(); await InitializeHandlerAsync();