public static CustomUserManager Create(IdentityFactoryOptions <CustomUserManager> options, IOwinContext context) { var manager = new CustomUserManager(new UserStoreInt(context.Get <AppUserIdentityDbContext>())); return(manager); }
public async Task <ClaimsIdentity> GenerateUserIdentityAsync(CustomUserManager manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here return(userIdentity); }
private async Task <SignInStatus> SignInOrTwoFactor(CustUserIdentity user, bool isPersistent) { if (await CustomUserManager.GetTwoFactorEnabledAsync(user.Id) && !await AuthenticationManager.TwoFactorBrowserRememberedAsync(user.Id.ToString())) { var identity = new ClaimsIdentity(DefaultAuthenticationTypes.TwoFactorCookie); identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id.ToString())); identity.AddClaim(new Claim(ClaimTypes.Name, user.UserName)); AuthenticationManager.SignIn(identity); return(SignInStatus.RequiresTwoFactorAuthentication); } await SignInAsync(user, isPersistent, false); return(SignInStatus.Success); }
public async Task <SignInStatus> PasswordSignIn(string userName, string password, bool isPersistent) { var user = await CustomUserManager.FindByNameAsync(userName); if (user == null) { return(SignInStatus.Failure); } if (await CustomUserManager.CheckPasswordAsync(user, password)) { return(await SignInOrTwoFactor(user, isPersistent)); } if (await CustomUserManager.IsLockedOutAsync(user.Id)) { return(SignInStatus.LockedOut); } return(SignInStatus.Failure); }
public SignIn(CustomUserManager customManager, IAuthenticationManager authManager) { CustomUserManager = customManager; AuthenticationManager = authManager; }