コード例 #1
0
        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
            }));
        }
コード例 #2
0
ファイル: AuthController.cs プロジェクト: EdShel/ESportRaise
        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));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
 public TokenRefreshService(TokenRefreshResponseDTO response)
 {
     username      = response.username;
     token         = response.token;
     this.response = response;
 }