From ef411276d689d8f56fae84d3e65bbee5a91682c2 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Mon, 3 Jul 2017 11:54:01 -0700 Subject: [PATCH] Switch to new Auth API (#1296) --- ...thenticationServiceCollectionExtensions.cs | 7 +++---- ...ntityServiceServiceCollectionExtensions.cs | 2 +- .../IdentityServiceCollectionExtensions.cs | 19 ++++++------------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/samples/IdentityOIDCWebApplicationSample/Extensions/AuthenticationServiceCollectionExtensions.cs b/samples/IdentityOIDCWebApplicationSample/Extensions/AuthenticationServiceCollectionExtensions.cs index b9c7be4a25..102b63605a 100644 --- a/samples/IdentityOIDCWebApplicationSample/Extensions/AuthenticationServiceCollectionExtensions.cs +++ b/samples/IdentityOIDCWebApplicationSample/Extensions/AuthenticationServiceCollectionExtensions.cs @@ -21,10 +21,9 @@ namespace Microsoft.AspNetCore.Authentication.Extensions sharedOptions.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; sharedOptions.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; - }); - - services.AddOpenIdConnectAuthentication(); - services.AddCookieAuthentication(); + }) + .AddOpenIdConnect() + .AddCookie(); return services; } diff --git a/src/Microsoft.AspNetCore.Identity.Service/IdentityServiceServiceCollectionExtensions.cs b/src/Microsoft.AspNetCore.Identity.Service/IdentityServiceServiceCollectionExtensions.cs index 02cc7b4d24..5a0dab6d45 100644 --- a/src/Microsoft.AspNetCore.Identity.Service/IdentityServiceServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNetCore.Identity.Service/IdentityServiceServiceCollectionExtensions.cs @@ -53,7 +53,7 @@ namespace Microsoft.Extensions.DependencyInjection services.AddTransient, IdentityServiceOptionsDefaultSetup>(); services.AddTransient, IdentityServiceOptionsSetup>(); - services.AddCookieAuthentication(IdentityServiceOptions.CookieAuthenticationScheme, options => + services.AddAuthentication().AddCookie(IdentityServiceOptions.CookieAuthenticationScheme, options => { options.CookieHttpOnly = true; options.CookieSecure = CookieSecurePolicy.Always; diff --git a/src/Microsoft.AspNetCore.Identity/IdentityServiceCollectionExtensions.cs b/src/Microsoft.AspNetCore.Identity/IdentityServiceCollectionExtensions.cs index 774cf4161c..71b4c325bb 100644 --- a/src/Microsoft.AspNetCore.Identity/IdentityServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNetCore.Identity/IdentityServiceCollectionExtensions.cs @@ -63,32 +63,25 @@ namespace Microsoft.Extensions.DependencyInjection where TRole : class { // Services used by identity - services.AddAuthenticationCore(options => + services.AddAuthentication(options => { options.DefaultAuthenticateScheme = IdentityConstants.ApplicationScheme; options.DefaultChallengeScheme = IdentityConstants.ApplicationScheme; options.DefaultSignInScheme = IdentityConstants.ExternalScheme; - }); - - services.AddCookieAuthentication(IdentityConstants.ApplicationScheme, o => + }).AddCookie(IdentityConstants.ApplicationScheme, o => { o.LoginPath = new PathString("/Account/Login"); o.Events = new CookieAuthenticationEvents { OnValidatePrincipal = SecurityStampValidator.ValidatePrincipalAsync }; - }); - - services.AddCookieAuthentication(IdentityConstants.ExternalScheme, o => + }).AddCookie(IdentityConstants.ExternalScheme, o => { o.CookieName = IdentityConstants.ExternalScheme; o.ExpireTimeSpan = TimeSpan.FromMinutes(5); - }); - - services.AddCookieAuthentication(IdentityConstants.TwoFactorRememberMeScheme, - o => o.CookieName = IdentityConstants.TwoFactorRememberMeScheme); - - services.AddCookieAuthentication(IdentityConstants.TwoFactorUserIdScheme, o => + }).AddCookie(IdentityConstants.TwoFactorRememberMeScheme, + o => o.CookieName = IdentityConstants.TwoFactorRememberMeScheme) + .AddCookie(IdentityConstants.TwoFactorUserIdScheme, o => { o.CookieName = IdentityConstants.TwoFactorUserIdScheme; o.ExpireTimeSpan = TimeSpan.FromMinutes(5);