public async Task <ObjectResult> RefreshAsync() { bool hasToken = HttpContext.Request.Headers.TryGetValue("Authorization", out StringValues tokenHeader); if (!hasToken) { throw new BadRequestException("Provide the expired token in the Athorization header!"); } string token = tokenHeader.ToString().Substring("Bearer ".Length); string refreshToken = HttpContext.Request.Cookies["refreshToken"]; var request = new TokenRefreshRequestDTO { AuthToken = token, RefreshToken = refreshToken }; TokenRefreshResponseDTO response = await authService.RefreshTokenAsync(request); HttpContext.Response.Cookies.Append("refreshToken", response.RefreshToken, new CookieOptions { HttpOnly = true, Secure = true }); return(Ok(new TokenRefreshResponse { AccessToken = "Bearer " + response.Token })); }
public async Task <ActionResult> RefreshTokenAsync([FromBody] TokenRefreshRequest request) { var requestDTO = new TokenRefreshRequestDTO { RefreshToken = request.RefreshToken, UserName = User.Identity.Name }; TokenRefreshResponseDTO response = await authService.RefreshTokenAsync(requestDTO); return(Ok(response)); }
public IHttpActionResult Refresh([FromBody] TokenRefreshResponseDTO token) { TokenRefreshService service = new TokenRefreshService(token); var response = service.RefreshService(); if (response.isSuccessful == false) { return(Content(HttpStatusCode.BadRequest, response)); } return(Ok(response)); }
public TokenRefreshService(TokenRefreshResponseDTO response) { username = response.username; token = response.token; this.response = response; }