Switch to new Auth API (#1296)

This commit is contained in:
Hao Kung 2017-07-03 11:54:01 -07:00 committed by GitHub
parent 661f6d5103
commit ef411276d6
3 changed files with 10 additions and 18 deletions

View File

@ -21,10 +21,9 @@ namespace Microsoft.AspNetCore.Authentication.Extensions
sharedOptions.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; sharedOptions.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
sharedOptions.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; sharedOptions.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
}); })
.AddOpenIdConnect()
services.AddOpenIdConnectAuthentication(); .AddCookie();
services.AddCookieAuthentication();
return services; return services;
} }

View File

@ -53,7 +53,7 @@ namespace Microsoft.Extensions.DependencyInjection
services.AddTransient<IConfigureOptions<IdentityServiceOptions>, IdentityServiceOptionsDefaultSetup>(); services.AddTransient<IConfigureOptions<IdentityServiceOptions>, IdentityServiceOptionsDefaultSetup>();
services.AddTransient<IConfigureOptions<IdentityServiceOptions>, IdentityServiceOptionsSetup>(); services.AddTransient<IConfigureOptions<IdentityServiceOptions>, IdentityServiceOptionsSetup>();
services.AddCookieAuthentication(IdentityServiceOptions.CookieAuthenticationScheme, options => services.AddAuthentication().AddCookie(IdentityServiceOptions.CookieAuthenticationScheme, options =>
{ {
options.CookieHttpOnly = true; options.CookieHttpOnly = true;
options.CookieSecure = CookieSecurePolicy.Always; options.CookieSecure = CookieSecurePolicy.Always;

View File

@ -63,32 +63,25 @@ namespace Microsoft.Extensions.DependencyInjection
where TRole : class where TRole : class
{ {
// Services used by identity // Services used by identity
services.AddAuthenticationCore(options => services.AddAuthentication(options =>
{ {
options.DefaultAuthenticateScheme = IdentityConstants.ApplicationScheme; options.DefaultAuthenticateScheme = IdentityConstants.ApplicationScheme;
options.DefaultChallengeScheme = IdentityConstants.ApplicationScheme; options.DefaultChallengeScheme = IdentityConstants.ApplicationScheme;
options.DefaultSignInScheme = IdentityConstants.ExternalScheme; options.DefaultSignInScheme = IdentityConstants.ExternalScheme;
}); }).AddCookie(IdentityConstants.ApplicationScheme, o =>
services.AddCookieAuthentication(IdentityConstants.ApplicationScheme, o =>
{ {
o.LoginPath = new PathString("/Account/Login"); o.LoginPath = new PathString("/Account/Login");
o.Events = new CookieAuthenticationEvents o.Events = new CookieAuthenticationEvents
{ {
OnValidatePrincipal = SecurityStampValidator.ValidatePrincipalAsync OnValidatePrincipal = SecurityStampValidator.ValidatePrincipalAsync
}; };
}); }).AddCookie(IdentityConstants.ExternalScheme, o =>
services.AddCookieAuthentication(IdentityConstants.ExternalScheme, o =>
{ {
o.CookieName = IdentityConstants.ExternalScheme; o.CookieName = IdentityConstants.ExternalScheme;
o.ExpireTimeSpan = TimeSpan.FromMinutes(5); o.ExpireTimeSpan = TimeSpan.FromMinutes(5);
}); }).AddCookie(IdentityConstants.TwoFactorRememberMeScheme,
o => o.CookieName = IdentityConstants.TwoFactorRememberMeScheme)
services.AddCookieAuthentication(IdentityConstants.TwoFactorRememberMeScheme, .AddCookie(IdentityConstants.TwoFactorUserIdScheme, o =>
o => o.CookieName = IdentityConstants.TwoFactorRememberMeScheme);
services.AddCookieAuthentication(IdentityConstants.TwoFactorUserIdScheme, o =>
{ {
o.CookieName = IdentityConstants.TwoFactorUserIdScheme; o.CookieName = IdentityConstants.TwoFactorUserIdScheme;
o.ExpireTimeSpan = TimeSpan.FromMinutes(5); o.ExpireTimeSpan = TimeSpan.FromMinutes(5);