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>
|
||||
public virtual IServiceCollection Services { get; }
|
||||
|
||||
|
||||
private AuthenticationBuilder AddSchemeHelper<TOptions, THandler>(string authenticationScheme, string displayName, Action<TOptions> configureOptions)
|
||||
where TOptions : class, new()
|
||||
where TOptions : AuthenticationSchemeOptions, new()
|
||||
where THandler : class, IAuthenticationHandler
|
||||
{
|
||||
Services.Configure<AuthenticationOptions>(o =>
|
||||
|
|
@ -41,6 +40,10 @@ namespace Microsoft.AspNetCore.Authentication
|
|||
{
|
||||
Services.Configure(authenticationScheme, configureOptions);
|
||||
}
|
||||
Services.AddOptions<TOptions>(authenticationScheme).Validate(o => {
|
||||
o.Validate(authenticationScheme);
|
||||
return true;
|
||||
});
|
||||
Services.AddTransient<THandler>();
|
||||
return this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,8 +82,7 @@ namespace Microsoft.AspNetCore.Authentication
|
|||
Scheme = scheme;
|
||||
Context = context;
|
||||
|
||||
Options = OptionsMonitor.Get(Scheme.Name) ?? new TOptions();
|
||||
Options.Validate(Scheme.Name);
|
||||
Options = OptionsMonitor.Get(Scheme.Name);
|
||||
|
||||
await InitializeEventsAsync();
|
||||
await InitializeHandlerAsync();
|
||||
|
|
|
|||
Loading…
Reference in New Issue