From 1c30f33c925a97b105b3f9d34497218b0c9342b6 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Mon, 3 Jul 2017 12:56:39 -0700 Subject: [PATCH] Remove AddXyzAuth extension methods --- .../CookieExtensions.cs | 15 --------------- .../FacebookExtensions.cs | 11 ----------- .../GoogleExtensions.cs | 12 ------------ .../JwtBearerExtensions.cs | 14 -------------- .../MicrosoftAccountExtensions.cs | 12 ------------ .../OAuthExtensions.cs | 14 -------------- .../OpenIdConnectExtensions.cs | 13 ------------- .../TwitterExtensions.cs | 13 ------------- .../AuthenticationMiddleware.cs | 2 -- .../FacebookTests.cs | 10 ++++------ .../GoogleTests.cs | 3 ++- .../JwtBearerTests.cs | 5 +++-- .../MicrosoftAccountTests.cs | 3 ++- .../OAuthTests.cs | 17 +++++++++-------- .../TwitterTests.cs | 4 ++-- 15 files changed, 22 insertions(+), 126 deletions(-) diff --git a/src/Microsoft.AspNetCore.Authentication.Cookies/CookieExtensions.cs b/src/Microsoft.AspNetCore.Authentication.Cookies/CookieExtensions.cs index 67c4416ebb..61f72e361f 100644 --- a/src/Microsoft.AspNetCore.Authentication.Cookies/CookieExtensions.cs +++ b/src/Microsoft.AspNetCore.Authentication.Cookies/CookieExtensions.cs @@ -25,20 +25,5 @@ namespace Microsoft.Extensions.DependencyInjection builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, PostConfigureCookieAuthenticationOptions>()); return builder.AddScheme(authenticationScheme, configureOptions); } - - - // REMOVE below once callers have been updated - public static IServiceCollection AddCookieAuthentication(this IServiceCollection services) => services.AddCookieAuthentication(CookieAuthenticationDefaults.AuthenticationScheme); - - public static IServiceCollection AddCookieAuthentication(this IServiceCollection services, string authenticationScheme) => services.AddCookieAuthentication(authenticationScheme, configureOptions: null); - - public static IServiceCollection AddCookieAuthentication(this IServiceCollection services, Action configureOptions) => - services.AddCookieAuthentication(CookieAuthenticationDefaults.AuthenticationScheme, configureOptions); - - public static IServiceCollection AddCookieAuthentication(this IServiceCollection services, string authenticationScheme, Action configureOptions) - { - services.TryAddEnumerable(ServiceDescriptor.Singleton, PostConfigureCookieAuthenticationOptions>()); - return services.AddScheme(authenticationScheme, configureOptions); - } } } diff --git a/src/Microsoft.AspNetCore.Authentication.Facebook/FacebookExtensions.cs b/src/Microsoft.AspNetCore.Authentication.Facebook/FacebookExtensions.cs index e4dcbfee8b..1cb1ef03eb 100644 --- a/src/Microsoft.AspNetCore.Authentication.Facebook/FacebookExtensions.cs +++ b/src/Microsoft.AspNetCore.Authentication.Facebook/FacebookExtensions.cs @@ -17,16 +17,5 @@ namespace Microsoft.Extensions.DependencyInjection public static AuthenticationBuilder AddFacebook(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) => builder.AddOAuth(authenticationScheme, configureOptions); - - - // REMOVE below once callers have been updated - public static IServiceCollection AddFacebookAuthentication(this IServiceCollection services) - => services.AddFacebookAuthentication(FacebookDefaults.AuthenticationScheme, _ => { }); - - public static IServiceCollection AddFacebookAuthentication(this IServiceCollection services, Action configureOptions) - => services.AddFacebookAuthentication(FacebookDefaults.AuthenticationScheme, configureOptions); - - public static IServiceCollection AddFacebookAuthentication(this IServiceCollection services, string authenticationScheme, Action configureOptions) - => services.AddOAuthAuthentication(authenticationScheme, configureOptions); } } diff --git a/src/Microsoft.AspNetCore.Authentication.Google/GoogleExtensions.cs b/src/Microsoft.AspNetCore.Authentication.Google/GoogleExtensions.cs index ee42c5564c..7bb9b7bebd 100644 --- a/src/Microsoft.AspNetCore.Authentication.Google/GoogleExtensions.cs +++ b/src/Microsoft.AspNetCore.Authentication.Google/GoogleExtensions.cs @@ -17,17 +17,5 @@ namespace Microsoft.Extensions.DependencyInjection public static AuthenticationBuilder AddGoogle(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) => builder.AddOAuth(authenticationScheme, configureOptions); - - - // REMOVE below once callers have been updated - - public static IServiceCollection AddGoogleAuthentication(this IServiceCollection services) - => services.AddGoogleAuthentication(GoogleDefaults.AuthenticationScheme, _ => { }); - - public static IServiceCollection AddGoogleAuthentication(this IServiceCollection services, Action configureOptions) - => services.AddGoogleAuthentication(GoogleDefaults.AuthenticationScheme, configureOptions); - - public static IServiceCollection AddGoogleAuthentication(this IServiceCollection services, string authenticationScheme, Action configureOptions) - => services.AddOAuthAuthentication(authenticationScheme, configureOptions); } } diff --git a/src/Microsoft.AspNetCore.Authentication.JwtBearer/JwtBearerExtensions.cs b/src/Microsoft.AspNetCore.Authentication.JwtBearer/JwtBearerExtensions.cs index 4f051bd39a..698c0118e0 100644 --- a/src/Microsoft.AspNetCore.Authentication.JwtBearer/JwtBearerExtensions.cs +++ b/src/Microsoft.AspNetCore.Authentication.JwtBearer/JwtBearerExtensions.cs @@ -22,19 +22,5 @@ namespace Microsoft.Extensions.DependencyInjection builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, JwtBearerPostConfigureOptions>()); return builder.AddScheme(authenticationScheme, configureOptions); } - - - // REMOVE once callers updated - public static IServiceCollection AddJwtBearerAuthentication(this IServiceCollection services) - => services.AddJwtBearerAuthentication(JwtBearerDefaults.AuthenticationScheme, _ => { }); - - public static IServiceCollection AddJwtBearerAuthentication(this IServiceCollection services, Action configureOptions) - => services.AddJwtBearerAuthentication(JwtBearerDefaults.AuthenticationScheme, configureOptions); - - public static IServiceCollection AddJwtBearerAuthentication(this IServiceCollection services, string authenticationScheme, Action configureOptions) - { - services.TryAddEnumerable(ServiceDescriptor.Singleton, JwtBearerPostConfigureOptions>()); - return services.AddScheme(authenticationScheme, configureOptions); - } } } diff --git a/src/Microsoft.AspNetCore.Authentication.MicrosoftAccount/MicrosoftAccountExtensions.cs b/src/Microsoft.AspNetCore.Authentication.MicrosoftAccount/MicrosoftAccountExtensions.cs index 9a53fd7700..8da6daaac8 100644 --- a/src/Microsoft.AspNetCore.Authentication.MicrosoftAccount/MicrosoftAccountExtensions.cs +++ b/src/Microsoft.AspNetCore.Authentication.MicrosoftAccount/MicrosoftAccountExtensions.cs @@ -17,17 +17,5 @@ namespace Microsoft.Extensions.DependencyInjection public static AuthenticationBuilder AddMicrosoftAccount(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) => builder.AddOAuth(authenticationScheme, configureOptions); - - - // REMOVE below once callers have been updated - - public static IServiceCollection AddMicrosoftAccountAuthentication(this IServiceCollection services) - => services.AddMicrosoftAccountAuthentication(MicrosoftAccountDefaults.AuthenticationScheme, _ => { }); - - public static IServiceCollection AddMicrosoftAccountAuthentication(this IServiceCollection services, Action configureOptions) - => services.AddMicrosoftAccountAuthentication(MicrosoftAccountDefaults.AuthenticationScheme, configureOptions); - - public static IServiceCollection AddMicrosoftAccountAuthentication(this IServiceCollection services, string authenticationScheme, Action configureOptions) - => services.AddOAuthAuthentication(authenticationScheme, configureOptions); } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Authentication.OAuth/OAuthExtensions.cs b/src/Microsoft.AspNetCore.Authentication.OAuth/OAuthExtensions.cs index 5720d8e4f4..8c9d34c5f9 100644 --- a/src/Microsoft.AspNetCore.Authentication.OAuth/OAuthExtensions.cs +++ b/src/Microsoft.AspNetCore.Authentication.OAuth/OAuthExtensions.cs @@ -21,19 +21,5 @@ namespace Microsoft.Extensions.DependencyInjection builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, OAuthPostConfigureOptions>()); return builder.AddRemoteScheme(authenticationScheme, authenticationScheme, configureOptions); } - - // REMOVE below once callers have been updated - public static IServiceCollection AddOAuthAuthentication(this IServiceCollection services, string authenticationScheme, Action configureOptions) - { - return services.AddOAuthAuthentication>(authenticationScheme, configureOptions); - } - - public static IServiceCollection AddOAuthAuthentication(this IServiceCollection services, string authenticationScheme, Action configureOptions) - where TOptions : OAuthOptions, new() - where THandler : OAuthHandler - { - services.TryAddEnumerable(ServiceDescriptor.Singleton, OAuthPostConfigureOptions>()); - return services.AddRemoteScheme(authenticationScheme, authenticationScheme, configureOptions); - } } } diff --git a/src/Microsoft.AspNetCore.Authentication.OpenIdConnect/OpenIdConnectExtensions.cs b/src/Microsoft.AspNetCore.Authentication.OpenIdConnect/OpenIdConnectExtensions.cs index 7ba262bf39..43059b3ffe 100644 --- a/src/Microsoft.AspNetCore.Authentication.OpenIdConnect/OpenIdConnectExtensions.cs +++ b/src/Microsoft.AspNetCore.Authentication.OpenIdConnect/OpenIdConnectExtensions.cs @@ -22,18 +22,5 @@ namespace Microsoft.Extensions.DependencyInjection builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, OpenIdConnectPostConfigureOptions>()); return builder.AddRemoteScheme(authenticationScheme, authenticationScheme, configureOptions); } - - // REMOVE once callers have been updated - public static IServiceCollection AddOpenIdConnectAuthentication(this IServiceCollection services) - => services.AddOpenIdConnectAuthentication(OpenIdConnectDefaults.AuthenticationScheme, _ => { }); - - public static IServiceCollection AddOpenIdConnectAuthentication(this IServiceCollection services, Action configureOptions) - => services.AddOpenIdConnectAuthentication(OpenIdConnectDefaults.AuthenticationScheme, configureOptions); - - public static IServiceCollection AddOpenIdConnectAuthentication(this IServiceCollection services, string authenticationScheme, Action configureOptions) - { - services.TryAddEnumerable(ServiceDescriptor.Singleton, OpenIdConnectPostConfigureOptions>()); - return services.AddRemoteScheme(authenticationScheme, authenticationScheme, configureOptions); - } } } diff --git a/src/Microsoft.AspNetCore.Authentication.Twitter/TwitterExtensions.cs b/src/Microsoft.AspNetCore.Authentication.Twitter/TwitterExtensions.cs index e49244920e..bd0a3b1e20 100644 --- a/src/Microsoft.AspNetCore.Authentication.Twitter/TwitterExtensions.cs +++ b/src/Microsoft.AspNetCore.Authentication.Twitter/TwitterExtensions.cs @@ -22,18 +22,5 @@ namespace Microsoft.Extensions.DependencyInjection builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, TwitterPostConfigureOptions>()); return builder.AddRemoteScheme(authenticationScheme, authenticationScheme, configureOptions); } - - // REMOVE below once callers have been updated. - public static IServiceCollection AddTwitterAuthentication(this IServiceCollection services) - => services.AddTwitterAuthentication(TwitterDefaults.AuthenticationScheme, _ => { }); - - public static IServiceCollection AddTwitterAuthentication(this IServiceCollection services, Action configureOptions) - => services.AddTwitterAuthentication(TwitterDefaults.AuthenticationScheme, configureOptions); - - public static IServiceCollection AddTwitterAuthentication(this IServiceCollection services, string authenticationScheme, Action configureOptions) - { - services.TryAddEnumerable(ServiceDescriptor.Singleton, TwitterPostConfigureOptions>()); - return services.AddRemoteScheme(authenticationScheme, authenticationScheme, configureOptions); - } } } diff --git a/src/Microsoft.AspNetCore.Authentication/AuthenticationMiddleware.cs b/src/Microsoft.AspNetCore.Authentication/AuthenticationMiddleware.cs index eba561d1da..0c62cc3c39 100644 --- a/src/Microsoft.AspNetCore.Authentication/AuthenticationMiddleware.cs +++ b/src/Microsoft.AspNetCore.Authentication/AuthenticationMiddleware.cs @@ -37,8 +37,6 @@ namespace Microsoft.AspNetCore.Authentication OriginalPathBase = context.Request.PathBase }); - // REVIEW: alternatively could depend on a routing middleware to do this - // Give any IAuthenticationRequestHandler schemes a chance to handle the request var handlers = context.RequestServices.GetRequiredService(); foreach (var scheme in await Schemes.GetRequestHandlerSchemesAsync()) diff --git a/test/Microsoft.AspNetCore.Authentication.Test/FacebookTests.cs b/test/Microsoft.AspNetCore.Authentication.Test/FacebookTests.cs index e6b5574df1..43c52b0fd9 100644 --- a/test/Microsoft.AspNetCore.Authentication.Test/FacebookTests.cs +++ b/test/Microsoft.AspNetCore.Authentication.Test/FacebookTests.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; @@ -16,10 +15,8 @@ using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.TestHost; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging.Abstractions; -using Microsoft.Extensions.Options; using Newtonsoft.Json; using Xunit; @@ -30,7 +27,8 @@ namespace Microsoft.AspNetCore.Authentication.Facebook [Fact] public async Task VerifySchemeDefaults() { - var services = new ServiceCollection().AddFacebookAuthentication().AddSingleton(new ConfigurationBuilder().Build()); + var services = new ServiceCollection(); + services.AddAuthentication().AddFacebook(); var sp = services.BuildServiceProvider(); var schemeProvider = sp.GetRequiredService(); var scheme = await schemeProvider.GetSchemeAsync(FacebookDefaults.AuthenticationScheme); @@ -44,7 +42,7 @@ namespace Microsoft.AspNetCore.Authentication.Facebook { var server = CreateServer( app => { }, - services => services.AddFacebookAuthentication(o => o.SignInScheme = "Whatever"), + services => services.AddAuthentication().AddFacebook(o => o.SignInScheme = "Whatever"), context => { // REVIEW: Gross. @@ -60,7 +58,7 @@ namespace Microsoft.AspNetCore.Authentication.Facebook { var server = CreateServer( app => { }, - services => services.AddFacebookAuthentication(o => o.AppId = "Whatever"), + services => services.AddAuthentication().AddFacebook(o => o.AppId = "Whatever"), context => { // REVIEW: Gross. diff --git a/test/Microsoft.AspNetCore.Authentication.Test/GoogleTests.cs b/test/Microsoft.AspNetCore.Authentication.Test/GoogleTests.cs index 2eae266702..3bfea45df8 100644 --- a/test/Microsoft.AspNetCore.Authentication.Test/GoogleTests.cs +++ b/test/Microsoft.AspNetCore.Authentication.Test/GoogleTests.cs @@ -29,7 +29,8 @@ namespace Microsoft.AspNetCore.Authentication.Google [Fact] public async Task VerifySchemeDefaults() { - var services = new ServiceCollection().AddGoogleAuthentication().AddSingleton(new ConfigurationBuilder().Build()); + var services = new ServiceCollection(); + services.AddAuthentication().AddGoogle(); var sp = services.BuildServiceProvider(); var schemeProvider = sp.GetRequiredService(); var scheme = await schemeProvider.GetSchemeAsync(GoogleDefaults.AuthenticationScheme); diff --git a/test/Microsoft.AspNetCore.Authentication.Test/JwtBearerTests.cs b/test/Microsoft.AspNetCore.Authentication.Test/JwtBearerTests.cs index a9b158d2b0..c7153ded30 100644 --- a/test/Microsoft.AspNetCore.Authentication.Test/JwtBearerTests.cs +++ b/test/Microsoft.AspNetCore.Authentication.Test/JwtBearerTests.cs @@ -29,7 +29,8 @@ namespace Microsoft.AspNetCore.Authentication.JwtBearer [Fact] public async Task VerifySchemeDefaults() { - var services = new ServiceCollection().AddJwtBearerAuthentication().AddSingleton(new ConfigurationBuilder().Build()); + var services = new ServiceCollection(); + services.AddAuthentication().AddJwtBearer(); var sp = services.BuildServiceProvider(); var schemeProvider = sp.GetRequiredService(); var scheme = await schemeProvider.GetSchemeAsync(JwtBearerDefaults.AuthenticationScheme); @@ -747,7 +748,7 @@ namespace Microsoft.AspNetCore.Authentication.JwtBearer } }); }) - .ConfigureServices(services => services.AddJwtBearerAuthentication(options)); + .ConfigureServices(services => services.AddAuthentication().AddJwtBearer(options)); return new TestServer(builder); } diff --git a/test/Microsoft.AspNetCore.Authentication.Test/MicrosoftAccountTests.cs b/test/Microsoft.AspNetCore.Authentication.Test/MicrosoftAccountTests.cs index f516940432..941dd13481 100644 --- a/test/Microsoft.AspNetCore.Authentication.Test/MicrosoftAccountTests.cs +++ b/test/Microsoft.AspNetCore.Authentication.Test/MicrosoftAccountTests.cs @@ -30,7 +30,8 @@ namespace Microsoft.AspNetCore.Authentication.Tests.MicrosoftAccount [Fact] public async Task VerifySchemeDefaults() { - var services = new ServiceCollection().AddMicrosoftAccountAuthentication().AddSingleton(new ConfigurationBuilder().Build()); + var services = new ServiceCollection(); + services.AddAuthentication().AddMicrosoftAccount(); var sp = services.BuildServiceProvider(); var schemeProvider = sp.GetRequiredService(); var scheme = await schemeProvider.GetSchemeAsync(MicrosoftAccountDefaults.AuthenticationScheme); diff --git a/test/Microsoft.AspNetCore.Authentication.Test/OAuthTests.cs b/test/Microsoft.AspNetCore.Authentication.Test/OAuthTests.cs index 62d11e52aa..ea0c941c91 100644 --- a/test/Microsoft.AspNetCore.Authentication.Test/OAuthTests.cs +++ b/test/Microsoft.AspNetCore.Authentication.Test/OAuthTests.cs @@ -19,7 +19,8 @@ namespace Microsoft.AspNetCore.Authentication.OAuth [Fact] public async Task VerifySchemeDefaults() { - var services = new ServiceCollection().AddOAuthAuthentication("oauth", o => { }); + var services = new ServiceCollection(); + services.AddAuthentication().AddOAuth("oauth", o => { }); var sp = services.BuildServiceProvider(); var schemeProvider = sp.GetRequiredService(); var scheme = await schemeProvider.GetSchemeAsync("oauth"); @@ -33,7 +34,7 @@ namespace Microsoft.AspNetCore.Authentication.OAuth { var server = CreateServer( app => { }, - services => services.AddOAuthAuthentication("weeblie", o => + services => services.AddAuthentication().AddOAuth("weeblie", o => { o.SignInScheme = "whatever"; o.CallbackPath = "/"; @@ -56,7 +57,7 @@ namespace Microsoft.AspNetCore.Authentication.OAuth { var server = CreateServer( app => { }, - services => services.AddOAuthAuthentication("weeblie", o => + services => services.AddAuthentication().AddOAuth("weeblie", o => { o.SignInScheme = "whatever"; o.ClientId = "Whatever;"; @@ -79,7 +80,7 @@ namespace Microsoft.AspNetCore.Authentication.OAuth { var server = CreateServer( app => { }, - services => services.AddOAuthAuthentication("weeblie", o => + services => services.AddAuthentication().AddOAuth("weeblie", o => { o.ClientId = "Whatever;"; o.ClientSecret = "Whatever;"; @@ -102,7 +103,7 @@ namespace Microsoft.AspNetCore.Authentication.OAuth { var server = CreateServer( app => { }, - services => services.AddOAuthAuthentication("weeblie", o => + services => services.AddAuthentication().AddOAuth("weeblie", o => { o.ClientId = "Whatever;"; o.ClientSecret = "Whatever;"; @@ -125,7 +126,7 @@ namespace Microsoft.AspNetCore.Authentication.OAuth { var server = CreateServer( app => { }, - services => services.AddOAuthAuthentication("weeblie", o => + services => services.AddAuthentication().AddOAuth("weeblie", o => { o.ClientId = "Whatever;"; o.ClientSecret = "Whatever;"; @@ -148,7 +149,7 @@ namespace Microsoft.AspNetCore.Authentication.OAuth { var server = CreateServer( app => { }, - s => s.AddOAuthAuthentication( + s => s.AddAuthentication().AddOAuth( "Weblie", opt => { @@ -180,7 +181,7 @@ namespace Microsoft.AspNetCore.Authentication.OAuth { var server = CreateServer( app => { }, - s => s.AddOAuthAuthentication( + s => s.AddAuthentication().AddOAuth( "Weblie", opt => { diff --git a/test/Microsoft.AspNetCore.Authentication.Test/TwitterTests.cs b/test/Microsoft.AspNetCore.Authentication.Test/TwitterTests.cs index 76f6b1aad9..1c387d889a 100644 --- a/test/Microsoft.AspNetCore.Authentication.Test/TwitterTests.cs +++ b/test/Microsoft.AspNetCore.Authentication.Test/TwitterTests.cs @@ -10,7 +10,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.TestHost; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Xunit; @@ -21,7 +20,8 @@ namespace Microsoft.AspNetCore.Authentication.Twitter [Fact] public async Task VerifySchemeDefaults() { - var services = new ServiceCollection().AddTwitterAuthentication().AddSingleton(new ConfigurationBuilder().Build()); + var services = new ServiceCollection(); + services.AddAuthentication().AddTwitter(); var sp = services.BuildServiceProvider(); var schemeProvider = sp.GetRequiredService(); var scheme = await schemeProvider.GetSchemeAsync(TwitterDefaults.AuthenticationScheme);