From d4abd5499a809019770a415f7c32d57c3aecd137 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Fri, 30 Jun 2017 14:09:45 -0700 Subject: [PATCH] React to API changes in CookieAuthenticationOptions --- ...ntityServiceServiceCollectionExtensions.cs | 16 +++++++------- .../SessionManager.cs | 2 +- .../IdentityServiceCollectionExtensions.cs | 21 +++++++++++-------- .../FunctionalTest.cs | 2 +- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/Microsoft.AspNetCore.Identity.Service/IdentityServiceServiceCollectionExtensions.cs b/src/Microsoft.AspNetCore.Identity.Service/IdentityServiceServiceCollectionExtensions.cs index 5a0dab6d45..bd80c5cd05 100644 --- a/src/Microsoft.AspNetCore.Identity.Service/IdentityServiceServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNetCore.Identity.Service/IdentityServiceServiceCollectionExtensions.cs @@ -55,20 +55,20 @@ namespace Microsoft.Extensions.DependencyInjection services.AddAuthentication().AddCookie(IdentityServiceOptions.CookieAuthenticationScheme, options => { - options.CookieHttpOnly = true; - options.CookieSecure = CookieSecurePolicy.Always; - options.CookiePath = "/tfp/IdentityService/signinsignup"; - options.CookieName = IdentityServiceOptions.AuthenticationCookieName; + options.Cookie.HttpOnly = true; + options.Cookie.SecurePolicy = CookieSecurePolicy.Always; + options.Cookie.Path = "/tfp/IdentityService/signinsignup"; + options.Cookie.Name = IdentityServiceOptions.AuthenticationCookieName; }); services.ConfigureApplicationCookie(options => { options.LoginPath = $"/tfp/IdentityService/Account/Login"; options.AccessDeniedPath = $"/tfp/IdentityService/Account/Denied"; - options.CookiePath = $"/tfp/IdentityService"; + options.Cookie.Path = $"/tfp/IdentityService"; }); - services.ConfigureApplicationCookie(options => options.CookiePath = $"/tfp/IdentityService"); - services.Configure(IdentityConstants.TwoFactorRememberMeScheme, options => options.CookiePath = $"/tfp/IdentityService"); - services.Configure(IdentityConstants.TwoFactorUserIdScheme, options => options.CookiePath = $"/tfp/IdentityService"); + services.ConfigureApplicationCookie(options => options.Cookie.Path = $"/tfp/IdentityService"); + services.Configure(IdentityConstants.TwoFactorRememberMeScheme, options => options.Cookie.Path = $"/tfp/IdentityService"); + services.Configure(IdentityConstants.TwoFactorUserIdScheme, options => options.Cookie.Path = $"/tfp/IdentityService"); services.AddTransient, IdentityServiceAuthorizationOptionsSetup>(); diff --git a/src/Microsoft.AspNetCore.Identity.Service/SessionManager.cs b/src/Microsoft.AspNetCore.Identity.Service/SessionManager.cs index 7b302d3cc7..c83f9df2c0 100644 --- a/src/Microsoft.AspNetCore.Identity.Service/SessionManager.cs +++ b/src/Microsoft.AspNetCore.Identity.Service/SessionManager.cs @@ -123,7 +123,7 @@ namespace Microsoft.AspNetCore.Identity.Service var clientId = application.FindFirstValue(IdentityServiceClaimTypes.ClientId); var logoutUris = application.FindAll(IdentityServiceClaimTypes.LogoutRedirectUri); - var duration = _sessionCookieOptions.ExpireTimeSpan; + var duration = _sessionCookieOptions.Cookie.Expiration ?? default(TimeSpan); var expiration = _timeStampManager.GetTimeStampInEpochTime(duration); var identity = new ClaimsIdentity( diff --git a/src/Microsoft.AspNetCore.Identity/IdentityServiceCollectionExtensions.cs b/src/Microsoft.AspNetCore.Identity/IdentityServiceCollectionExtensions.cs index 71b4c325bb..61c6048d10 100644 --- a/src/Microsoft.AspNetCore.Identity/IdentityServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNetCore.Identity/IdentityServiceCollectionExtensions.cs @@ -68,23 +68,26 @@ namespace Microsoft.Extensions.DependencyInjection options.DefaultAuthenticateScheme = IdentityConstants.ApplicationScheme; options.DefaultChallengeScheme = IdentityConstants.ApplicationScheme; options.DefaultSignInScheme = IdentityConstants.ExternalScheme; - }).AddCookie(IdentityConstants.ApplicationScheme, o => + }) + .AddCookie(IdentityConstants.ApplicationScheme, o => { o.LoginPath = new PathString("/Account/Login"); o.Events = new CookieAuthenticationEvents { OnValidatePrincipal = SecurityStampValidator.ValidatePrincipalAsync }; - }).AddCookie(IdentityConstants.ExternalScheme, o => + }) + .AddCookie(IdentityConstants.ExternalScheme, o => { - o.CookieName = IdentityConstants.ExternalScheme; - o.ExpireTimeSpan = TimeSpan.FromMinutes(5); - }).AddCookie(IdentityConstants.TwoFactorRememberMeScheme, - o => o.CookieName = IdentityConstants.TwoFactorRememberMeScheme) + o.Cookie.Name = IdentityConstants.ExternalScheme; + o.Cookie.Expiration = TimeSpan.FromMinutes(5); + }) + .AddCookie(IdentityConstants.TwoFactorRememberMeScheme, + o => o.Cookie.Name = IdentityConstants.TwoFactorRememberMeScheme) .AddCookie(IdentityConstants.TwoFactorUserIdScheme, o => { - o.CookieName = IdentityConstants.TwoFactorUserIdScheme; - o.ExpireTimeSpan = TimeSpan.FromMinutes(5); + o.Cookie.Name = IdentityConstants.TwoFactorUserIdScheme; + o.Cookie.Expiration = TimeSpan.FromMinutes(5); }); // Hosting doesn't add IHttpContextAccessor by default @@ -111,4 +114,4 @@ namespace Microsoft.Extensions.DependencyInjection return new IdentityBuilder(typeof(TUser), typeof(TRole), services); } } -} \ No newline at end of file +} diff --git a/test/Microsoft.AspNetCore.Identity.InMemory.Test/FunctionalTest.cs b/test/Microsoft.AspNetCore.Identity.InMemory.Test/FunctionalTest.cs index d98020a10d..af00e6e0fe 100644 --- a/test/Microsoft.AspNetCore.Identity.InMemory.Test/FunctionalTest.cs +++ b/test/Microsoft.AspNetCore.Identity.InMemory.Test/FunctionalTest.cs @@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Identity.InMemory { services.ConfigureApplicationCookie(options => { - options.ExpireTimeSpan = TimeSpan.FromMinutes(10); + options.Cookie.Expiration = TimeSpan.FromMinutes(10); options.SlidingExpiration = false; }); services.AddSingleton(clock);