public ActionResult Login([FromBody] LoginInputModel inputModel) { try { User foundUser = UserService.Login(inputModel); if (foundUser == null) { return(Unauthorized()); } var tokenString = AuthenticationHelper.GenerateJWTToken(foundUser); return(Ok(new { ID = foundUser.ID, Username = foundUser.Username, Role = foundUser.UserRole, Token = tokenString })); } catch (UnauthorizedAccessException ex) { return(Unauthorized(ex.Message)); } }
public string GenerateJWTToken(User foundUser) { if (foundUser == null) { throw new ArgumentException("User can't be null"); } if (foundUser.Password == null || foundUser.Salt == null) { throw new ArgumentException("User is missing a password or salt"); } return(AuthenticationHelper.GenerateJWTToken(foundUser)); }