public TokenValidationService(ITokenRepository tokenRepository, ITokenGenerator tokenGenerator, IOptions <TokenServiceConfiguration> configuration) { _tokenRepository = tokenRepository; _tokenGenerator = tokenGenerator; _configuration = configuration.Value; _tokenHandler = new JwtSecurityTokenHandler(); }
public JwtTokenService(IGenericRepository <ActiveRefreshToken> activeRefreshTokensGR, IGenericRepository <User> usersGR, IUserConnectionService userConnectionService, TokenServiceConfiguration configuration) { _activeRefreshTokensGR = activeRefreshTokensGR; _usersGR = usersGR; _userConnectionService = userConnectionService; _configuration = configuration; }
public TokenManagementService(IOptions <TokenServiceConfiguration> configuration, ITokenRepository tokenRepository, ITokenNotifier notifier, IPasswordProvider passwordProvider, ITokenDescriptorModelValidator tokenDescriptorModelValidator, ILogger <TokenManagementService> logger) { _configuration = configuration.Value; _tokenRepository = tokenRepository; _notifier = notifier; _passwordProvider = passwordProvider; _tokenDescriptorModelValidator = tokenDescriptorModelValidator; _logger = logger; }
public void Initialize() { _privateKey = _passwordProvider.GetNextBytePassword(PasswordLength); _issuer = _fixture.Create <string>(); _audience = _fixture.Create <string>(); _tokenDescriptor = new TokenDescriptor { Issuer = _issuer, Audience = _audience, Ttl = TtlSeconds, ExpirationDate = DateTime.UtcNow.AddSeconds(30), PrivateKey = Convert.ToBase64String(_privateKey), IsActive = true }; _tokenRepository = new Mock <ITokenRepository>(); _tokenRepository.Setup(x => x.GetAsync(_issuer, _audience, CancellationToken.None)) .ReturnsAsync(_tokenDescriptor); _token = _tokenGenerator.CreateToken(_issuer, _audience, _privateKey, _ttl); var stringToken = _handler.WriteToken(_token); _tokenModel = new TokenModel(stringToken); var configurationOptions = new TokenServiceConfiguration { ClockSkew = TimeSpan.Zero, }; _tokenServiceConfiguration = new Mock <IOptions <TokenServiceConfiguration> >(); _tokenServiceConfiguration.Setup(x => x.Value).Returns(configurationOptions); _tokenService = new TokenValidationService(_tokenRepository.Object, _tokenGenerator, _tokenServiceConfiguration.Object); }
public TokenRemoveHosting(IServiceProvider serviceProvider, TokenServiceConfiguration tokenServiceConfiguration) { _serviceProvider = serviceProvider; _tokenServiceConfiguration = tokenServiceConfiguration; }
public static void UseJwtTokenService(this IServiceCollection services, TokenServiceConfiguration configuration) { services.AddSingleton(configuration); services.AddScoped <ITokenService, JwtTokenService>(); services.AddHostedService <TokenRemoveHosting>(); }