示例#1
0
        public async Task <LoginResponse> RefreshToken(string refreshToken)
        {
            var decryptRsa = _taposRsa.Decrypt(refreshToken, "v1");

            if (decryptRsa == null)
            {
                throw new MyAppException("refresh token not found");
            }

            var refreshTokenObject = JsonConvert.DeserializeObject <RefreshTokenResponse>(decryptRsa);
            var refreshTokenKey    = refreshTokenObject.UserId + "_refreshtoken";

            var cacheData = await _cache.GetStringAsync(refreshTokenKey);

            if (cacheData == null)
            {
                throw new MyAppException("refresh token not found");
            }

            if (cacheData != refreshToken)
            {
                throw new MyAppException("refresh token not found");
            }

            var user = await _userManager.FindByIdAsync(refreshTokenObject.UserId.ToString());

            return(await GenerateJSONWebToken(user));
        }
示例#2
0
        public async Task <LogInResponse> RefreshToken(RefreshTokenRequest refreshToken)
        {
            var decryptRSA = _taposRSA.Decrypt(refreshToken.Token, "v1");

            if (decryptRSA == null)
            {
                throw new ExceptionManagementHelper("Refresh Token Not Found");
            }

            var refreshTokenObj = JsonConvert.DeserializeObject <RefreshTokenResponse>(decryptRSA);

            var refreshTokenKey = refreshTokenObj.UserId.ToString() + "_refreshToken";

            var cacheData = await _distributedCache.GetStringAsync(refreshTokenKey);

            if (cacheData == null)
            {
                throw new ExceptionManagementHelper("Refresh Token Not Found");
            }

            if (cacheData != refreshToken.Token)
            {
                throw new ExceptionManagementHelper("Refresh Token Not Found");
            }

            var user = await _userManager.FindByIdAsync(refreshTokenObj.UserId.ToString());

            return(await GenerateJSONWebTokenAsync(user));
        }