From df325deaf355f99239c1319932bc28eb3a837372 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Fri, 7 Jul 2017 12:04:32 -0700 Subject: [PATCH] Add AddAuthentication(defaultScheme) overload --- .../AuthenticationServiceCollectionExtensions.cs | 3 +++ .../CookieTests.cs | 2 +- .../FacebookTests.cs | 10 ++-------- .../JwtBearerTests.cs | 2 +- .../MicrosoftAccountTests.cs | 6 +----- .../OpenIdConnect/TestServerBuilder.cs | 6 +----- 6 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/Microsoft.AspNetCore.Authentication/AuthenticationServiceCollectionExtensions.cs b/src/Microsoft.AspNetCore.Authentication/AuthenticationServiceCollectionExtensions.cs index 28291f4196..e1beea7b6e 100644 --- a/src/Microsoft.AspNetCore.Authentication/AuthenticationServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNetCore.Authentication/AuthenticationServiceCollectionExtensions.cs @@ -27,6 +27,9 @@ namespace Microsoft.Extensions.DependencyInjection return new AuthenticationBuilder(services); } + public static AuthenticationBuilder AddAuthentication(this IServiceCollection services, string defaultScheme) + => services.AddAuthentication(o => o.DefaultScheme = defaultScheme); + public static AuthenticationBuilder AddAuthentication(this IServiceCollection services, Action configureOptions) { if (services == null) { diff --git a/test/Microsoft.AspNetCore.Authentication.Test/CookieTests.cs b/test/Microsoft.AspNetCore.Authentication.Test/CookieTests.cs index 83083cbf0a..c711fde493 100644 --- a/test/Microsoft.AspNetCore.Authentication.Test/CookieTests.cs +++ b/test/Microsoft.AspNetCore.Authentication.Test/CookieTests.cs @@ -1247,7 +1247,7 @@ namespace Microsoft.AspNetCore.Authentication.Cookies => CreateServerWithServices(s => { s.AddSingleton(_clock); - s.AddAuthentication(o => o.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(configureOptions); + s.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(configureOptions); s.AddSingleton(); }, testpath, baseAddress); diff --git a/test/Microsoft.AspNetCore.Authentication.Test/FacebookTests.cs b/test/Microsoft.AspNetCore.Authentication.Test/FacebookTests.cs index 35752ec6b0..75de0652e4 100644 --- a/test/Microsoft.AspNetCore.Authentication.Test/FacebookTests.cs +++ b/test/Microsoft.AspNetCore.Authentication.Test/FacebookTests.cs @@ -79,10 +79,7 @@ namespace Microsoft.AspNetCore.Authentication.Facebook }, services => { - services.AddAuthentication(options => - { - options.DefaultScheme = "External"; - }) + services.AddAuthentication("External") .AddCookie("External", o => { }) .AddFacebook(o => { @@ -218,10 +215,7 @@ namespace Microsoft.AspNetCore.Authentication.Facebook app => app.UseAuthentication(), services => { - services.AddAuthentication(options => - { - options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; - }) + services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie() .AddFacebook(o => { diff --git a/test/Microsoft.AspNetCore.Authentication.Test/JwtBearerTests.cs b/test/Microsoft.AspNetCore.Authentication.Test/JwtBearerTests.cs index e001bd9950..97adb21054 100644 --- a/test/Microsoft.AspNetCore.Authentication.Test/JwtBearerTests.cs +++ b/test/Microsoft.AspNetCore.Authentication.Test/JwtBearerTests.cs @@ -748,7 +748,7 @@ namespace Microsoft.AspNetCore.Authentication.JwtBearer } }); }) - .ConfigureServices(services => services.AddAuthentication(o => o.DefaultScheme = JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options)); + .ConfigureServices(services => services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).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 b63ad1f7d6..2e249a833a 100644 --- a/test/Microsoft.AspNetCore.Authentication.Test/MicrosoftAccountTests.cs +++ b/test/Microsoft.AspNetCore.Authentication.Test/MicrosoftAccountTests.cs @@ -224,11 +224,7 @@ namespace Microsoft.AspNetCore.Authentication.Tests.MicrosoftAccount }) .ConfigureServices(services => { - services.AddAuthentication(o => - { - o.DefaultScheme = TestExtensions.CookieAuthenticationScheme; - }); - services.AddAuthentication() + services.AddAuthentication(TestExtensions.CookieAuthenticationScheme) .AddCookie(TestExtensions.CookieAuthenticationScheme, o => { }) .AddMicrosoftAccount(configureOptions); }); diff --git a/test/Microsoft.AspNetCore.Authentication.Test/OpenIdConnect/TestServerBuilder.cs b/test/Microsoft.AspNetCore.Authentication.Test/OpenIdConnect/TestServerBuilder.cs index 4d6a268217..c37da8c043 100644 --- a/test/Microsoft.AspNetCore.Authentication.Test/OpenIdConnect/TestServerBuilder.cs +++ b/test/Microsoft.AspNetCore.Authentication.Test/OpenIdConnect/TestServerBuilder.cs @@ -109,11 +109,7 @@ namespace Microsoft.AspNetCore.Authentication.Test.OpenIdConnect }) .ConfigureServices(services => { - services.AddAuthentication(o => - { - o.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; - }); - services.AddAuthentication() + services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie() .AddOpenIdConnect(options); });