예제 #1
0
        public void createRefreshToken(TokenRefreshDAL tokenRefreshDAL)
        {
            TokenRefreshDAL oldTokenRefreshDAL = _dbContext.TokenRefresh.FirstOrDefault(x => x.UserId == tokenRefreshDAL.UserId);

            if (oldTokenRefreshDAL == null)
            {
                _dbContext.Add(tokenRefreshDAL);
            }
            else
            {
                oldTokenRefreshDAL.Token       = tokenRefreshDAL.Token;
                oldTokenRefreshDAL.IssuedTime  = tokenRefreshDAL.IssuedTime;
                oldTokenRefreshDAL.ExpiresTime = tokenRefreshDAL.ExpiresTime;
            }
        }
        public string updateTokens(string oldRefreshToken, int userId)
        {
            var checkTokenDAL = new TokenRefreshDAL
            {
                UserId = userId,
                Token  = oldRefreshToken
            };

            if (_unitOfWork.TokenRefreshRepository.checkRefreshToken(checkTokenDAL) == true)
            {
                string token = createRefreshToken(userId, 5);
                return(token);
            }
            else
            {
                return(null);
            }
        }
예제 #3
0
        public bool checkRefreshToken(TokenRefreshDAL tokenRefreshDAL)
        {
            TokenRefreshDAL tokenRefresh = _dbContext.TokenRefresh.FirstOrDefault(x => x.UserId == tokenRefreshDAL.UserId);

            if (tokenRefresh != null)
            {
                if (tokenRefreshDAL.Token != null && tokenRefresh.Token == tokenRefreshDAL.Token)
                {
                    return(true);
                }
                else
                {
                    tokenRefresh.Token = null;
                    _dbContext.SaveChanges();
                    return(false);
                }
            }
            return(false);
        }
        public string createRefreshToken(int userId, int lifetime)
        {
            TokenRefreshDAL tokenRefreshDAL = new TokenRefreshDAL
            {
                UserId      = userId,
                Token       = Guid.NewGuid().ToString(),
                IssuedTime  = DateTime.Now,
                ExpiresTime = DateTime.Now.AddMinutes(lifetime)
            };

            try
            {
                _unitOfWork.TokenRefreshRepository.createRefreshToken(tokenRefreshDAL);
                _unitOfWork.Save();
                return(tokenRefreshDAL.Token);
            }
            catch
            {
                throw;
            }
        }