示例#1
0
        private async Task <string> GenerateRefreshToken(Guid userId)
        {
            await _refreshTokenRepository.DeleteExpired(userId);

            var randomNumber = new byte[256];

            using (var rng = RandomNumberGenerator.Create())
            {
                rng.GetBytes(randomNumber);

                var token = Convert.ToBase64String(randomNumber);

                _refreshTokenRepository.Create(new RefreshToken
                {
                    UserId         = userId,
                    Value          = token,
                    ExpirationDate = DateTime.Now.AddDays(14)
                });

                await _refreshTokenRepository.SaveChanges();

                return(token);
            }
        }