From f8733aa1030569dcd934f48e3fc1bd0dd0df14b5 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Thu, 3 Sep 2015 15:43:56 -0700 Subject: [PATCH] Fix cookie authentication type regression --- .../IdentityServiceCollectionExtensions.cs | 15 ++++++--------- .../UserClaimsPrincipalFactory.cs | 2 +- .../FunctionalTest.cs | 8 ++++---- .../UserClaimsPrincipalFactoryTest.cs | 2 +- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/Microsoft.AspNet.Identity/IdentityServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Identity/IdentityServiceCollectionExtensions.cs index 1762e5c11e..c87ccffbea 100644 --- a/src/Microsoft.AspNet.Identity/IdentityServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Identity/IdentityServiceCollectionExtensions.cs @@ -2,9 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Authentication; using Microsoft.AspNet.Identity; -using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection.Extensions; namespace Microsoft.Framework.DependencyInjection @@ -45,7 +43,11 @@ namespace Microsoft.Framework.DependencyInjection { // Services used by identity services.AddOptions(); - services.AddAuthentication(); + services.AddAuthentication(options => + { + // This is the Default value for ExternalCookieAuthenticationScheme + options.SignInScheme = new IdentityCookieOptions().ExternalCookieAuthenticationScheme; + }); // Identity services services.TryAddSingleton(); @@ -64,13 +66,8 @@ namespace Microsoft.Framework.DependencyInjection if (setupAction != null) { - services.Configure(setupAction); + services.Configure(setupAction); } - services.Configure(options => - { - // This is the Default value for ExternalCookieAuthenticationScheme - options.SignInScheme = new IdentityCookieOptions().ExternalCookieAuthenticationScheme; - }); return new IdentityBuilder(typeof(TUser), typeof(TRole), services); } diff --git a/src/Microsoft.AspNet.Identity/UserClaimsPrincipalFactory.cs b/src/Microsoft.AspNet.Identity/UserClaimsPrincipalFactory.cs index 5430a94c83..7b89e0867c 100644 --- a/src/Microsoft.AspNet.Identity/UserClaimsPrincipalFactory.cs +++ b/src/Microsoft.AspNet.Identity/UserClaimsPrincipalFactory.cs @@ -85,7 +85,7 @@ namespace Microsoft.AspNet.Identity } var userId = await UserManager.GetUserIdAsync(user); var userName = await UserManager.GetUserNameAsync(user); - var id = new ClaimsIdentity(Options.Cookies.TwoFactorRememberMeCookieAuthenticationScheme, + var id = new ClaimsIdentity(Options.Cookies.ApplicationCookieAuthenticationScheme, Options.ClaimsIdentity.UserNameClaimType, Options.ClaimsIdentity.RoleClaimType); id.AddClaim(new Claim(Options.ClaimsIdentity.UserIdClaimType, userId)); diff --git a/test/Microsoft.AspNet.Identity.InMemory.Test/FunctionalTest.cs b/test/Microsoft.AspNet.Identity.InMemory.Test/FunctionalTest.cs index 2ab22326c3..557904df85 100644 --- a/test/Microsoft.AspNet.Identity.InMemory.Test/FunctionalTest.cs +++ b/test/Microsoft.AspNet.Identity.InMemory.Test/FunctionalTest.cs @@ -147,7 +147,7 @@ namespace Microsoft.AspNet.Identity.InMemory var transaction2 = await SendAsync(server, "http://example.com/twofactorRememeber"); transaction2.Response.StatusCode.ShouldBe(HttpStatusCode.OK); - string setCookie = transaction2.SetCookie; + var setCookie = transaction2.SetCookie; setCookie.ShouldContain(new IdentityCookieOptions().TwoFactorRememberMeCookieAuthenticationScheme + "="); setCookie.ShouldContain("; expires="); @@ -170,9 +170,9 @@ namespace Microsoft.AspNet.Identity.InMemory var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Add("Cookie", cookie); - HttpResponseMessage response2 = await server.CreateClient().SendAsync(request); - string text = await response2.Content.ReadAsStringAsync(); - XElement me = XElement.Parse(text); + var response2 = await server.CreateClient().SendAsync(request); + var text = await response2.Content.ReadAsStringAsync(); + var me = XElement.Parse(text); return me; } diff --git a/test/Microsoft.AspNet.Identity.Test/UserClaimsPrincipalFactoryTest.cs b/test/Microsoft.AspNet.Identity.Test/UserClaimsPrincipalFactoryTest.cs index 4581c4d27f..2a3aff8713 100644 --- a/test/Microsoft.AspNet.Identity.Test/UserClaimsPrincipalFactoryTest.cs +++ b/test/Microsoft.AspNet.Identity.Test/UserClaimsPrincipalFactoryTest.cs @@ -83,7 +83,7 @@ namespace Microsoft.AspNet.Identity.Test var manager = userManager.Object; Assert.NotNull(identity); Assert.Equal(1, principal.Identities.Count()); - Assert.Equal(identityOptions.Cookies.TwoFactorRememberMeCookieAuthenticationScheme, identity.AuthenticationType); + Assert.Equal(identityOptions.Cookies.ApplicationCookieAuthenticationScheme, identity.AuthenticationType); var claims = identity.Claims.ToList(); Assert.NotNull(claims); Assert.True(