예제 #1
0
        public IActionResult RefreshToken([FromBody] JToken jsonBody)
        {
            var response = new LoginResponse {
                Result = ResultType.Error
            };

            var refreshTokenValue = jsonBody.Value <string>("refreshToken");

            if (string.IsNullOrWhiteSpace(refreshTokenValue))
            {
                response.Messages.Add(_localizationService.GetResource("account.token.refreshtoken.nullrefreshtoken"));
                return(BadRequest(response));
            }

            var token = _tokenStoreService.FindToken(refreshTokenValue);

            if (token == null)
            {
                response.Messages.Add(_localizationService.GetResource("account.token.refreshtoken.nulltoken"));
                return(Unauthorized(response));
            }


            var jwtToken = _tokenFactoryService.CreateJwtTokens(token.Customer);

            _tokenStoreService.AddCustomerToken(token.Customer, jwtToken.RefreshTokenSerial, jwtToken.AccessToken, _tokenFactoryService.GetRefreshTokenSerial(refreshTokenValue));

            response.Result       = ResultType.Success;
            response.AccessToken  = jwtToken.AccessToken;
            response.RefreshToken = jwtToken.RefreshToken;

            return(Ok(response));
        }
예제 #2
0
        public IActionResult RefreshToken([FromQuery] string refreshToken)
        {
            if (string.IsNullOrWhiteSpace(refreshToken))
            {
                return(BadRequest("refreshToken is not set."));
            }

            UserToken token = tokenStoreService.FindToken(refreshToken);

            if (token == null)
            {
                return(Unauthorized());
            }

            (string accessToken, string newRefreshToken, IEnumerable <Claim> claims) = tokenStoreService.CreateJwtTokens(token.User.Username, refreshToken);

            return(Ok(new AccessTokenDTO {
                access_token = accessToken, refresh_token = newRefreshToken
            }));
        }
예제 #3
0
        public IActionResult RefreshToken([FromBody] Token model)
        {
            var refreshTokenValue = model.RefreshToken;

            if (string.IsNullOrWhiteSpace(refreshTokenValue))
            {
                return(BadRequest("refreshToken is not set."));
            }

            var token = _tokenStoreService.FindToken(refreshTokenValue);

            if (token == null)
            {
                return(Unauthorized());
            }
            var user   = _userService.GetUserById(token.UserId);
            var result = _tokenFactoryService.CreateJwtTokensAsync(user);

            _tokenStoreService.AddUserToken(user, result.RefreshTokenSerial, result.AccessToken, _tokenFactoryService.GetRefreshTokenSerial(refreshTokenValue));

            return(Ok(new { access_token = result.AccessToken, refresh_token = result.RefreshToken }));
        }