Remove ConfigureAwait(false) everywhere
This commit is contained in:
parent
5e36691909
commit
c4d32ef1d6
|
|
@ -42,13 +42,18 @@ namespace Microsoft.AspNet.Identity.InMemory
|
||||||
|
|
||||||
public Task<InMemoryRole> FindByName(string roleName)
|
public Task<InMemoryRole> FindByName(string roleName)
|
||||||
{
|
{
|
||||||
return Task.FromResult(Roles.SingleOrDefault(r => String.Equals(r.Name, roleName, StringComparison.OrdinalIgnoreCase)));
|
return
|
||||||
|
Task.FromResult(
|
||||||
|
Roles.SingleOrDefault(r => String.Equals(r.Name, roleName, StringComparison.OrdinalIgnoreCase)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public IQueryable<InMemoryRole> Roles { get { return _roles.Values.AsQueryable(); } }
|
public IQueryable<InMemoryRole> Roles
|
||||||
|
{
|
||||||
|
get { return _roles.Values.AsQueryable(); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,11 +6,11 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Identity.InMemory
|
namespace Microsoft.AspNet.Identity.InMemory
|
||||||
{
|
{
|
||||||
public class InMemoryUserStore<TUser> :
|
public class InMemoryUserStore<TUser> :
|
||||||
IUserLoginStore<TUser, string>,
|
IUserLoginStore<TUser, string>,
|
||||||
IUserRoleStore<TUser, string>,
|
IUserRoleStore<TUser, string>,
|
||||||
IUserClaimStore<TUser, string>,
|
IUserClaimStore<TUser, string>,
|
||||||
IUserPasswordStore<TUser, string>,
|
IUserPasswordStore<TUser, string>,
|
||||||
IUserSecurityStampStore<TUser, string>,
|
IUserSecurityStampStore<TUser, string>,
|
||||||
IUserEmailStore<TUser, string>,
|
IUserEmailStore<TUser, string>,
|
||||||
IUserLockoutStore<TUser, string>,
|
IUserLockoutStore<TUser, string>,
|
||||||
|
|
@ -46,129 +46,6 @@ namespace Microsoft.AspNet.Identity.InMemory
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task AddLogin(TUser user, UserLoginInfo login)
|
|
||||||
{
|
|
||||||
user.Logins.Add(login);
|
|
||||||
_logins[login] = user;
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task RemoveLogin(TUser user, UserLoginInfo login)
|
|
||||||
{
|
|
||||||
var logs =
|
|
||||||
user.Logins.Where(l => l.ProviderKey == login.ProviderKey && l.LoginProvider == login.LoginProvider)
|
|
||||||
.ToList();
|
|
||||||
foreach (var l in logs)
|
|
||||||
{
|
|
||||||
user.Logins.Remove(l);
|
|
||||||
_logins[l] = null;
|
|
||||||
}
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<IList<UserLoginInfo>> GetLogins(TUser user)
|
|
||||||
{
|
|
||||||
return Task.FromResult(user.Logins);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<TUser> Find(UserLoginInfo login)
|
|
||||||
{
|
|
||||||
if (_logins.ContainsKey(login))
|
|
||||||
{
|
|
||||||
return Task.FromResult(_logins[login]);
|
|
||||||
}
|
|
||||||
return Task.FromResult<TUser>(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task SetPasswordHash(TUser user, string passwordHash)
|
|
||||||
{
|
|
||||||
user.PasswordHash = passwordHash;
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<string> GetPasswordHash(TUser user)
|
|
||||||
{
|
|
||||||
return Task.FromResult(user.PasswordHash);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<bool> HasPassword(TUser user)
|
|
||||||
{
|
|
||||||
return Task.FromResult(user.PasswordHash != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task AddToRole(TUser user, string role)
|
|
||||||
{
|
|
||||||
user.Roles.Add(role);
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task RemoveFromRole(TUser user, string role)
|
|
||||||
{
|
|
||||||
user.Roles.Remove(role);
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<IList<string>> GetRoles(TUser user)
|
|
||||||
{
|
|
||||||
return Task.FromResult(user.Roles);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<bool> IsInRole(TUser user, string role)
|
|
||||||
{
|
|
||||||
return Task.FromResult(user.Roles.Contains(role));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task SetSecurityStamp(TUser user, string stamp)
|
|
||||||
{
|
|
||||||
user.SecurityStamp = stamp;
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<string> GetSecurityStamp(TUser user)
|
|
||||||
{
|
|
||||||
return Task.FromResult(user.SecurityStamp);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task Create(TUser user)
|
|
||||||
{
|
|
||||||
_users[user.Id] = user;
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task Update(TUser user)
|
|
||||||
{
|
|
||||||
_users[user.Id] = user;
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<TUser> FindById(string userId)
|
|
||||||
{
|
|
||||||
if (_users.ContainsKey(userId))
|
|
||||||
{
|
|
||||||
return Task.FromResult(_users[userId]);
|
|
||||||
}
|
|
||||||
return Task.FromResult<TUser>(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<TUser> FindByName(string userName)
|
|
||||||
{
|
|
||||||
return Task.FromResult(Users.FirstOrDefault(u => String.Equals(u.UserName, userName, StringComparison.OrdinalIgnoreCase)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task Delete(TUser user)
|
|
||||||
{
|
|
||||||
if (user == null || !_users.ContainsKey(user.Id))
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Unknown user");
|
|
||||||
}
|
|
||||||
_users.Remove(user.Id);
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task SetEmail(TUser user, string email)
|
public Task SetEmail(TUser user, string email)
|
||||||
{
|
{
|
||||||
user.Email = email;
|
user.Email = email;
|
||||||
|
|
@ -193,7 +70,9 @@ namespace Microsoft.AspNet.Identity.InMemory
|
||||||
|
|
||||||
public Task<TUser> FindByEmail(string email)
|
public Task<TUser> FindByEmail(string email)
|
||||||
{
|
{
|
||||||
return Task.FromResult(Users.FirstOrDefault(u => String.Equals(u.Email, email, StringComparison.OrdinalIgnoreCase)));
|
return
|
||||||
|
Task.FromResult(
|
||||||
|
Users.FirstOrDefault(u => String.Equals(u.Email, email, StringComparison.OrdinalIgnoreCase)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<DateTimeOffset> GetLockoutEndDate(TUser user)
|
public Task<DateTimeOffset> GetLockoutEndDate(TUser user)
|
||||||
|
|
@ -235,6 +114,98 @@ namespace Microsoft.AspNet.Identity.InMemory
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task AddLogin(TUser user, UserLoginInfo login)
|
||||||
|
{
|
||||||
|
user.Logins.Add(login);
|
||||||
|
_logins[login] = user;
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task RemoveLogin(TUser user, UserLoginInfo login)
|
||||||
|
{
|
||||||
|
var logs =
|
||||||
|
user.Logins.Where(l => l.ProviderKey == login.ProviderKey && l.LoginProvider == login.LoginProvider)
|
||||||
|
.ToList();
|
||||||
|
foreach (var l in logs)
|
||||||
|
{
|
||||||
|
user.Logins.Remove(l);
|
||||||
|
_logins[l] = null;
|
||||||
|
}
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<IList<UserLoginInfo>> GetLogins(TUser user)
|
||||||
|
{
|
||||||
|
return Task.FromResult(user.Logins);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<TUser> Find(UserLoginInfo login)
|
||||||
|
{
|
||||||
|
if (_logins.ContainsKey(login))
|
||||||
|
{
|
||||||
|
return Task.FromResult(_logins[login]);
|
||||||
|
}
|
||||||
|
return Task.FromResult<TUser>(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Create(TUser user)
|
||||||
|
{
|
||||||
|
_users[user.Id] = user;
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Update(TUser user)
|
||||||
|
{
|
||||||
|
_users[user.Id] = user;
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<TUser> FindById(string userId)
|
||||||
|
{
|
||||||
|
if (_users.ContainsKey(userId))
|
||||||
|
{
|
||||||
|
return Task.FromResult(_users[userId]);
|
||||||
|
}
|
||||||
|
return Task.FromResult<TUser>(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<TUser> FindByName(string userName)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
Task.FromResult(
|
||||||
|
Users.FirstOrDefault(u => String.Equals(u.UserName, userName, StringComparison.OrdinalIgnoreCase)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Delete(TUser user)
|
||||||
|
{
|
||||||
|
if (user == null || !_users.ContainsKey(user.Id))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Unknown user");
|
||||||
|
}
|
||||||
|
_users.Remove(user.Id);
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task SetPasswordHash(TUser user, string passwordHash)
|
||||||
|
{
|
||||||
|
user.PasswordHash = passwordHash;
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<string> GetPasswordHash(TUser user)
|
||||||
|
{
|
||||||
|
return Task.FromResult(user.PasswordHash);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<bool> HasPassword(TUser user)
|
||||||
|
{
|
||||||
|
return Task.FromResult(user.PasswordHash != null);
|
||||||
|
}
|
||||||
|
|
||||||
public Task SetPhoneNumber(TUser user, string phoneNumber)
|
public Task SetPhoneNumber(TUser user, string phoneNumber)
|
||||||
{
|
{
|
||||||
user.PhoneNumber = phoneNumber;
|
user.PhoneNumber = phoneNumber;
|
||||||
|
|
@ -257,17 +228,37 @@ namespace Microsoft.AspNet.Identity.InMemory
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LoginComparer : IEqualityComparer<UserLoginInfo>
|
public Task AddToRole(TUser user, string role)
|
||||||
{
|
{
|
||||||
public bool Equals(UserLoginInfo x, UserLoginInfo y)
|
user.Roles.Add(role);
|
||||||
{
|
return Task.FromResult(0);
|
||||||
return x.LoginProvider == y.LoginProvider && x.ProviderKey == y.ProviderKey;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public int GetHashCode(UserLoginInfo obj)
|
public Task RemoveFromRole(TUser user, string role)
|
||||||
{
|
{
|
||||||
return (obj.ProviderKey + "--" + obj.LoginProvider).GetHashCode();
|
user.Roles.Remove(role);
|
||||||
}
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<IList<string>> GetRoles(TUser user)
|
||||||
|
{
|
||||||
|
return Task.FromResult(user.Roles);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<bool> IsInRole(TUser user, string role)
|
||||||
|
{
|
||||||
|
return Task.FromResult(user.Roles.Contains(role));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task SetSecurityStamp(TUser user, string stamp)
|
||||||
|
{
|
||||||
|
user.SecurityStamp = stamp;
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<string> GetSecurityStamp(TUser user)
|
||||||
|
{
|
||||||
|
return Task.FromResult(user.SecurityStamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task SetTwoFactorEnabled(TUser user, bool enabled)
|
public Task SetTwoFactorEnabled(TUser user, bool enabled)
|
||||||
|
|
@ -280,5 +271,18 @@ namespace Microsoft.AspNet.Identity.InMemory
|
||||||
{
|
{
|
||||||
return Task.FromResult(user.TwoFactorEnabled);
|
return Task.FromResult(user.TwoFactorEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class LoginComparer : IEqualityComparer<UserLoginInfo>
|
||||||
|
{
|
||||||
|
public bool Equals(UserLoginInfo x, UserLoginInfo y)
|
||||||
|
{
|
||||||
|
return x.LoginProvider == y.LoginProvider && x.ProviderKey == y.ProviderKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetHashCode(UserLoginInfo obj)
|
||||||
|
{
|
||||||
|
return (obj.ProviderKey + "--" + obj.LoginProvider).GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -72,12 +72,11 @@ namespace Microsoft.AspNet.Identity
|
||||||
id.AddClaim(new Claim(UserNameClaimType, user.UserName, ClaimValueTypes.String));
|
id.AddClaim(new Claim(UserNameClaimType, user.UserName, ClaimValueTypes.String));
|
||||||
if (manager.SupportsUserSecurityStamp)
|
if (manager.SupportsUserSecurityStamp)
|
||||||
{
|
{
|
||||||
id.AddClaim(new Claim(SecurityStampClaimType,
|
id.AddClaim(new Claim(SecurityStampClaimType, await manager.GetSecurityStamp(user.Id)));
|
||||||
await manager.GetSecurityStamp(user.Id).ConfigureAwait(false)));
|
|
||||||
}
|
}
|
||||||
if (manager.SupportsUserRole)
|
if (manager.SupportsUserRole)
|
||||||
{
|
{
|
||||||
var roles = await manager.GetRoles(user.Id).ConfigureAwait(false);
|
var roles = await manager.GetRoles(user.Id);
|
||||||
foreach (var roleName in roles)
|
foreach (var roleName in roles)
|
||||||
{
|
{
|
||||||
id.AddClaim(new Claim(RoleClaimType, roleName, ClaimValueTypes.String));
|
id.AddClaim(new Claim(RoleClaimType, roleName, ClaimValueTypes.String));
|
||||||
|
|
@ -85,7 +84,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
}
|
}
|
||||||
if (manager.SupportsUserClaim)
|
if (manager.SupportsUserClaim)
|
||||||
{
|
{
|
||||||
id.AddClaims(await manager.GetClaims(user.Id).ConfigureAwait(false));
|
id.AddClaims(await manager.GetClaims(user.Id));
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,4 +87,4 @@ namespace Microsoft.AspNet.Identity
|
||||||
return areSame;
|
return areSame;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TUser"></typeparam>
|
/// <typeparam name="TUser"></typeparam>
|
||||||
/// <typeparam name="TKey"></typeparam>
|
/// <typeparam name="TKey"></typeparam>
|
||||||
public interface IUserValidator<TUser, TKey>
|
public interface IUserValidator<TUser, TKey>
|
||||||
where TUser : class, IUser<TKey>
|
where TUser : class, IUser<TKey>
|
||||||
where TKey : IEquatable<TKey>
|
where TKey : IEquatable<TKey>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
using System.Threading.Tasks;
|
namespace Microsoft.AspNet.Identity
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Identity
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a message
|
/// Represents a message
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,9 @@ namespace Microsoft.AspNet.Identity
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual PasswordVerificationResult VerifyHashedPassword(string hashedPassword, string providedPassword)
|
public virtual PasswordVerificationResult VerifyHashedPassword(string hashedPassword, string providedPassword)
|
||||||
{
|
{
|
||||||
return Crypto.VerifyHashedPassword(hashedPassword, providedPassword) ? PasswordVerificationResult.Success : PasswordVerificationResult.Failed;
|
return Crypto.VerifyHashedPassword(hashedPassword, providedPassword)
|
||||||
|
? PasswordVerificationResult.Success
|
||||||
|
: PasswordVerificationResult.Failed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -68,7 +68,10 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
errors.Add(Resources.PasswordRequireUpper);
|
errors.Add(Resources.PasswordRequireUpper);
|
||||||
}
|
}
|
||||||
return Task.FromResult(errors.Count == 0 ? IdentityResult.Success : IdentityResult.Failed(String.Join(" ", errors)));
|
return
|
||||||
|
Task.FromResult(errors.Count == 0
|
||||||
|
? IdentityResult.Success
|
||||||
|
: IdentityResult.Failed(String.Join(" ", errors)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#if NET45
|
|
||||||
|
#if NET45
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
@ -112,4 +113,4 @@ namespace Microsoft.AspNet.Identity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -94,7 +94,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
|
|
||||||
private async Task<IdentityResult> ValidateRoleInternal(TRole role)
|
private async Task<IdentityResult> ValidateRoleInternal(TRole role)
|
||||||
{
|
{
|
||||||
return (RoleValidator == null) ? IdentityResult.Success : await RoleValidator.Validate(this, role).ConfigureAwait(false);
|
return (RoleValidator == null) ? IdentityResult.Success : await RoleValidator.Validate(this, role);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -137,7 +137,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
await Store.Update(role).ConfigureAwait(false);
|
await Store.Update(role);
|
||||||
return IdentityResult.Success;
|
return IdentityResult.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -154,7 +154,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
throw new ArgumentNullException("role");
|
throw new ArgumentNullException("role");
|
||||||
}
|
}
|
||||||
|
|
||||||
await Store.Delete(role).ConfigureAwait(false);
|
await Store.Delete(role);
|
||||||
return IdentityResult.Success;
|
return IdentityResult.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -171,7 +171,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
throw new ArgumentNullException("roleName");
|
throw new ArgumentNullException("roleName");
|
||||||
}
|
}
|
||||||
|
|
||||||
return await FindByName(roleName).ConfigureAwait(false) != null;
|
return await FindByName(roleName) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -182,7 +182,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
public virtual async Task<TRole> FindById(TKey roleId)
|
public virtual async Task<TRole> FindById(TKey roleId)
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
return await Store.FindById(roleId).ConfigureAwait(false);
|
return await Store.FindById(roleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -198,7 +198,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
throw new ArgumentNullException("roleName");
|
throw new ArgumentNullException("roleName");
|
||||||
}
|
}
|
||||||
|
|
||||||
return await Store.FindByName(roleName).ConfigureAwait(false);
|
return await Store.FindByName(roleName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ThrowIfDisposed()
|
private void ThrowIfDisposed()
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,8 @@ namespace Microsoft.AspNet.Identity
|
||||||
return IdentityResult.Success;
|
return IdentityResult.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task ValidateRoleName(RoleManager<TRole, TKey> manager, TRole role, ICollection<string> errors)
|
private static async Task ValidateRoleName(RoleManager<TRole, TKey> manager, TRole role,
|
||||||
|
ICollection<string> errors)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(role.Name))
|
if (string.IsNullOrWhiteSpace(role.Name))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
private IPasswordHasher _passwordHasher;
|
private IPasswordHasher _passwordHasher;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor which takes a service provider to find the default interfaces to hook up
|
/// Constructor which takes a service provider to find the default interfaces to hook up
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="serviceProvider"></param>
|
/// <param name="serviceProvider"></param>
|
||||||
public UserManager(IServiceProvider serviceProvider)
|
public UserManager(IServiceProvider serviceProvider)
|
||||||
|
|
@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
UserValidator = serviceProvider.GetService<IUserValidator<TUser, TKey>>();
|
UserValidator = serviceProvider.GetService<IUserValidator<TUser, TKey>>();
|
||||||
PasswordValidator = serviceProvider.GetService<IPasswordValidator>();
|
PasswordValidator = serviceProvider.GetService<IPasswordValidator>();
|
||||||
ClaimsIdentityFactory = serviceProvider.GetService<IClaimsIdentityFactory<TUser, TKey>>();
|
ClaimsIdentityFactory = serviceProvider.GetService<IClaimsIdentityFactory<TUser, TKey>>();
|
||||||
//TODO: Store = serviceProvider.GetService<IUserStore<TUser, TKey>>();
|
Store = serviceProvider.GetService<IUserStore<TUser, TKey>>();
|
||||||
// TODO: maybe each optional store as well? Email and SMS services?
|
// TODO: maybe each optional store as well? Email and SMS services?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -320,8 +320,11 @@ namespace Microsoft.AspNet.Identity
|
||||||
return ClaimsIdentityFactory.Create(this, user, authenticationType);
|
return ClaimsIdentityFactory.Create(this, user, authenticationType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<IdentityResult> ValidateUserInternal(TUser user) {
|
private async Task<IdentityResult> ValidateUserInternal(TUser user)
|
||||||
return (UserValidator == null) ? IdentityResult.Success : await UserValidator.Validate(this, user).ConfigureAwait(false);
|
{
|
||||||
|
return (UserValidator == null)
|
||||||
|
? IdentityResult.Success
|
||||||
|
: await UserValidator.Validate(this, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -332,7 +335,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
public virtual async Task<IdentityResult> Create(TUser user)
|
public virtual async Task<IdentityResult> Create(TUser user)
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
await UpdateSecurityStampInternal(user).ConfigureAwait(false);
|
await UpdateSecurityStampInternal(user);
|
||||||
var result = await ValidateUserInternal(user);
|
var result = await ValidateUserInternal(user);
|
||||||
if (!result.Succeeded)
|
if (!result.Succeeded)
|
||||||
{
|
{
|
||||||
|
|
@ -340,9 +343,9 @@ namespace Microsoft.AspNet.Identity
|
||||||
}
|
}
|
||||||
if (UserLockoutEnabledByDefault && SupportsUserLockout)
|
if (UserLockoutEnabledByDefault && SupportsUserLockout)
|
||||||
{
|
{
|
||||||
await GetUserLockoutStore().SetLockoutEnabled(user, true).ConfigureAwait(false);
|
await GetUserLockoutStore().SetLockoutEnabled(user, true);
|
||||||
}
|
}
|
||||||
await Store.Create(user).ConfigureAwait(false);
|
await Store.Create(user);
|
||||||
return IdentityResult.Success;
|
return IdentityResult.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -363,7 +366,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
await Store.Update(user).ConfigureAwait(false);
|
await Store.Update(user);
|
||||||
return IdentityResult.Success;
|
return IdentityResult.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -379,7 +382,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("user");
|
throw new ArgumentNullException("user");
|
||||||
}
|
}
|
||||||
await Store.Delete(user).ConfigureAwait(false);
|
await Store.Delete(user);
|
||||||
return IdentityResult.Success;
|
return IdentityResult.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -438,12 +441,12 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("password");
|
throw new ArgumentNullException("password");
|
||||||
}
|
}
|
||||||
var result = await UpdatePasswordInternal(passwordStore, user, password).ConfigureAwait(false);
|
var result = await UpdatePasswordInternal(passwordStore, user, password);
|
||||||
if (!result.Succeeded)
|
if (!result.Succeeded)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return await Create(user).ConfigureAwait(false);
|
return await Create(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -455,12 +458,12 @@ namespace Microsoft.AspNet.Identity
|
||||||
public virtual async Task<TUser> Find(string userName, string password)
|
public virtual async Task<TUser> Find(string userName, string password)
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var user = await FindByName(userName).ConfigureAwait(false);
|
var user = await FindByName(userName);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return await CheckPassword(user, password).ConfigureAwait(false) ? user : null;
|
return await CheckPassword(user, password) ? user : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -477,7 +480,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return await VerifyPassword(passwordStore, user, password).ConfigureAwait(false);
|
return await VerifyPassword(passwordStore, user, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -489,13 +492,13 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var passwordStore = GetPasswordStore();
|
var passwordStore = GetPasswordStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
return await passwordStore.HasPassword(user).ConfigureAwait(false);
|
return await passwordStore.HasPassword(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -508,23 +511,23 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var passwordStore = GetPasswordStore();
|
var passwordStore = GetPasswordStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
var hash = await passwordStore.GetPasswordHash(user).ConfigureAwait(false);
|
var hash = await passwordStore.GetPasswordHash(user);
|
||||||
if (hash != null)
|
if (hash != null)
|
||||||
{
|
{
|
||||||
return new IdentityResult(Resources.UserAlreadyHasPassword);
|
return new IdentityResult(Resources.UserAlreadyHasPassword);
|
||||||
}
|
}
|
||||||
var result = await UpdatePasswordInternal(passwordStore, user, password).ConfigureAwait(false);
|
var result = await UpdatePasswordInternal(passwordStore, user, password);
|
||||||
if (!result.Succeeded)
|
if (!result.Succeeded)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return await Update(user).ConfigureAwait(false);
|
return await Update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -539,20 +542,20 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var passwordStore = GetPasswordStore();
|
var passwordStore = GetPasswordStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
if (await VerifyPassword(passwordStore, user, currentPassword).ConfigureAwait(false))
|
if (await VerifyPassword(passwordStore, user, currentPassword))
|
||||||
{
|
{
|
||||||
var result = await UpdatePasswordInternal(passwordStore, user, newPassword).ConfigureAwait(false);
|
var result = await UpdatePasswordInternal(passwordStore, user, newPassword);
|
||||||
if (!result.Succeeded)
|
if (!result.Succeeded)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return await Update(user).ConfigureAwait(false);
|
return await Update(user);
|
||||||
}
|
}
|
||||||
return IdentityResult.Failed(Resources.PasswordMismatch);
|
return IdentityResult.Failed(Resources.PasswordMismatch);
|
||||||
}
|
}
|
||||||
|
|
@ -566,15 +569,15 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var passwordStore = GetPasswordStore();
|
var passwordStore = GetPasswordStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
await passwordStore.SetPasswordHash(user, null).ConfigureAwait(false);
|
await passwordStore.SetPasswordHash(user, null);
|
||||||
await UpdateSecurityStampInternal(user).ConfigureAwait(false);
|
await UpdateSecurityStampInternal(user);
|
||||||
return await Update(user).ConfigureAwait(false);
|
return await Update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<IdentityResult> UpdatePasswordInternal(IUserPasswordStore<TUser, TKey> passwordStore,
|
internal async Task<IdentityResult> UpdatePasswordInternal(IUserPasswordStore<TUser, TKey> passwordStore,
|
||||||
|
|
@ -582,15 +585,15 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
if (PasswordValidator != null)
|
if (PasswordValidator != null)
|
||||||
{
|
{
|
||||||
var result = await PasswordValidator.Validate(newPassword).ConfigureAwait(false);
|
var result = await PasswordValidator.Validate(newPassword);
|
||||||
if (!result.Succeeded)
|
if (!result.Succeeded)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await
|
await
|
||||||
passwordStore.SetPasswordHash(user, PasswordHasher.HashPassword(newPassword)).ConfigureAwait(false);
|
passwordStore.SetPasswordHash(user, PasswordHasher.HashPassword(newPassword));
|
||||||
await UpdateSecurityStampInternal(user).ConfigureAwait(false);
|
await UpdateSecurityStampInternal(user);
|
||||||
return IdentityResult.Success;
|
return IdentityResult.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -604,7 +607,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
protected virtual async Task<bool> VerifyPassword(IUserPasswordStore<TUser, TKey> store, TUser user,
|
protected virtual async Task<bool> VerifyPassword(IUserPasswordStore<TUser, TKey> store, TUser user,
|
||||||
string password)
|
string password)
|
||||||
{
|
{
|
||||||
var hash = await store.GetPasswordHash(user).ConfigureAwait(false);
|
var hash = await store.GetPasswordHash(user);
|
||||||
return PasswordHasher.VerifyHashedPassword(hash, password) != PasswordVerificationResult.Failed;
|
return PasswordHasher.VerifyHashedPassword(hash, password) != PasswordVerificationResult.Failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -628,13 +631,13 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var securityStore = GetSecurityStore();
|
var securityStore = GetSecurityStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
return await securityStore.GetSecurityStamp(user).ConfigureAwait(false);
|
return await securityStore.GetSecurityStamp(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -646,14 +649,14 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var securityStore = GetSecurityStore();
|
var securityStore = GetSecurityStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
await securityStore.SetSecurityStamp(user, NewSecurityStamp()).ConfigureAwait(false);
|
await securityStore.SetSecurityStamp(user, NewSecurityStamp());
|
||||||
return await Update(user).ConfigureAwait(false);
|
return await Update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -677,24 +680,24 @@ namespace Microsoft.AspNet.Identity
|
||||||
public virtual async Task<IdentityResult> ResetPassword(TKey userId, string token, string newPassword)
|
public virtual async Task<IdentityResult> ResetPassword(TKey userId, string token, string newPassword)
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
// Make sure the token is valid and the stamp matches
|
// Make sure the token is valid and the stamp matches
|
||||||
if (!await VerifyUserToken(userId, "ResetPassword", token).ConfigureAwait(false))
|
if (!await VerifyUserToken(userId, "ResetPassword", token))
|
||||||
{
|
{
|
||||||
return IdentityResult.Failed(Resources.InvalidToken);
|
return IdentityResult.Failed(Resources.InvalidToken);
|
||||||
}
|
}
|
||||||
var passwordStore = GetPasswordStore();
|
var passwordStore = GetPasswordStore();
|
||||||
var result = await UpdatePasswordInternal(passwordStore, user, newPassword).ConfigureAwait(false);
|
var result = await UpdatePasswordInternal(passwordStore, user, newPassword);
|
||||||
if (!result.Succeeded)
|
if (!result.Succeeded)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return await Update(user).ConfigureAwait(false);
|
return await Update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the security stamp if the store supports it
|
// Update the security stamp if the store supports it
|
||||||
|
|
@ -702,7 +705,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
if (SupportsUserSecurityStamp)
|
if (SupportsUserSecurityStamp)
|
||||||
{
|
{
|
||||||
await GetSecurityStore().SetSecurityStamp(user, NewSecurityStamp()).ConfigureAwait(false);
|
await GetSecurityStore().SetSecurityStamp(user, NewSecurityStamp());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -746,15 +749,15 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("login");
|
throw new ArgumentNullException("login");
|
||||||
}
|
}
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
await loginStore.RemoveLogin(user, login).ConfigureAwait(false);
|
await loginStore.RemoveLogin(user, login);
|
||||||
await UpdateSecurityStampInternal(user).ConfigureAwait(false);
|
await UpdateSecurityStampInternal(user);
|
||||||
return await Update(user).ConfigureAwait(false);
|
return await Update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -771,19 +774,19 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("login");
|
throw new ArgumentNullException("login");
|
||||||
}
|
}
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
var existingUser = await Find(login).ConfigureAwait(false);
|
var existingUser = await Find(login);
|
||||||
if (existingUser != null)
|
if (existingUser != null)
|
||||||
{
|
{
|
||||||
return IdentityResult.Failed(Resources.ExternalLoginExists);
|
return IdentityResult.Failed(Resources.ExternalLoginExists);
|
||||||
}
|
}
|
||||||
await loginStore.AddLogin(user, login).ConfigureAwait(false);
|
await loginStore.AddLogin(user, login);
|
||||||
return await Update(user).ConfigureAwait(false);
|
return await Update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -795,13 +798,13 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var loginStore = GetLoginStore();
|
var loginStore = GetLoginStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
return await loginStore.GetLogins(user).ConfigureAwait(false);
|
return await loginStore.GetLogins(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
// IUserClaimStore methods
|
// IUserClaimStore methods
|
||||||
|
|
@ -829,14 +832,14 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("claim");
|
throw new ArgumentNullException("claim");
|
||||||
}
|
}
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
await claimStore.AddClaim(user, claim).ConfigureAwait(false);
|
await claimStore.AddClaim(user, claim);
|
||||||
return await Update(user).ConfigureAwait(false);
|
return await Update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -849,14 +852,14 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var claimStore = GetClaimStore();
|
var claimStore = GetClaimStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
await claimStore.RemoveClaim(user, claim).ConfigureAwait(false);
|
await claimStore.RemoveClaim(user, claim);
|
||||||
return await Update(user).ConfigureAwait(false);
|
return await Update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -868,13 +871,13 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var claimStore = GetClaimStore();
|
var claimStore = GetClaimStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
return await claimStore.GetClaims(user).ConfigureAwait(false);
|
return await claimStore.GetClaims(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IUserRoleStore<TUser, TKey> GetUserRoleStore()
|
private IUserRoleStore<TUser, TKey> GetUserRoleStore()
|
||||||
|
|
@ -897,19 +900,19 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var userRoleStore = GetUserRoleStore();
|
var userRoleStore = GetUserRoleStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
var userRoles = await userRoleStore.GetRoles(user).ConfigureAwait(false);
|
var userRoles = await userRoleStore.GetRoles(user);
|
||||||
if (userRoles.Contains(role))
|
if (userRoles.Contains(role))
|
||||||
{
|
{
|
||||||
return new IdentityResult(Resources.UserAlreadyInRole);
|
return new IdentityResult(Resources.UserAlreadyInRole);
|
||||||
}
|
}
|
||||||
await userRoleStore.AddToRole(user, role).ConfigureAwait(false);
|
await userRoleStore.AddToRole(user, role);
|
||||||
return await Update(user).ConfigureAwait(false);
|
return await Update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -922,18 +925,18 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var userRoleStore = GetUserRoleStore();
|
var userRoleStore = GetUserRoleStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
if (!await userRoleStore.IsInRole(user, role).ConfigureAwait(false))
|
if (!await userRoleStore.IsInRole(user, role))
|
||||||
{
|
{
|
||||||
return new IdentityResult(Resources.UserNotInRole);
|
return new IdentityResult(Resources.UserNotInRole);
|
||||||
}
|
}
|
||||||
await userRoleStore.RemoveFromRole(user, role).ConfigureAwait(false);
|
await userRoleStore.RemoveFromRole(user, role);
|
||||||
return await Update(user).ConfigureAwait(false);
|
return await Update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -945,13 +948,13 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var userRoleStore = GetUserRoleStore();
|
var userRoleStore = GetUserRoleStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
return await userRoleStore.GetRoles(user).ConfigureAwait(false);
|
return await userRoleStore.GetRoles(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -964,13 +967,13 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var userRoleStore = GetUserRoleStore();
|
var userRoleStore = GetUserRoleStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
return await userRoleStore.IsInRole(user, role).ConfigureAwait(false);
|
return await userRoleStore.IsInRole(user, role);
|
||||||
}
|
}
|
||||||
|
|
||||||
// IUserEmailStore methods
|
// IUserEmailStore methods
|
||||||
|
|
@ -993,13 +996,13 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var store = GetEmailStore();
|
var store = GetEmailStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
return await store.GetEmail(user).ConfigureAwait(false);
|
return await store.GetEmail(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1012,16 +1015,16 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var store = GetEmailStore();
|
var store = GetEmailStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
await store.SetEmail(user, email).ConfigureAwait(false);
|
await store.SetEmail(user, email);
|
||||||
await store.SetEmailConfirmed(user, false).ConfigureAwait(false);
|
await store.SetEmailConfirmed(user, false);
|
||||||
await UpdateSecurityStampInternal(user).ConfigureAwait(false);
|
await UpdateSecurityStampInternal(user);
|
||||||
return await Update(user).ConfigureAwait(false);
|
return await Update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1061,7 +1064,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var store = GetEmailStore();
|
var store = GetEmailStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
|
|
@ -1071,8 +1074,8 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
return IdentityResult.Failed(Resources.InvalidToken);
|
return IdentityResult.Failed(Resources.InvalidToken);
|
||||||
}
|
}
|
||||||
await store.SetEmailConfirmed(user, true).ConfigureAwait(false);
|
await store.SetEmailConfirmed(user, true);
|
||||||
return await Update(user).ConfigureAwait(false);
|
return await Update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1084,13 +1087,13 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var store = GetEmailStore();
|
var store = GetEmailStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
return await store.GetEmailConfirmed(user).ConfigureAwait(false);
|
return await store.GetEmailConfirmed(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
// IUserPhoneNumberStore methods
|
// IUserPhoneNumberStore methods
|
||||||
|
|
@ -1113,13 +1116,13 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var store = GetPhoneNumberStore();
|
var store = GetPhoneNumberStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
return await store.GetPhoneNumber(user).ConfigureAwait(false);
|
return await store.GetPhoneNumber(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1132,16 +1135,16 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var store = GetPhoneNumberStore();
|
var store = GetPhoneNumberStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
await store.SetPhoneNumber(user, phoneNumber).ConfigureAwait(false);
|
await store.SetPhoneNumber(user, phoneNumber);
|
||||||
await store.SetPhoneNumberConfirmed(user, false).ConfigureAwait(false);
|
await store.SetPhoneNumberConfirmed(user, false);
|
||||||
await UpdateSecurityStampInternal(user).ConfigureAwait(false);
|
await UpdateSecurityStampInternal(user);
|
||||||
return await Update(user).ConfigureAwait(false);
|
return await Update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1155,20 +1158,20 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var store = GetPhoneNumberStore();
|
var store = GetPhoneNumberStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
if (!await VerifyChangePhoneNumberToken(userId, token, phoneNumber).ConfigureAwait(false))
|
if (!await VerifyChangePhoneNumberToken(userId, token, phoneNumber))
|
||||||
{
|
{
|
||||||
return IdentityResult.Failed(Resources.InvalidToken);
|
return IdentityResult.Failed(Resources.InvalidToken);
|
||||||
}
|
}
|
||||||
await store.SetPhoneNumber(user, phoneNumber).ConfigureAwait(false);
|
await store.SetPhoneNumber(user, phoneNumber);
|
||||||
await store.SetPhoneNumberConfirmed(user, true).ConfigureAwait(false);
|
await store.SetPhoneNumberConfirmed(user, true);
|
||||||
await UpdateSecurityStampInternal(user).ConfigureAwait(false);
|
await UpdateSecurityStampInternal(user);
|
||||||
return await Update(user).ConfigureAwait(false);
|
return await Update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1180,13 +1183,13 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var store = GetPhoneNumberStore();
|
var store = GetPhoneNumberStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
return await store.GetPhoneNumberConfirmed(user).ConfigureAwait(false);
|
return await store.GetPhoneNumberConfirmed(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Two factor APIS
|
// Two factor APIS
|
||||||
|
|
@ -1195,7 +1198,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
internal async Task<SecurityToken> CreateSecurityToken(TKey userId)
|
internal async Task<SecurityToken> CreateSecurityToken(TKey userId)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
new SecurityToken(Encoding.Unicode.GetBytes(await GetSecurityStamp(userId).ConfigureAwait(false)));
|
new SecurityToken(Encoding.Unicode.GetBytes(await GetSecurityStamp(userId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1248,14 +1251,14 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
throw new NotSupportedException(Resources.NoTokenProvider);
|
throw new NotSupportedException(Resources.NoTokenProvider);
|
||||||
}
|
}
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
// Make sure the token is valid
|
// Make sure the token is valid
|
||||||
return await UserTokenProvider.Validate(purpose, token, this, user).ConfigureAwait(false);
|
return await UserTokenProvider.Validate(purpose, token, this, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1271,13 +1274,13 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
throw new NotSupportedException(Resources.NoTokenProvider);
|
throw new NotSupportedException(Resources.NoTokenProvider);
|
||||||
}
|
}
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
return await UserTokenProvider.Generate(purpose, this, user).ConfigureAwait(false);
|
return await UserTokenProvider.Generate(purpose, this, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1307,7 +1310,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
public virtual async Task<IList<string>> GetValidTwoFactorProviders(TKey userId)
|
public virtual async Task<IList<string>> GetValidTwoFactorProviders(TKey userId)
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
|
|
@ -1334,7 +1337,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
public virtual async Task<bool> VerifyTwoFactorToken(TKey userId, string twoFactorProvider, string token)
|
public virtual async Task<bool> VerifyTwoFactorToken(TKey userId, string twoFactorProvider, string token)
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
|
|
@ -1347,7 +1350,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
}
|
}
|
||||||
// Make sure the token is valid
|
// Make sure the token is valid
|
||||||
var provider = _factors[twoFactorProvider];
|
var provider = _factors[twoFactorProvider];
|
||||||
return await provider.Validate(twoFactorProvider, token, this, user).ConfigureAwait(false);
|
return await provider.Validate(twoFactorProvider, token, this, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1359,7 +1362,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
public virtual async Task<string> GenerateTwoFactorToken(TKey userId, string twoFactorProvider)
|
public virtual async Task<string> GenerateTwoFactorToken(TKey userId, string twoFactorProvider)
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
|
|
@ -1370,7 +1373,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
throw new NotSupportedException(String.Format(CultureInfo.CurrentCulture, Resources.NoTwoFactorProvider,
|
throw new NotSupportedException(String.Format(CultureInfo.CurrentCulture, Resources.NoTwoFactorProvider,
|
||||||
twoFactorProvider));
|
twoFactorProvider));
|
||||||
}
|
}
|
||||||
return await _factors[twoFactorProvider].Generate(twoFactorProvider, this, user).ConfigureAwait(false);
|
return await _factors[twoFactorProvider].Generate(twoFactorProvider, this, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1384,7 +1387,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
string token)
|
string token)
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
|
|
@ -1395,7 +1398,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
throw new NotSupportedException(String.Format(CultureInfo.CurrentCulture, Resources.NoTwoFactorProvider,
|
throw new NotSupportedException(String.Format(CultureInfo.CurrentCulture, Resources.NoTwoFactorProvider,
|
||||||
twoFactorProvider));
|
twoFactorProvider));
|
||||||
}
|
}
|
||||||
await _factors[twoFactorProvider].Notify(token, this, user).ConfigureAwait(false);
|
await _factors[twoFactorProvider].Notify(token, this, user);
|
||||||
return IdentityResult.Success;
|
return IdentityResult.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1419,13 +1422,13 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var store = GetUserTwoFactorStore();
|
var store = GetUserTwoFactorStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
return await store.GetTwoFactorEnabled(user).ConfigureAwait(false);
|
return await store.GetTwoFactorEnabled(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1438,15 +1441,15 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var store = GetUserTwoFactorStore();
|
var store = GetUserTwoFactorStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
await store.SetTwoFactorEnabled(user, enabled).ConfigureAwait(false);
|
await store.SetTwoFactorEnabled(user, enabled);
|
||||||
await UpdateSecurityStampInternal(user).ConfigureAwait(false);
|
await UpdateSecurityStampInternal(user);
|
||||||
return await Update(user).ConfigureAwait(false);
|
return await Update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SMS/Email methods
|
// SMS/Email methods
|
||||||
|
|
@ -1513,13 +1516,13 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var store = GetUserLockoutStore();
|
var store = GetUserLockoutStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
if (!await store.GetLockoutEnabled(user).ConfigureAwait(false))
|
if (!await store.GetLockoutEnabled(user))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -1537,14 +1540,14 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var store = GetUserLockoutStore();
|
var store = GetUserLockoutStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
await store.SetLockoutEnabled(user, enabled).ConfigureAwait(false);
|
await store.SetLockoutEnabled(user, enabled);
|
||||||
return await Update(user).ConfigureAwait(false);
|
return await Update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1556,13 +1559,13 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var store = GetUserLockoutStore();
|
var store = GetUserLockoutStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
return await store.GetLockoutEnabled(user).ConfigureAwait(false);
|
return await store.GetLockoutEnabled(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1574,13 +1577,13 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var store = GetUserLockoutStore();
|
var store = GetUserLockoutStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
return await store.GetLockoutEndDate(user).ConfigureAwait(false);
|
return await store.GetLockoutEndDate(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1593,7 +1596,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var store = GetUserLockoutStore();
|
var store = GetUserLockoutStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
|
|
@ -1603,8 +1606,8 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
return IdentityResult.Failed(Resources.LockoutNotEnabled);
|
return IdentityResult.Failed(Resources.LockoutNotEnabled);
|
||||||
}
|
}
|
||||||
await store.SetLockoutEndDate(user, lockoutEnd).ConfigureAwait(false);
|
await store.SetLockoutEndDate(user, lockoutEnd);
|
||||||
return await Update(user).ConfigureAwait(false);
|
return await Update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1618,23 +1621,23 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var store = GetUserLockoutStore();
|
var store = GetUserLockoutStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
// If this puts the user over the threshold for lockout, lock them out and reset the access failed count
|
// If this puts the user over the threshold for lockout, lock them out and reset the access failed count
|
||||||
var count = await store.IncrementAccessFailedCount(user).ConfigureAwait(false);
|
var count = await store.IncrementAccessFailedCount(user);
|
||||||
if (count < MaxFailedAccessAttemptsBeforeLockout)
|
if (count < MaxFailedAccessAttemptsBeforeLockout)
|
||||||
{
|
{
|
||||||
return await Update(user).ConfigureAwait(false);
|
return await Update(user);
|
||||||
}
|
}
|
||||||
await
|
await
|
||||||
store.SetLockoutEndDate(user, DateTimeOffset.UtcNow.Add(DefaultAccountLockoutTimeSpan))
|
store.SetLockoutEndDate(user, DateTimeOffset.UtcNow.Add(DefaultAccountLockoutTimeSpan))
|
||||||
.ConfigureAwait(false);
|
;
|
||||||
await store.ResetAccessFailedCount(user).ConfigureAwait(false);
|
await store.ResetAccessFailedCount(user);
|
||||||
return await Update(user).ConfigureAwait(false);
|
return await Update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1646,14 +1649,14 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var store = GetUserLockoutStore();
|
var store = GetUserLockoutStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
await store.ResetAccessFailedCount(user).ConfigureAwait(false);
|
await store.ResetAccessFailedCount(user);
|
||||||
return await Update(user).ConfigureAwait(false);
|
return await Update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1665,13 +1668,13 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
var store = GetUserLockoutStore();
|
var store = GetUserLockoutStore();
|
||||||
var user = await FindById(userId).ConfigureAwait(false);
|
var user = await FindById(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
|
||||||
userId));
|
userId));
|
||||||
}
|
}
|
||||||
return await store.GetAccessFailedCount(user).ConfigureAwait(false);
|
return await store.GetAccessFailedCount(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ThrowIfDisposed()
|
private void ThrowIfDisposed()
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
|
#if NET45
|
||||||
|
using System.Net.Mail;
|
||||||
|
#endif
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
#if NET45
|
|
||||||
using System.Net.Mail;
|
|
||||||
#endif
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Identity
|
namespace Microsoft.AspNet.Identity
|
||||||
|
|
@ -60,7 +60,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
}
|
}
|
||||||
return errors.Count > 0 ? IdentityResult.Failed(errors.ToArray()) : IdentityResult.Success;
|
return errors.Count > 0 ? IdentityResult.Failed(errors.ToArray()) : IdentityResult.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Revisit extensibility for Validators
|
// TODO: Revisit extensibility for Validators
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -127,7 +127,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
// make sure email is not empty, valid, and unique
|
// 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, TKey> manager, TUser user, List<string> errors)
|
||||||
{
|
{
|
||||||
var email = await manager.GetEmailStore().GetEmail(user).ConfigureAwait(false);
|
var email = await manager.GetEmailStore().GetEmail(user);
|
||||||
if (string.IsNullOrWhiteSpace(email))
|
if (string.IsNullOrWhiteSpace(email))
|
||||||
{
|
{
|
||||||
errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.PropertyTooShort, "Email"));
|
errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.PropertyTooShort, "Email"));
|
||||||
|
|
|
||||||
|
|
@ -57,8 +57,8 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
public async Task UserValidatorBlocksShortEmailsWhenRequiresUniqueEmail(string email)
|
public async Task UserValidatorBlocksShortEmailsWhenRequiresUniqueEmail(string email)
|
||||||
{
|
{
|
||||||
var manager = CreateManager();
|
var manager = CreateManager();
|
||||||
var user = new InMemoryUser("UpdateBlocked") { Email = email };
|
var user = new InMemoryUser("UpdateBlocked") {Email = email};
|
||||||
manager.UserValidator = new UserValidator<InMemoryUser, string> { RequireUniqueEmail = true };
|
manager.UserValidator = new UserValidator<InMemoryUser, string> {RequireUniqueEmail = true};
|
||||||
IdentityResultAssert.IsFailure(await manager.Create(user), "Email cannot be null or empty.");
|
IdentityResultAssert.IsFailure(await manager.Create(user), "Email cannot be null or empty.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,9 +69,9 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
public async Task UserValidatorBlocksInvalidEmailsWhenRequiresUniqueEmail(string email)
|
public async Task UserValidatorBlocksInvalidEmailsWhenRequiresUniqueEmail(string email)
|
||||||
{
|
{
|
||||||
var manager = CreateManager();
|
var manager = CreateManager();
|
||||||
var user = new InMemoryUser("UpdateBlocked") { Email = email };
|
var user = new InMemoryUser("UpdateBlocked") {Email = email};
|
||||||
manager.UserValidator = new UserValidator<InMemoryUser, string> { RequireUniqueEmail = true };
|
manager.UserValidator = new UserValidator<InMemoryUser, string> {RequireUniqueEmail = true};
|
||||||
IdentityResultAssert.IsFailure(await manager.Create(user), "Email '"+email+"' is invalid.");
|
IdentityResultAssert.IsFailure(await manager.Create(user), "Email '" + email + "' is invalid.");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -82,7 +82,8 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
var user = new InMemoryUser("AddPasswordBlocked");
|
var user = new InMemoryUser("AddPasswordBlocked");
|
||||||
IdentityResultAssert.IsSuccess(await manager.Create(user));
|
IdentityResultAssert.IsSuccess(await manager.Create(user));
|
||||||
manager.PasswordValidator = new AlwaysBadValidator();
|
manager.PasswordValidator = new AlwaysBadValidator();
|
||||||
IdentityResultAssert.IsFailure(await manager.AddPassword(user.Id, "password"), AlwaysBadValidator.ErrorMessage);
|
IdentityResultAssert.IsFailure(await manager.AddPassword(user.Id, "password"),
|
||||||
|
AlwaysBadValidator.ErrorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -92,7 +93,8 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
var user = new InMemoryUser("ChangePasswordBlocked");
|
var user = new InMemoryUser("ChangePasswordBlocked");
|
||||||
IdentityResultAssert.IsSuccess(await manager.Create(user, "password"));
|
IdentityResultAssert.IsSuccess(await manager.Create(user, "password"));
|
||||||
manager.PasswordValidator = new AlwaysBadValidator();
|
manager.PasswordValidator = new AlwaysBadValidator();
|
||||||
IdentityResultAssert.IsFailure(await manager.ChangePassword(user.Id, "password", "new"), AlwaysBadValidator.ErrorMessage);
|
IdentityResultAssert.IsFailure(await manager.ChangePassword(user.Id, "password", "new"),
|
||||||
|
AlwaysBadValidator.ErrorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -151,7 +153,8 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
var user = new InMemoryUser("CannotAddAnotherPassword");
|
var user = new InMemoryUser("CannotAddAnotherPassword");
|
||||||
IdentityResultAssert.IsSuccess(await manager.Create(user, "Password"));
|
IdentityResultAssert.IsSuccess(await manager.Create(user, "Password"));
|
||||||
Assert.True(await manager.HasPassword(user.Id));
|
Assert.True(await manager.HasPassword(user.Id));
|
||||||
IdentityResultAssert.IsFailure(await manager.AddPassword(user.Id, "password"), "User already has a password set.");
|
IdentityResultAssert.IsFailure(await manager.AddPassword(user.Id, "password"),
|
||||||
|
"User already has a password set.");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -216,7 +219,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
var manager = CreateManager();
|
var manager = CreateManager();
|
||||||
var user = new InMemoryUser("ClaimsAddRemove");
|
var user = new InMemoryUser("ClaimsAddRemove");
|
||||||
IdentityResultAssert.IsSuccess(await manager.Create(user));
|
IdentityResultAssert.IsSuccess(await manager.Create(user));
|
||||||
Claim[] claims = { new Claim("c", "v"), new Claim("c2", "v2"), new Claim("c2", "v3") };
|
Claim[] claims = {new Claim("c", "v"), new Claim("c2", "v2"), new Claim("c2", "v3")};
|
||||||
foreach (Claim c in claims)
|
foreach (Claim c in claims)
|
||||||
{
|
{
|
||||||
IdentityResultAssert.IsSuccess(await manager.AddClaim(user.Id, c));
|
IdentityResultAssert.IsSuccess(await manager.AddClaim(user.Id, c));
|
||||||
|
|
@ -259,7 +262,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
{
|
{
|
||||||
var manager = CreateManager();
|
var manager = CreateManager();
|
||||||
var user = new InMemoryUser("dupe") {Email = "yup@yup.com"};
|
var user = new InMemoryUser("dupe") {Email = "yup@yup.com"};
|
||||||
var user2 = new InMemoryUser("dupeEmail") { Email = "yup@yup.com" };
|
var user2 = new InMemoryUser("dupeEmail") {Email = "yup@yup.com"};
|
||||||
IdentityResultAssert.IsSuccess(await manager.Create(user));
|
IdentityResultAssert.IsSuccess(await manager.Create(user));
|
||||||
IdentityResultAssert.IsSuccess(await manager.Create(user2));
|
IdentityResultAssert.IsSuccess(await manager.Create(user2));
|
||||||
}
|
}
|
||||||
|
|
@ -268,9 +271,9 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
public async Task AddDupeEmailFallsWhenUniqueEmailRequired()
|
public async Task AddDupeEmailFallsWhenUniqueEmailRequired()
|
||||||
{
|
{
|
||||||
var manager = CreateManager();
|
var manager = CreateManager();
|
||||||
manager.UserValidator = new UserValidator<InMemoryUser, string> { RequireUniqueEmail = true };
|
manager.UserValidator = new UserValidator<InMemoryUser, string> {RequireUniqueEmail = true};
|
||||||
var user = new InMemoryUser("dupe") { Email = "yup@yup.com" };
|
var user = new InMemoryUser("dupe") {Email = "yup@yup.com"};
|
||||||
var user2 = new InMemoryUser("dupeEmail") { Email = "yup@yup.com" };
|
var user2 = new InMemoryUser("dupeEmail") {Email = "yup@yup.com"};
|
||||||
IdentityResultAssert.IsSuccess(await manager.Create(user));
|
IdentityResultAssert.IsSuccess(await manager.Create(user));
|
||||||
IdentityResultAssert.IsFailure(await manager.Create(user2), "Email 'yup@yup.com' is already taken.");
|
IdentityResultAssert.IsFailure(await manager.Create(user2), "Email 'yup@yup.com' is already taken.");
|
||||||
}
|
}
|
||||||
|
|
@ -307,7 +310,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
var manager = CreateManager();
|
var manager = CreateManager();
|
||||||
const string userName = "EmailTest";
|
const string userName = "EmailTest";
|
||||||
const string email = "email@test.com";
|
const string email = "email@test.com";
|
||||||
var user = new InMemoryUser(userName) { Email = email };
|
var user = new InMemoryUser(userName) {Email = email};
|
||||||
IdentityResultAssert.IsSuccess(await manager.Create(user));
|
IdentityResultAssert.IsSuccess(await manager.Create(user));
|
||||||
var fetch = await manager.FindByEmail(email);
|
var fetch = await manager.FindByEmail(email);
|
||||||
Assert.Equal(user, fetch);
|
Assert.Equal(user, fetch);
|
||||||
|
|
@ -384,11 +387,6 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
// TODO: No token provider implementations yet
|
// TODO: No token provider implementations yet
|
||||||
private class StaticTokenProvider : IUserTokenProvider<InMemoryUser, string>
|
private class StaticTokenProvider : IUserTokenProvider<InMemoryUser, string>
|
||||||
{
|
{
|
||||||
private static string MakeToken(string purpose, IUser<string> user)
|
|
||||||
{
|
|
||||||
return string.Join(":", user.Id, purpose, "ImmaToken");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<string> Generate(string purpose, UserManager<InMemoryUser, string> manager,
|
public Task<string> Generate(string purpose, UserManager<InMemoryUser, string> manager,
|
||||||
InMemoryUser user)
|
InMemoryUser user)
|
||||||
{
|
{
|
||||||
|
|
@ -410,6 +408,11 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
{
|
{
|
||||||
return Task.FromResult(true);
|
return Task.FromResult(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string MakeToken(string purpose, IUser<string> user)
|
||||||
|
{
|
||||||
|
return string.Join(":", user.Id, purpose, "ImmaToken");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -445,7 +448,8 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
var token = await manager.GeneratePasswordResetToken(user.Id);
|
var token = await manager.GeneratePasswordResetToken(user.Id);
|
||||||
Assert.NotNull(token);
|
Assert.NotNull(token);
|
||||||
manager.PasswordValidator = new AlwaysBadValidator();
|
manager.PasswordValidator = new AlwaysBadValidator();
|
||||||
IdentityResultAssert.IsFailure(await manager.ResetPassword(user.Id, token, newPassword), AlwaysBadValidator.ErrorMessage);
|
IdentityResultAssert.IsFailure(await manager.ResetPassword(user.Id, token, newPassword),
|
||||||
|
AlwaysBadValidator.ErrorMessage);
|
||||||
Assert.NotNull(await manager.Find(user.UserName, password));
|
Assert.NotNull(await manager.Find(user.UserName, password));
|
||||||
Assert.Equal(user, await manager.Find(user.UserName, password));
|
Assert.Equal(user, await manager.Find(user.UserName, password));
|
||||||
Assert.Equal(stamp, user.SecurityStamp);
|
Assert.Equal(stamp, user.SecurityStamp);
|
||||||
|
|
@ -641,7 +645,8 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
IdentityResultAssert.IsSuccess(await mgr.Create(user));
|
IdentityResultAssert.IsSuccess(await mgr.Create(user));
|
||||||
Assert.False(await mgr.GetLockoutEnabled(user.Id));
|
Assert.False(await mgr.GetLockoutEnabled(user.Id));
|
||||||
Assert.False(user.LockoutEnabled);
|
Assert.False(user.LockoutEnabled);
|
||||||
IdentityResultAssert.IsFailure(await mgr.SetLockoutEndDate(user.Id, new DateTimeOffset()), "Lockout is not enabled for this user.");
|
IdentityResultAssert.IsFailure(await mgr.SetLockoutEndDate(user.Id, new DateTimeOffset()),
|
||||||
|
"Lockout is not enabled for this user.");
|
||||||
Assert.False(await mgr.IsLockedOut(user.Id));
|
Assert.False(await mgr.IsLockedOut(user.Id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -650,7 +655,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
{
|
{
|
||||||
var mgr = CreateManager();
|
var mgr = CreateManager();
|
||||||
mgr.UserLockoutEnabledByDefault = true;
|
mgr.UserLockoutEnabledByDefault = true;
|
||||||
var user = new InMemoryUser("LockoutUtcNowTest") { LockoutEnd = DateTimeOffset.UtcNow.AddSeconds(-1) };
|
var user = new InMemoryUser("LockoutUtcNowTest") {LockoutEnd = DateTimeOffset.UtcNow.AddSeconds(-1)};
|
||||||
IdentityResultAssert.IsSuccess(await mgr.Create(user));
|
IdentityResultAssert.IsSuccess(await mgr.Create(user));
|
||||||
Assert.True(await mgr.GetLockoutEnabled(user.Id));
|
Assert.True(await mgr.GetLockoutEnabled(user.Id));
|
||||||
Assert.True(user.LockoutEnabled);
|
Assert.True(user.LockoutEnabled);
|
||||||
|
|
@ -675,7 +680,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
{
|
{
|
||||||
var mgr = CreateManager();
|
var mgr = CreateManager();
|
||||||
mgr.UserLockoutEnabledByDefault = true;
|
mgr.UserLockoutEnabledByDefault = true;
|
||||||
var user = new InMemoryUser("LockoutUtcNowTest") { LockoutEnd = DateTimeOffset.UtcNow.AddMinutes(5) };
|
var user = new InMemoryUser("LockoutUtcNowTest") {LockoutEnd = DateTimeOffset.UtcNow.AddMinutes(5)};
|
||||||
IdentityResultAssert.IsSuccess(await mgr.Create(user));
|
IdentityResultAssert.IsSuccess(await mgr.Create(user));
|
||||||
Assert.True(await mgr.GetLockoutEnabled(user.Id));
|
Assert.True(await mgr.GetLockoutEnabled(user.Id));
|
||||||
Assert.True(user.LockoutEnabled);
|
Assert.True(user.LockoutEnabled);
|
||||||
|
|
@ -709,11 +714,12 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
Assert.True(await manager.RoleExists(role.Name));
|
Assert.True(await manager.RoleExists(role.Name));
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AlwaysBadValidator : IUserValidator<InMemoryUser, string>, IRoleValidator<InMemoryRole, string>, IPasswordValidator
|
private class AlwaysBadValidator : IUserValidator<InMemoryUser, string>, IRoleValidator<InMemoryRole, string>,
|
||||||
|
IPasswordValidator
|
||||||
{
|
{
|
||||||
public const string ErrorMessage = "I'm Bad.";
|
public const string ErrorMessage = "I'm Bad.";
|
||||||
|
|
||||||
public Task<IdentityResult> Validate(UserManager<InMemoryUser, string> manager, InMemoryUser user)
|
public Task<IdentityResult> Validate(string password)
|
||||||
{
|
{
|
||||||
return Task.FromResult(IdentityResult.Failed(ErrorMessage));
|
return Task.FromResult(IdentityResult.Failed(ErrorMessage));
|
||||||
}
|
}
|
||||||
|
|
@ -723,7 +729,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
return Task.FromResult(IdentityResult.Failed(ErrorMessage));
|
return Task.FromResult(IdentityResult.Failed(ErrorMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<IdentityResult> Validate(string password)
|
public Task<IdentityResult> Validate(UserManager<InMemoryUser, string> manager, InMemoryUser user)
|
||||||
{
|
{
|
||||||
return Task.FromResult(IdentityResult.Failed(ErrorMessage));
|
return Task.FromResult(IdentityResult.Failed(ErrorMessage));
|
||||||
}
|
}
|
||||||
|
|
@ -1086,17 +1092,13 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
|
|
||||||
private class EmailTokenProvider : IUserTokenProvider<InMemoryUser, string>
|
private class EmailTokenProvider : IUserTokenProvider<InMemoryUser, string>
|
||||||
{
|
{
|
||||||
private static string MakeToken(string purpose)
|
|
||||||
{
|
|
||||||
return "email:" + purpose;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<string> Generate(string purpose, UserManager<InMemoryUser, string> manager, InMemoryUser user)
|
public Task<string> Generate(string purpose, UserManager<InMemoryUser, string> manager, InMemoryUser user)
|
||||||
{
|
{
|
||||||
return Task.FromResult(MakeToken(purpose));
|
return Task.FromResult(MakeToken(purpose));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<bool> Validate(string purpose, string token, UserManager<InMemoryUser, string> manager, InMemoryUser user)
|
public Task<bool> Validate(string purpose, string token, UserManager<InMemoryUser, string> manager,
|
||||||
|
InMemoryUser user)
|
||||||
{
|
{
|
||||||
return Task.FromResult(token == MakeToken(purpose));
|
return Task.FromResult(token == MakeToken(purpose));
|
||||||
}
|
}
|
||||||
|
|
@ -1110,21 +1112,22 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
{
|
{
|
||||||
return !string.IsNullOrEmpty(await manager.GetEmail(user.Id));
|
return !string.IsNullOrEmpty(await manager.GetEmail(user.Id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string MakeToken(string purpose)
|
||||||
|
{
|
||||||
|
return "email:" + purpose;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SmsTokenProvider : IUserTokenProvider<InMemoryUser, string>
|
private class SmsTokenProvider : IUserTokenProvider<InMemoryUser, string>
|
||||||
{
|
{
|
||||||
private static string MakeToken(string purpose)
|
|
||||||
{
|
|
||||||
return "sms:" + purpose;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<string> Generate(string purpose, UserManager<InMemoryUser, string> manager, InMemoryUser user)
|
public Task<string> Generate(string purpose, UserManager<InMemoryUser, string> manager, InMemoryUser user)
|
||||||
{
|
{
|
||||||
return Task.FromResult(MakeToken(purpose));
|
return Task.FromResult(MakeToken(purpose));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<bool> Validate(string purpose, string token, UserManager<InMemoryUser, string> manager, InMemoryUser user)
|
public Task<bool> Validate(string purpose, string token, UserManager<InMemoryUser, string> manager,
|
||||||
|
InMemoryUser user)
|
||||||
{
|
{
|
||||||
return Task.FromResult(token == MakeToken(purpose));
|
return Task.FromResult(token == MakeToken(purpose));
|
||||||
}
|
}
|
||||||
|
|
@ -1138,6 +1141,11 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
{
|
{
|
||||||
return !string.IsNullOrEmpty(await manager.GetPhoneNumber(user.Id));
|
return !string.IsNullOrEmpty(await manager.GetPhoneNumber(user.Id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string MakeToken(string purpose)
|
||||||
|
{
|
||||||
|
return "sms:" + purpose;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -1148,7 +1156,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
manager.EmailService = messageService;
|
manager.EmailService = messageService;
|
||||||
const string factorId = "EmailCode";
|
const string factorId = "EmailCode";
|
||||||
manager.RegisterTwoFactorProvider(factorId, new EmailTokenProvider());
|
manager.RegisterTwoFactorProvider(factorId, new EmailTokenProvider());
|
||||||
var user = new InMemoryUser("EmailCodeTest") { Email = "foo@foo.com" };
|
var user = new InMemoryUser("EmailCodeTest") {Email = "foo@foo.com"};
|
||||||
const string password = "password";
|
const string password = "password";
|
||||||
IdentityResultAssert.IsSuccess(await manager.Create(user, password));
|
IdentityResultAssert.IsSuccess(await manager.Create(user, password));
|
||||||
var stamp = user.SecurityStamp;
|
var stamp = user.SecurityStamp;
|
||||||
|
|
@ -1169,7 +1177,10 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
var manager = CreateManager();
|
var manager = CreateManager();
|
||||||
var user = new InMemoryUser("NotifyFail");
|
var user = new InMemoryUser("NotifyFail");
|
||||||
IdentityResultAssert.IsSuccess(await manager.Create(user));
|
IdentityResultAssert.IsSuccess(await manager.Create(user));
|
||||||
await ExceptionAssert.ThrowsAsync<NotSupportedException>(async () => await manager.NotifyTwoFactorToken(user.Id, "Bogus", "token"), "No IUserTwoFactorProvider for 'Bogus' is registered.");
|
await
|
||||||
|
ExceptionAssert.ThrowsAsync<NotSupportedException>(
|
||||||
|
async () => await manager.NotifyTwoFactorToken(user.Id, "Bogus", "token"),
|
||||||
|
"No IUserTwoFactorProvider for 'Bogus' is registered.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1235,7 +1246,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
var manager = CreateManager();
|
var manager = CreateManager();
|
||||||
var messageService = new TestMessageService();
|
var messageService = new TestMessageService();
|
||||||
manager.SmsService = messageService;
|
manager.SmsService = messageService;
|
||||||
var user = new InMemoryUser("SmsTest") { PhoneNumber = "4251234567" };
|
var user = new InMemoryUser("SmsTest") {PhoneNumber = "4251234567"};
|
||||||
IdentityResultAssert.IsSuccess(await manager.Create(user));
|
IdentityResultAssert.IsSuccess(await manager.Create(user));
|
||||||
await manager.SendSms(user.Id, "Hi");
|
await manager.SendSms(user.Id, "Hi");
|
||||||
Assert.NotNull(messageService.Message);
|
Assert.NotNull(messageService.Message);
|
||||||
|
|
@ -1248,7 +1259,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
var manager = CreateManager();
|
var manager = CreateManager();
|
||||||
var messageService = new TestMessageService();
|
var messageService = new TestMessageService();
|
||||||
manager.EmailService = messageService;
|
manager.EmailService = messageService;
|
||||||
var user = new InMemoryUser("EmailTest") { Email = "foo@foo.com" };
|
var user = new InMemoryUser("EmailTest") {Email = "foo@foo.com"};
|
||||||
IdentityResultAssert.IsSuccess(await manager.Create(user));
|
IdentityResultAssert.IsSuccess(await manager.Create(user));
|
||||||
await manager.SendEmail(user.Id, "Hi", "Body");
|
await manager.SendEmail(user.Id, "Hi", "Body");
|
||||||
Assert.NotNull(messageService.Message);
|
Assert.NotNull(messageService.Message);
|
||||||
|
|
@ -1264,7 +1275,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
manager.SmsService = messageService;
|
manager.SmsService = messageService;
|
||||||
const string factorId = "PhoneCode";
|
const string factorId = "PhoneCode";
|
||||||
manager.RegisterTwoFactorProvider(factorId, new SmsTokenProvider());
|
manager.RegisterTwoFactorProvider(factorId, new SmsTokenProvider());
|
||||||
var user = new InMemoryUser("PhoneCodeTest") { PhoneNumber = "4251234567" };
|
var user = new InMemoryUser("PhoneCodeTest") {PhoneNumber = "4251234567"};
|
||||||
IdentityResultAssert.IsSuccess(await manager.Create(user));
|
IdentityResultAssert.IsSuccess(await manager.Create(user));
|
||||||
var stamp = user.SecurityStamp;
|
var stamp = user.SecurityStamp;
|
||||||
Assert.NotNull(stamp);
|
Assert.NotNull(stamp);
|
||||||
|
|
@ -1308,7 +1319,9 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
var user = new InMemoryUser("PhoneCodeTest");
|
var user = new InMemoryUser("PhoneCodeTest");
|
||||||
IdentityResultAssert.IsSuccess(await manager.Create(user));
|
IdentityResultAssert.IsSuccess(await manager.Create(user));
|
||||||
const string error = "No IUserTwoFactorProvider for 'bogus' is registered.";
|
const string error = "No IUserTwoFactorProvider for 'bogus' is registered.";
|
||||||
await ExceptionAssert.ThrowsAsync<NotSupportedException>(() => manager.GenerateTwoFactorToken(user.Id, "bogus"), error);
|
await
|
||||||
|
ExceptionAssert.ThrowsAsync<NotSupportedException>(
|
||||||
|
() => manager.GenerateTwoFactorToken(user.Id, "bogus"), error);
|
||||||
await ExceptionAssert.ThrowsAsync<NotSupportedException>(
|
await ExceptionAssert.ThrowsAsync<NotSupportedException>(
|
||||||
() => manager.VerifyTwoFactorToken(user.Id, "bogus", "bogus"), error);
|
() => manager.VerifyTwoFactorToken(user.Id, "bogus", "bogus"), error);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
using System.Security.Claims;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Identity;
|
|
||||||
using Microsoft.AspNet.Testing;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Identity.Test
|
namespace Microsoft.AspNet.Identity.Test
|
||||||
|
|
@ -15,12 +11,12 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
{
|
{
|
||||||
var factory = new ClaimsIdentityFactory<TestUser, string>();
|
var factory = new ClaimsIdentityFactory<TestUser, string>();
|
||||||
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("manager",
|
await Assert.ThrowsAsync<ArgumentNullException>("manager",
|
||||||
async () => await factory.Create(null, null, "whatever"));
|
async () => await factory.Create(null, null, "whatever"));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user",
|
await Assert.ThrowsAsync<ArgumentNullException>("user",
|
||||||
async () => await factory.Create(manager, null, "whatever"));
|
async () => await factory.Create(manager, null, "whatever"));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("value",
|
await Assert.ThrowsAsync<ArgumentNullException>("value",
|
||||||
async () => await factory.Create(manager, new TestUser(), null));
|
async () => await factory.Create(manager, new TestUser(), null));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,4 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Identity.Test
|
namespace Microsoft.AspNet.Identity.Test
|
||||||
|
|
@ -25,6 +22,5 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
Assert.Equal(1, result.Errors.Count());
|
Assert.Equal(1, result.Errors.Count());
|
||||||
Assert.Equal("An unknown failure has occured.", result.Errors.First());
|
Assert.Equal("An unknown failure has occured.", result.Errors.First());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,41 +1,36 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Security.Claims;
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Identity.Test
|
namespace Microsoft.AspNet.Identity.Test
|
||||||
{
|
{
|
||||||
public class NoopRoleStore : IRoleStore<TestRole, string>
|
public class NoopRoleStore : IRoleStore<TestRole, string>
|
||||||
|
{
|
||||||
|
public Task Create(TestRole user)
|
||||||
{
|
{
|
||||||
public Task Create(TestRole user)
|
return Task.FromResult(0);
|
||||||
{
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task Update(TestRole user)
|
|
||||||
{
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<TestRole> FindById(string roleId)
|
|
||||||
{
|
|
||||||
return Task.FromResult<TestRole>(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<TestRole> FindByName(string userName)
|
|
||||||
{
|
|
||||||
return Task.FromResult<TestRole>(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task Delete(TestRole user)
|
|
||||||
{
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
public Task Update(TestRole user)
|
||||||
|
{
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<TestRole> FindById(string roleId)
|
||||||
|
{
|
||||||
|
return Task.FromResult<TestRole>(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<TestRole> FindByName(string userName)
|
||||||
|
{
|
||||||
|
return Task.FromResult<TestRole>(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Delete(TestRole user)
|
||||||
|
{
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,36 +2,35 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Identity.Test
|
namespace Microsoft.AspNet.Identity.Test
|
||||||
{
|
{
|
||||||
public class NoopUserStore : IUserStore<TestUser, string>
|
public class NoopUserStore : IUserStore<TestUser, string>
|
||||||
|
{
|
||||||
|
public Task Create(TestUser user)
|
||||||
{
|
{
|
||||||
public Task Create(TestUser user)
|
return Task.FromResult(0);
|
||||||
{
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task Update(TestUser user)
|
|
||||||
{
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<TestUser> FindById(string userId)
|
|
||||||
{
|
|
||||||
return Task.FromResult<TestUser>(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<TestUser> FindByName(string userName)
|
|
||||||
{
|
|
||||||
return Task.FromResult<TestUser>(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task Delete(TestUser user)
|
|
||||||
{
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
public Task Update(TestUser user)
|
||||||
|
{
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<TestUser> FindById(string userId)
|
||||||
|
{
|
||||||
|
return Task.FromResult<TestUser>(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<TestUser> FindByName(string userName)
|
||||||
|
{
|
||||||
|
return Task.FromResult<TestUser>(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Delete(TestUser user)
|
||||||
|
{
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,17 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
{
|
{
|
||||||
public class PasswordValidatorTest
|
public class PasswordValidatorTest
|
||||||
{
|
{
|
||||||
|
[Flags]
|
||||||
|
public enum Errors
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Length = 2,
|
||||||
|
Alpha = 4,
|
||||||
|
Upper = 8,
|
||||||
|
Lower = 16,
|
||||||
|
Digit = 32,
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ValidateThrowsWithNullTest()
|
public async Task ValidateThrowsWithNullTest()
|
||||||
{
|
{
|
||||||
|
|
@ -21,7 +32,7 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("")]
|
[InlineData("")]
|
||||||
[InlineData("abc")]
|
[InlineData("abc")]
|
||||||
[InlineData("abcde")]
|
[InlineData("abcde")]
|
||||||
public async Task FailsIfTooShortTests(string input)
|
public async Task FailsIfTooShortTests(string input)
|
||||||
{
|
{
|
||||||
|
|
@ -33,41 +44,32 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("abcdef")]
|
[InlineData("abcdef")]
|
||||||
[InlineData("aaaaaaaaaaa")]
|
[InlineData("aaaaaaaaaaa")]
|
||||||
public async Task SuccessIfLongEnoughTests(string input) {
|
public async Task SuccessIfLongEnoughTests(string input)
|
||||||
|
{
|
||||||
var valid = new PasswordValidator {RequiredLength = 6};
|
var valid = new PasswordValidator {RequiredLength = 6};
|
||||||
IdentityResultAssert.IsSuccess(await valid.Validate(input));
|
IdentityResultAssert.IsSuccess(await valid.Validate(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("a")]
|
[InlineData("a")]
|
||||||
[InlineData("aaaaaaaaaaa")]
|
[InlineData("aaaaaaaaaaa")]
|
||||||
public async Task FailsWithoutRequiredNonAlphanumericTests(string input)
|
public async Task FailsWithoutRequiredNonAlphanumericTests(string input)
|
||||||
{
|
{
|
||||||
var valid = new PasswordValidator { RequireNonLetterOrDigit = true };
|
var valid = new PasswordValidator {RequireNonLetterOrDigit = true};
|
||||||
IdentityResultAssert.IsFailure(await valid.Validate(input), "Passwords must have at least one non letter or digit character.");
|
IdentityResultAssert.IsFailure(await valid.Validate(input),
|
||||||
|
"Passwords must have at least one non letter or digit character.");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("@")]
|
[InlineData("@")]
|
||||||
[InlineData("abcd@e!ld!kajfd")]
|
[InlineData("abcd@e!ld!kajfd")]
|
||||||
[InlineData("!!!!!!")]
|
[InlineData("!!!!!!")]
|
||||||
public async Task SucceedsWithRequiredNonAlphanumericTests(string input)
|
public async Task SucceedsWithRequiredNonAlphanumericTests(string input)
|
||||||
{
|
{
|
||||||
var valid = new PasswordValidator { RequireNonLetterOrDigit = true };
|
var valid = new PasswordValidator {RequireNonLetterOrDigit = true};
|
||||||
IdentityResultAssert.IsSuccess(await valid.Validate(input));
|
IdentityResultAssert.IsSuccess(await valid.Validate(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Flags]
|
|
||||||
public enum Errors
|
|
||||||
{
|
|
||||||
None = 0,
|
|
||||||
Length = 2,
|
|
||||||
Alpha = 4,
|
|
||||||
Upper = 8,
|
|
||||||
Lower = 16,
|
|
||||||
Digit = 32,
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("abcde", Errors.Length | Errors.Alpha | Errors.Upper | Errors.Digit)]
|
[InlineData("abcde", Errors.Length | Errors.Alpha | Errors.Upper | Errors.Digit)]
|
||||||
[InlineData("a@B@cd", Errors.Digit)]
|
[InlineData("a@B@cd", Errors.Digit)]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,3 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Security.Claims;
|
|
||||||
using Moq;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
@ -60,7 +57,6 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
|
|
||||||
private class NotImplementedStore : IRoleStore<TestRole, string>
|
private class NotImplementedStore : IRoleStore<TestRole, string>
|
||||||
{
|
{
|
||||||
|
|
||||||
public Task Create(TestRole role)
|
public Task Create(TestRole role)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
|
@ -91,6 +87,5 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
// Setup
|
// Setup
|
||||||
var manager = new RoleManager<TestRole, string>(new NoopRoleStore());
|
var manager = new RoleManager<TestRole, string>(new NoopRoleStore());
|
||||||
var validator = new RoleValidator<TestRole, string>();
|
var validator = new RoleValidator<TestRole, string>();
|
||||||
var user = new TestRole { Name = input };
|
var user = new TestRole {Name = input};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = await validator.Validate(manager, user);
|
var result = await validator.Validate(manager, user);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Identity.Test
|
namespace Microsoft.AspNet.Identity.Test
|
||||||
{
|
{
|
||||||
public class TestRole : IRole<string>
|
public class TestRole : IRole<string>
|
||||||
|
|
@ -6,4 +5,4 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
public string Id { get; private set; }
|
public string Id { get; private set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -8,15 +8,15 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
public static class TestServices
|
public static class TestServices
|
||||||
{
|
{
|
||||||
public static IServiceProvider DefaultServiceProvider<TUser, TKey>()
|
public static IServiceProvider DefaultServiceProvider<TUser, TKey>()
|
||||||
where TUser : class,IUser<TKey>
|
where TUser : class, IUser<TKey>
|
||||||
where TKey : IEquatable<TKey>
|
where TKey : IEquatable<TKey>
|
||||||
{
|
{
|
||||||
var serviceCollection = new ServiceCollection { DefaultServices<TUser, TKey>() };
|
var serviceCollection = new ServiceCollection {DefaultServices<TUser, TKey>()};
|
||||||
return serviceCollection.BuildServiceProvider();
|
return serviceCollection.BuildServiceProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<IServiceDescriptor> DefaultServices<TUser, TKey>()
|
public static IEnumerable<IServiceDescriptor> DefaultServices<TUser, TKey>()
|
||||||
where TUser : class,IUser<TKey>
|
where TUser : class, IUser<TKey>
|
||||||
where TKey : IEquatable<TKey>
|
where TKey : IEquatable<TKey>
|
||||||
{
|
{
|
||||||
return new IServiceDescriptor[]
|
return new IServiceDescriptor[]
|
||||||
|
|
@ -25,6 +25,7 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
new ServiceDescriptor<IUserValidator<TUser, TKey>, UserValidator<TUser, TKey>>(),
|
new ServiceDescriptor<IUserValidator<TUser, TKey>, UserValidator<TUser, TKey>>(),
|
||||||
new ServiceDescriptor<IPasswordHasher, PasswordHasher>(),
|
new ServiceDescriptor<IPasswordHasher, PasswordHasher>(),
|
||||||
new ServiceDescriptor<IClaimsIdentityFactory<TUser, TKey>, ClaimsIdentityFactory<TUser, TKey>>(),
|
new ServiceDescriptor<IClaimsIdentityFactory<TUser, TKey>, ClaimsIdentityFactory<TUser, TKey>>(),
|
||||||
|
new ServiceDescriptor<IUserStore<TUser, TKey>, NoopUserStore>()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -39,12 +40,12 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
|
|
||||||
public Type ServiceType
|
public Type ServiceType
|
||||||
{
|
{
|
||||||
get { return typeof(TService); }
|
get { return typeof (TService); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type ImplementationType
|
public Type ImplementationType
|
||||||
{
|
{
|
||||||
get { return typeof(TImplementation); }
|
get { return typeof (TImplementation); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public object ImplementationInstance
|
public object ImplementationInstance
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Identity.Test
|
namespace Microsoft.AspNet.Identity.Test
|
||||||
{
|
{
|
||||||
public class TestUser : TestUser<string>
|
public class TestUser : TestUser<string>
|
||||||
|
|
@ -10,5 +9,4 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
public TKey Id { get; private set; }
|
public TKey Id { get; private set; }
|
||||||
public string UserName { get; set; }
|
public string UserName { get; set; }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
@ -1,27 +1,33 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Runtime;
|
|
||||||
using System.Security.Claims;
|
|
||||||
using Microsoft.AspNet.Testing;
|
|
||||||
using Moq;
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Security.Claims;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNet.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Identity.Test
|
namespace Microsoft.AspNet.Identity.Test
|
||||||
{
|
{
|
||||||
public class UserManagerTest
|
public class UserManagerTest
|
||||||
{
|
{
|
||||||
|
private class TestManager : UserManager<TestUser, string>
|
||||||
|
{
|
||||||
|
public IUserStore<TestUser, string> StorePublic { get { return base.Store; } }
|
||||||
|
|
||||||
|
public TestManager(IServiceProvider provider) : base(provider) { }
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ServiceProviderWireupTest()
|
public void ServiceProviderWireupTest()
|
||||||
{
|
{
|
||||||
var manager = new UserManager<TestUser, string>(TestServices.DefaultServiceProvider<TestUser, string>());
|
var manager = new TestManager(TestServices.DefaultServiceProvider<TestUser, string>());
|
||||||
Assert.NotNull(manager.PasswordHasher);
|
Assert.NotNull(manager.PasswordHasher);
|
||||||
Assert.NotNull(manager.PasswordValidator);
|
Assert.NotNull(manager.PasswordValidator);
|
||||||
Assert.NotNull(manager.UserValidator);
|
Assert.NotNull(manager.UserValidator);
|
||||||
|
Assert.NotNull(manager.StorePublic);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Mock fails in K (this works fine in net45)
|
//TODO: Mock fails in K (this works fine in net45)
|
||||||
//[Fact]
|
//[Fact]
|
||||||
//public async Task CreateTest()
|
//public async Task CreateTest()
|
||||||
//{
|
//{
|
||||||
|
|
@ -113,8 +119,12 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
Assert.False(manager.SupportsUserSecurityStamp);
|
Assert.False(manager.SupportsUserSecurityStamp);
|
||||||
await Assert.ThrowsAsync<NotSupportedException>(() => manager.UpdateSecurityStamp("bogus"));
|
await Assert.ThrowsAsync<NotSupportedException>(() => manager.UpdateSecurityStamp("bogus"));
|
||||||
await Assert.ThrowsAsync<NotSupportedException>(() => manager.GetSecurityStamp("bogus"));
|
await Assert.ThrowsAsync<NotSupportedException>(() => manager.GetSecurityStamp("bogus"));
|
||||||
await Assert.ThrowsAsync<NotSupportedException>(() => manager.VerifyChangePhoneNumberToken("bogus", "1", "111-111-1111"));
|
await
|
||||||
await Assert.ThrowsAsync<NotSupportedException>(() => manager.GenerateChangePhoneNumberToken("bogus", "111-111-1111"));
|
Assert.ThrowsAsync<NotSupportedException>(
|
||||||
|
() => manager.VerifyChangePhoneNumberToken("bogus", "1", "111-111-1111"));
|
||||||
|
await
|
||||||
|
Assert.ThrowsAsync<NotSupportedException>(
|
||||||
|
() => manager.GenerateChangePhoneNumberToken("bogus", "111-111-1111"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -144,7 +154,8 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
||||||
Assert.False(manager.SupportsUserTwoFactor);
|
Assert.False(manager.SupportsUserTwoFactor);
|
||||||
await Assert.ThrowsAsync<NotSupportedException>(async () => await manager.GetTwoFactorEnabled("bogus"));
|
await Assert.ThrowsAsync<NotSupportedException>(async () => await manager.GetTwoFactorEnabled("bogus"));
|
||||||
await Assert.ThrowsAsync<NotSupportedException>(async () => await manager.SetTwoFactorEnabled("bogus", true));
|
await
|
||||||
|
Assert.ThrowsAsync<NotSupportedException>(async () => await manager.SetTwoFactorEnabled("bogus", true));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -179,16 +190,6 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
manager.Dispose();
|
manager.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class BadPasswordValidtor : IPasswordValidator
|
|
||||||
{
|
|
||||||
public const string ErrorMessage = "I'm Bad.";
|
|
||||||
|
|
||||||
public Task<IdentityResult> Validate(string password)
|
|
||||||
{
|
|
||||||
return Task.FromResult(IdentityResult.Failed(ErrorMessage));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task PasswordValidatorBlocksCreate()
|
public async Task PasswordValidatorBlocksCreate()
|
||||||
{
|
{
|
||||||
|
|
@ -204,23 +205,32 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ManagerPublicNullChecks()
|
public async Task ManagerPublicNullChecks()
|
||||||
{
|
{
|
||||||
Assert.Throws<ArgumentNullException>("store", () => new UserManager<TestUser, string>((IUserStore<TestUser, string>)null));
|
Assert.Throws<ArgumentNullException>("store",
|
||||||
|
() => new UserManager<TestUser, string>((IUserStore<TestUser, string>) null));
|
||||||
|
Assert.Throws<ArgumentNullException>("serviceProvider",
|
||||||
|
() => new UserManager<TestUser, string>((IServiceProvider)null));
|
||||||
var manager = new UserManager<TestUser, string>(new NotImplementedStore());
|
var manager = new UserManager<TestUser, string>(new NotImplementedStore());
|
||||||
Assert.Throws<ArgumentNullException>(() => manager.ClaimsIdentityFactory = null);
|
Assert.Throws<ArgumentNullException>(() => manager.ClaimsIdentityFactory = null);
|
||||||
Assert.Throws<ArgumentNullException>(() => manager.PasswordHasher = null);
|
Assert.Throws<ArgumentNullException>(() => manager.PasswordHasher = null);
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await manager.CreateIdentity(null, "whatever"));
|
await
|
||||||
|
Assert.ThrowsAsync<ArgumentNullException>("user",
|
||||||
|
async () => await manager.CreateIdentity(null, "whatever"));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await manager.Create(null));
|
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await manager.Create(null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await manager.Create(null, null));
|
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await manager.Create(null, null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("password", async () => await manager.Create(new TestUser(), null));
|
await
|
||||||
|
Assert.ThrowsAsync<ArgumentNullException>("password",
|
||||||
|
async () => await manager.Create(new TestUser(), null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await manager.Update(null));
|
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await manager.Update(null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await manager.Delete(null));
|
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await manager.Delete(null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("claim", async () => await manager.AddClaim("bogus", null));
|
await Assert.ThrowsAsync<ArgumentNullException>("claim", async () => await manager.AddClaim("bogus", null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("userName", async () => await manager.FindByName(null));
|
await Assert.ThrowsAsync<ArgumentNullException>("userName", async () => await manager.FindByName(null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("userName", async () => await manager.Find(null, null));
|
await Assert.ThrowsAsync<ArgumentNullException>("userName", async () => await manager.Find(null, null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("login", async () => await manager.AddLogin("bogus", null));
|
await Assert.ThrowsAsync<ArgumentNullException>("login", async () => await manager.AddLogin("bogus", null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("login", async () => await manager.RemoveLogin("bogus", null));
|
await
|
||||||
|
Assert.ThrowsAsync<ArgumentNullException>("login", async () => await manager.RemoveLogin("bogus", null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("email", async () => await manager.FindByEmail(null));
|
await Assert.ThrowsAsync<ArgumentNullException>("email", async () => await manager.FindByEmail(null));
|
||||||
Assert.Throws<ArgumentNullException>("twoFactorProvider", () => manager.RegisterTwoFactorProvider(null, null));
|
Assert.Throws<ArgumentNullException>("twoFactorProvider",
|
||||||
|
() => manager.RegisterTwoFactorProvider(null, null));
|
||||||
Assert.Throws<ArgumentNullException>("provider", () => manager.RegisterTwoFactorProvider("bogus", null));
|
Assert.Throws<ArgumentNullException>("provider", () => manager.RegisterTwoFactorProvider("bogus", null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -358,27 +368,13 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(() => manager.ConfirmEmail(null, null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(() => manager.ConfirmEmail(null, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
private class NoOpTokenProvider : IUserTokenProvider<TestUser, string>
|
private class BadPasswordValidtor : IPasswordValidator
|
||||||
{
|
{
|
||||||
|
public const string ErrorMessage = "I'm Bad.";
|
||||||
|
|
||||||
public Task<string> Generate(string purpose, UserManager<TestUser, string> manager, TestUser user)
|
public Task<IdentityResult> Validate(string password)
|
||||||
{
|
{
|
||||||
return Task.FromResult("Test");
|
return Task.FromResult(IdentityResult.Failed(ErrorMessage));
|
||||||
}
|
|
||||||
|
|
||||||
public Task<bool> Validate(string purpose, string token, UserManager<TestUser, string> manager, TestUser user)
|
|
||||||
{
|
|
||||||
return Task.FromResult(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task Notify(string token, UserManager<TestUser, string> manager, TestUser user)
|
|
||||||
{
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<bool> IsValidProviderForUser(UserManager<TestUser, string> manager, TestUser user)
|
|
||||||
{
|
|
||||||
return Task.FromResult(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -393,6 +389,101 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
IUserRoleStore<TestUser, string>,
|
IUserRoleStore<TestUser, string>,
|
||||||
IUserSecurityStampStore<TestUser, string>
|
IUserSecurityStampStore<TestUser, string>
|
||||||
{
|
{
|
||||||
|
public Task<IList<Claim>> GetClaims(TestUser user)
|
||||||
|
{
|
||||||
|
return Task.FromResult<IList<Claim>>(new List<Claim>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task AddClaim(TestUser user, Claim claim)
|
||||||
|
{
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task RemoveClaim(TestUser user, Claim claim)
|
||||||
|
{
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task SetEmail(TestUser user, string email)
|
||||||
|
{
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<string> GetEmail(TestUser user)
|
||||||
|
{
|
||||||
|
return Task.FromResult("");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<bool> GetEmailConfirmed(TestUser user)
|
||||||
|
{
|
||||||
|
return Task.FromResult(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task SetEmailConfirmed(TestUser user, bool confirmed)
|
||||||
|
{
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<TestUser> FindByEmail(string email)
|
||||||
|
{
|
||||||
|
return Task.FromResult<TestUser>(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<DateTimeOffset> GetLockoutEndDate(TestUser user)
|
||||||
|
{
|
||||||
|
return Task.FromResult(DateTimeOffset.MinValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task SetLockoutEndDate(TestUser user, DateTimeOffset lockoutEnd)
|
||||||
|
{
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<int> IncrementAccessFailedCount(TestUser user)
|
||||||
|
{
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task ResetAccessFailedCount(TestUser user)
|
||||||
|
{
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<int> GetAccessFailedCount(TestUser user)
|
||||||
|
{
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<bool> GetLockoutEnabled(TestUser user)
|
||||||
|
{
|
||||||
|
return Task.FromResult(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task SetLockoutEnabled(TestUser user, bool enabled)
|
||||||
|
{
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task AddLogin(TestUser user, UserLoginInfo login)
|
||||||
|
{
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task RemoveLogin(TestUser user, UserLoginInfo login)
|
||||||
|
{
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<IList<UserLoginInfo>> GetLogins(TestUser user)
|
||||||
|
{
|
||||||
|
return Task.FromResult<IList<UserLoginInfo>>(new List<UserLoginInfo>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<TestUser> Find(UserLoginInfo login)
|
||||||
|
{
|
||||||
|
return Task.FromResult<TestUser>(null);
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -437,66 +528,6 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
return Task.FromResult(false);
|
return Task.FromResult(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<IList<Claim>> GetClaims(TestUser user)
|
|
||||||
{
|
|
||||||
return Task.FromResult<IList<Claim>>(new List<Claim>());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task AddClaim(TestUser user, Claim claim)
|
|
||||||
{
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task RemoveClaim(TestUser user, Claim claim)
|
|
||||||
{
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task AddLogin(TestUser user, UserLoginInfo login)
|
|
||||||
{
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task RemoveLogin(TestUser user, UserLoginInfo login)
|
|
||||||
{
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<IList<UserLoginInfo>> GetLogins(TestUser user)
|
|
||||||
{
|
|
||||||
return Task.FromResult<IList<UserLoginInfo>>(new List<UserLoginInfo>());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<TestUser> Find(UserLoginInfo login)
|
|
||||||
{
|
|
||||||
return Task.FromResult<TestUser>(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task SetEmail(TestUser user, string email)
|
|
||||||
{
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<string> GetEmail(TestUser user)
|
|
||||||
{
|
|
||||||
return Task.FromResult("");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<bool> GetEmailConfirmed(TestUser user)
|
|
||||||
{
|
|
||||||
return Task.FromResult(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task SetEmailConfirmed(TestUser user, bool confirmed)
|
|
||||||
{
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<TestUser> FindByEmail(string email)
|
|
||||||
{
|
|
||||||
return Task.FromResult<TestUser>(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task SetPhoneNumber(TestUser user, string phoneNumber)
|
public Task SetPhoneNumber(TestUser user, string phoneNumber)
|
||||||
{
|
{
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
|
|
@ -517,51 +548,6 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<DateTimeOffset> GetLockoutEndDate(TestUser user)
|
|
||||||
{
|
|
||||||
return Task.FromResult(DateTimeOffset.MinValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task SetLockoutEndDate(TestUser user, DateTimeOffset lockoutEnd)
|
|
||||||
{
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<int> IncrementAccessFailedCount(TestUser user)
|
|
||||||
{
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task ResetAccessFailedCount(TestUser user)
|
|
||||||
{
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<int> GetAccessFailedCount(TestUser user)
|
|
||||||
{
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<bool> GetLockoutEnabled(TestUser user)
|
|
||||||
{
|
|
||||||
return Task.FromResult(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task SetLockoutEnabled(TestUser user, bool enabled)
|
|
||||||
{
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task SetTwoFactorEnabled(TestUser user, bool enabled)
|
|
||||||
{
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<bool> GetTwoFactorEnabled(TestUser user)
|
|
||||||
{
|
|
||||||
return Task.FromResult(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task AddToRole(TestUser user, string roleName)
|
public Task AddToRole(TestUser user, string roleName)
|
||||||
{
|
{
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
|
|
@ -591,10 +577,44 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
{
|
{
|
||||||
return Task.FromResult("");
|
return Task.FromResult("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task SetTwoFactorEnabled(TestUser user, bool enabled)
|
||||||
|
{
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<bool> GetTwoFactorEnabled(TestUser user)
|
||||||
|
{
|
||||||
|
return Task.FromResult(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class NotImplementedStore :
|
private class NoOpTokenProvider : IUserTokenProvider<TestUser, string>
|
||||||
IUserPasswordStore<TestUser, string>,
|
{
|
||||||
|
public Task<string> Generate(string purpose, UserManager<TestUser, string> manager, TestUser user)
|
||||||
|
{
|
||||||
|
return Task.FromResult("Test");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<bool> Validate(string purpose, string token, UserManager<TestUser, string> manager,
|
||||||
|
TestUser user)
|
||||||
|
{
|
||||||
|
return Task.FromResult(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Notify(string token, UserManager<TestUser, string> manager, TestUser user)
|
||||||
|
{
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<bool> IsValidProviderForUser(UserManager<TestUser, string> manager, TestUser user)
|
||||||
|
{
|
||||||
|
return Task.FromResult(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class NotImplementedStore :
|
||||||
|
IUserPasswordStore<TestUser, string>,
|
||||||
IUserClaimStore<TestUser, string>,
|
IUserClaimStore<TestUser, string>,
|
||||||
IUserLoginStore<TestUser, string>,
|
IUserLoginStore<TestUser, string>,
|
||||||
IUserEmailStore<TestUser, string>,
|
IUserEmailStore<TestUser, string>,
|
||||||
|
|
@ -602,6 +622,101 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
IUserLockoutStore<TestUser, string>,
|
IUserLockoutStore<TestUser, string>,
|
||||||
IUserTwoFactorStore<TestUser, string>
|
IUserTwoFactorStore<TestUser, string>
|
||||||
{
|
{
|
||||||
|
public Task<IList<Claim>> GetClaims(TestUser user)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task AddClaim(TestUser user, Claim claim)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task RemoveClaim(TestUser user, Claim claim)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task SetEmail(TestUser user, string email)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<string> GetEmail(TestUser user)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<bool> GetEmailConfirmed(TestUser user)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task SetEmailConfirmed(TestUser user, bool confirmed)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<TestUser> FindByEmail(string email)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<DateTimeOffset> GetLockoutEndDate(TestUser user)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task SetLockoutEndDate(TestUser user, DateTimeOffset lockoutEnd)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<int> IncrementAccessFailedCount(TestUser user)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task ResetAccessFailedCount(TestUser user)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<int> GetAccessFailedCount(TestUser user)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<bool> GetLockoutEnabled(TestUser user)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task SetLockoutEnabled(TestUser user, bool enabled)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task AddLogin(TestUser user, UserLoginInfo login)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task RemoveLogin(TestUser user, UserLoginInfo login)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<IList<UserLoginInfo>> GetLogins(TestUser user)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<TestUser> Find(UserLoginInfo login)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
|
@ -647,66 +762,6 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<IList<Claim>> GetClaims(TestUser user)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task AddClaim(TestUser user, Claim claim)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task RemoveClaim(TestUser user, Claim claim)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task AddLogin(TestUser user, UserLoginInfo login)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task RemoveLogin(TestUser user, UserLoginInfo login)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<IList<UserLoginInfo>> GetLogins(TestUser user)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<TestUser> Find(UserLoginInfo login)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task SetEmail(TestUser user, string email)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<string> GetEmail(TestUser user)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<bool> GetEmailConfirmed(TestUser user)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task SetEmailConfirmed(TestUser user, bool confirmed)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<TestUser> FindByEmail(string email)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task SetPhoneNumber(TestUser user, string phoneNumber)
|
public Task SetPhoneNumber(TestUser user, string phoneNumber)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
|
@ -727,41 +782,6 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<DateTimeOffset> GetLockoutEndDate(TestUser user)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task SetLockoutEndDate(TestUser user, DateTimeOffset lockoutEnd)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<int> IncrementAccessFailedCount(TestUser user)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task ResetAccessFailedCount(TestUser user)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<int> GetAccessFailedCount(TestUser user)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<bool> GetLockoutEnabled(TestUser user)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task SetLockoutEnabled(TestUser user, bool enabled)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task SetTwoFactorEnabled(TestUser user, bool enabled)
|
public Task SetTwoFactorEnabled(TestUser user, bool enabled)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
// Setup
|
// Setup
|
||||||
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
||||||
var validator = new UserValidator<TestUser, string>();
|
var validator = new UserValidator<TestUser, string>();
|
||||||
var user = new TestUser() { UserName = input };
|
var user = new TestUser {UserName = input};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = await validator.Validate(manager, user);
|
var result = await validator.Validate(manager, user);
|
||||||
|
|
@ -47,7 +47,7 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
// Setup
|
// Setup
|
||||||
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
||||||
var validator = new UserValidator<TestUser, string>();
|
var validator = new UserValidator<TestUser, string>();
|
||||||
var user = new TestUser() {UserName=userName};
|
var user = new TestUser {UserName = userName};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = await validator.Validate(manager, user);
|
var result = await validator.Validate(manager, user);
|
||||||
|
|
@ -57,7 +57,7 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
{
|
{
|
||||||
IdentityResultAssert.IsSuccess(result);
|
IdentityResultAssert.IsSuccess(result);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IdentityResultAssert.IsFailure(result);
|
IdentityResultAssert.IsFailure(result);
|
||||||
}
|
}
|
||||||
|
|
@ -73,8 +73,8 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
{
|
{
|
||||||
// Setup
|
// Setup
|
||||||
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
var manager = new UserManager<TestUser, string>(new NoopUserStore());
|
||||||
var validator = new UserValidator<TestUser, string>() { AllowOnlyAlphanumericUserNames = false };
|
var validator = new UserValidator<TestUser, string> {AllowOnlyAlphanumericUserNames = false};
|
||||||
var user = new TestUser() { UserName = userName };
|
var user = new TestUser {UserName = userName};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = await validator.Validate(manager, user);
|
var result = await validator.Validate(manager, user);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue