Rename Add[HttpSignIn] -> AddAuthentication
Also DefaultAuthenticationTypes.ApplicationCookie -> ClaimsIdentityOptions.DefaultAuthenticationType
This commit is contained in:
parent
076ea0385f
commit
07f72c2fb9
|
|
@ -41,7 +41,7 @@ namespace IdentitySamples
|
|||
|
||||
// Add Identity services to the services container
|
||||
services.AddIdentitySqlServer<ApplicationDbContext, ApplicationUser>()
|
||||
.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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace Microsoft.Framework.DependencyInjection
|
|||
{
|
||||
public static class IdentityBuilderExtensions
|
||||
{
|
||||
public static IdentityBuilder<TUser, TRole> AddHttpSignIn<TUser, TRole>(this IdentityBuilder<TUser, TRole> builder)
|
||||
public static IdentityBuilder<TUser, TRole> AddAuthentication<TUser, TRole>(this IdentityBuilder<TUser, TRole> builder)
|
||||
where TUser : class
|
||||
where TRole : class
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,10 +11,11 @@ namespace Microsoft.AspNet.Identity
|
|||
/// ClaimType used for the security stamp by default
|
||||
/// </summary>
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
|
@ -25,7 +25,6 @@
|
|||
<Compile Include="ClaimsIdentityFactory.cs" />
|
||||
<Compile Include="ClaimsIdentityOptions.cs" />
|
||||
<Compile Include="Crypto.cs" />
|
||||
<Compile Include="DefaultAuthenticationTypes.cs" />
|
||||
<Compile Include="PhoneNumberTokenProvider.cs" />
|
||||
<Compile Include="IAuthenticationManager.cs" />
|
||||
<Compile Include="IClaimsIdentityFactory.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<HttpContext>();
|
||||
var response = new Mock<HttpResponse>();
|
||||
context.Setup(c => c.Response).Returns(response.Object).Verifiable();
|
||||
response.Setup(r => r.SignIn(It.Is<ClaimsIdentity>(i => i.AuthenticationType == DefaultAuthenticationTypes.ApplicationCookie), It.Is<AuthenticationProperties>(v => v.IsPersistent == isPersistent))).Verifiable();
|
||||
response.Setup(r => r.SignIn(It.Is<ClaimsIdentity>(i => i.AuthenticationType == ClaimsIdentityOptions.DefaultAuthenticationType), It.Is<AuthenticationProperties>(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<TestRole>();
|
||||
var claimsFactory = new Mock<ClaimsIdentityFactory<TestUser, TestRole>>(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<TestUser>(manager.Object, signInService, claimsFactory.Object);
|
||||
|
||||
// Act
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Identity.Authentication.Test
|
|||
{
|
||||
var httpContext = new Mock<HttpContext>();
|
||||
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<Exception>(() => SecurityStampValidator.OnValidateIdentity<IdentityUser>(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 });
|
||||
|
|
|
|||
|
|
@ -583,7 +583,7 @@ namespace Microsoft.AspNet.Identity.EntityFramework.InMemory.Test
|
|||
|
||||
var claimsFactory = new ClaimsIdentityFactory<InMemoryUser, IdentityRole>(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(
|
||||
|
|
|
|||
|
|
@ -693,7 +693,7 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test
|
|||
|
||||
var claimsFactory = new ClaimsIdentityFactory<IdentityUser, IdentityRole>(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));
|
||||
|
|
|
|||
|
|
@ -583,7 +583,7 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test
|
|||
|
||||
var claimsFactory = new ClaimsIdentityFactory<ApplicationUser, ApplicationRole>(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));
|
||||
|
|
|
|||
|
|
@ -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<HttpContext>();
|
||||
|
|
@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
|||
app.UseServices(services =>
|
||||
{
|
||||
services.AddInstance(contextAccessor.Object);
|
||||
services.AddIdentity<ApplicationUser, IdentityRole>().AddInMemory().AddHttpSignIn();
|
||||
services.AddIdentity<ApplicationUser, IdentityRole>().AddInMemory().AddAuthentication();
|
||||
});
|
||||
|
||||
// Act
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Reference in New Issue