Add AddAuthentication(defaultScheme) overload

This commit is contained in:
Hao Kung 2017-07-07 12:04:32 -07:00 committed by Hao Kung
parent 38d33cfbf2
commit df325deaf3
6 changed files with 9 additions and 20 deletions

View File

@ -27,6 +27,9 @@ namespace Microsoft.Extensions.DependencyInjection
return new AuthenticationBuilder(services); 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<AuthenticationOptions> configureOptions) { public static AuthenticationBuilder AddAuthentication(this IServiceCollection services, Action<AuthenticationOptions> configureOptions) {
if (services == null) if (services == null)
{ {

View File

@ -1247,7 +1247,7 @@ namespace Microsoft.AspNetCore.Authentication.Cookies
=> CreateServerWithServices(s => => CreateServerWithServices(s =>
{ {
s.AddSingleton<ISystemClock>(_clock); s.AddSingleton<ISystemClock>(_clock);
s.AddAuthentication(o => o.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(configureOptions); s.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(configureOptions);
s.AddSingleton<IClaimsTransformation, ClaimsTransformer>(); s.AddSingleton<IClaimsTransformation, ClaimsTransformer>();
}, testpath, baseAddress); }, testpath, baseAddress);

View File

@ -79,10 +79,7 @@ namespace Microsoft.AspNetCore.Authentication.Facebook
}, },
services => services =>
{ {
services.AddAuthentication(options => services.AddAuthentication("External")
{
options.DefaultScheme = "External";
})
.AddCookie("External", o => { }) .AddCookie("External", o => { })
.AddFacebook(o => .AddFacebook(o =>
{ {
@ -218,10 +215,7 @@ namespace Microsoft.AspNetCore.Authentication.Facebook
app => app.UseAuthentication(), app => app.UseAuthentication(),
services => services =>
{ {
services.AddAuthentication(options => services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie() .AddCookie()
.AddFacebook(o => .AddFacebook(o =>
{ {

View File

@ -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); return new TestServer(builder);
} }

View File

@ -224,11 +224,7 @@ namespace Microsoft.AspNetCore.Authentication.Tests.MicrosoftAccount
}) })
.ConfigureServices(services => .ConfigureServices(services =>
{ {
services.AddAuthentication(o => services.AddAuthentication(TestExtensions.CookieAuthenticationScheme)
{
o.DefaultScheme = TestExtensions.CookieAuthenticationScheme;
});
services.AddAuthentication()
.AddCookie(TestExtensions.CookieAuthenticationScheme, o => { }) .AddCookie(TestExtensions.CookieAuthenticationScheme, o => { })
.AddMicrosoftAccount(configureOptions); .AddMicrosoftAccount(configureOptions);
}); });

View File

@ -109,11 +109,7 @@ namespace Microsoft.AspNetCore.Authentication.Test.OpenIdConnect
}) })
.ConfigureServices(services => .ConfigureServices(services =>
{ {
services.AddAuthentication(o => services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
{
o.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
});
services.AddAuthentication()
.AddCookie() .AddCookie()
.AddOpenIdConnect(options); .AddOpenIdConnect(options);
}); });