public async Task <IActionResult> RevokeToken([FromBody] RequestTokenDTO requestToken) { var token = requestToken.RequestToken ?? Request.Cookies["refreshToken"]; if (string.IsNullOrEmpty(token)) { return(BadRequest(new { message = "Token is required" })); } var response = await _repo.RevokeToken(token, ipAddress()); if (!response) { return(NotFound(new { message = "Token not found" })); } return(Ok(new { message = "Token revoked" })); }
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()); }