public async Task <AccessRefreshTokensDto> GenerateAccessRefreshTokens(Guid userId, string userName, string email) { var refreshToken = _jwtFactory.GenerateRefreshToken(); var oldRefreshTokens = await _dbContext.RefreshTokens .Where(rt => rt.UserId == userId) .ToListAsync(); _dbContext.RemoveRange(oldRefreshTokens); _dbContext.RefreshTokens.Add(new RefreshTokenModel { Token = refreshToken, ExpiresIn = DateTime.UtcNow.AddSeconds(AuthConstants.RefreshTokenLifetimeInSeconds), UserId = userId, }); await _dbContext.SaveChangesAsync(); var accessToken = await _jwtFactory.GenerateAccessToken(userId, userName, email); return(new AccessRefreshTokensDto { AccessToken = accessToken, RefreshToken = refreshToken }); }
public async Task <AccessTokenDTO> GenerateAccessToken(int userId, string userName, string email) { var refreshToken = _jwtFactory.GenerateRefreshToken(); _context.RefreshTokens.Add(new RefreshToken { Token = refreshToken, UserId = userId }); await _context.SaveChangesAsync(); var accessToken = await _jwtFactory.GenerateAccessToken(userId, userName, email); return(new AccessTokenDTO(accessToken, refreshToken)); }
public void Should_Return_RefreshToken() { // Arrange var options = Options.Create(new JwtIssuerOptions()); var sut = new JwtFactory(options); // Act var token = sut.GenerateRefreshToken(); // Assert token.ShouldNotBeNull(); }