public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null) { ViewBag.ReturnUrl = returnUrl; if (ModelState.IsValid) { // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, set shouldLockout: true var user = new MyUser { Id = model.Username, UserName = model.Username }; // This is where we do the LDAP Authentication var result = await SignInManager.PasswordSignInAsync(user, model.Password, false, false); // If user authenticates, we the do the Authorization (set Claims) if (result.Succeeded) { // Query LDAP to get the user user = await UserManager.FindByIdAsync(user.Id); // Set user roles (by mapping LDAP groups to application defined roles) user.Roles = await UserManager.GetRolesAsync(user) as List <string>; var claimsPrincipal = await SignInManager.CreateUserPrincipalAsync(user); if (claimsPrincipal != null && claimsPrincipal.Identity != null) { // Set the claims to the user await HttpContext.Authentication.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrincipal); return(RedirectToAction("Index", "App")); } else { ModelState.AddModelError(string.Empty, "Insufficient privileges. Please contact your Administrator to get access to the application."); } } else { ModelState.AddModelError(string.Empty, "Invalid login attempt."); } } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task<IActionResult> Login(LoginViewModel model, string returnUrl = null) { ViewBag.ReturnUrl = returnUrl; if (ModelState.IsValid) { // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, set shouldLockout: true var user = new MyUser { Id = model.Username, UserName = model.Username }; // This is where we do the LDAP Authentication var result = await SignInManager.PasswordSignInAsync(user, model.Password, false, false); // If user authenticates, we the do the Authorization (set Claims) if (result.Succeeded) { // Query LDAP to get the user user = await UserManager.FindByIdAsync(user.Id); // Set user roles (by mapping LDAP groups to application defined roles) user.Roles = await UserManager.GetRolesAsync(user) as List<string>; var claimsPrincipal = await SignInManager.CreateUserPrincipalAsync(user); if (claimsPrincipal != null && claimsPrincipal.Identity != null) { // Set the claims to the user await Context.Authentication.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrincipal); return RedirectToAction("Index", "App"); } else { ModelState.AddModelError(string.Empty, "Insufficient privileges. Please contact your Administrator to get access to the application."); } } else { ModelState.AddModelError(string.Empty, "Invalid login attempt."); } } // If we got this far, something failed, redisplay form return View(model); }
public Task SetNormalizedUserNameAsync(MyUser user, string normalizedName, CancellationToken cancellationToken) { throw new NotImplementedException(); }
public Task <bool> HasPasswordAsync(MyUser user, CancellationToken cancellationToken) { throw new NotImplementedException(); }
public Task <string> GetUserNameAsync(MyUser user, CancellationToken cancellationToken) { throw new NotImplementedException(); }
public Task <IdentityResult> DeleteAsync(MyUser user, CancellationToken cancellationToken) { throw new NotImplementedException(); }
public Task SetPasswordHashAsync(MyUser user, string passwordHash, CancellationToken cancellationToken) { throw new NotImplementedException(); }