public IActionResult Authenticate(AuthenticateRequest model) { try { var response = _authLogic.Authenticate(model); if (response == null) { return(BadRequest(new { message = "Username or password is incorrect" })); } return(Ok(response)); } catch (Exception e) { return(BadRequest(new { message = e.ToString() })); } }
public IActionResult CreateToken([FromBody] PostLoginInputViewModel login) { IActionResult response = Unauthorized(); var user = _authLogic.Authenticate(login); if (user != null) { var tokenString = BuildToken(user: user); RefreshToken newRefreshToken = _refreshTokenLogic.CreateNewToken(user.Id, newToken: GenerateRefreshToken()); response = new ObjectResult(new { token = tokenString, refreshToken = newRefreshToken.Token }); } return(response); }