public async Task <IActionResult> Authenticate([FromBody] AutUserForAuthenticationDto autUser) { if (!await _authManager.ValidateUser(autUser)) { _logger.LogWarn($"{nameof(Authenticate)}: Authentication failed. Wrong user name or password."); return(Unauthorized()); } return(Ok(new { Token = await _authManager.CreateToken() })); }
public async Task <bool> ValidateUser(AutUserForAuthenticationDto userForAuth) { _user = await _userManager.FindByNameAsync(userForAuth.UserName); return(_user != null && await _userManager.CheckPasswordAsync(_user, userForAuth.Password)); }