From 697b397b9b764b2b1aaa3488ecbed01183cdd5cd Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Thu, 23 Jul 2020 15:00:01 -0700 Subject: [PATCH] Revert AuthenticationAddXyz overload changes (#24253) --- .../IdentityServiceCollectionExtensions.cs | 30 ------ .../CertificateAuthenticationExtensions.cs | 40 +------- .../samples/CookieSessionSample/Startup.cs | 7 +- .../Cookies/src/CookieExtensions.cs | 27 +----- .../Core/src/AuthenticationBuilder.cs | 95 ++----------------- .../Facebook/src/FacebookExtensions.cs | 23 +---- .../Google/src/GoogleExtensions.cs | 23 +---- .../JwtBearer/src/JwtBearerExtensions.cs | 23 +---- .../src/MicrosoftAccountExtensions.cs | 25 +---- .../Negotiate/src/NegotiateExtensions.cs | 47 +-------- .../OAuth/src/OAuthExtensions.cs | 32 +------ .../src/OpenIdConnectExtensions.cs | 23 +---- .../Twitter/src/TwitterExtensions.cs | 23 +---- .../src/WsFederationExtensions.cs | 47 +-------- 14 files changed, 28 insertions(+), 437 deletions(-) diff --git a/src/Identity/Core/src/IdentityServiceCollectionExtensions.cs b/src/Identity/Core/src/IdentityServiceCollectionExtensions.cs index ffbc9f563e..45e3d567eb 100644 --- a/src/Identity/Core/src/IdentityServiceCollectionExtensions.cs +++ b/src/Identity/Core/src/IdentityServiceCollectionExtensions.cs @@ -110,21 +110,6 @@ namespace Microsoft.Extensions.DependencyInjection public static IServiceCollection ConfigureApplicationCookie(this IServiceCollection services, Action configure) => services.Configure(IdentityConstants.ApplicationScheme, configure); - /// - /// Configures the application cookie. - /// - /// TService: A service resolved from the IServiceProvider for use when configuring this authentication provider. If you need multiple services then specify IServiceProvider and resolve them directly. - /// The services available in the application. - /// An action to configure the . - /// The services. - public static IServiceCollection ConfigureApplicationCookie(this IServiceCollection services, Action configure) where TService : class - { - services.AddOptions(IdentityConstants.ApplicationScheme) - .Configure(configure); - - return services; - } - /// /// Configure the external cookie. /// @@ -133,20 +118,5 @@ namespace Microsoft.Extensions.DependencyInjection /// The services. public static IServiceCollection ConfigureExternalCookie(this IServiceCollection services, Action configure) => services.Configure(IdentityConstants.ExternalScheme, configure); - - /// - /// Configure the external cookie. - /// - /// TService: A service resolved from the IServiceProvider for use when configuring this authentication provider. If you need multiple services then specify IServiceProvider and resolve them directly. - /// The services available in the application. - /// An action to configure the . - /// The services. - public static IServiceCollection ConfigureExternalCookie(this IServiceCollection services, Action configure) where TService : class - { - services.AddOptions(IdentityConstants.ExternalScheme) - .Configure(configure); - - return services; - } } } diff --git a/src/Security/Authentication/Certificate/src/CertificateAuthenticationExtensions.cs b/src/Security/Authentication/Certificate/src/CertificateAuthenticationExtensions.cs index 8224eb16ce..8da8e2e1c9 100644 --- a/src/Security/Authentication/Certificate/src/CertificateAuthenticationExtensions.cs +++ b/src/Security/Authentication/Certificate/src/CertificateAuthenticationExtensions.cs @@ -28,7 +28,7 @@ namespace Microsoft.Extensions.DependencyInjection /// /// The . public static AuthenticationBuilder AddCertificate(this AuthenticationBuilder builder, string authenticationScheme) - => builder.AddCertificate(authenticationScheme, configureOptions: (Action)null); + => builder.AddCertificate(authenticationScheme, configureOptions: null); /// /// Adds certificate authentication. @@ -39,16 +39,6 @@ namespace Microsoft.Extensions.DependencyInjection public static AuthenticationBuilder AddCertificate(this AuthenticationBuilder builder, Action configureOptions) => builder.AddCertificate(CertificateAuthenticationDefaults.AuthenticationScheme, configureOptions); - /// - /// Adds certificate authentication. - /// - /// TService: A service resolved from the IServiceProvider for use when configuring this authentication provider. If you need multiple services then specify IServiceProvider and resolve them directly. - /// The . - /// - /// The . - public static AuthenticationBuilder AddCertificate(this AuthenticationBuilder builder, Action configureOptions) where TService : class - => builder.AddCertificate(CertificateAuthenticationDefaults.AuthenticationScheme, configureOptions); - /// /// Adds certificate authentication. /// @@ -60,33 +50,7 @@ namespace Microsoft.Extensions.DependencyInjection this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) - { - Action configureOptionsWithServices; - if (configureOptions == null) - { - configureOptionsWithServices = null; - } - else - { - configureOptionsWithServices = (options, _) => configureOptions(options); - } - - return builder.AddCertificate(authenticationScheme, configureOptionsWithServices); - } - - /// - /// Adds certificate authentication. - /// - /// TService: A service resolved from the IServiceProvider for use when configuring this authentication provider. If you need multiple services then specify IServiceProvider and resolve them directly. - /// The . - /// - /// - /// The . - public static AuthenticationBuilder AddCertificate( - this AuthenticationBuilder builder, - string authenticationScheme, - Action configureOptions) where TService : class - => builder.AddScheme(authenticationScheme, configureOptions); + => builder.AddScheme(authenticationScheme, configureOptions); /// /// Adds certificate authentication. diff --git a/src/Security/Authentication/Cookies/samples/CookieSessionSample/Startup.cs b/src/Security/Authentication/Cookies/samples/CookieSessionSample/Startup.cs index c538866d7e..7266159707 100644 --- a/src/Security/Authentication/Cookies/samples/CookieSessionSample/Startup.cs +++ b/src/Security/Authentication/Cookies/samples/CookieSessionSample/Startup.cs @@ -14,14 +14,15 @@ namespace CookieSessionSample { public void ConfigureServices(IServiceCollection services) { - services.AddSingleton(); - // This can be removed after https://github.com/aspnet/IISIntegration/issues/371 services.AddAuthentication(options => { options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme; - }).AddCookie((o, ticketStore) => o.SessionStore = ticketStore); + }).AddCookie(); + + services.AddOptions(CookieAuthenticationDefaults.AuthenticationScheme) + .Configure((o, ticketStore) => o.SessionStore = ticketStore); } public void Configure(IApplicationBuilder app) diff --git a/src/Security/Authentication/Cookies/src/CookieExtensions.cs b/src/Security/Authentication/Cookies/src/CookieExtensions.cs index a67a708149..7763e6a624 100644 --- a/src/Security/Authentication/Cookies/src/CookieExtensions.cs +++ b/src/Security/Authentication/Cookies/src/CookieExtensions.cs @@ -15,40 +15,19 @@ namespace Microsoft.Extensions.DependencyInjection => builder.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme); public static AuthenticationBuilder AddCookie(this AuthenticationBuilder builder, string authenticationScheme) - => builder.AddCookie(authenticationScheme, configureOptions: (Action)null); + => builder.AddCookie(authenticationScheme, configureOptions: null); - public static AuthenticationBuilder AddCookie(this AuthenticationBuilder builder, Action configureOptions) - => builder.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, configureOptions); - - public static AuthenticationBuilder AddCookie(this AuthenticationBuilder builder, Action configureOptions) where TService : class + public static AuthenticationBuilder AddCookie(this AuthenticationBuilder builder, Action configureOptions) => builder.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, configureOptions); public static AuthenticationBuilder AddCookie(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) => builder.AddCookie(authenticationScheme, displayName: null, configureOptions: configureOptions); - public static AuthenticationBuilder AddCookie(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) where TService : class - => builder.AddCookie(authenticationScheme, displayName: null, configureOptions: configureOptions); - public static AuthenticationBuilder AddCookie(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) - { - Action configureOptionsWithServices; - if (configureOptions == null) - { - configureOptionsWithServices = null; - } - else - { - configureOptionsWithServices = (options, _) => configureOptions(options); - } - - return builder.AddCookie(authenticationScheme, displayName, configureOptionsWithServices); - } - - public static AuthenticationBuilder AddCookie(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) where TService : class { builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, PostConfigureCookieAuthenticationOptions>()); builder.Services.AddOptions(authenticationScheme).Validate(o => o.Cookie.Expiration == null, "Cookie.Expiration is ignored, use ExpireTimeSpan instead."); - return builder.AddScheme(authenticationScheme, displayName, configureOptions); + return builder.AddScheme(authenticationScheme, displayName, configureOptions); } } } diff --git a/src/Security/Authentication/Core/src/AuthenticationBuilder.cs b/src/Security/Authentication/Core/src/AuthenticationBuilder.cs index 829fe007d7..d4efd0c847 100644 --- a/src/Security/Authentication/Core/src/AuthenticationBuilder.cs +++ b/src/Security/Authentication/Core/src/AuthenticationBuilder.cs @@ -25,31 +25,25 @@ namespace Microsoft.AspNetCore.Authentication /// public virtual IServiceCollection Services { get; } - private AuthenticationBuilder AddSchemeHelper(string authenticationScheme, string displayName, Action configureOptions) where TService : class + private AuthenticationBuilder AddSchemeHelper(string authenticationScheme, string displayName, Action configureOptions) where TOptions : AuthenticationSchemeOptions, new() where THandler : class, IAuthenticationHandler { Services.Configure(o => { - o.AddScheme(authenticationScheme, scheme => - { + o.AddScheme(authenticationScheme, scheme => { scheme.HandlerType = typeof(THandler); scheme.DisplayName = displayName; }); }); - - var optionsBuilder = Services.AddOptions(authenticationScheme) - .Validate(o => - { - o.Validate(authenticationScheme); - return true; - }); - if (configureOptions != null) { - optionsBuilder.Configure(configureOptions); + Services.Configure(authenticationScheme, configureOptions); } - + Services.AddOptions(authenticationScheme).Validate(o => { + o.Validate(authenticationScheme); + return true; + }); Services.AddTransient(); return this; } @@ -66,22 +60,7 @@ namespace Microsoft.AspNetCore.Authentication public virtual AuthenticationBuilder AddScheme(string authenticationScheme, string displayName, Action configureOptions) where TOptions : AuthenticationSchemeOptions, new() where THandler : AuthenticationHandler - => AddSchemeHelper(authenticationScheme, displayName, MapConfiguration(configureOptions)); - - /// - /// Adds a which can be used by . - /// - /// The type to configure the handler."/>. - /// The used to handle this scheme. - /// TService: A service resolved from the IServiceProvider for use when configuring this authentication provider. If you need multiple services then specify IServiceProvider and resolve them directly. - /// The name of this scheme. - /// The display name of this scheme. - /// Used to configure the scheme options. - /// The builder. - public virtual AuthenticationBuilder AddScheme(string authenticationScheme, string displayName, Action configureOptions) where TService : class - where TOptions : AuthenticationSchemeOptions, new() - where THandler : AuthenticationHandler - => AddSchemeHelper(authenticationScheme, displayName, configureOptions); + => AddSchemeHelper(authenticationScheme, displayName, configureOptions); /// /// Adds a which can be used by . @@ -96,20 +75,6 @@ namespace Microsoft.AspNetCore.Authentication where THandler : AuthenticationHandler => AddScheme(authenticationScheme, displayName: null, configureOptions: configureOptions); - /// - /// Adds a which can be used by . - /// - /// The type to configure the handler."/>. - /// The used to handle this scheme. - /// TService: A service resolved from the IServiceProvider for use when configuring this authentication provider. If you need multiple services then specify IServiceProvider and resolve them directly. - /// The name of this scheme. - /// Used to configure the scheme options. - /// The builder. - public virtual AuthenticationBuilder AddScheme(string authenticationScheme, Action configureOptions) where TService : class - where TOptions : AuthenticationSchemeOptions, new() - where THandler : AuthenticationHandler - => AddScheme(authenticationScheme, displayName: null, configureOptions: configureOptions); - /// /// Adds a based that supports remote authentication /// which can be used by . @@ -128,25 +93,6 @@ namespace Microsoft.AspNetCore.Authentication return AddScheme(authenticationScheme, displayName, configureOptions: configureOptions); } - /// - /// Adds a based that supports remote authentication - /// which can be used by . - /// - /// The type to configure the handler."/>. - /// The used to handle this scheme. - /// TService: A service resolved from the IServiceProvider for use when configuring this authentication provider. If you need multiple services then specify IServiceProvider and resolve them directly. - /// The name of this scheme. - /// The display name of this scheme. - /// Used to configure the scheme options. - /// The builder. - public virtual AuthenticationBuilder AddRemoteScheme(string authenticationScheme, string displayName, Action configureOptions) where TService : class - where TOptions : RemoteAuthenticationOptions, new() - where THandler : RemoteAuthenticationHandler - { - Services.TryAddEnumerable(ServiceDescriptor.Singleton, EnsureSignInScheme>()); - return AddScheme(authenticationScheme, displayName, configureOptions: configureOptions); - } - /// /// Adds a based authentication handler which can be used to /// redirect to other authentication schemes. @@ -156,30 +102,7 @@ namespace Microsoft.AspNetCore.Authentication /// Used to configure the scheme options. /// The builder. public virtual AuthenticationBuilder AddPolicyScheme(string authenticationScheme, string displayName, Action configureOptions) - => AddSchemeHelper(authenticationScheme, displayName, MapConfiguration(configureOptions)); - - /// - /// Adds a based authentication handler which can be used to - /// redirect to other authentication schemes. - /// - /// The name of this scheme. - /// The display name of this scheme. - /// Used to configure the scheme options. - /// The builder. - public virtual AuthenticationBuilder AddPolicyScheme(string authenticationScheme, string displayName, Action configureOptions) where TService : class - => AddSchemeHelper(authenticationScheme, displayName, configureOptions); - - private Action MapConfiguration(Action configureOptions) - { - if (configureOptions == null) - { - return null; - } - else - { - return (options, _) => configureOptions(options); - } - } + => AddSchemeHelper(authenticationScheme, displayName, configureOptions); // Used to ensure that there's always a default sign in scheme that's not itself private class EnsureSignInScheme : IPostConfigureOptions where TOptions : RemoteAuthenticationOptions diff --git a/src/Security/Authentication/Facebook/src/FacebookExtensions.cs b/src/Security/Authentication/Facebook/src/FacebookExtensions.cs index b32b35c6c1..2273724a42 100644 --- a/src/Security/Authentication/Facebook/src/FacebookExtensions.cs +++ b/src/Security/Authentication/Facebook/src/FacebookExtensions.cs @@ -15,31 +15,10 @@ namespace Microsoft.Extensions.DependencyInjection public static AuthenticationBuilder AddFacebook(this AuthenticationBuilder builder, Action configureOptions) => builder.AddFacebook(FacebookDefaults.AuthenticationScheme, configureOptions); - public static AuthenticationBuilder AddFacebook(this AuthenticationBuilder builder, Action configureOptions) where TService : class - => builder.AddFacebook(FacebookDefaults.AuthenticationScheme, configureOptions); - public static AuthenticationBuilder AddFacebook(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) => builder.AddFacebook(authenticationScheme, FacebookDefaults.DisplayName, configureOptions); - public static AuthenticationBuilder AddFacebook(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) where TService : class - => builder.AddFacebook(authenticationScheme, FacebookDefaults.DisplayName, configureOptions); - public static AuthenticationBuilder AddFacebook(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) - { - Action configureOptionsWithServices; - if (configureOptions == null) - { - configureOptionsWithServices = null; - } - else - { - configureOptionsWithServices = (options, _) => configureOptions(options); - } - - return builder.AddFacebook(authenticationScheme, displayName, configureOptionsWithServices); - } - - public static AuthenticationBuilder AddFacebook(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) where TService : class - => builder.AddOAuth(authenticationScheme, displayName, configureOptions); + => builder.AddOAuth(authenticationScheme, displayName, configureOptions); } } diff --git a/src/Security/Authentication/Google/src/GoogleExtensions.cs b/src/Security/Authentication/Google/src/GoogleExtensions.cs index 88add9610d..95547014ca 100644 --- a/src/Security/Authentication/Google/src/GoogleExtensions.cs +++ b/src/Security/Authentication/Google/src/GoogleExtensions.cs @@ -15,31 +15,10 @@ namespace Microsoft.Extensions.DependencyInjection public static AuthenticationBuilder AddGoogle(this AuthenticationBuilder builder, Action configureOptions) => builder.AddGoogle(GoogleDefaults.AuthenticationScheme, configureOptions); - public static AuthenticationBuilder AddGoogle(this AuthenticationBuilder builder, Action configureOptions) where TService : class - => builder.AddGoogle(GoogleDefaults.AuthenticationScheme, configureOptions); - public static AuthenticationBuilder AddGoogle(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) => builder.AddGoogle(authenticationScheme, GoogleDefaults.DisplayName, configureOptions); - public static AuthenticationBuilder AddGoogle(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) where TService : class - => builder.AddGoogle(authenticationScheme, GoogleDefaults.DisplayName, configureOptions); - public static AuthenticationBuilder AddGoogle(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) - { - Action configureOptionsWithServices; - if (configureOptions == null) - { - configureOptionsWithServices = null; - } - else - { - configureOptionsWithServices = (options, _) => configureOptions(options); - } - - return builder.AddGoogle(authenticationScheme, displayName, configureOptionsWithServices); - } - - public static AuthenticationBuilder AddGoogle(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) where TService : class - => builder.AddOAuth(authenticationScheme, displayName, configureOptions); + => builder.AddOAuth(authenticationScheme, displayName, configureOptions); } } diff --git a/src/Security/Authentication/JwtBearer/src/JwtBearerExtensions.cs b/src/Security/Authentication/JwtBearer/src/JwtBearerExtensions.cs index a5aa46a451..334407c0da 100644 --- a/src/Security/Authentication/JwtBearer/src/JwtBearerExtensions.cs +++ b/src/Security/Authentication/JwtBearer/src/JwtBearerExtensions.cs @@ -17,34 +17,13 @@ namespace Microsoft.Extensions.DependencyInjection public static AuthenticationBuilder AddJwtBearer(this AuthenticationBuilder builder, Action configureOptions) => builder.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, configureOptions); - public static AuthenticationBuilder AddJwtBearer(this AuthenticationBuilder builder, Action configureOptions) where TService : class - => builder.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, configureOptions); - public static AuthenticationBuilder AddJwtBearer(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) => builder.AddJwtBearer(authenticationScheme, displayName: null, configureOptions: configureOptions); - public static AuthenticationBuilder AddJwtBearer(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) where TService : class - => builder.AddJwtBearer(authenticationScheme, displayName: null, configureOptions: configureOptions); - public static AuthenticationBuilder AddJwtBearer(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) - { - Action configureOptionsWithServices; - if (configureOptions == null) - { - configureOptionsWithServices = null; - } - else - { - configureOptionsWithServices = (options, _) => configureOptions(options); - } - - return builder.AddJwtBearer(authenticationScheme, displayName, configureOptionsWithServices); - } - - public static AuthenticationBuilder AddJwtBearer(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) where TService : class { builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, JwtBearerPostConfigureOptions>()); - return builder.AddScheme(authenticationScheme, displayName, configureOptions); + return builder.AddScheme(authenticationScheme, displayName, configureOptions); } } } diff --git a/src/Security/Authentication/MicrosoftAccount/src/MicrosoftAccountExtensions.cs b/src/Security/Authentication/MicrosoftAccount/src/MicrosoftAccountExtensions.cs index 0c59ce3504..7f24e5af77 100644 --- a/src/Security/Authentication/MicrosoftAccount/src/MicrosoftAccountExtensions.cs +++ b/src/Security/Authentication/MicrosoftAccount/src/MicrosoftAccountExtensions.cs @@ -15,31 +15,10 @@ namespace Microsoft.Extensions.DependencyInjection public static AuthenticationBuilder AddMicrosoftAccount(this AuthenticationBuilder builder, Action configureOptions) => builder.AddMicrosoftAccount(MicrosoftAccountDefaults.AuthenticationScheme, configureOptions); - public static AuthenticationBuilder AddMicrosoftAccount(this AuthenticationBuilder builder, Action configureOptions) where TService : class - => builder.AddMicrosoftAccount(MicrosoftAccountDefaults.AuthenticationScheme, configureOptions); - public static AuthenticationBuilder AddMicrosoftAccount(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) => builder.AddMicrosoftAccount(authenticationScheme, MicrosoftAccountDefaults.DisplayName, configureOptions); - public static AuthenticationBuilder AddMicrosoftAccount(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) where TService : class - => builder.AddMicrosoftAccount(authenticationScheme, MicrosoftAccountDefaults.DisplayName, configureOptions); - public static AuthenticationBuilder AddMicrosoftAccount(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) - { - Action configureOptionsWithServices; - if (configureOptions == null) - { - configureOptionsWithServices = null; - } - else - { - configureOptionsWithServices = (options, _) => configureOptions(options); - } - - return builder.AddMicrosoftAccount(authenticationScheme, displayName, configureOptionsWithServices); - } - - public static AuthenticationBuilder AddMicrosoftAccount(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) where TService : class - => builder.AddOAuth(authenticationScheme, displayName, configureOptions); + => builder.AddOAuth(authenticationScheme, displayName, configureOptions); } -} +} \ No newline at end of file diff --git a/src/Security/Authentication/Negotiate/src/NegotiateExtensions.cs b/src/Security/Authentication/Negotiate/src/NegotiateExtensions.cs index 401c3dc839..f5bbf8cbc8 100644 --- a/src/Security/Authentication/Negotiate/src/NegotiateExtensions.cs +++ b/src/Security/Authentication/Negotiate/src/NegotiateExtensions.cs @@ -31,16 +31,6 @@ namespace Microsoft.Extensions.DependencyInjection public static AuthenticationBuilder AddNegotiate(this AuthenticationBuilder builder, Action configureOptions) => builder.AddNegotiate(NegotiateDefaults.AuthenticationScheme, configureOptions); - /// - /// Adds and configures Negotiate authentication. - /// - /// TService: A service resolved from the IServiceProvider for use when configuring this authentication provider. If you need multiple services then specify IServiceProvider and resolve them directly. - /// The . - /// Allows for configuring the authentication handler. - /// The original builder. - public static AuthenticationBuilder AddNegotiate(this AuthenticationBuilder builder, Action configureOptions) where TService : class - => builder.AddNegotiate(NegotiateDefaults.AuthenticationScheme, configureOptions); - /// /// Adds and configures Negotiate authentication. /// @@ -51,17 +41,6 @@ namespace Microsoft.Extensions.DependencyInjection public static AuthenticationBuilder AddNegotiate(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) => builder.AddNegotiate(authenticationScheme, displayName: null, configureOptions: configureOptions); - /// - /// Adds and configures Negotiate authentication. - /// - /// TService: A service resolved from the IServiceProvider for use when configuring this authentication provider. If you need multiple services then specify IServiceProvider and resolve them directly. - /// The . - /// The scheme name used to identify the authentication handler internally. - /// Allows for configuring the authentication handler. - /// The original builder. - public static AuthenticationBuilder AddNegotiate(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) where TService : class - => builder.AddNegotiate(authenticationScheme, displayName: null, configureOptions: configureOptions); - /// /// Adds and configures Negotiate authentication. /// @@ -71,33 +50,9 @@ namespace Microsoft.Extensions.DependencyInjection /// Allows for configuring the authentication handler. /// The original builder. public static AuthenticationBuilder AddNegotiate(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) - { - Action configureOptionsWithServices; - if (configureOptions == null) - { - configureOptionsWithServices = null; - } - else - { - configureOptionsWithServices = (options, _) => configureOptions(options); - } - - return builder.AddNegotiate(authenticationScheme, displayName, configureOptionsWithServices); - } - - /// - /// Adds and configures Negotiate authentication. - /// - /// TService: A service resolved from the IServiceProvider for use when configuring this authentication provider. If you need multiple services then specify IServiceProvider and resolve them directly. - /// The . - /// The scheme name used to identify the authentication handler internally. - /// The name displayed to users when selecting an authentication handler. The default is null to prevent this from displaying. - /// Allows for configuring the authentication handler. - /// The original builder. - public static AuthenticationBuilder AddNegotiate(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) where TService : class { builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, PostConfigureNegotiateOptions>()); - return builder.AddScheme(authenticationScheme, displayName, configureOptions); + return builder.AddScheme(authenticationScheme, displayName, configureOptions); } } } diff --git a/src/Security/Authentication/OAuth/src/OAuthExtensions.cs b/src/Security/Authentication/OAuth/src/OAuthExtensions.cs index 69bb2d73d3..22c541a0ac 100644 --- a/src/Security/Authentication/OAuth/src/OAuthExtensions.cs +++ b/src/Security/Authentication/OAuth/src/OAuthExtensions.cs @@ -14,50 +14,20 @@ namespace Microsoft.Extensions.DependencyInjection public static AuthenticationBuilder AddOAuth(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) => builder.AddOAuth>(authenticationScheme, configureOptions); - public static AuthenticationBuilder AddOAuth(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) where TService : class - => builder.AddOAuth, TService>(authenticationScheme, configureOptions); - public static AuthenticationBuilder AddOAuth(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) => builder.AddOAuth>(authenticationScheme, displayName, configureOptions); - public static AuthenticationBuilder AddOAuth(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) where TService : class - => builder.AddOAuth, TService>(authenticationScheme, displayName, configureOptions); - public static AuthenticationBuilder AddOAuth(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) where TOptions : OAuthOptions, new() where THandler : OAuthHandler => builder.AddOAuth(authenticationScheme, OAuthDefaults.DisplayName, configureOptions); - public static AuthenticationBuilder AddOAuth(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) - where TOptions : OAuthOptions, new() - where THandler : OAuthHandler - where TService : class - => builder.AddOAuth(authenticationScheme, OAuthDefaults.DisplayName, configureOptions); - public static AuthenticationBuilder AddOAuth(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) where TOptions : OAuthOptions, new() where THandler : OAuthHandler - { - Action configureOptionsWithServices; - if (configureOptions == null) - { - configureOptionsWithServices = null; - } - else - { - configureOptionsWithServices = (options, _) => configureOptions(options); - } - - return builder.AddOAuth(authenticationScheme, displayName, configureOptionsWithServices); - } - - public static AuthenticationBuilder AddOAuth(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) - where TOptions : OAuthOptions, new() - where THandler : OAuthHandler - where TService : class { builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, OAuthPostConfigureOptions>()); - return builder.AddRemoteScheme(authenticationScheme, displayName, configureOptions); + return builder.AddRemoteScheme(authenticationScheme, displayName, configureOptions); } } } diff --git a/src/Security/Authentication/OpenIdConnect/src/OpenIdConnectExtensions.cs b/src/Security/Authentication/OpenIdConnect/src/OpenIdConnectExtensions.cs index 482452bca2..f427bebaff 100644 --- a/src/Security/Authentication/OpenIdConnect/src/OpenIdConnectExtensions.cs +++ b/src/Security/Authentication/OpenIdConnect/src/OpenIdConnectExtensions.cs @@ -17,34 +17,13 @@ namespace Microsoft.Extensions.DependencyInjection public static AuthenticationBuilder AddOpenIdConnect(this AuthenticationBuilder builder, Action configureOptions) => builder.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, configureOptions); - public static AuthenticationBuilder AddOpenIdConnect(this AuthenticationBuilder builder, Action configureOptions) where TService : class - => builder.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, configureOptions); - public static AuthenticationBuilder AddOpenIdConnect(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) => builder.AddOpenIdConnect(authenticationScheme, OpenIdConnectDefaults.DisplayName, configureOptions); - public static AuthenticationBuilder AddOpenIdConnect(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) where TService : class - => builder.AddOpenIdConnect(authenticationScheme, OpenIdConnectDefaults.DisplayName, configureOptions); - public static AuthenticationBuilder AddOpenIdConnect(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) - { - Action configureOptionsWithServices; - if (configureOptions == null) - { - configureOptionsWithServices = null; - } - else - { - configureOptionsWithServices = (options, _) => configureOptions(options); - } - - return builder.AddOpenIdConnect(authenticationScheme, displayName, configureOptionsWithServices); - } - - public static AuthenticationBuilder AddOpenIdConnect(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) where TService : class { builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, OpenIdConnectPostConfigureOptions>()); - return builder.AddRemoteScheme(authenticationScheme, displayName, configureOptions); + return builder.AddRemoteScheme(authenticationScheme, displayName, configureOptions); } } } diff --git a/src/Security/Authentication/Twitter/src/TwitterExtensions.cs b/src/Security/Authentication/Twitter/src/TwitterExtensions.cs index f6f6b93a9e..7243805692 100644 --- a/src/Security/Authentication/Twitter/src/TwitterExtensions.cs +++ b/src/Security/Authentication/Twitter/src/TwitterExtensions.cs @@ -17,34 +17,13 @@ namespace Microsoft.Extensions.DependencyInjection public static AuthenticationBuilder AddTwitter(this AuthenticationBuilder builder, Action configureOptions) => builder.AddTwitter(TwitterDefaults.AuthenticationScheme, configureOptions); - public static AuthenticationBuilder AddTwitter(this AuthenticationBuilder builder, Action configureOptions) where TService : class - => builder.AddTwitter(TwitterDefaults.AuthenticationScheme, configureOptions); - public static AuthenticationBuilder AddTwitter(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) => builder.AddTwitter(authenticationScheme, TwitterDefaults.DisplayName, configureOptions); - public static AuthenticationBuilder AddTwitter(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) where TService : class - => builder.AddTwitter(authenticationScheme, TwitterDefaults.DisplayName, configureOptions); - public static AuthenticationBuilder AddTwitter(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) - { - Action configureOptionsWithServices; - if (configureOptions == null) - { - configureOptionsWithServices = null; - } - else - { - configureOptionsWithServices = (options, _) => configureOptions(options); - } - - return builder.AddTwitter(authenticationScheme, displayName, configureOptionsWithServices); - } - - public static AuthenticationBuilder AddTwitter(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) where TService : class { builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, TwitterPostConfigureOptions>()); - return builder.AddRemoteScheme(authenticationScheme, displayName, configureOptions); + return builder.AddRemoteScheme(authenticationScheme, displayName, configureOptions); } } } diff --git a/src/Security/Authentication/WsFederation/src/WsFederationExtensions.cs b/src/Security/Authentication/WsFederation/src/WsFederationExtensions.cs index 6a9ffad239..47091d58d5 100644 --- a/src/Security/Authentication/WsFederation/src/WsFederationExtensions.cs +++ b/src/Security/Authentication/WsFederation/src/WsFederationExtensions.cs @@ -31,16 +31,6 @@ namespace Microsoft.Extensions.DependencyInjection public static AuthenticationBuilder AddWsFederation(this AuthenticationBuilder builder, Action configureOptions) => builder.AddWsFederation(WsFederationDefaults.AuthenticationScheme, configureOptions); - /// - /// Registers the using the default authentication scheme, display name, and the given options configuration. - /// - /// TService: A service resolved from the IServiceProvider for use when configuring this authentication provider. If you need multiple services then specify IServiceProvider and resolve them directly. - /// - /// A delegate that configures the . - /// - public static AuthenticationBuilder AddWsFederation(this AuthenticationBuilder builder, Action configureOptions) where TService : class - => builder.AddWsFederation(WsFederationDefaults.AuthenticationScheme, configureOptions); - /// /// Registers the using the given authentication scheme, default display name, and the given options configuration. /// @@ -51,17 +41,6 @@ namespace Microsoft.Extensions.DependencyInjection public static AuthenticationBuilder AddWsFederation(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) => builder.AddWsFederation(authenticationScheme, WsFederationDefaults.DisplayName, configureOptions); - /// - /// Registers the using the given authentication scheme, default display name, and the given options configuration. - /// - /// TService: A service resolved from the IServiceProvider for use when configuring this authentication provider. If you need multiple services then specify IServiceProvider and resolve them directly. - /// - /// - /// A delegate that configures the . - /// - public static AuthenticationBuilder AddWsFederation(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) where TService : class - => builder.AddWsFederation(authenticationScheme, WsFederationDefaults.DisplayName, configureOptions); - /// /// Registers the using the given authentication scheme, display name, and options configuration. /// @@ -71,33 +50,9 @@ namespace Microsoft.Extensions.DependencyInjection /// A delegate that configures the . /// public static AuthenticationBuilder AddWsFederation(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) - { - Action configureOptionsWithServices; - if (configureOptions == null) - { - configureOptionsWithServices = null; - } - else - { - configureOptionsWithServices = (options, _) => configureOptions(options); - } - - return builder.AddWsFederation(authenticationScheme, displayName, configureOptionsWithServices); - } - - /// - /// Registers the using the given authentication scheme, display name, and options configuration. - /// - /// TService: A service resolved from the IServiceProvider for use when configuring this authentication provider. If you need multiple services then specify IServiceProvider and resolve them directly. - /// - /// - /// - /// A delegate that configures the . - /// - public static AuthenticationBuilder AddWsFederation(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) where TService : class { builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, WsFederationPostConfigureOptions>()); - return builder.AddRemoteScheme(authenticationScheme, displayName, configureOptions); + return builder.AddRemoteScheme(authenticationScheme, displayName, configureOptions); } } }