From b7e122fbac4207b003dc07f6101e50218be8ff21 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Mon, 25 Mar 2019 11:35:39 -0700 Subject: [PATCH] Hook auth options validation into validation feature (#8665) --- .../Authentication/Core/src/AuthenticationBuilder.cs | 7 +++++-- .../Authentication/Core/src/AuthenticationHandler.cs | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Security/Authentication/Core/src/AuthenticationBuilder.cs b/src/Security/Authentication/Core/src/AuthenticationBuilder.cs index 401b1f488c..d4efd0c847 100644 --- a/src/Security/Authentication/Core/src/AuthenticationBuilder.cs +++ b/src/Security/Authentication/Core/src/AuthenticationBuilder.cs @@ -25,9 +25,8 @@ namespace Microsoft.AspNetCore.Authentication /// public virtual IServiceCollection Services { get; } - private AuthenticationBuilder AddSchemeHelper(string authenticationScheme, string displayName, Action configureOptions) - where TOptions : class, new() + where TOptions : AuthenticationSchemeOptions, new() where THandler : class, IAuthenticationHandler { Services.Configure(o => @@ -41,6 +40,10 @@ namespace Microsoft.AspNetCore.Authentication { Services.Configure(authenticationScheme, configureOptions); } + Services.AddOptions(authenticationScheme).Validate(o => { + o.Validate(authenticationScheme); + return true; + }); Services.AddTransient(); return this; } diff --git a/src/Security/Authentication/Core/src/AuthenticationHandler.cs b/src/Security/Authentication/Core/src/AuthenticationHandler.cs index 5c9a6473f1..5f8a8d588f 100644 --- a/src/Security/Authentication/Core/src/AuthenticationHandler.cs +++ b/src/Security/Authentication/Core/src/AuthenticationHandler.cs @@ -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();