public async Task <string> AuthorizeAsync(EmailAndPasswordModel emailAndPassword) { var user = await userManager.FindByEmailAsync(emailAndPassword.Email); if (user == null) { throw new UnauthorizedAccessException(); } var result = await signInManager.PasswordSignInAsync(user.UserName, emailAndPassword.Password, false, false); if (result.Succeeded) { return(tokenGeneration.GenerateJwtToken(user)); } logger.LogWarning($"Authentication failed for username {user.UserName}"); throw new UnauthorizedAccessException(); }
public async Task <ActionResult> Login(EmailAndPasswordModel loginDto) { var jwt = await authorizationService.AuthorizeAsync(loginDto); return(Ok(new { token = jwt })); }