diff --git a/samples/IdentitySample.Mvc/Startup.cs b/samples/IdentitySample.Mvc/Startup.cs index ae402d5c0a..5b5641f6ea 100644 --- a/samples/IdentitySample.Mvc/Startup.cs +++ b/samples/IdentitySample.Mvc/Startup.cs @@ -41,7 +41,7 @@ namespace IdentitySamples // Add Identity services to the services container services.AddIdentitySqlServer() - .AddHttpSignIn() + .AddAuthentication() .SetupOptions(options => { options.Password.RequireDigit = false; @@ -65,7 +65,7 @@ namespace IdentitySamples // Add cookie-based authentication to the request pipeline app.UseCookieAuthentication(new CookieAuthenticationOptions { - AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, + AuthenticationType = ClaimsIdentityOptions.DefaultAuthenticationType, LoginPath = new PathString("/Account/Login"), Notifications = new CookieAuthenticationNotifications { diff --git a/src/Microsoft.AspNet.Identity.Authentication/IdentityBuilderExtensions.cs b/src/Microsoft.AspNet.Identity.Authentication/IdentityBuilderExtensions.cs index b4e81a0593..2ca3a34adc 100644 --- a/src/Microsoft.AspNet.Identity.Authentication/IdentityBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Identity.Authentication/IdentityBuilderExtensions.cs @@ -8,7 +8,7 @@ namespace Microsoft.Framework.DependencyInjection { public static class IdentityBuilderExtensions { - public static IdentityBuilder AddHttpSignIn(this IdentityBuilder builder) + public static IdentityBuilder AddAuthentication(this IdentityBuilder builder) where TUser : class where TRole : class { diff --git a/src/Microsoft.AspNet.Identity/ClaimsIdentityOptions.cs b/src/Microsoft.AspNet.Identity/ClaimsIdentityOptions.cs index eb3ac935ea..3ef007b107 100644 --- a/src/Microsoft.AspNet.Identity/ClaimsIdentityOptions.cs +++ b/src/Microsoft.AspNet.Identity/ClaimsIdentityOptions.cs @@ -11,10 +11,11 @@ namespace Microsoft.AspNet.Identity /// ClaimType used for the security stamp by default /// public static readonly string DefaultSecurityStampClaimType = "AspNet.Identity.SecurityStamp"; + public static readonly string DefaultAuthenticationType = typeof(ClaimsIdentityOptions).Namespace + ".Application"; public ClaimsIdentityOptions() { - AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie; + AuthenticationType = DefaultAuthenticationType; RoleClaimType = ClaimTypes.Role; SecurityStampClaimType = DefaultSecurityStampClaimType; UserIdClaimType = ClaimTypes.NameIdentifier; diff --git a/src/Microsoft.AspNet.Identity/DefaultAuthenticationTypes.cs b/src/Microsoft.AspNet.Identity/DefaultAuthenticationTypes.cs deleted file mode 100644 index 384bf8794f..0000000000 --- a/src/Microsoft.AspNet.Identity/DefaultAuthenticationTypes.cs +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace Microsoft.AspNet.Identity -{ - public static class DefaultAuthenticationTypes - { - public static readonly string ApplicationCookie = typeof(DefaultAuthenticationTypes).Namespace + ".Application"; - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Identity/Microsoft.AspNet.Identity.kproj b/src/Microsoft.AspNet.Identity/Microsoft.AspNet.Identity.kproj index ee7363ba94..fa2772ca76 100644 --- a/src/Microsoft.AspNet.Identity/Microsoft.AspNet.Identity.kproj +++ b/src/Microsoft.AspNet.Identity/Microsoft.AspNet.Identity.kproj @@ -25,7 +25,6 @@ - diff --git a/test/Microsoft.AspNet.Identity.Authentication.Test/HttpSignInTest.cs b/test/Microsoft.AspNet.Identity.Authentication.Test/HttpSignInTest.cs index f82391ca06..388382ac28 100644 --- a/test/Microsoft.AspNet.Identity.Authentication.Test/HttpSignInTest.cs +++ b/test/Microsoft.AspNet.Identity.Authentication.Test/HttpSignInTest.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Identity.Authentication.Test // IBuilder app = new Builder(new ServiceCollection().BuildServiceProvider()); // app.UseCookieAuthentication(new CookieAuthenticationOptions // { - // AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie + // AuthenticationType = ClaimsIdentityOptions.DefaultAuthenticationType // }); // TODO: how to functionally test context? @@ -311,7 +311,7 @@ namespace Microsoft.AspNet.Identity.Authentication.Test var context = new Mock(); var response = new Mock(); context.Setup(c => c.Response).Returns(response.Object).Verifiable(); - response.Setup(r => r.SignIn(It.Is(i => i.AuthenticationType == DefaultAuthenticationTypes.ApplicationCookie), It.Is(v => v.IsPersistent == isPersistent))).Verifiable(); + response.Setup(r => r.SignIn(It.Is(i => i.AuthenticationType == ClaimsIdentityOptions.DefaultAuthenticationType), It.Is(v => v.IsPersistent == isPersistent))).Verifiable(); var id = new ClaimsIdentity(HttpAuthenticationManager.TwoFactorRememberedAuthenticationType); id.AddClaim(new Claim(ClaimTypes.Name, user.Id)); var authResult = new AuthenticationResult(id, new AuthenticationProperties(), new AuthenticationDescription()); @@ -321,7 +321,7 @@ namespace Microsoft.AspNet.Identity.Authentication.Test var signInService = new HttpAuthenticationManager(contextAccessor.Object); var roleManager = MockHelpers.MockRoleManager(); var claimsFactory = new Mock>(manager.Object, roleManager.Object); - claimsFactory.Setup(m => m.CreateAsync(user, manager.Object.Options.ClaimsIdentity, CancellationToken.None)).ReturnsAsync(new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie)).Verifiable(); + claimsFactory.Setup(m => m.CreateAsync(user, manager.Object.Options.ClaimsIdentity, CancellationToken.None)).ReturnsAsync(new ClaimsIdentity(ClaimsIdentityOptions.DefaultAuthenticationType)).Verifiable(); var helper = new SignInManager(manager.Object, signInService, claimsFactory.Object); // Act diff --git a/test/Microsoft.AspNet.Identity.Authentication.Test/SecurityStampValidatorTest.cs b/test/Microsoft.AspNet.Identity.Authentication.Test/SecurityStampValidatorTest.cs index 589ee700a7..74c9c88ca6 100644 --- a/test/Microsoft.AspNet.Identity.Authentication.Test/SecurityStampValidatorTest.cs +++ b/test/Microsoft.AspNet.Identity.Authentication.Test/SecurityStampValidatorTest.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Identity.Authentication.Test { var httpContext = new Mock(); httpContext.Setup(c => c.ApplicationServices).Returns(new ServiceCollection().BuildServiceProvider()); - var id = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie); + var id = new ClaimsIdentity(ClaimsIdentityOptions.DefaultAuthenticationType); var ticket = new AuthenticationTicket(id, new AuthenticationProperties { IssuedUtc = DateTimeOffset.UtcNow }); var context = new CookieValidateIdentityContext(httpContext.Object, ticket, new CookieAuthenticationOptions()); await Assert.ThrowsAsync(() => SecurityStampValidator.OnValidateIdentity(TimeSpan.Zero).Invoke(context)); @@ -46,7 +46,7 @@ namespace Microsoft.AspNet.Identity.Authentication.Test var services = new ServiceCollection(); services.AddInstance(signInManager.Object); httpContext.Setup(c => c.ApplicationServices).Returns(services.BuildServiceProvider()); - var id = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie); + var id = new ClaimsIdentity(ClaimsIdentityOptions.DefaultAuthenticationType); id.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id)); var ticket = new AuthenticationTicket(id, new AuthenticationProperties { IssuedUtc = DateTimeOffset.UtcNow, IsPersistent = isPersistent }); @@ -74,7 +74,7 @@ namespace Microsoft.AspNet.Identity.Authentication.Test var services = new ServiceCollection(); services.AddInstance(signInManager.Object); httpContext.Setup(c => c.ApplicationServices).Returns(services.BuildServiceProvider()); - var id = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie); + var id = new ClaimsIdentity(ClaimsIdentityOptions.DefaultAuthenticationType); id.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id)); var ticket = new AuthenticationTicket(id, new AuthenticationProperties { IssuedUtc = DateTimeOffset.UtcNow }); @@ -102,7 +102,7 @@ namespace Microsoft.AspNet.Identity.Authentication.Test var services = new ServiceCollection(); services.AddInstance(signInManager.Object); httpContext.Setup(c => c.ApplicationServices).Returns(services.BuildServiceProvider()); - var id = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie); + var id = new ClaimsIdentity(ClaimsIdentityOptions.DefaultAuthenticationType); id.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id)); var ticket = new AuthenticationTicket(id, new AuthenticationProperties()); @@ -131,7 +131,7 @@ namespace Microsoft.AspNet.Identity.Authentication.Test var services = new ServiceCollection(); services.AddInstance(signInManager.Object); httpContext.Setup(c => c.ApplicationServices).Returns(services.BuildServiceProvider()); - var id = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie); + var id = new ClaimsIdentity(ClaimsIdentityOptions.DefaultAuthenticationType); id.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id)); var ticket = new AuthenticationTicket(id, new AuthenticationProperties { IssuedUtc = DateTimeOffset.UtcNow }); diff --git a/test/Microsoft.AspNet.Identity.EntityFramework.InMemory.Test/InMemoryUserStoreTest.cs b/test/Microsoft.AspNet.Identity.EntityFramework.InMemory.Test/InMemoryUserStoreTest.cs index 70893ba36b..c92b9f3592 100644 --- a/test/Microsoft.AspNet.Identity.EntityFramework.InMemory.Test/InMemoryUserStoreTest.cs +++ b/test/Microsoft.AspNet.Identity.EntityFramework.InMemory.Test/InMemoryUserStoreTest.cs @@ -583,7 +583,7 @@ namespace Microsoft.AspNet.Identity.EntityFramework.InMemory.Test var claimsFactory = new ClaimsIdentityFactory(manager, role); var identity = await claimsFactory.CreateAsync(user, new ClaimsIdentityOptions()); - Assert.Equal(DefaultAuthenticationTypes.ApplicationCookie, identity.AuthenticationType); + Assert.Equal(ClaimsIdentityOptions.DefaultAuthenticationType, identity.AuthenticationType); var claims = identity.Claims.ToList(); Assert.NotNull(claims); Assert.True( diff --git a/test/Microsoft.AspNet.Identity.EntityFramework.Test/UserStoreTest.cs b/test/Microsoft.AspNet.Identity.EntityFramework.Test/UserStoreTest.cs index 5814656781..ffef48a667 100644 --- a/test/Microsoft.AspNet.Identity.EntityFramework.Test/UserStoreTest.cs +++ b/test/Microsoft.AspNet.Identity.EntityFramework.Test/UserStoreTest.cs @@ -693,7 +693,7 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test var claimsFactory = new ClaimsIdentityFactory(manager, role); var identity = await claimsFactory.CreateAsync(user, new ClaimsIdentityOptions()); - Assert.Equal(DefaultAuthenticationTypes.ApplicationCookie, identity.AuthenticationType); + Assert.Equal(ClaimsIdentityOptions.DefaultAuthenticationType, identity.AuthenticationType); var claims = identity.Claims.ToList(); Assert.NotNull(claims); Assert.True( @@ -717,7 +717,7 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test // Remove a role claim and make sure its not there IdentityResultAssert.IsSuccess(await role.RemoveClaimAsync(local, localClaims[0])); identity = await claimsFactory.CreateAsync(user, new ClaimsIdentityOptions()); - Assert.Equal(DefaultAuthenticationTypes.ApplicationCookie, identity.AuthenticationType); + Assert.Equal(ClaimsIdentityOptions.DefaultAuthenticationType, identity.AuthenticationType); claims = identity.Claims.ToList(); Assert.False(claims.Any(c => c.Type == localClaims[0].Type && c.Value == localClaims[0].Value)); Assert.True(claims.Any(c => c.Type == localClaims[1].Type && c.Value == localClaims[1].Value)); diff --git a/test/Microsoft.AspNet.Identity.EntityFramework.Test/UserStoreTestBase.cs b/test/Microsoft.AspNet.Identity.EntityFramework.Test/UserStoreTestBase.cs index 066dc80bac..76787d3bcf 100644 --- a/test/Microsoft.AspNet.Identity.EntityFramework.Test/UserStoreTestBase.cs +++ b/test/Microsoft.AspNet.Identity.EntityFramework.Test/UserStoreTestBase.cs @@ -583,7 +583,7 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test var claimsFactory = new ClaimsIdentityFactory(manager, role); var identity = await claimsFactory.CreateAsync(user, new ClaimsIdentityOptions()); - Assert.Equal(DefaultAuthenticationTypes.ApplicationCookie, identity.AuthenticationType); + Assert.Equal(ClaimsIdentityOptions.DefaultAuthenticationType, identity.AuthenticationType); var claims = identity.Claims.ToList(); Assert.NotNull(claims); Assert.True( @@ -607,7 +607,7 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test // Remove a role claim and make sure its not there IdentityResultAssert.IsSuccess(await role.RemoveClaimAsync(local, localClaims[0])); identity = await claimsFactory.CreateAsync(user, new ClaimsIdentityOptions()); - Assert.Equal(DefaultAuthenticationTypes.ApplicationCookie, identity.AuthenticationType); + Assert.Equal(ClaimsIdentityOptions.DefaultAuthenticationType, identity.AuthenticationType); claims = identity.Claims.ToList(); Assert.False(claims.Any(c => c.Type == localClaims[0].Type && c.Value == localClaims[0].Value)); Assert.True(claims.Any(c => c.Type == localClaims[1].Type && c.Value == localClaims[1].Value)); diff --git a/test/Microsoft.AspNet.Identity.InMemory.Test/HttpSignInTest.cs b/test/Microsoft.AspNet.Identity.InMemory.Test/HttpSignInTest.cs index 2cb08b5a56..62c5135778 100644 --- a/test/Microsoft.AspNet.Identity.InMemory.Test/HttpSignInTest.cs +++ b/test/Microsoft.AspNet.Identity.InMemory.Test/HttpSignInTest.cs @@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test IBuilder app = new Builder.Builder(new ServiceCollection().BuildServiceProvider()); app.UseCookieAuthentication(new CookieAuthenticationOptions { - AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie + AuthenticationType = ClaimsIdentityOptions.DefaultAuthenticationType }); var context = new Mock(); @@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test app.UseServices(services => { services.AddInstance(contextAccessor.Object); - services.AddIdentity().AddInMemory().AddHttpSignIn(); + services.AddIdentity().AddInMemory().AddAuthentication(); }); // Act diff --git a/test/Microsoft.AspNet.Identity.Test/ClaimsIdentityFactoryTest.cs b/test/Microsoft.AspNet.Identity.Test/ClaimsIdentityFactoryTest.cs index 5b23b31f8f..c0c04e0e0f 100644 --- a/test/Microsoft.AspNet.Identity.Test/ClaimsIdentityFactoryTest.cs +++ b/test/Microsoft.AspNet.Identity.Test/ClaimsIdentityFactoryTest.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Identity.Test async () => await factory.CreateAsync(new TestUser(), null)); } - #if NET45 +#if NET45 //TODO: Mock fails in K (this works fine in net45) [Theory] [InlineData(false, false, false)] @@ -77,7 +77,7 @@ namespace Microsoft.AspNet.Identity.Test // Assert var manager = userManager.Object; Assert.NotNull(identity); - Assert.Equal(DefaultAuthenticationTypes.ApplicationCookie, identity.AuthenticationType); + Assert.Equal(ClaimsIdentityOptions.DefaultAuthenticationType, identity.AuthenticationType); var claims = identity.Claims.ToList(); Assert.NotNull(claims); Assert.True( diff --git a/test/Shared/UserManagerTestBase.cs b/test/Shared/UserManagerTestBase.cs index e9aeb84340..50895b4a0b 100644 --- a/test/Shared/UserManagerTestBase.cs +++ b/test/Shared/UserManagerTestBase.cs @@ -413,7 +413,7 @@ namespace Microsoft.AspNet.Identity.Test var identity = await claimsFactory.CreateAsync(user, new ClaimsIdentityOptions()); var claims = identity.Claims.ToList(); Assert.NotNull(claims); - Assert.Equal(DefaultAuthenticationTypes.ApplicationCookie, identity.AuthenticationType); + Assert.Equal(ClaimsIdentityOptions.DefaultAuthenticationType, identity.AuthenticationType); Assert.True( claims.Any(c => c.Type == manager.Options.ClaimsIdentity.UserNameClaimType && c.Value == user.UserName)); Assert.True(claims.Any(c => c.Type == manager.Options.ClaimsIdentity.UserIdClaimType && c.Value == user.Id));