public async Task <TokenOutputDto> RefreshToken(TokenInputDto model) { var user = await _userManager.FindByEmailAsync(model.Email); var checkRefreshToken = await _userManager.VerifyUserTokenAsync(user, "BBC", "RefreshToken", model.RefreshToken); if (checkRefreshToken) { //set new refresh token model.RefreshToken = await _userManager.GenerateUserTokenAsync(user, "BBC", "RefreshToken"); await _userManager.SetAuthenticationTokenAsync(user, "BBC", "RefreshToken", model.RefreshToken); var tokenModel = new TokenOutputDto() { UserId = user.Id, UserName = user.UserName, HasVerifiedEmail = true, RefreshToken = model.RefreshToken }; JwtSecurityToken jwtSecurityToken = await CreateJwtToken(user); tokenModel.Token = new JwtSecurityTokenHandler().WriteToken(jwtSecurityToken); return(tokenModel); } return(new TokenOutputDto() { Errors = new string[] { "Not Found User", } }); }
public async Task <IActionResult> UpdateToken([FromBody] TokenInputDto model) { var result = await _manageService.RefreshToken(model); if (result.Errors != null) { return(BadRequest(result.Errors)); } return(Ok(result)); }