Hook auth options validation into validation feature (#8665)
This commit is contained in:
parent
6641a02ff2
commit
b7e122fbac
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue