зеркало из https://github.com/aspnet/Identity.git
Remove IUser/IRole and TKey from Managers
This commit is contained in:
Родитель
041db7cb69
Коммит
6807da690a
|
@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Identity.Entity
|
|||
/// </summary>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
/// <typeparam name="TUserRole"></typeparam>
|
||||
public class IdentityRole<TKey, TUserRole> : IRole<TKey>
|
||||
public class IdentityRole<TKey, TUserRole>
|
||||
where TUserRole : IdentityUserRole<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Identity.Entity
|
|||
}
|
||||
}
|
||||
|
||||
public class IdentityUser<TKey, TLogin, TRole, TClaim> : IUser<TKey>
|
||||
public class IdentityUser<TKey, TLogin, TRole, TClaim>
|
||||
where TLogin : IdentityUserLogin<TKey>
|
||||
where TRole : IdentityUserRole<TKey>
|
||||
where TClaim : IdentityUserClaim<TKey>
|
||||
|
|
|
@ -8,8 +8,8 @@ using Microsoft.Data.Entity;
|
|||
namespace Microsoft.AspNet.Identity.Entity
|
||||
{
|
||||
public class RoleStore<TRole, TKey> :
|
||||
IQueryableRoleStore<TRole, TKey>
|
||||
where TRole : class,IRole<TKey>
|
||||
IQueryableRoleStore<TRole>
|
||||
where TRole : IdentityRole
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
private bool _disposed;
|
||||
|
@ -80,17 +80,34 @@ namespace Microsoft.AspNet.Identity.Entity
|
|||
await SaveChanges(cancellationToken);
|
||||
}
|
||||
|
||||
public Task<string> GetRoleId(TRole role, CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
return Task.FromResult(role.Id);
|
||||
}
|
||||
|
||||
public Task<string> GetRoleName(TRole role, CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
return Task.FromResult(role.Name);
|
||||
}
|
||||
|
||||
|
||||
public virtual TKey ConvertId(string userId)
|
||||
{
|
||||
return (TKey)Convert.ChangeType(userId, typeof(TKey));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find a role by id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual Task<TRole> FindById(TKey id, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual Task<TRole> FindById(string id, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
return Roles.SingleOrDefaultAsync(r => r.Id.Equals(id), cancellationToken);
|
||||
var roleId = ConvertId(id);
|
||||
return Roles.SingleOrDefaultAsync(r => r.Id.Equals(roleId), cancellationToken);
|
||||
//return GetRoleAggregate(u => u.Id.Equals(id));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Security.Claims;
|
||||
|
@ -16,16 +17,16 @@ namespace Microsoft.AspNet.Identity.Entity
|
|||
}
|
||||
|
||||
public class UserStore<TUser, TRole, TKey, TUserLogin, TUserRole, TUserClaim> :
|
||||
IUserLoginStore<TUser, TKey>,
|
||||
IUserClaimStore<TUser, TKey>,
|
||||
IUserRoleStore<TUser, TKey>,
|
||||
IUserPasswordStore<TUser, TKey>,
|
||||
IUserSecurityStampStore<TUser, TKey>,
|
||||
IQueryableUserStore<TUser, TKey>,
|
||||
IUserEmailStore<TUser, TKey>,
|
||||
IUserPhoneNumberStore<TUser, TKey>,
|
||||
IUserTwoFactorStore<TUser, TKey>,
|
||||
IUserLockoutStore<TUser, TKey>
|
||||
IUserLoginStore<TUser>,
|
||||
IUserClaimStore<TUser>,
|
||||
IUserRoleStore<TUser>,
|
||||
IUserPasswordStore<TUser>,
|
||||
IUserSecurityStampStore<TUser>,
|
||||
IQueryableUserStore<TUser>,
|
||||
IUserEmailStore<TUser>,
|
||||
IUserPhoneNumberStore<TUser>,
|
||||
IUserTwoFactorStore<TUser>,
|
||||
IUserLockoutStore<TUser>
|
||||
where TKey : IEquatable<TKey>
|
||||
where TUser : IdentityUser<TKey, TUserLogin, TUserRole, TUserClaim>
|
||||
where TRole : IdentityRole<TKey, TUserRole>
|
||||
|
@ -65,6 +66,16 @@ namespace Microsoft.AspNet.Identity.Entity
|
|||
//.Include(u => u.Logins)
|
||||
}
|
||||
|
||||
public Task<string> GetUserId(TUser user, CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
return Task.FromResult(Convert.ToString(user.Id, CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
public Task<string> GetUserName(TUser user, CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
return Task.FromResult(user.UserName);
|
||||
}
|
||||
|
||||
public async virtual Task Create(TUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
@ -101,17 +112,23 @@ namespace Microsoft.AspNet.Identity.Entity
|
|||
await SaveChanges(cancellationToken);
|
||||
}
|
||||
|
||||
public virtual TKey ConvertUserId(string userId)
|
||||
{
|
||||
return (TKey)Convert.ChangeType(userId, typeof(TKey));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find a user by id
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual Task<TUser> FindById(TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual Task<TUser> FindById(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
return Users.SingleOrDefaultAsync(u => u.Id.Equals(userId), cancellationToken);
|
||||
var id = ConvertUserId(userId);
|
||||
return Users.SingleOrDefaultAsync(u => u.Id.Equals(id), cancellationToken);
|
||||
// TODO: return GetUserAggregate(u => u.Id.Equals(userId), cancellationToken);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ using System;
|
|||
|
||||
namespace Microsoft.AspNet.Identity.InMemory
|
||||
{
|
||||
public class InMemoryRole : IRole<string>
|
||||
public class InMemoryRole
|
||||
{
|
||||
public InMemoryRole(string roleName)
|
||||
{
|
||||
|
|
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace Microsoft.AspNet.Identity.InMemory
|
||||
{
|
||||
public class InMemoryRoleStore<TRole> : IQueryableRoleStore<TRole, string> where TRole : class,IRole<string>
|
||||
public class InMemoryRoleStore<TRole> : IQueryableRoleStore<TRole> where TRole : InMemoryRole
|
||||
|
||||
{
|
||||
private readonly Dictionary<string, TRole> _roles = new Dictionary<string, TRole>();
|
||||
|
@ -27,6 +27,16 @@ namespace Microsoft.AspNet.Identity.InMemory
|
|||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public Task<string> GetRoleId(TRole role, CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
return Task.FromResult(role.Id);
|
||||
}
|
||||
|
||||
public Task<string> GetRoleName(TRole role, CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
return Task.FromResult(role.Name);
|
||||
}
|
||||
|
||||
public Task Update(TRole role, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
_roles[role.Id] = role;
|
||||
|
|
|
@ -4,7 +4,7 @@ using System.Security.Claims;
|
|||
|
||||
namespace Microsoft.AspNet.Identity.InMemory
|
||||
{
|
||||
public class InMemoryUser : IUser<string>
|
||||
public class InMemoryUser
|
||||
{
|
||||
private readonly IList<Claim> _claims;
|
||||
private readonly IList<UserLoginInfo> _logins;
|
||||
|
|
|
@ -8,16 +8,16 @@ using System.Threading.Tasks;
|
|||
namespace Microsoft.AspNet.Identity.InMemory
|
||||
{
|
||||
public class InMemoryUserStore<TUser> :
|
||||
IUserLoginStore<TUser, string>,
|
||||
IUserRoleStore<TUser, string>,
|
||||
IUserClaimStore<TUser, string>,
|
||||
IUserPasswordStore<TUser, string>,
|
||||
IUserSecurityStampStore<TUser, string>,
|
||||
IUserEmailStore<TUser, string>,
|
||||
IUserLockoutStore<TUser, string>,
|
||||
IUserPhoneNumberStore<TUser, string>,
|
||||
IQueryableUserStore<TUser, string>,
|
||||
IUserTwoFactorStore<TUser, string>
|
||||
IUserLoginStore<TUser>,
|
||||
IUserRoleStore<TUser>,
|
||||
IUserClaimStore<TUser>,
|
||||
IUserPasswordStore<TUser>,
|
||||
IUserSecurityStampStore<TUser>,
|
||||
IUserEmailStore<TUser>,
|
||||
IUserLockoutStore<TUser>,
|
||||
IUserPhoneNumberStore<TUser>,
|
||||
IQueryableUserStore<TUser>,
|
||||
IUserTwoFactorStore<TUser>
|
||||
where TUser : InMemoryUser
|
||||
{
|
||||
private readonly Dictionary<UserLoginInfo, TUser> _logins =
|
||||
|
@ -149,6 +149,16 @@ namespace Microsoft.AspNet.Identity.InMemory
|
|||
return Task.FromResult<TUser>(null);
|
||||
}
|
||||
|
||||
public Task<string> GetUserId(TUser user, CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
return Task.FromResult(user.Id);
|
||||
}
|
||||
|
||||
public Task<string> GetUserName(TUser user, CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
return Task.FromResult(user.UserName);
|
||||
}
|
||||
|
||||
public Task Create(TUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
_users[user.Id] = user;
|
||||
|
|
|
@ -7,9 +7,7 @@ using Microsoft.AspNet.Abstractions.Security;
|
|||
|
||||
namespace Microsoft.AspNet.Identity.Security
|
||||
{
|
||||
public class SignInManager<TUser, TKey>
|
||||
where TUser : class, IUser<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
public class SignInManager<TUser> where TUser : class
|
||||
{
|
||||
private string _authType;
|
||||
public string AuthenticationType
|
||||
|
@ -18,7 +16,7 @@ namespace Microsoft.AspNet.Identity.Security
|
|||
set { _authType = value; }
|
||||
}
|
||||
|
||||
public UserManager<TUser, TKey> UserManager { get; set; }
|
||||
public UserManager<TUser> UserManager { get; set; }
|
||||
public HttpContext Context { get; set; }
|
||||
|
||||
|
||||
|
@ -139,7 +137,9 @@ namespace Microsoft.AspNet.Identity.Security
|
|||
{
|
||||
return SignInStatus.Failure;
|
||||
}
|
||||
if (await UserManager.IsLockedOut(user.Id))
|
||||
// TODO: overloads taking TUser?
|
||||
var userId = await UserManager.GetUserId(user);
|
||||
if (await UserManager.IsLockedOut(userId))
|
||||
{
|
||||
return SignInStatus.LockedOut;
|
||||
}
|
||||
|
@ -152,8 +152,8 @@ namespace Microsoft.AspNet.Identity.Security
|
|||
if (shouldLockout)
|
||||
{
|
||||
// If lockout is requested, increment access failed count which might lock out the user
|
||||
await UserManager.AccessFailed(user.Id);
|
||||
if (await UserManager.IsLockedOut(user.Id))
|
||||
await UserManager.AccessFailed(userId);
|
||||
if (await UserManager.IsLockedOut(userId))
|
||||
{
|
||||
return SignInStatus.LockedOut;
|
||||
}
|
||||
|
|
|
@ -10,10 +10,8 @@ namespace Microsoft.AspNet.Identity
|
|||
/// Creates a ClaimsIdentity from a User
|
||||
/// </summary>
|
||||
/// <typeparam name="TUser"></typeparam>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public class ClaimsIdentityFactory<TUser, TKey> : IClaimsIdentityFactory<TUser, TKey>
|
||||
where TUser : class, IUser<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
public class ClaimsIdentityFactory<TUser> : IClaimsIdentityFactory<TUser>
|
||||
where TUser : class
|
||||
{
|
||||
/// <summary>
|
||||
/// ClaimType used for the security stamp by default
|
||||
|
@ -57,8 +55,9 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="manager"></param>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="authenticationType"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<ClaimsIdentity> Create(UserManager<TUser, TKey> manager, TUser user,
|
||||
public virtual async Task<ClaimsIdentity> Create(UserManager<TUser> manager, TUser user,
|
||||
string authenticationType, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if (manager == null)
|
||||
|
@ -69,16 +68,18 @@ namespace Microsoft.AspNet.Identity
|
|||
{
|
||||
throw new ArgumentNullException("user");
|
||||
}
|
||||
var userId = await manager.GetUserId(user, cancellationToken);
|
||||
var userName = await manager.GetUserName(user, cancellationToken);
|
||||
var id = new ClaimsIdentity(authenticationType, UserNameClaimType, RoleClaimType);
|
||||
id.AddClaim(new Claim(UserIdClaimType, Convert.ToString(user.Id, CultureInfo.InvariantCulture), ClaimValueTypes.String));
|
||||
id.AddClaim(new Claim(UserNameClaimType, user.UserName, ClaimValueTypes.String));
|
||||
id.AddClaim(new Claim(UserIdClaimType, userId));
|
||||
id.AddClaim(new Claim(UserNameClaimType, userName, ClaimValueTypes.String));
|
||||
if (manager.SupportsUserSecurityStamp)
|
||||
{
|
||||
id.AddClaim(new Claim(SecurityStampClaimType, await manager.GetSecurityStamp(user.Id, cancellationToken)));
|
||||
id.AddClaim(new Claim(SecurityStampClaimType, await manager.GetSecurityStamp(userId, cancellationToken)));
|
||||
}
|
||||
if (manager.SupportsUserRole)
|
||||
{
|
||||
var roles = await manager.GetRoles(user.Id, cancellationToken);
|
||||
var roles = await manager.GetRoles(userId, cancellationToken);
|
||||
foreach (var roleName in roles)
|
||||
{
|
||||
id.AddClaim(new Claim(RoleClaimType, roleName, ClaimValueTypes.String));
|
||||
|
@ -86,7 +87,7 @@ namespace Microsoft.AspNet.Identity
|
|||
}
|
||||
if (manager.SupportsUserClaim)
|
||||
{
|
||||
id.AddClaims(await manager.GetClaims(user.Id, cancellationToken));
|
||||
id.AddClaims(await manager.GetClaims(userId, cancellationToken));
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
|
|
@ -9,10 +9,8 @@ namespace Microsoft.AspNet.Identity
|
|||
/// Interface for creating a ClaimsIdentity from an IUser
|
||||
/// </summary>
|
||||
/// <typeparam name="TUser"></typeparam>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public interface IClaimsIdentityFactory<TUser, TKey>
|
||||
where TUser : class, IUser<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
public interface IClaimsIdentityFactory<TUser>
|
||||
where TUser : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Create a ClaimsIdentity from an user using a UserManager
|
||||
|
@ -22,6 +20,6 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="authenticationType"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<ClaimsIdentity> Create(UserManager<TUser, TKey> manager, TUser user, string authenticationType, CancellationToken cancellationToken = default(CancellationToken));
|
||||
Task<ClaimsIdentity> Create(UserManager<TUser> manager, TUser user, string authenticationType, CancellationToken cancellationToken = default(CancellationToken));
|
||||
}
|
||||
}
|
|
@ -6,16 +6,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// Interface that exposes an IQueryable roles
|
||||
/// </summary>
|
||||
/// <typeparam name="TRole"></typeparam>
|
||||
public interface IQueryableRoleStore<TRole> : IQueryableRoleStore<TRole, string> where TRole : IRole<string>
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interface that exposes an IQueryable roles
|
||||
/// </summary>
|
||||
/// <typeparam name="TRole"></typeparam>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public interface IQueryableRoleStore<TRole, in TKey> : IRoleStore<TRole, TKey> where TRole : IRole<TKey>
|
||||
public interface IQueryableRoleStore<TRole> : IRoleStore<TRole> where TRole : class
|
||||
{
|
||||
/// <summary>
|
||||
/// IQueryable users
|
||||
|
|
|
@ -2,20 +2,12 @@
|
|||
|
||||
namespace Microsoft.AspNet.Identity
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface that exposes an IQueryable users
|
||||
/// </summary>
|
||||
/// <typeparam name="TUser"></typeparam>
|
||||
public interface IQueryableUserStore<TUser> : IQueryableUserStore<TUser, string> where TUser : class, IUser<string>
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interface that exposes an IQueryable users
|
||||
/// </summary>
|
||||
/// <typeparam name="TUser"></typeparam>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public interface IQueryableUserStore<TUser, in TKey> : IUserStore<TUser, TKey> where TUser : class, IUser<TKey>
|
||||
public interface IQueryableUserStore<TUser> : IUserStore<TUser> where TUser : class
|
||||
{
|
||||
/// <summary>
|
||||
/// IQueryable users
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
namespace Microsoft.AspNet.Identity
|
||||
{
|
||||
/// <summary>
|
||||
/// Mimimal set of data needed to persist role data
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public interface IRole<out TKey>
|
||||
{
|
||||
/// <summary>
|
||||
/// Id of the role
|
||||
/// </summary>
|
||||
TKey Id { get; }
|
||||
//namespace Microsoft.AspNet.Identity
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// Mimimal set of data needed to persist role data
|
||||
// /// </summary>
|
||||
// /// <typeparam name="TKey"></typeparam>
|
||||
// public interface IRole<out TKey>
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// Id of the role
|
||||
// /// </summary>
|
||||
// TKey Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of the role
|
||||
/// </summary>
|
||||
string Name { get; set; }
|
||||
}
|
||||
}
|
||||
// /// <summary>
|
||||
// /// Name of the role
|
||||
// /// </summary>
|
||||
// string Name { get; set; }
|
||||
// }
|
||||
//}
|
|
@ -8,8 +8,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// Interface that exposes basic role management
|
||||
/// </summary>
|
||||
/// <typeparam name="TRole"></typeparam>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public interface IRoleStore<TRole, in TKey> : IDisposable where TRole : IRole<TKey>
|
||||
public interface IRoleStore<TRole> : IDisposable where TRole : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Insert a new role
|
||||
|
@ -35,13 +34,29 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <returns></returns>
|
||||
Task Delete(TRole role, CancellationToken cancellationToken = default(CancellationToken));
|
||||
|
||||
/// <summary>
|
||||
/// Returns a role's id
|
||||
/// </summary>
|
||||
/// <param name="role"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> GetRoleId(TRole role, CancellationToken cancellationToken = default(CancellationToken));
|
||||
|
||||
/// <summary>
|
||||
/// Returns a role's name
|
||||
/// </summary>
|
||||
/// <param name="role"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> GetRoleName(TRole role, CancellationToken cancellationToken = default(CancellationToken));
|
||||
|
||||
/// <summary>
|
||||
/// Finds a role by id
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<TRole> FindById(TKey roleId, CancellationToken cancellationToken = default(CancellationToken));
|
||||
Task<TRole> FindById(string roleId, CancellationToken cancellationToken = default(CancellationToken));
|
||||
|
||||
/// <summary>
|
||||
/// Find a role by name
|
||||
|
|
|
@ -9,9 +9,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// </summary>
|
||||
/// <typeparam name="TRole"></typeparam>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public interface IRoleValidator<TRole, TKey>
|
||||
where TRole : class, IRole<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
public interface IRoleValidator<TRole> where TRole : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Validate the user
|
||||
|
@ -20,6 +18,6 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="manager"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IdentityResult> Validate(RoleManager<TRole, TKey> manager, TRole role, CancellationToken cancellationToken = default(CancellationToken));
|
||||
Task<IdentityResult> Validate(RoleManager<TRole> manager, TRole role, CancellationToken cancellationToken = default(CancellationToken));
|
||||
}
|
||||
}
|
|
@ -1,19 +1,19 @@
|
|||
namespace Microsoft.AspNet.Identity
|
||||
{
|
||||
/// <summary>
|
||||
/// Minimal interface for a user with id and username
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public interface IUser<out TKey>
|
||||
{
|
||||
/// <summary>
|
||||
/// Unique key for the user
|
||||
/// </summary>
|
||||
TKey Id { get; }
|
||||
//namespace Microsoft.AspNet.Identity
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// Minimal interface for a user with id and username
|
||||
// /// </summary>
|
||||
// /// <typeparam name="TKey"></typeparam>
|
||||
// public interface IUser<out TKey>
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// Unique key for the user
|
||||
// /// </summary>
|
||||
// TKey Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Unique username
|
||||
/// </summary>
|
||||
string UserName { get; set; }
|
||||
}
|
||||
}
|
||||
// /// <summary>
|
||||
// /// Unique username
|
||||
// /// </summary>
|
||||
// string UserName { get; set; }
|
||||
// }
|
||||
//}
|
|
@ -9,8 +9,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// Stores user specific claims
|
||||
/// </summary>
|
||||
/// <typeparam name="TUser"></typeparam>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public interface IUserClaimStore<TUser, in TKey> : IUserStore<TUser, TKey> where TUser : class, IUser<TKey>
|
||||
public interface IUserClaimStore<TUser> : IUserStore<TUser> where TUser : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the claims for the user with the issuer set
|
||||
|
|
|
@ -7,8 +7,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// Stores a user's email
|
||||
/// </summary>
|
||||
/// <typeparam name="TUser"></typeparam>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public interface IUserEmailStore<TUser, in TKey> : IUserStore<TUser, TKey> where TUser : class, IUser<TKey>
|
||||
public interface IUserEmailStore<TUser> : IUserStore<TUser> where TUser : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Set the user email
|
||||
|
|
|
@ -8,8 +8,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// Stores information which can be used to implement account lockout, including access failures and lockout status
|
||||
/// </summary>
|
||||
/// <typeparam name="TUser"></typeparam>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public interface IUserLockoutStore<TUser, in TKey> : IUserStore<TUser, TKey> where TUser : class, IUser<TKey>
|
||||
public interface IUserLockoutStore<TUser> : IUserStore<TUser> where TUser : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the DateTimeOffset that represents the end of a user's lockout, any time in the past should be considered
|
||||
|
|
|
@ -8,8 +8,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// Interface that maps users to login providers, i.e. Google, Facebook, Twitter, Microsoft
|
||||
/// </summary>
|
||||
/// <typeparam name="TUser"></typeparam>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public interface IUserLoginStore<TUser, in TKey> : IUserStore<TUser, TKey> where TUser : class, IUser<TKey>
|
||||
public interface IUserLoginStore<TUser> : IUserStore<TUser> where TUser : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds a user login with the specified provider and key
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.AspNet.Identity
|
||||
{
|
||||
/// <summary>
|
||||
/// Stores a user's email
|
||||
/// </summary>
|
||||
/// <typeparam name="TUser"></typeparam>
|
||||
public interface IUserNameStore<TUser, in TKey> : IUserStore<TUser> where TUser : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Set the user name
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task SetUserName(TUser user, string userName, CancellationToken cancellationToken = default(CancellationToken));
|
||||
|
||||
/// <summary>
|
||||
/// Get the user name
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> GetUserName(TUser user, CancellationToken cancellationToken = default(CancellationToken));
|
||||
|
||||
/// <summary>
|
||||
/// Returns the user associated with this name
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<TUser> FindByName(string name, CancellationToken cancellationToken = default(CancellationToken));
|
||||
}
|
||||
}
|
|
@ -7,8 +7,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// Stores a user's password hash
|
||||
/// </summary>
|
||||
/// <typeparam name="TUser"></typeparam>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public interface IUserPasswordStore<TUser, in TKey> : IUserStore<TUser, TKey> where TUser : class, IUser<TKey>
|
||||
public interface IUserPasswordStore<TUser> : IUserStore<TUser> where TUser : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Set the user password hash
|
||||
|
|
|
@ -7,8 +7,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// Stores a user's phoneNumber
|
||||
/// </summary>
|
||||
/// <typeparam name="TUser"></typeparam>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public interface IUserPhoneNumberStore<TUser, in TKey> : IUserStore<TUser, TKey> where TUser : class, IUser<TKey>
|
||||
public interface IUserPhoneNumberStore<TUser> : IUserStore<TUser> where TUser : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Set the user PhoneNumber
|
||||
|
|
|
@ -8,8 +8,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// Interface that maps users to their roles
|
||||
/// </summary>
|
||||
/// <typeparam name="TUser"></typeparam>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public interface IUserRoleStore<TUser, in TKey> : IUserStore<TUser, TKey> where TUser : class, IUser<TKey>
|
||||
public interface IUserRoleStore<TUser> : IUserStore<TUser> where TUser : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds a user to role
|
||||
|
|
|
@ -7,8 +7,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// Stores a user's security stamp
|
||||
/// </summary>
|
||||
/// <typeparam name="TUser"></typeparam>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public interface IUserSecurityStampStore<TUser, in TKey> : IUserStore<TUser, TKey> where TUser : class, IUser<TKey>
|
||||
public interface IUserSecurityStampStore<TUser> : IUserStore<TUser> where TUser : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Set the security stamp for the user
|
||||
|
|
|
@ -9,8 +9,24 @@ namespace Microsoft.AspNet.Identity
|
|||
/// </summary>
|
||||
/// <typeparam name="TUser"></typeparam>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public interface IUserStore<TUser, in TKey> : IDisposable where TUser : class, IUser<TKey>
|
||||
public interface IUserStore<TUser> : IDisposable where TUser : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the user id for a user
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> GetUserId(TUser user, CancellationToken cancellationToken = default(CancellationToken));
|
||||
|
||||
/// <summary>
|
||||
/// Returns the user's name
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> GetUserName(TUser user, CancellationToken cancellationToken = default(CancellationToken));
|
||||
|
||||
/// <summary>
|
||||
/// Insert a new user
|
||||
/// </summary>
|
||||
|
@ -41,14 +57,15 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="userId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<TUser> FindById(TKey userId, CancellationToken cancellationToken = default(CancellationToken));
|
||||
Task<TUser> FindById(string userId, CancellationToken cancellationToken = default(CancellationToken));
|
||||
|
||||
/// <summary>
|
||||
/// Find a user by name
|
||||
/// Returns the user associated with this name
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<TUser> FindByName(string userName, CancellationToken cancellationToken = default(CancellationToken));
|
||||
Task<TUser> FindByName(string name, CancellationToken cancellationToken = default(CancellationToken));
|
||||
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <summary>
|
||||
/// Interface to generate user tokens
|
||||
/// </summary>
|
||||
public interface IUserTokenProvider<TUser, TKey> where TUser : class, IUser<TKey> where TKey : IEquatable<TKey>
|
||||
public interface IUserTokenProvider<TUser> where TUser : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Generate a token for a user
|
||||
|
@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="user"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> Generate(string purpose, UserManager<TUser, TKey> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken));
|
||||
Task<string> Generate(string purpose, UserManager<TUser> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken));
|
||||
|
||||
/// <summary>
|
||||
/// Validate and unprotect a token, returns null if invalid
|
||||
|
@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="user"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> Validate(string purpose, string token, UserManager<TUser, TKey> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken));
|
||||
Task<bool> Validate(string purpose, string token, UserManager<TUser> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken));
|
||||
|
||||
/// <summary>
|
||||
/// Notifies the user that a token has been generated, i.e. via email or sms, or can no-op
|
||||
|
@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="user"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task Notify(string token, UserManager<TUser, TKey> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken));
|
||||
Task Notify(string token, UserManager<TUser> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken));
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if provider can be used for this user, i.e. could require a user to have an email
|
||||
|
@ -47,6 +47,6 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="user"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> IsValidProviderForUser(UserManager<TUser, TKey> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken));
|
||||
Task<bool> IsValidProviderForUser(UserManager<TUser> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken));
|
||||
}
|
||||
}
|
|
@ -7,8 +7,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// Stores whether two factor is enabled for a user
|
||||
/// </summary>
|
||||
/// <typeparam name="TUser"></typeparam>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public interface IUserTwoFactorStore<TUser, in TKey> : IUserStore<TUser, TKey> where TUser : class, IUser<TKey>
|
||||
public interface IUserTwoFactorStore<TUser> : IUserStore<TUser> where TUser : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets whether two factor is enabled for the user
|
||||
|
|
|
@ -8,10 +8,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// Used to validate a user
|
||||
/// </summary>
|
||||
/// <typeparam name="TUser"></typeparam>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public interface IUserValidator<TUser, TKey>
|
||||
where TUser : class, IUser<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
public interface IUserValidator<TUser> where TUser : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Validate the user
|
||||
|
@ -20,6 +17,6 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="user"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IdentityResult> Validate(UserManager<TUser, TKey> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken));
|
||||
Task<IdentityResult> Validate(UserManager<TUser> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken));
|
||||
}
|
||||
}
|
|
@ -9,26 +9,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// Exposes role related api which will automatically save changes to the RoleStore
|
||||
/// </summary>
|
||||
/// <typeparam name="TRole"></typeparam>
|
||||
public class RoleManager<TRole> : RoleManager<TRole, string> where TRole : class, IRole<string>
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="store"></param>
|
||||
public RoleManager(IRoleStore<TRole, string> store)
|
||||
: base(store)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Exposes role related api which will automatically save changes to the RoleStore
|
||||
/// </summary>
|
||||
/// <typeparam name="TRole"></typeparam>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public class RoleManager<TRole, TKey> : IDisposable
|
||||
where TRole : class, IRole<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
public class RoleManager<TRole> : IDisposable where TRole : class
|
||||
{
|
||||
private bool _disposed;
|
||||
|
||||
|
@ -36,25 +17,25 @@ namespace Microsoft.AspNet.Identity
|
|||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="store">The IRoleStore is responsible for commiting changes via the UpdateAsync/CreateAsync methods</param>
|
||||
public RoleManager(IRoleStore<TRole, TKey> store)
|
||||
public RoleManager(IRoleStore<TRole> store)
|
||||
{
|
||||
if (store == null)
|
||||
{
|
||||
throw new ArgumentNullException("store");
|
||||
}
|
||||
Store = store;
|
||||
RoleValidator = new RoleValidator<TRole, TKey>();
|
||||
RoleValidator = new RoleValidator<TRole>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Persistence abstraction that the Manager operates against
|
||||
/// </summary>
|
||||
protected IRoleStore<TRole, TKey> Store { get; private set; }
|
||||
protected IRoleStore<TRole> Store { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Used to validate roles before persisting changes
|
||||
/// </summary>
|
||||
public IRoleValidator<TRole, TKey> RoleValidator { get; set; }
|
||||
public IRoleValidator<TRole> RoleValidator { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns an IQueryable of roles if the store is an IQueryableRoleStore
|
||||
|
@ -63,7 +44,7 @@ namespace Microsoft.AspNet.Identity
|
|||
{
|
||||
get
|
||||
{
|
||||
var queryableStore = Store as IQueryableRoleStore<TRole, TKey>;
|
||||
var queryableStore = Store as IQueryableRoleStore<TRole>;
|
||||
if (queryableStore == null)
|
||||
{
|
||||
throw new NotSupportedException(Resources.StoreNotIQueryableRoleStore);
|
||||
|
@ -80,7 +61,7 @@ namespace Microsoft.AspNet.Identity
|
|||
get
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return Store is IQueryableRoleStore<TRole, TKey>;
|
||||
return Store is IQueryableRoleStore<TRole>;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,12 +166,36 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="roleId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<TRole> FindById(TKey roleId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<TRole> FindById(string roleId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return await Store.FindById(roleId, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the name of the role
|
||||
/// </summary>
|
||||
/// <param name="role"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<string> GetRoleName(TRole role, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return await Store.GetRoleName(role, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the role id for a role
|
||||
/// </summary>
|
||||
/// <param name="role"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<string> GetRoleId(TRole role, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return await Store.GetRoleId(role, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find a role by name
|
||||
/// </summary>
|
||||
|
|
|
@ -10,10 +10,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// Validates roles before they are saved
|
||||
/// </summary>
|
||||
/// <typeparam name="TRole"></typeparam>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public class RoleValidator<TRole, TKey> : IRoleValidator<TRole, TKey>
|
||||
where TRole : class, IRole<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
public class RoleValidator<TRole> : IRoleValidator<TRole> where TRole : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Validates a role before saving
|
||||
|
@ -22,7 +19,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="role"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IdentityResult> Validate(RoleManager<TRole, TKey> manager, TRole role, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IdentityResult> Validate(RoleManager<TRole> manager, TRole role, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if (manager == null)
|
||||
{
|
||||
|
@ -41,19 +38,20 @@ namespace Microsoft.AspNet.Identity
|
|||
return IdentityResult.Success;
|
||||
}
|
||||
|
||||
private static async Task ValidateRoleName(RoleManager<TRole, TKey> manager, TRole role,
|
||||
private static async Task ValidateRoleName(RoleManager<TRole> manager, TRole role,
|
||||
ICollection<string> errors)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(role.Name))
|
||||
var roleName = await manager.GetRoleName(role);
|
||||
if (string.IsNullOrWhiteSpace(roleName))
|
||||
{
|
||||
errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.PropertyTooShort, "Name"));
|
||||
}
|
||||
else
|
||||
{
|
||||
var owner = await manager.FindByName(role.Name);
|
||||
if (owner != null && !EqualityComparer<TKey>.Default.Equals(owner.Id, role.Id))
|
||||
var owner = await manager.FindByName(roleName);
|
||||
if (owner != null && !string.Equals(await manager.GetRoleId(owner), await manager.GetRoleId(role)))
|
||||
{
|
||||
errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.DuplicateName, role.Name));
|
||||
errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.DuplicateName, roleName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,15 +14,12 @@ namespace Microsoft.AspNet.Identity
|
|||
/// Exposes user related api which will automatically save changes to the UserStore
|
||||
/// </summary>
|
||||
/// <typeparam name="TUser"></typeparam>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public class UserManager<TUser, TKey> : IDisposable
|
||||
where TUser : class, IUser<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
public class UserManager<TUser> : IDisposable where TUser : class
|
||||
{
|
||||
private readonly Dictionary<string, IUserTokenProvider<TUser, TKey>> _factors =
|
||||
new Dictionary<string, IUserTokenProvider<TUser, TKey>>();
|
||||
private readonly Dictionary<string, IUserTokenProvider<TUser>> _factors =
|
||||
new Dictionary<string, IUserTokenProvider<TUser>>();
|
||||
|
||||
private IClaimsIdentityFactory<TUser, TKey> _claimsFactory;
|
||||
private IClaimsIdentityFactory<TUser> _claimsFactory;
|
||||
private TimeSpan _defaultLockout = TimeSpan.Zero;
|
||||
private bool _disposed;
|
||||
private IPasswordHasher _passwordHasher;
|
||||
|
@ -40,10 +37,10 @@ namespace Microsoft.AspNet.Identity
|
|||
throw new ArgumentNullException("serviceProvider");
|
||||
}
|
||||
PasswordHasher = serviceProvider.GetService<IPasswordHasher>();
|
||||
UserValidator = serviceProvider.GetService<IUserValidator<TUser, TKey>>();
|
||||
UserValidator = serviceProvider.GetService<IUserValidator<TUser>>();
|
||||
PasswordValidator = serviceProvider.GetService<IPasswordValidator>();
|
||||
ClaimsIdentityFactory = serviceProvider.GetService<IClaimsIdentityFactory<TUser, TKey>>();
|
||||
Store = serviceProvider.GetService<IUserStore<TUser, TKey>>();
|
||||
ClaimsIdentityFactory = serviceProvider.GetService<IClaimsIdentityFactory<TUser>>();
|
||||
Store = serviceProvider.GetService<IUserStore<TUser>>();
|
||||
// TODO: maybe each optional store as well? Email and SMS services?
|
||||
}
|
||||
|
||||
|
@ -51,22 +48,22 @@ namespace Microsoft.AspNet.Identity
|
|||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="store">The IUserStore is responsible for commiting changes via the UpdateAsync/CreateAsync methods</param>
|
||||
public UserManager(IUserStore<TUser, TKey> store)
|
||||
public UserManager(IUserStore<TUser> store)
|
||||
{
|
||||
if (store == null)
|
||||
{
|
||||
throw new ArgumentNullException("store");
|
||||
}
|
||||
Store = store;
|
||||
UserValidator = new UserValidator<TUser, TKey>();
|
||||
UserValidator = new UserValidator<TUser>();
|
||||
PasswordHasher = new PasswordHasher();
|
||||
ClaimsIdentityFactory = new ClaimsIdentityFactory<TUser, TKey>();
|
||||
ClaimsIdentityFactory = new ClaimsIdentityFactory<TUser>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Persistence abstraction that the Manager operates against
|
||||
/// </summary>
|
||||
protected internal IUserStore<TUser, TKey> Store { get; set; }
|
||||
protected internal IUserStore<TUser> Store { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Used to hash/verify passwords
|
||||
|
@ -92,7 +89,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <summary>
|
||||
/// Used to validate users before persisting changes
|
||||
/// </summary>
|
||||
public IUserValidator<TUser, TKey> UserValidator { get; set; }
|
||||
public IUserValidator<TUser> UserValidator { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Used to validate passwords before persisting changes
|
||||
|
@ -102,7 +99,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <summary>
|
||||
/// Used to create claims identities from users
|
||||
/// </summary>
|
||||
public IClaimsIdentityFactory<TUser, TKey> ClaimsIdentityFactory
|
||||
public IClaimsIdentityFactory<TUser> ClaimsIdentityFactory
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -133,7 +130,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <summary>
|
||||
/// Used for generating ResetPassword and Confirmation Tokens
|
||||
/// </summary>
|
||||
public IUserTokenProvider<TUser, TKey> UserTokenProvider { get; set; }
|
||||
public IUserTokenProvider<TUser> UserTokenProvider { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// If true, will enable user lockout when users are created
|
||||
|
@ -162,7 +159,7 @@ namespace Microsoft.AspNet.Identity
|
|||
get
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return Store is IUserTwoFactorStore<TUser, TKey>;
|
||||
return Store is IUserTwoFactorStore<TUser>;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,7 +171,7 @@ namespace Microsoft.AspNet.Identity
|
|||
get
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return Store is IUserPasswordStore<TUser, TKey>;
|
||||
return Store is IUserPasswordStore<TUser>;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -186,7 +183,7 @@ namespace Microsoft.AspNet.Identity
|
|||
get
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return Store is IUserSecurityStampStore<TUser, TKey>;
|
||||
return Store is IUserSecurityStampStore<TUser>;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -198,7 +195,7 @@ namespace Microsoft.AspNet.Identity
|
|||
get
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return Store is IUserRoleStore<TUser, TKey>;
|
||||
return Store is IUserRoleStore<TUser>;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,7 +207,7 @@ namespace Microsoft.AspNet.Identity
|
|||
get
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return Store is IUserLoginStore<TUser, TKey>;
|
||||
return Store is IUserLoginStore<TUser>;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -222,7 +219,7 @@ namespace Microsoft.AspNet.Identity
|
|||
get
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return Store is IUserEmailStore<TUser, TKey>;
|
||||
return Store is IUserEmailStore<TUser>;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -234,7 +231,7 @@ namespace Microsoft.AspNet.Identity
|
|||
get
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return Store is IUserPhoneNumberStore<TUser, TKey>;
|
||||
return Store is IUserPhoneNumberStore<TUser>;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -246,7 +243,7 @@ namespace Microsoft.AspNet.Identity
|
|||
get
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return Store is IUserClaimStore<TUser, TKey>;
|
||||
return Store is IUserClaimStore<TUser>;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -258,7 +255,7 @@ namespace Microsoft.AspNet.Identity
|
|||
get
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return Store is IUserLockoutStore<TUser, TKey>;
|
||||
return Store is IUserLockoutStore<TUser>;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -270,7 +267,7 @@ namespace Microsoft.AspNet.Identity
|
|||
get
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return Store is IQueryableUserStore<TUser, TKey>;
|
||||
return Store is IQueryableUserStore<TUser>;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -281,7 +278,7 @@ namespace Microsoft.AspNet.Identity
|
|||
{
|
||||
get
|
||||
{
|
||||
var queryableStore = Store as IQueryableUserStore<TUser, TKey>;
|
||||
var queryableStore = Store as IQueryableUserStore<TUser>;
|
||||
if (queryableStore == null)
|
||||
{
|
||||
throw new NotSupportedException(Resources.StoreNotIQueryableUserStore);
|
||||
|
@ -293,7 +290,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <summary>
|
||||
/// Dictionary mapping user two factor providers
|
||||
/// </summary>
|
||||
public IDictionary<string, IUserTokenProvider<TUser, TKey>> TwoFactorProviders
|
||||
public IDictionary<string, IUserTokenProvider<TUser>> TwoFactorProviders
|
||||
{
|
||||
get { return _factors; }
|
||||
}
|
||||
|
@ -399,7 +396,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="userId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual Task<TUser> FindById(TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual Task<TUser> FindById(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return Store.FindById(userId, cancellationToken);
|
||||
|
@ -422,9 +419,9 @@ namespace Microsoft.AspNet.Identity
|
|||
}
|
||||
|
||||
// IUserPasswordStore methods
|
||||
private IUserPasswordStore<TUser, TKey> GetPasswordStore()
|
||||
private IUserPasswordStore<TUser> GetPasswordStore()
|
||||
{
|
||||
var cast = Store as IUserPasswordStore<TUser, TKey>;
|
||||
var cast = Store as IUserPasswordStore<TUser>;
|
||||
if (cast == null)
|
||||
{
|
||||
throw new NotSupportedException(Resources.StoreNotIUserPasswordStore);
|
||||
|
@ -458,6 +455,30 @@ namespace Microsoft.AspNet.Identity
|
|||
return await Create(user, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the user's name
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<string> GetUserName(TUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return await Store.GetUserName(user, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the user's id
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<string> GetUserId(TUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return await Store.GetUserId(user, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a user with the specified username and password or null if there is no match.
|
||||
/// </summary>
|
||||
|
@ -500,7 +521,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="userId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<bool> HasPassword(TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<bool> HasPassword(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var passwordStore = GetPasswordStore();
|
||||
|
@ -520,7 +541,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="password"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IdentityResult> AddPassword(TKey userId, string password, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IdentityResult> AddPassword(string userId, string password, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var passwordStore = GetPasswordStore();
|
||||
|
@ -551,7 +572,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="newPassword"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IdentityResult> ChangePassword(TKey userId, string currentPassword,
|
||||
public virtual async Task<IdentityResult> ChangePassword(string userId, string currentPassword,
|
||||
string newPassword, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
@ -580,7 +601,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="userId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IdentityResult> RemovePassword(TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IdentityResult> RemovePassword(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var passwordStore = GetPasswordStore();
|
||||
|
@ -595,7 +616,7 @@ namespace Microsoft.AspNet.Identity
|
|||
return await Update(user, cancellationToken);
|
||||
}
|
||||
|
||||
internal async Task<IdentityResult> UpdatePasswordInternal(IUserPasswordStore<TUser, TKey> passwordStore,
|
||||
internal async Task<IdentityResult> UpdatePasswordInternal(IUserPasswordStore<TUser> passwordStore,
|
||||
TUser user, string newPassword, CancellationToken cancellationToken)
|
||||
{
|
||||
if (PasswordValidator != null)
|
||||
|
@ -620,7 +641,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="password"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
protected virtual async Task<bool> VerifyPassword(IUserPasswordStore<TUser, TKey> store, TUser user,
|
||||
protected virtual async Task<bool> VerifyPassword(IUserPasswordStore<TUser> store, TUser user,
|
||||
string password, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
var hash = await store.GetPasswordHash(user, cancellationToken);
|
||||
|
@ -628,9 +649,9 @@ namespace Microsoft.AspNet.Identity
|
|||
}
|
||||
|
||||
// IUserSecurityStampStore methods
|
||||
private IUserSecurityStampStore<TUser, TKey> GetSecurityStore()
|
||||
private IUserSecurityStampStore<TUser> GetSecurityStore()
|
||||
{
|
||||
var cast = Store as IUserSecurityStampStore<TUser, TKey>;
|
||||
var cast = Store as IUserSecurityStampStore<TUser>;
|
||||
if (cast == null)
|
||||
{
|
||||
throw new NotSupportedException(Resources.StoreNotIUserSecurityStampStore);
|
||||
|
@ -644,7 +665,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="userId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<string> GetSecurityStamp(TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<string> GetSecurityStamp(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var securityStore = GetSecurityStore();
|
||||
|
@ -663,7 +684,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="userId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IdentityResult> UpdateSecurityStamp(TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IdentityResult> UpdateSecurityStamp(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var securityStore = GetSecurityStore();
|
||||
|
@ -683,7 +704,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="userId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<string> GeneratePasswordResetToken(TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<string> GeneratePasswordResetToken(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return await GenerateUserToken("ResetPassword", userId, cancellationToken);
|
||||
|
@ -697,7 +718,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="newPassword"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IdentityResult> ResetPassword(TKey userId, string token, string newPassword, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IdentityResult> ResetPassword(string userId, string token, string newPassword, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var user = await FindById(userId, cancellationToken);
|
||||
|
@ -735,9 +756,9 @@ namespace Microsoft.AspNet.Identity
|
|||
}
|
||||
|
||||
// IUserLoginStore methods
|
||||
private IUserLoginStore<TUser, TKey> GetLoginStore()
|
||||
private IUserLoginStore<TUser> GetLoginStore()
|
||||
{
|
||||
var cast = Store as IUserLoginStore<TUser, TKey>;
|
||||
var cast = Store as IUserLoginStore<TUser>;
|
||||
if (cast == null)
|
||||
{
|
||||
throw new NotSupportedException(Resources.StoreNotIUserLoginStore);
|
||||
|
@ -762,7 +783,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="login"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IdentityResult> RemoveLogin(TKey userId, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IdentityResult> RemoveLogin(string userId, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var loginStore = GetLoginStore();
|
||||
|
@ -788,7 +809,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="login"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IdentityResult> AddLogin(TKey userId, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IdentityResult> AddLogin(string userId, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var loginStore = GetLoginStore();
|
||||
|
@ -817,7 +838,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="userId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IList<UserLoginInfo>> GetLogins(TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IList<UserLoginInfo>> GetLogins(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var loginStore = GetLoginStore();
|
||||
|
@ -831,9 +852,9 @@ namespace Microsoft.AspNet.Identity
|
|||
}
|
||||
|
||||
// IUserClaimStore methods
|
||||
private IUserClaimStore<TUser, TKey> GetClaimStore()
|
||||
private IUserClaimStore<TUser> GetClaimStore()
|
||||
{
|
||||
var cast = Store as IUserClaimStore<TUser, TKey>;
|
||||
var cast = Store as IUserClaimStore<TUser>;
|
||||
if (cast == null)
|
||||
{
|
||||
throw new NotSupportedException(Resources.StoreNotIUserClaimStore);
|
||||
|
@ -848,7 +869,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="claim"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IdentityResult> AddClaim(TKey userId, Claim claim, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IdentityResult> AddClaim(string userId, Claim claim, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var claimStore = GetClaimStore();
|
||||
|
@ -873,7 +894,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="claim"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IdentityResult> RemoveClaim(TKey userId, Claim claim, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IdentityResult> RemoveClaim(string userId, Claim claim, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var claimStore = GetClaimStore();
|
||||
|
@ -893,7 +914,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="userId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IList<Claim>> GetClaims(TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IList<Claim>> GetClaims(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var claimStore = GetClaimStore();
|
||||
|
@ -906,9 +927,9 @@ namespace Microsoft.AspNet.Identity
|
|||
return await claimStore.GetClaims(user, cancellationToken);
|
||||
}
|
||||
|
||||
private IUserRoleStore<TUser, TKey> GetUserRoleStore()
|
||||
private IUserRoleStore<TUser> GetUserRoleStore()
|
||||
{
|
||||
var cast = Store as IUserRoleStore<TUser, TKey>;
|
||||
var cast = Store as IUserRoleStore<TUser>;
|
||||
if (cast == null)
|
||||
{
|
||||
throw new NotSupportedException(Resources.StoreNotIUserRoleStore);
|
||||
|
@ -923,7 +944,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="role"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IdentityResult> AddToRole(TKey userId, string role, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IdentityResult> AddToRole(string userId, string role, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var userRoleStore = GetUserRoleStore();
|
||||
|
@ -949,7 +970,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="role"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IdentityResult> RemoveFromRole(TKey userId, string role, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IdentityResult> RemoveFromRole(string userId, string role, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var userRoleStore = GetUserRoleStore();
|
||||
|
@ -973,7 +994,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="userId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IList<string>> GetRoles(TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IList<string>> GetRoles(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var userRoleStore = GetUserRoleStore();
|
||||
|
@ -993,7 +1014,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="role"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<bool> IsInRole(TKey userId, string role, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<bool> IsInRole(string userId, string role, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var userRoleStore = GetUserRoleStore();
|
||||
|
@ -1007,9 +1028,9 @@ namespace Microsoft.AspNet.Identity
|
|||
}
|
||||
|
||||
// IUserEmailStore methods
|
||||
internal IUserEmailStore<TUser, TKey> GetEmailStore()
|
||||
internal IUserEmailStore<TUser> GetEmailStore()
|
||||
{
|
||||
var cast = Store as IUserEmailStore<TUser, TKey>;
|
||||
var cast = Store as IUserEmailStore<TUser>;
|
||||
if (cast == null)
|
||||
{
|
||||
throw new NotSupportedException(Resources.StoreNotIUserEmailStore);
|
||||
|
@ -1022,7 +1043,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<string> GetEmail(TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<string> GetEmail(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var store = GetEmailStore();
|
||||
|
@ -1041,7 +1062,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="userId"></param>
|
||||
/// <param name="email"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IdentityResult> SetEmail(TKey userId, string email, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IdentityResult> SetEmail(string userId, string email, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var store = GetEmailStore();
|
||||
|
@ -1078,7 +1099,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public virtual Task<string> GenerateEmailConfirmationToken(TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual Task<string> GenerateEmailConfirmationToken(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return GenerateUserToken("Confirmation", userId, cancellationToken);
|
||||
|
@ -1091,7 +1112,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="token"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IdentityResult> ConfirmEmail(TKey userId, string token, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IdentityResult> ConfirmEmail(string userId, string token, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var store = GetEmailStore();
|
||||
|
@ -1115,7 +1136,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="userId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<bool> IsEmailConfirmed(TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<bool> IsEmailConfirmed(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var store = GetEmailStore();
|
||||
|
@ -1129,9 +1150,9 @@ namespace Microsoft.AspNet.Identity
|
|||
}
|
||||
|
||||
// IUserPhoneNumberStore methods
|
||||
internal IUserPhoneNumberStore<TUser, TKey> GetPhoneNumberStore()
|
||||
internal IUserPhoneNumberStore<TUser> GetPhoneNumberStore()
|
||||
{
|
||||
var cast = Store as IUserPhoneNumberStore<TUser, TKey>;
|
||||
var cast = Store as IUserPhoneNumberStore<TUser>;
|
||||
if (cast == null)
|
||||
{
|
||||
throw new NotSupportedException(Resources.StoreNotIUserPhoneNumberStore);
|
||||
|
@ -1145,7 +1166,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="userId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<string> GetPhoneNumber(TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<string> GetPhoneNumber(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var store = GetPhoneNumberStore();
|
||||
|
@ -1165,7 +1186,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="phoneNumber"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IdentityResult> SetPhoneNumber(TKey userId, string phoneNumber, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IdentityResult> SetPhoneNumber(string userId, string phoneNumber, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var store = GetPhoneNumberStore();
|
||||
|
@ -1189,7 +1210,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="token"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IdentityResult> ChangePhoneNumber(TKey userId, string phoneNumber, string token, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IdentityResult> ChangePhoneNumber(string userId, string phoneNumber, string token, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var store = GetPhoneNumberStore();
|
||||
|
@ -1215,7 +1236,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="userId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<bool> IsPhoneNumberConfirmed(TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<bool> IsPhoneNumberConfirmed(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var store = GetPhoneNumberStore();
|
||||
|
@ -1231,7 +1252,7 @@ namespace Microsoft.AspNet.Identity
|
|||
// Two factor APIS
|
||||
|
||||
#if NET45
|
||||
internal async Task<SecurityToken> CreateSecurityToken(TKey userId)
|
||||
internal async Task<SecurityToken> CreateSecurityToken(string userId)
|
||||
{
|
||||
return
|
||||
new SecurityToken(Encoding.Unicode.GetBytes(await GetSecurityStamp(userId)));
|
||||
|
@ -1243,7 +1264,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="userId"></param>
|
||||
/// <param name="phoneNumber"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<string> GenerateChangePhoneNumberToken(TKey userId, string phoneNumber)
|
||||
public virtual async Task<string> GenerateChangePhoneNumberToken(string userId, string phoneNumber)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return
|
||||
|
@ -1259,7 +1280,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="token"></param>
|
||||
/// <param name="phoneNumber"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<bool> VerifyChangePhoneNumberToken(TKey userId, string token, string phoneNumber)
|
||||
public virtual async Task<bool> VerifyChangePhoneNumberToken(string userId, string token, string phoneNumber)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
#if NET45
|
||||
|
@ -1281,7 +1302,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="token"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<bool> VerifyUserToken(TKey userId, string purpose, string token, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<bool> VerifyUserToken(string userId, string purpose, string token, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
if (UserTokenProvider == null)
|
||||
|
@ -1305,7 +1326,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="userId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<string> GenerateUserToken(string purpose, TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<string> GenerateUserToken(string purpose, string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
if (UserTokenProvider == null)
|
||||
|
@ -1326,7 +1347,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// </summary>
|
||||
/// <param name="twoFactorProvider"></param>
|
||||
/// <param name="provider"></param>
|
||||
public virtual void RegisterTwoFactorProvider(string twoFactorProvider, IUserTokenProvider<TUser, TKey> provider)
|
||||
public virtual void RegisterTwoFactorProvider(string twoFactorProvider, IUserTokenProvider<TUser> provider)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
if (twoFactorProvider == null)
|
||||
|
@ -1346,7 +1367,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="userId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IList<string>> GetValidTwoFactorProviders(TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IList<string>> GetValidTwoFactorProviders(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var user = await FindById(userId, cancellationToken);
|
||||
|
@ -1374,7 +1395,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="token"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<bool> VerifyTwoFactorToken(TKey userId, string twoFactorProvider, string token, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<bool> VerifyTwoFactorToken(string userId, string twoFactorProvider, string token, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var user = await FindById(userId, cancellationToken);
|
||||
|
@ -1400,7 +1421,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="twoFactorProvider"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<string> GenerateTwoFactorToken(TKey userId, string twoFactorProvider, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<string> GenerateTwoFactorToken(string userId, string twoFactorProvider, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var user = await FindById(userId, cancellationToken);
|
||||
|
@ -1425,7 +1446,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="token"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IdentityResult> NotifyTwoFactorToken(TKey userId, string twoFactorProvider,
|
||||
public virtual async Task<IdentityResult> NotifyTwoFactorToken(string userId, string twoFactorProvider,
|
||||
string token, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
@ -1445,9 +1466,9 @@ namespace Microsoft.AspNet.Identity
|
|||
}
|
||||
|
||||
// IUserFactorStore methods
|
||||
internal IUserTwoFactorStore<TUser, TKey> GetUserTwoFactorStore()
|
||||
internal IUserTwoFactorStore<TUser> GetUserTwoFactorStore()
|
||||
{
|
||||
var cast = Store as IUserTwoFactorStore<TUser, TKey>;
|
||||
var cast = Store as IUserTwoFactorStore<TUser>;
|
||||
if (cast == null)
|
||||
{
|
||||
throw new NotSupportedException(Resources.StoreNotIUserTwoFactorStore);
|
||||
|
@ -1461,7 +1482,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="userId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<bool> GetTwoFactorEnabled(TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<bool> GetTwoFactorEnabled(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var store = GetUserTwoFactorStore();
|
||||
|
@ -1481,7 +1502,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="enabled"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IdentityResult> SetTwoFactorEnabled(TKey userId, bool enabled, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IdentityResult> SetTwoFactorEnabled(string userId, bool enabled, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var store = GetUserTwoFactorStore();
|
||||
|
@ -1506,7 +1527,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="body"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task SendEmail(TKey userId, string subject, string body, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task SendEmail(string userId, string subject, string body, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
if (EmailService != null)
|
||||
|
@ -1528,7 +1549,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="message"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task SendSms(TKey userId, string message, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task SendSms(string userId, string message, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
if (SmsService != null)
|
||||
|
@ -1543,9 +1564,9 @@ namespace Microsoft.AspNet.Identity
|
|||
}
|
||||
|
||||
// IUserLockoutStore methods
|
||||
internal IUserLockoutStore<TUser, TKey> GetUserLockoutStore()
|
||||
internal IUserLockoutStore<TUser> GetUserLockoutStore()
|
||||
{
|
||||
var cast = Store as IUserLockoutStore<TUser, TKey>;
|
||||
var cast = Store as IUserLockoutStore<TUser>;
|
||||
if (cast == null)
|
||||
{
|
||||
throw new NotSupportedException(Resources.StoreNotIUserLockoutStore);
|
||||
|
@ -1559,7 +1580,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="userId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<bool> IsLockedOut(TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<bool> IsLockedOut(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var store = GetUserLockoutStore();
|
||||
|
@ -1583,7 +1604,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="userId"></param>
|
||||
/// <param name="enabled"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IdentityResult> SetLockoutEnabled(TKey userId, bool enabled, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IdentityResult> SetLockoutEnabled(string userId, bool enabled, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var store = GetUserLockoutStore();
|
||||
|
@ -1602,7 +1623,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<bool> GetLockoutEnabled(TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<bool> GetLockoutEnabled(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var store = GetUserLockoutStore();
|
||||
|
@ -1621,7 +1642,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="userId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<DateTimeOffset> GetLockoutEndDate(TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<DateTimeOffset> GetLockoutEndDate(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var store = GetUserLockoutStore();
|
||||
|
@ -1641,7 +1662,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="lockoutEnd"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IdentityResult> SetLockoutEndDate(TKey userId, DateTimeOffset lockoutEnd, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IdentityResult> SetLockoutEndDate(string userId, DateTimeOffset lockoutEnd, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var store = GetUserLockoutStore();
|
||||
|
@ -1667,7 +1688,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="userId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IdentityResult> AccessFailed(TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IdentityResult> AccessFailed(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var store = GetUserLockoutStore();
|
||||
|
@ -1695,7 +1716,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="userId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IdentityResult> ResetAccessFailedCount(TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IdentityResult> ResetAccessFailedCount(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var store = GetUserLockoutStore();
|
||||
|
@ -1714,7 +1735,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<int> GetAccessFailedCount(TKey userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<int> GetAccessFailedCount(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
var store = GetUserLockoutStore();
|
||||
|
|
|
@ -14,10 +14,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// Validates users before they are saved
|
||||
/// </summary>
|
||||
/// <typeparam name="TUser"></typeparam>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public class UserValidator<TUser, TKey> : IUserValidator<TUser, TKey>
|
||||
where TUser : class, IUser<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
public class UserValidator<TUser> : IUserValidator<TUser> where TUser : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
|
@ -44,7 +41,7 @@ namespace Microsoft.AspNet.Identity
|
|||
/// <param name="user"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IdentityResult> Validate(UserManager<TUser, TKey> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual async Task<IdentityResult> Validate(UserManager<TUser> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if (manager == null)
|
||||
{
|
||||
|
@ -105,29 +102,30 @@ namespace Microsoft.AspNet.Identity
|
|||
return IsUpper(c) || IsLower(c) || IsDigit(c) || c == '@' || c == '_' || c == '.';
|
||||
}
|
||||
|
||||
private async Task ValidateUserName(UserManager<TUser, TKey> manager, TUser user, ICollection<string> errors)
|
||||
private async Task ValidateUserName(UserManager<TUser> manager, TUser user, ICollection<string> errors)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(user.UserName))
|
||||
var userName = await manager.GetUserName(user);
|
||||
if (string.IsNullOrWhiteSpace(userName))
|
||||
{
|
||||
errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.PropertyTooShort, "UserName"));
|
||||
}
|
||||
else if (AllowOnlyAlphanumericUserNames && !user.UserName.All(IsAlphaNumeric))
|
||||
else if (AllowOnlyAlphanumericUserNames && !userName.All(IsAlphaNumeric))
|
||||
{
|
||||
// If any characters are not letters or digits, its an illegal user name
|
||||
errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.InvalidUserName, user.UserName));
|
||||
errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.InvalidUserName, userName));
|
||||
}
|
||||
else
|
||||
{
|
||||
var owner = await manager.FindByName(user.UserName);
|
||||
if (owner != null && !EqualityComparer<TKey>.Default.Equals(owner.Id, user.Id))
|
||||
var owner = await manager.FindByName(userName);
|
||||
if (owner != null && !string.Equals(await manager.GetUserId(owner), await manager.GetUserId(user)))
|
||||
{
|
||||
errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.DuplicateName, user.UserName));
|
||||
errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.DuplicateName, userName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// make sure email is not empty, valid, and unique
|
||||
private static async Task ValidateEmail(UserManager<TUser, TKey> manager, TUser user, List<string> errors)
|
||||
private static async Task ValidateEmail(UserManager<TUser> manager, TUser user, List<string> errors)
|
||||
{
|
||||
var email = await manager.GetEmailStore().GetEmail(user);
|
||||
if (string.IsNullOrWhiteSpace(email))
|
||||
|
@ -147,7 +145,7 @@ namespace Microsoft.AspNet.Identity
|
|||
}
|
||||
#endif
|
||||
var owner = await manager.FindByEmail(email);
|
||||
if (owner != null && !EqualityComparer<TKey>.Default.Equals(owner.Id, user.Id))
|
||||
if (owner != null && !string.Equals(await manager.GetUserId(owner), await manager.GetUserId(user)))
|
||||
{
|
||||
errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.DuplicateEmail, email));
|
||||
}
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -59,7 +59,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
|||
{
|
||||
var manager = CreateManager();
|
||||
var user = new InMemoryUser("UpdateBlocked") {Email = email};
|
||||
manager.UserValidator = new UserValidator<InMemoryUser, string> {RequireUniqueEmail = true};
|
||||
manager.UserValidator = new UserValidator<InMemoryUser> {RequireUniqueEmail = true};
|
||||
IdentityResultAssert.IsFailure(await manager.Create(user), "Email cannot be null or empty.");
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
|||
{
|
||||
var manager = CreateManager();
|
||||
var user = new InMemoryUser("UpdateBlocked") {Email = email};
|
||||
manager.UserValidator = new UserValidator<InMemoryUser, string> {RequireUniqueEmail = true};
|
||||
manager.UserValidator = new UserValidator<InMemoryUser> {RequireUniqueEmail = true};
|
||||
IdentityResultAssert.IsFailure(await manager.Create(user), "Email '" + email + "' is invalid.");
|
||||
}
|
||||
#endif
|
||||
|
@ -272,7 +272,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
|||
public async Task AddDupeEmailFallsWhenUniqueEmailRequired()
|
||||
{
|
||||
var manager = CreateManager();
|
||||
manager.UserValidator = new UserValidator<InMemoryUser, string> {RequireUniqueEmail = true};
|
||||
manager.UserValidator = new UserValidator<InMemoryUser> {RequireUniqueEmail = true};
|
||||
var user = new InMemoryUser("dupe") {Email = "yup@yup.com"};
|
||||
var user2 = new InMemoryUser("dupeEmail") {Email = "yup@yup.com"};
|
||||
IdentityResultAssert.IsSuccess(await manager.Create(user));
|
||||
|
@ -361,7 +361,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
|||
}
|
||||
|
||||
var identity = await manager.CreateIdentity(user, "test");
|
||||
var claimsFactory = manager.ClaimsIdentityFactory as ClaimsIdentityFactory<InMemoryUser, string>;
|
||||
var claimsFactory = manager.ClaimsIdentityFactory as ClaimsIdentityFactory<InMemoryUser>;
|
||||
Assert.NotNull(claimsFactory);
|
||||
var claims = identity.Claims;
|
||||
Assert.NotNull(claims);
|
||||
|
@ -386,31 +386,31 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
|||
}
|
||||
|
||||
// TODO: No token provider implementations yet
|
||||
private class StaticTokenProvider : IUserTokenProvider<InMemoryUser, string>
|
||||
private class StaticTokenProvider : IUserTokenProvider<InMemoryUser>
|
||||
{
|
||||
public Task<string> Generate(string purpose, UserManager<InMemoryUser, string> manager,
|
||||
public Task<string> Generate(string purpose, UserManager<InMemoryUser> manager,
|
||||
InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return Task.FromResult(MakeToken(purpose, user));
|
||||
}
|
||||
|
||||
public Task<bool> Validate(string purpose, string token, UserManager<InMemoryUser, string> manager,
|
||||
public Task<bool> Validate(string purpose, string token, UserManager<InMemoryUser> manager,
|
||||
InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return Task.FromResult(token == MakeToken(purpose, user));
|
||||
}
|
||||
|
||||
public Task Notify(string token, UserManager<InMemoryUser, string> manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public Task Notify(string token, UserManager<InMemoryUser> manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public Task<bool> IsValidProviderForUser(UserManager<InMemoryUser, string> manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public Task<bool> IsValidProviderForUser(UserManager<InMemoryUser> manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
private static string MakeToken(string purpose, IUser<string> user)
|
||||
private static string MakeToken(string purpose, InMemoryUser user)
|
||||
{
|
||||
return string.Join(":", user.Id, purpose, "ImmaToken");
|
||||
}
|
||||
|
@ -715,7 +715,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
|||
Assert.True(await manager.RoleExists(role.Name));
|
||||
}
|
||||
|
||||
private class AlwaysBadValidator : IUserValidator<InMemoryUser, string>, IRoleValidator<InMemoryRole, string>,
|
||||
private class AlwaysBadValidator : IUserValidator<InMemoryUser>, IRoleValidator<InMemoryRole>,
|
||||
IPasswordValidator
|
||||
{
|
||||
public const string ErrorMessage = "I'm Bad.";
|
||||
|
@ -725,12 +725,12 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
|||
return Task.FromResult(IdentityResult.Failed(ErrorMessage));
|
||||
}
|
||||
|
||||
public Task<IdentityResult> Validate(RoleManager<InMemoryRole, string> manager, InMemoryRole role, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public Task<IdentityResult> Validate(RoleManager<InMemoryRole> manager, InMemoryRole role, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return Task.FromResult(IdentityResult.Failed(ErrorMessage));
|
||||
}
|
||||
|
||||
public Task<IdentityResult> Validate(UserManager<InMemoryUser, string> manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public Task<IdentityResult> Validate(UserManager<InMemoryUser> manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return Task.FromResult(IdentityResult.Failed(ErrorMessage));
|
||||
}
|
||||
|
@ -1091,25 +1091,25 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
|||
Assert.False(await manager.VerifyChangePhoneNumberToken(user.Id, token1, num2));
|
||||
}
|
||||
|
||||
private class EmailTokenProvider : IUserTokenProvider<InMemoryUser, string>
|
||||
private class EmailTokenProvider : IUserTokenProvider<InMemoryUser>
|
||||
{
|
||||
public Task<string> Generate(string purpose, UserManager<InMemoryUser, string> manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public Task<string> Generate(string purpose, UserManager<InMemoryUser> manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return Task.FromResult(MakeToken(purpose));
|
||||
}
|
||||
|
||||
public Task<bool> Validate(string purpose, string token, UserManager<InMemoryUser, string> manager,
|
||||
public Task<bool> Validate(string purpose, string token, UserManager<InMemoryUser> manager,
|
||||
InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return Task.FromResult(token == MakeToken(purpose));
|
||||
}
|
||||
|
||||
public Task Notify(string token, UserManager<InMemoryUser, string> manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public Task Notify(string token, UserManager<InMemoryUser> manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return manager.SendEmail(user.Id, token, token);
|
||||
}
|
||||
|
||||
public async Task<bool> IsValidProviderForUser(UserManager<InMemoryUser, string> manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public async Task<bool> IsValidProviderForUser(UserManager<InMemoryUser> manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return !string.IsNullOrEmpty(await manager.GetEmail(user.Id));
|
||||
}
|
||||
|
@ -1120,27 +1120,27 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
|||
}
|
||||
}
|
||||
|
||||
private class SmsTokenProvider : IUserTokenProvider<InMemoryUser, string>
|
||||
private class SmsTokenProvider : IUserTokenProvider<InMemoryUser>
|
||||
{
|
||||
public Task<string> Generate(string purpose, UserManager<InMemoryUser, string> manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public Task<string> Generate(string purpose, UserManager<InMemoryUser> manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return Task.FromResult(MakeToken(purpose));
|
||||
}
|
||||
|
||||
public Task<bool> Validate(string purpose, string token, UserManager<InMemoryUser, string> manager,
|
||||
public Task<bool> Validate(string purpose, string token, UserManager<InMemoryUser> manager,
|
||||
InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return Task.FromResult(token == MakeToken(purpose));
|
||||
}
|
||||
|
||||
public Task Notify(string token, UserManager<InMemoryUser, string> manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public Task Notify(string token, UserManager<InMemoryUser> manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return manager.SendSms(user.Id, token);
|
||||
return manager.SendSms(user.Id, token, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<bool> IsValidProviderForUser(UserManager<InMemoryUser, string> manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public async Task<bool> IsValidProviderForUser(UserManager<InMemoryUser> manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return !string.IsNullOrEmpty(await manager.GetPhoneNumber(user.Id));
|
||||
return !string.IsNullOrEmpty(await manager.GetPhoneNumber(user.Id, cancellationToken));
|
||||
}
|
||||
|
||||
private static string MakeToken(string purpose)
|
||||
|
@ -1406,9 +1406,9 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
|||
Assert.False(await manager.VerifyTwoFactorToken(user.Id, factorId, "bogus"));
|
||||
}
|
||||
|
||||
private static UserManager<InMemoryUser, string> CreateManager()
|
||||
private static UserManager<InMemoryUser> CreateManager()
|
||||
{
|
||||
return new UserManager<InMemoryUser, string>(new InMemoryUserStore<InMemoryUser>());
|
||||
return new UserManager<InMemoryUser>(new InMemoryUserStore<InMemoryUser>());
|
||||
}
|
||||
|
||||
private static RoleManager<InMemoryRole> CreateRoleManager()
|
||||
|
|
|
@ -17,10 +17,10 @@ namespace Microsoft.AspNet.Identity.Security.Test
|
|||
public async Task EnsureClaimsIdentityFactoryCreateIdentityCalled()
|
||||
{
|
||||
// Setup
|
||||
var store = new Mock<IUserStore<TestUser, string>>();
|
||||
var store = new Mock<IUserStore<TestUser>>();
|
||||
var user = new TestUser { UserName = "Foo" };
|
||||
var userManager = new UserManager<TestUser, string>(store.Object);
|
||||
var identityFactory = new Mock<IClaimsIdentityFactory<TestUser, string>>();
|
||||
var userManager = new UserManager<TestUser>(store.Object);
|
||||
var identityFactory = new Mock<IClaimsIdentityFactory<TestUser>>();
|
||||
const string authType = "Test";
|
||||
var testIdentity = new ClaimsIdentity(authType);
|
||||
identityFactory.Setup(s => s.Create(userManager, user, authType, CancellationToken.None)).ReturnsAsync(testIdentity).Verifiable();
|
||||
|
@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Identity.Security.Test
|
|||
var response = new Mock<HttpResponse>();
|
||||
context.Setup(c => c.Response).Returns(response.Object).Verifiable();
|
||||
response.Setup(r => r.SignIn(testIdentity, It.IsAny<AuthenticationProperties>())).Verifiable();
|
||||
var helper = new SignInManager<TestUser, string> { UserManager = userManager, AuthenticationType = authType, Context = context.Object };
|
||||
var helper = new SignInManager<TestUser> { UserManager = userManager, AuthenticationType = authType, Context = context.Object };
|
||||
|
||||
// Act
|
||||
await helper.SignIn(user, false, false);
|
||||
|
@ -43,10 +43,10 @@ namespace Microsoft.AspNet.Identity.Security.Test
|
|||
{
|
||||
// Setup
|
||||
var user = new TestUser { UserName = "Foo" };
|
||||
var manager = new Mock<UserManager<TestUser, string>>();
|
||||
var manager = new Mock<UserManager<TestUser>>();
|
||||
manager.Setup(m => m.IsLockedOut(user.Id, CancellationToken.None)).ReturnsAsync(true).Verifiable();
|
||||
manager.Setup(m => m.FindByName(user.UserName, CancellationToken.None)).ReturnsAsync(user).Verifiable();
|
||||
var helper = new SignInManager<TestUser, string> { UserManager = manager.Object };
|
||||
var helper = new SignInManager<TestUser> { UserManager = manager.Object };
|
||||
|
||||
// Act
|
||||
var result = await helper.PasswordSignIn(user.UserName, "bogus", false, false);
|
||||
|
@ -61,7 +61,7 @@ namespace Microsoft.AspNet.Identity.Security.Test
|
|||
{
|
||||
// Setup
|
||||
var user = new TestUser { UserName = "Foo" };
|
||||
var manager = new Mock<UserManager<TestUser, string>>();
|
||||
var manager = new Mock<UserManager<TestUser>>();
|
||||
manager.Setup(m => m.IsLockedOut(user.Id, CancellationToken.None)).ReturnsAsync(false).Verifiable();
|
||||
manager.Setup(m => m.FindByName(user.UserName, CancellationToken.None)).ReturnsAsync(user).Verifiable();
|
||||
manager.Setup(m => m.CheckPassword(user, "password", CancellationToken.None)).ReturnsAsync(true).Verifiable();
|
||||
|
@ -70,7 +70,7 @@ namespace Microsoft.AspNet.Identity.Security.Test
|
|||
var response = new Mock<HttpResponse>();
|
||||
context.Setup(c => c.Response).Returns(response.Object).Verifiable();
|
||||
response.Setup(r => r.SignIn(It.IsAny<ClaimsIdentity>(), It.IsAny<AuthenticationProperties>())).Verifiable();
|
||||
var helper = new SignInManager<TestUser, string> { UserManager = manager.Object, Context = context.Object };
|
||||
var helper = new SignInManager<TestUser> { UserManager = manager.Object, Context = context.Object };
|
||||
|
||||
// Act
|
||||
var result = await helper.PasswordSignIn(user.UserName, "password", false, false);
|
||||
|
@ -85,11 +85,11 @@ namespace Microsoft.AspNet.Identity.Security.Test
|
|||
{
|
||||
// Setup
|
||||
var user = new TestUser { UserName = "Foo" };
|
||||
var manager = new Mock<UserManager<TestUser, string>>();
|
||||
var manager = new Mock<UserManager<TestUser>>();
|
||||
manager.Setup(m => m.IsLockedOut(user.Id, CancellationToken.None)).ReturnsAsync(false).Verifiable();
|
||||
manager.Setup(m => m.FindByName(user.UserName, CancellationToken.None)).ReturnsAsync(user).Verifiable();
|
||||
manager.Setup(m => m.CheckPassword(user, "bogus", CancellationToken.None)).ReturnsAsync(false).Verifiable();
|
||||
var helper = new SignInManager<TestUser, string> { UserManager = manager.Object };
|
||||
var helper = new SignInManager<TestUser> { UserManager = manager.Object };
|
||||
|
||||
// Act
|
||||
var result = await helper.PasswordSignIn(user.UserName, "bogus", false, false);
|
||||
|
@ -104,9 +104,9 @@ namespace Microsoft.AspNet.Identity.Security.Test
|
|||
public async Task PasswordSignInFailsWithUnknownUser()
|
||||
{
|
||||
// Setup
|
||||
var manager = new Mock<UserManager<TestUser, string>>();
|
||||
var manager = new Mock<UserManager<TestUser>>();
|
||||
manager.Setup(m => m.FindByName("bogus", CancellationToken.None)).ReturnsAsync(null).Verifiable();
|
||||
var helper = new SignInManager<TestUser, string> { UserManager = manager.Object };
|
||||
var helper = new SignInManager<TestUser> { UserManager = manager.Object };
|
||||
|
||||
// Act
|
||||
var result = await helper.PasswordSignIn("bogus", "bogus", false, false);
|
||||
|
@ -120,7 +120,7 @@ namespace Microsoft.AspNet.Identity.Security.Test
|
|||
public async Task PasswordSignInFailsWithNoUserManager()
|
||||
{
|
||||
// Setup
|
||||
var helper = new SignInManager<TestUser, string>();
|
||||
var helper = new SignInManager<TestUser>();
|
||||
|
||||
// Act
|
||||
var result = await helper.PasswordSignIn("bogus", "bogus", false, false);
|
||||
|
@ -134,7 +134,7 @@ namespace Microsoft.AspNet.Identity.Security.Test
|
|||
{
|
||||
// Setup
|
||||
var user = new TestUser();
|
||||
var helper = new SignInManager<TestUser, string>();
|
||||
var helper = new SignInManager<TestUser>();
|
||||
|
||||
// Act
|
||||
var result = await helper.CreateUserIdentity(user);
|
||||
|
@ -149,7 +149,7 @@ namespace Microsoft.AspNet.Identity.Security.Test
|
|||
{
|
||||
// Setup
|
||||
var user = new TestUser { UserName = "Foo" };
|
||||
var manager = new Mock<UserManager<TestUser, string>>();
|
||||
var manager = new Mock<UserManager<TestUser>>();
|
||||
var lockedout = false;
|
||||
manager.Setup(m => m.AccessFailed(user.Id, CancellationToken.None)).Returns(() =>
|
||||
{
|
||||
|
@ -159,7 +159,7 @@ namespace Microsoft.AspNet.Identity.Security.Test
|
|||
manager.Setup(m => m.IsLockedOut(user.Id, CancellationToken.None)).Returns(() => Task.FromResult(lockedout));
|
||||
manager.Setup(m => m.FindByName(user.UserName, CancellationToken.None)).ReturnsAsync(user).Verifiable();
|
||||
manager.Setup(m => m.CheckPassword(user, "bogus", CancellationToken.None)).ReturnsAsync(false).Verifiable();
|
||||
var helper = new SignInManager<TestUser, string> { UserManager = manager.Object };
|
||||
var helper = new SignInManager<TestUser> { UserManager = manager.Object };
|
||||
|
||||
// Act
|
||||
var result = await helper.PasswordSignIn(user.UserName, "bogus", false, true);
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
namespace Microsoft.AspNet.Identity.Security.Test
|
||||
{
|
||||
public class TestUser : TestUser<string>
|
||||
public class TestUser
|
||||
{
|
||||
}
|
||||
|
||||
public class TestUser<TKey> : IUser<TKey>
|
||||
{
|
||||
public TKey Id { get; private set; }
|
||||
public string Id { get; private set; }
|
||||
public string UserName { get; set; }
|
||||
}
|
||||
}
|
|
@ -13,8 +13,8 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
[Fact]
|
||||
public async Task CreateIdentityNullChecks()
|
||||
{
|
||||
var factory = new ClaimsIdentityFactory<TestUser, string>();
|
||||
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
||||
var factory = new ClaimsIdentityFactory<TestUser>();
|
||||
var manager = new UserManager<TestUser>(new NoopUserStore());
|
||||
await Assert.ThrowsAsync<ArgumentNullException>("manager",
|
||||
async () => await factory.Create(null, null, "whatever"));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>("user",
|
||||
|
@ -33,17 +33,19 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
public async Task EnsureClaimsIdentityHasExpectedClaims(bool supportRoles, bool supportClaims)
|
||||
{
|
||||
// Setup
|
||||
var userManager = new Mock<UserManager<TestUser, string>>();
|
||||
var userManager = new Mock<UserManager<TestUser>>();
|
||||
var user = new TestUser { UserName = "Foo" };
|
||||
userManager.Setup(m => m.SupportsUserRole).Returns(supportRoles);
|
||||
userManager.Setup(m => m.SupportsUserClaim).Returns(supportClaims);
|
||||
userManager.Setup(m => m.GetUserId(user, CancellationToken.None)).ReturnsAsync(user.Id);
|
||||
userManager.Setup(m => m.GetUserName(user, CancellationToken.None)).ReturnsAsync(user.UserName);
|
||||
var roleClaims = new[] { "Admin", "Local" };
|
||||
userManager.Setup(m => m.GetRoles(user.Id, CancellationToken.None)).ReturnsAsync(roleClaims);
|
||||
var userClaims = new[] { new Claim("Whatever", "Value"), new Claim("Whatever2", "Value2") };
|
||||
userManager.Setup(m => m.GetClaims(user.Id, CancellationToken.None)).ReturnsAsync(userClaims);
|
||||
|
||||
const string authType = "Microsoft.AspNet.Identity";
|
||||
var factory = new ClaimsIdentityFactory<TestUser, string>();
|
||||
var factory = new ClaimsIdentityFactory<TestUser>();
|
||||
|
||||
// Act
|
||||
var identity = await factory.Create(userManager.Object, user, authType);
|
||||
|
|
|
@ -3,7 +3,7 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace Microsoft.AspNet.Identity.Test
|
||||
{
|
||||
public class NoopRoleStore : IRoleStore<TestRole, string>
|
||||
public class NoopRoleStore : IRoleStore<TestRole>
|
||||
{
|
||||
public Task Create(TestRole user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
|
@ -15,6 +15,11 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public Task<string> GetRoleName(TestRole role, CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
return Task.FromResult<string>(null);
|
||||
}
|
||||
|
||||
public Task<TestRole> FindById(string roleId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return Task.FromResult<TestRole>(null);
|
||||
|
@ -33,5 +38,10 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public Task<string> GetRoleId(TestRole role, CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
return Task.FromResult<string>(null);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,8 +3,18 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace Microsoft.AspNet.Identity.Test
|
||||
{
|
||||
public class NoopUserStore : IUserStore<TestUser, string>
|
||||
public class NoopUserStore : IUserStore<TestUser>
|
||||
{
|
||||
public Task<string> GetUserId(TestUser user, CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
return Task.FromResult(user.Id);
|
||||
}
|
||||
|
||||
public Task<string> GetUserName(TestUser user, CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
return Task.FromResult(user.UserName);
|
||||
}
|
||||
|
||||
public Task Create(TestUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
|
|
|
@ -11,13 +11,13 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
[Fact]
|
||||
public void ConstructorThrowsWithNullStore()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>("store", () => new RoleManager<TestRole, string>(null));
|
||||
Assert.Throws<ArgumentNullException>("store", () => new RoleManager<TestRole>(null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RolesQueryableFailWhenStoreNotImplemented()
|
||||
{
|
||||
var manager = new RoleManager<TestRole, string>(new NoopRoleStore());
|
||||
var manager = new RoleManager<TestRole>(new NoopRoleStore());
|
||||
Assert.False(manager.SupportsQueryableRoles);
|
||||
Assert.Throws<NotSupportedException>(() => manager.Roles.Count());
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
[Fact]
|
||||
public void DisposeAfterDisposeDoesNotThrow()
|
||||
{
|
||||
var manager = new RoleManager<TestRole, string>(new NoopRoleStore());
|
||||
var manager = new RoleManager<TestRole>(new NoopRoleStore());
|
||||
manager.Dispose();
|
||||
manager.Dispose();
|
||||
}
|
||||
|
@ -34,8 +34,8 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
public async Task RoleManagerPublicNullChecks()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>("store",
|
||||
() => new RoleManager<TestRole, string>(null));
|
||||
var manager = new RoleManager<TestRole, string>(new NotImplementedStore());
|
||||
() => new RoleManager<TestRole>(null));
|
||||
var manager = new RoleManager<TestRole>(new NotImplementedStore());
|
||||
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await manager.Create(null));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await manager.Update(null));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await manager.Delete(null));
|
||||
|
@ -46,7 +46,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
[Fact]
|
||||
public async Task RoleStoreMethodsThrowWhenDisposed()
|
||||
{
|
||||
var manager = new RoleManager<TestRole, string>(new NoopRoleStore());
|
||||
var manager = new RoleManager<TestRole>(new NoopRoleStore());
|
||||
manager.Dispose();
|
||||
await Assert.ThrowsAsync<ObjectDisposedException>(() => manager.FindById(null));
|
||||
await Assert.ThrowsAsync<ObjectDisposedException>(() => manager.FindByName(null));
|
||||
|
@ -56,7 +56,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
await Assert.ThrowsAsync<ObjectDisposedException>(() => manager.Delete(null));
|
||||
}
|
||||
|
||||
private class NotImplementedStore : IRoleStore<TestRole, string>
|
||||
private class NotImplementedStore : IRoleStore<TestRole>
|
||||
{
|
||||
public Task Create(TestRole role, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
|
@ -73,6 +73,16 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<string> GetRoleId(TestRole role, CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<string> GetRoleName(TestRole role, CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<TestRole> FindById(string roleId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
|
|
@ -10,8 +10,8 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
public async Task ValidateThrowsWithNull()
|
||||
{
|
||||
// Setup
|
||||
var manager = new RoleManager<TestRole, string>(new NoopRoleStore());
|
||||
var validator = new RoleValidator<TestRole, string>();
|
||||
var manager = new RoleManager<TestRole>(new NoopRoleStore());
|
||||
var validator = new RoleValidator<TestRole>();
|
||||
|
||||
// Act
|
||||
// Assert
|
||||
|
@ -25,8 +25,8 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
public async Task ValidateFailsWithTooShortRoleName(string input)
|
||||
{
|
||||
// Setup
|
||||
var manager = new RoleManager<TestRole, string>(new NoopRoleStore());
|
||||
var validator = new RoleValidator<TestRole, string>();
|
||||
var manager = new RoleManager<TestRole>(new NoopRoleStore());
|
||||
var validator = new RoleValidator<TestRole>();
|
||||
var user = new TestRole {Name = input};
|
||||
|
||||
// Act
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
namespace Microsoft.AspNet.Identity.Test
|
||||
{
|
||||
public class TestRole : IRole<string>
|
||||
public class TestRole
|
||||
{
|
||||
public string Id { get; private set; }
|
||||
public string Name { get; set; }
|
||||
|
|
|
@ -9,15 +9,14 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
public static class TestServices
|
||||
{
|
||||
public static IEnumerable<IServiceDescriptor> DefaultServices<TUser, TKey>()
|
||||
where TUser : class, IUser<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
where TUser : class
|
||||
{
|
||||
var describer = new ServiceDescriber();
|
||||
yield return describer.Transient<IPasswordValidator, PasswordValidator>();
|
||||
yield return describer.Transient<IUserValidator<TUser, TKey>, UserValidator<TUser, TKey>>();
|
||||
yield return describer.Transient<IUserValidator<TUser>, UserValidator<TUser>>();
|
||||
yield return describer.Transient<IPasswordHasher, PasswordHasher>();
|
||||
yield return describer.Transient<IClaimsIdentityFactory<TUser, TKey>, ClaimsIdentityFactory<TUser, TKey>>();
|
||||
yield return describer.Transient<IUserStore<TUser, TKey>, NoopUserStore>();
|
||||
yield return describer.Transient<IClaimsIdentityFactory<TUser>, ClaimsIdentityFactory<TUser>>();
|
||||
yield return describer.Transient<IUserStore<TUser>, NoopUserStore>();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,17 +2,14 @@ using System;
|
|||
|
||||
namespace Microsoft.AspNet.Identity.Test
|
||||
{
|
||||
public class TestUser : TestUser<string>
|
||||
public class TestUser
|
||||
{
|
||||
public TestUser()
|
||||
{
|
||||
Id = Guid.NewGuid().ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public class TestUser<TKey> : IUser<TKey>
|
||||
{
|
||||
public TKey Id { get; set; }
|
||||
public string Id { get; set; }
|
||||
public string UserName { get; set; }
|
||||
}
|
||||
}
|
|
@ -13,9 +13,9 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
{
|
||||
public class UserManagerTest
|
||||
{
|
||||
private class TestManager : UserManager<TestUser, string>
|
||||
private class TestManager : UserManager<TestUser>
|
||||
{
|
||||
public IUserStore<TestUser, string> StorePublic { get { return base.Store; } }
|
||||
public IUserStore<TestUser> StorePublic { get { return base.Store; } }
|
||||
|
||||
public TestManager(IServiceProvider provider) : base(provider) { }
|
||||
}
|
||||
|
@ -36,11 +36,11 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
public async Task CreateCallsStore()
|
||||
{
|
||||
// Setup
|
||||
var store = new Mock<IUserStore<TestUser, string>>();
|
||||
var store = new Mock<IUserStore<TestUser>>();
|
||||
var user = new TestUser { UserName = "Foo" };
|
||||
store.Setup(s => s.Create(user, CancellationToken.None)).Returns(Task.FromResult(0)).Verifiable();
|
||||
var validator = new Mock<UserValidator<TestUser, string>>();
|
||||
var userManager = new UserManager<TestUser, string>(store.Object);
|
||||
var validator = new Mock<UserValidator<TestUser>>();
|
||||
var userManager = new UserManager<TestUser>(store.Object);
|
||||
validator.Setup(v => v.Validate(userManager, user, CancellationToken.None)).Returns(Task.FromResult(IdentityResult.Success)).Verifiable();
|
||||
userManager.UserValidator = validator.Object;
|
||||
|
||||
|
@ -56,10 +56,10 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
public async Task DeleteCallsStore()
|
||||
{
|
||||
// Setup
|
||||
var store = new Mock<IUserStore<TestUser, string>>();
|
||||
var store = new Mock<IUserStore<TestUser>>();
|
||||
var user = new TestUser { UserName = "Foo" };
|
||||
store.Setup(s => s.Delete(user, CancellationToken.None)).Returns(Task.FromResult(0)).Verifiable();
|
||||
var userManager = new UserManager<TestUser, string>(store.Object);
|
||||
var userManager = new UserManager<TestUser>(store.Object);
|
||||
|
||||
// Act
|
||||
var result = await userManager.Delete(user);
|
||||
|
@ -73,11 +73,11 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
public async Task UpdateCallsStore()
|
||||
{
|
||||
// Setup
|
||||
var store = new Mock<IUserStore<TestUser, string>>();
|
||||
var store = new Mock<IUserStore<TestUser>>();
|
||||
var user = new TestUser { UserName = "Foo" };
|
||||
store.Setup(s => s.Update(user, CancellationToken.None)).Returns(Task.FromResult(0)).Verifiable();
|
||||
var validator = new Mock<UserValidator<TestUser, string>>();
|
||||
var userManager = new UserManager<TestUser, string>(store.Object);
|
||||
var validator = new Mock<UserValidator<TestUser>>();
|
||||
var userManager = new UserManager<TestUser>(store.Object);
|
||||
validator.Setup(v => v.Validate(userManager, user, CancellationToken.None)).Returns(Task.FromResult(IdentityResult.Success)).Verifiable();
|
||||
userManager.UserValidator = validator.Object;
|
||||
|
||||
|
@ -93,10 +93,10 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
public async Task FindByIdCallsStore()
|
||||
{
|
||||
// Setup
|
||||
var store = new Mock<IUserStore<TestUser, string>>();
|
||||
var store = new Mock<IUserStore<TestUser>>();
|
||||
var user = new TestUser { UserName = "Foo" };
|
||||
store.Setup(s => s.FindById(user.Id, CancellationToken.None)).Returns(Task.FromResult(user)).Verifiable();
|
||||
var userManager = new UserManager<TestUser, string>(store.Object);
|
||||
var userManager = new UserManager<TestUser>(store.Object);
|
||||
|
||||
// Act
|
||||
var result = await userManager.FindById(user.Id);
|
||||
|
@ -110,10 +110,10 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
public async Task FindByNameCallsStore()
|
||||
{
|
||||
// Setup
|
||||
var store = new Mock<IUserStore<TestUser, string>>();
|
||||
var store = new Mock<IUserStore<TestUser>>();
|
||||
var user = new TestUser {UserName="Foo"};
|
||||
store.Setup(s => s.FindByName(user.UserName, CancellationToken.None)).Returns(Task.FromResult(user)).Verifiable();
|
||||
var userManager = new UserManager<TestUser, string>(store.Object);
|
||||
var userManager = new UserManager<TestUser>(store.Object);
|
||||
|
||||
// Act
|
||||
var result = await userManager.FindByName(user.UserName);
|
||||
|
@ -128,21 +128,21 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
[Fact]
|
||||
public async Task CheckPasswordWithNullUserReturnsFalse()
|
||||
{
|
||||
var manager = new UserManager<TestUser, string>(new EmptyStore());
|
||||
var manager = new UserManager<TestUser>(new EmptyStore());
|
||||
Assert.False(await manager.CheckPassword(null, "whatevs"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FindWithUnknownUserAndPasswordReturnsNull()
|
||||
{
|
||||
var manager = new UserManager<TestUser, string>(new EmptyStore());
|
||||
var manager = new UserManager<TestUser>(new EmptyStore());
|
||||
Assert.Null(await manager.Find("bogus", "whatevs"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsersQueryableFailWhenStoreNotImplemented()
|
||||
{
|
||||
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
||||
var manager = new UserManager<TestUser>(new NoopUserStore());
|
||||
Assert.False(manager.SupportsQueryableUsers);
|
||||
Assert.Throws<NotSupportedException>(() => manager.Users.Count());
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
[Fact]
|
||||
public async Task UsersEmailMethodsFailWhenStoreNotImplemented()
|
||||
{
|
||||
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
||||
var manager = new UserManager<TestUser>(new NoopUserStore());
|
||||
Assert.False(manager.SupportsUserEmail);
|
||||
await Assert.ThrowsAsync<NotSupportedException>(() => manager.FindByEmail(null));
|
||||
await Assert.ThrowsAsync<NotSupportedException>(() => manager.SetEmail(null, null));
|
||||
|
@ -162,7 +162,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
[Fact]
|
||||
public async Task UsersPhoneNumberMethodsFailWhenStoreNotImplemented()
|
||||
{
|
||||
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
||||
var manager = new UserManager<TestUser>(new NoopUserStore());
|
||||
Assert.False(manager.SupportsUserPhoneNumber);
|
||||
await Assert.ThrowsAsync<NotSupportedException>(async () => await manager.SetPhoneNumber(null, null));
|
||||
await Assert.ThrowsAsync<NotSupportedException>(async () => await manager.SetPhoneNumber(null, null));
|
||||
|
@ -172,7 +172,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
[Fact]
|
||||
public async Task TokenMethodsThrowWithNoTokenProvider()
|
||||
{
|
||||
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
||||
var manager = new UserManager<TestUser>(new NoopUserStore());
|
||||
await Assert.ThrowsAsync<NotSupportedException>(
|
||||
async () => await manager.GenerateUserToken(null, null));
|
||||
await Assert.ThrowsAsync<NotSupportedException>(
|
||||
|
@ -182,7 +182,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
[Fact]
|
||||
public async Task PasswordMethodsFailWhenStoreNotImplemented()
|
||||
{
|
||||
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
||||
var manager = new UserManager<TestUser>(new NoopUserStore());
|
||||
Assert.False(manager.SupportsUserPassword);
|
||||
await Assert.ThrowsAsync<NotSupportedException>(() => manager.Create(null, null));
|
||||
await Assert.ThrowsAsync<NotSupportedException>(() => manager.ChangePassword(null, null, null));
|
||||
|
@ -195,7 +195,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
[Fact]
|
||||
public async Task SecurityStampMethodsFailWhenStoreNotImplemented()
|
||||
{
|
||||
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
||||
var manager = new UserManager<TestUser>(new NoopUserStore());
|
||||
Assert.False(manager.SupportsUserSecurityStamp);
|
||||
await Assert.ThrowsAsync<NotSupportedException>(() => manager.UpdateSecurityStamp("bogus"));
|
||||
await Assert.ThrowsAsync<NotSupportedException>(() => manager.GetSecurityStamp("bogus"));
|
||||
|
@ -210,7 +210,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
[Fact]
|
||||
public async Task LoginMethodsFailWhenStoreNotImplemented()
|
||||
{
|
||||
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
||||
var manager = new UserManager<TestUser>(new NoopUserStore());
|
||||
Assert.False(manager.SupportsUserLogin);
|
||||
await Assert.ThrowsAsync<NotSupportedException>(async () => await manager.AddLogin("bogus", null));
|
||||
await Assert.ThrowsAsync<NotSupportedException>(async () => await manager.RemoveLogin("bogus", null));
|
||||
|
@ -221,7 +221,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
[Fact]
|
||||
public async Task ClaimMethodsFailWhenStoreNotImplemented()
|
||||
{
|
||||
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
||||
var manager = new UserManager<TestUser>(new NoopUserStore());
|
||||
Assert.False(manager.SupportsUserClaim);
|
||||
await Assert.ThrowsAsync<NotSupportedException>(async () => await manager.AddClaim("bogus", null));
|
||||
await Assert.ThrowsAsync<NotSupportedException>(async () => await manager.RemoveClaim("bogus", null));
|
||||
|
@ -231,7 +231,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
[Fact]
|
||||
public async Task TwoFactorStoreMethodsFailWhenStoreNotImplemented()
|
||||
{
|
||||
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
||||
var manager = new UserManager<TestUser>(new NoopUserStore());
|
||||
Assert.False(manager.SupportsUserTwoFactor);
|
||||
await Assert.ThrowsAsync<NotSupportedException>(async () => await manager.GetTwoFactorEnabled("bogus"));
|
||||
await
|
||||
|
@ -241,7 +241,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
[Fact]
|
||||
public async Task LockoutStoreMethodsFailWhenStoreNotImplemented()
|
||||
{
|
||||
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
||||
var manager = new UserManager<TestUser>(new NoopUserStore());
|
||||
Assert.False(manager.SupportsUserLockout);
|
||||
await Assert.ThrowsAsync<NotSupportedException>(async () => await manager.GetLockoutEnabled("bogus"));
|
||||
await Assert.ThrowsAsync<NotSupportedException>(async () => await manager.SetLockoutEnabled("bogus", true));
|
||||
|
@ -254,7 +254,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
[Fact]
|
||||
public async Task RoleMethodsFailWhenStoreNotImplemented()
|
||||
{
|
||||
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
||||
var manager = new UserManager<TestUser>(new NoopUserStore());
|
||||
Assert.False(manager.SupportsUserRole);
|
||||
await Assert.ThrowsAsync<NotSupportedException>(async () => await manager.AddToRole("bogus", null));
|
||||
await Assert.ThrowsAsync<NotSupportedException>(async () => await manager.GetRoles("bogus"));
|
||||
|
@ -265,7 +265,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
[Fact]
|
||||
public void DisposeAfterDisposeDoesNotThrow()
|
||||
{
|
||||
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
||||
var manager = new UserManager<TestUser>(new NoopUserStore());
|
||||
manager.Dispose();
|
||||
manager.Dispose();
|
||||
}
|
||||
|
@ -274,7 +274,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
public async Task PasswordValidatorBlocksCreate()
|
||||
{
|
||||
// TODO: Can switch to Mock eventually
|
||||
var manager = new UserManager<TestUser, string>(new EmptyStore())
|
||||
var manager = new UserManager<TestUser>(new EmptyStore())
|
||||
{
|
||||
PasswordValidator = new BadPasswordValidtor()
|
||||
};
|
||||
|
@ -286,10 +286,10 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
public async Task ManagerPublicNullChecks()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>("store",
|
||||
() => new UserManager<TestUser, string>((IUserStore<TestUser, string>) null));
|
||||
() => new UserManager<TestUser>((IUserStore<TestUser>) null));
|
||||
Assert.Throws<ArgumentNullException>("serviceProvider",
|
||||
() => new UserManager<TestUser, string>((IServiceProvider)null));
|
||||
var manager = new UserManager<TestUser, string>(new NotImplementedStore());
|
||||
() => new UserManager<TestUser>((IServiceProvider)null));
|
||||
var manager = new UserManager<TestUser>(new NotImplementedStore());
|
||||
Assert.Throws<ArgumentNullException>(() => manager.ClaimsIdentityFactory = null);
|
||||
Assert.Throws<ArgumentNullException>(() => manager.PasswordHasher = null);
|
||||
await
|
||||
|
@ -317,7 +317,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
[Fact]
|
||||
public async Task MethodsFailWithUnknownUserTest()
|
||||
{
|
||||
var manager = new UserManager<TestUser, string>(new EmptyStore())
|
||||
var manager = new UserManager<TestUser>(new EmptyStore())
|
||||
{
|
||||
UserTokenProvider = new NoOpTokenProvider()
|
||||
};
|
||||
|
@ -413,7 +413,7 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
[Fact]
|
||||
public async Task MethodsThrowWhenDisposedTest()
|
||||
{
|
||||
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
||||
var manager = new UserManager<TestUser>(new NoopUserStore());
|
||||
manager.Dispose();
|
||||
Assert.Throws<ObjectDisposedException>(() => manager.ClaimsIdentityFactory);
|
||||
await Assert.ThrowsAsync<ObjectDisposedException>(() => manager.AddClaim("bogus", null));
|
||||
|
@ -459,15 +459,15 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
}
|
||||
|
||||
private class EmptyStore :
|
||||
IUserPasswordStore<TestUser, string>,
|
||||
IUserClaimStore<TestUser, string>,
|
||||
IUserLoginStore<TestUser, string>,
|
||||
IUserEmailStore<TestUser, string>,
|
||||
IUserPhoneNumberStore<TestUser, string>,
|
||||
IUserLockoutStore<TestUser, string>,
|
||||
IUserTwoFactorStore<TestUser, string>,
|
||||
IUserRoleStore<TestUser, string>,
|
||||
IUserSecurityStampStore<TestUser, string>
|
||||
IUserPasswordStore<TestUser>,
|
||||
IUserClaimStore<TestUser>,
|
||||
IUserLoginStore<TestUser>,
|
||||
IUserEmailStore<TestUser>,
|
||||
IUserPhoneNumberStore<TestUser>,
|
||||
IUserLockoutStore<TestUser>,
|
||||
IUserTwoFactorStore<TestUser>,
|
||||
IUserRoleStore<TestUser>,
|
||||
IUserSecurityStampStore<TestUser>
|
||||
{
|
||||
public Task<IList<Claim>> GetClaims(TestUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
|
@ -667,40 +667,50 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
{
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
|
||||
public Task<string> GetUserId(TestUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return Task.FromResult<string>(null);
|
||||
}
|
||||
|
||||
public Task<string> GetUserName(TestUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return Task.FromResult<string>(null);
|
||||
}
|
||||
}
|
||||
|
||||
private class NoOpTokenProvider : IUserTokenProvider<TestUser, string>
|
||||
private class NoOpTokenProvider : IUserTokenProvider<TestUser>
|
||||
{
|
||||
public Task<string> Generate(string purpose, UserManager<TestUser, string> manager, TestUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public Task<string> Generate(string purpose, UserManager<TestUser> manager, TestUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return Task.FromResult("Test");
|
||||
}
|
||||
|
||||
public Task<bool> Validate(string purpose, string token, UserManager<TestUser, string> manager,
|
||||
public Task<bool> Validate(string purpose, string token, UserManager<TestUser> manager,
|
||||
TestUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
public Task Notify(string token, UserManager<TestUser, string> manager, TestUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public Task Notify(string token, UserManager<TestUser> manager, TestUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public Task<bool> IsValidProviderForUser(UserManager<TestUser, string> manager, TestUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public Task<bool> IsValidProviderForUser(UserManager<TestUser> manager, TestUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
}
|
||||
|
||||
private class NotImplementedStore :
|
||||
IUserPasswordStore<TestUser, string>,
|
||||
IUserClaimStore<TestUser, string>,
|
||||
IUserLoginStore<TestUser, string>,
|
||||
IUserEmailStore<TestUser, string>,
|
||||
IUserPhoneNumberStore<TestUser, string>,
|
||||
IUserLockoutStore<TestUser, string>,
|
||||
IUserTwoFactorStore<TestUser, string>
|
||||
IUserPasswordStore<TestUser>,
|
||||
IUserClaimStore<TestUser>,
|
||||
IUserLoginStore<TestUser>,
|
||||
IUserEmailStore<TestUser>,
|
||||
IUserPhoneNumberStore<TestUser>,
|
||||
IUserLockoutStore<TestUser>,
|
||||
IUserTwoFactorStore<TestUser>
|
||||
{
|
||||
public Task<IList<Claim>> GetClaims(TestUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
|
@ -802,6 +812,16 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<string> GetUserId(TestUser user, CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<string> GetUserName(TestUser user, CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task Create(TestUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
|
|
@ -10,8 +10,8 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
public async Task ValidateThrowsWithNull()
|
||||
{
|
||||
// Setup
|
||||
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
||||
var validator = new UserValidator<TestUser, string>();
|
||||
var manager = new UserManager<TestUser>(new NoopUserStore());
|
||||
var validator = new UserValidator<TestUser>();
|
||||
|
||||
// Act
|
||||
// Assert
|
||||
|
@ -25,8 +25,8 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
public async Task ValidateFailsWithTooShortUserNames(string input)
|
||||
{
|
||||
// Setup
|
||||
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
||||
var validator = new UserValidator<TestUser, string>();
|
||||
var manager = new UserManager<TestUser>(new NoopUserStore());
|
||||
var validator = new UserValidator<TestUser>();
|
||||
var user = new TestUser {UserName = input};
|
||||
|
||||
// Act
|
||||
|
@ -45,8 +45,8 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
public async Task DefaultAlphaNumericOnlyUserNameValidation(string userName, bool expectSuccess)
|
||||
{
|
||||
// Setup
|
||||
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
||||
var validator = new UserValidator<TestUser, string>();
|
||||
var manager = new UserManager<TestUser>(new NoopUserStore());
|
||||
var validator = new UserValidator<TestUser>();
|
||||
var user = new TestUser {UserName = userName};
|
||||
|
||||
// Act
|
||||
|
@ -72,8 +72,8 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
public async Task CanAllowNonAlphaNumericUserName(string userName, bool expectSuccess)
|
||||
{
|
||||
// Setup
|
||||
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
||||
var validator = new UserValidator<TestUser, string> {AllowOnlyAlphanumericUserNames = false};
|
||||
var manager = new UserManager<TestUser>(new NoopUserStore());
|
||||
var validator = new UserValidator<TestUser> {AllowOnlyAlphanumericUserNames = false};
|
||||
var user = new TestUser {UserName = userName};
|
||||
|
||||
// Act
|
||||
|
|
Загрузка…
Ссылка в новой задаче