public async Task <ActionResult <TokenResultDTO> > RenewToken() { // Get the currently logged in user. var user = await GetCurrentUserAsync(); // Check whether a valid user was resolved. if (user != null) { // Get the token for given user. var userToken = GetToken(user); // Generate the token response for given user. return(Ok(TokenResultDTO.FromToken(userToken))); } return(Unauthorized()); }
public async Task <ActionResult <TokenResultDTO> > RequestToken([FromBody] RequestTokenDTO model) { // Find a user that matches the given username. var user = await userManager.FindByNameAsync(model.UserName); // Check whether a valid user was resolved. if (user != null) { // Validate whether the provided password matches our user model. var result = await signInManager.CheckPasswordSignInAsync(user, model.Password, false); // Check whether the username/password combination matched. if (result.Succeeded) { // Get the token for given user. var userToken = GetToken(user); // Generate the token response for given user. return(Ok(TokenResultDTO.FromToken(userToken))); } } return(BadRequest()); }