internal TokenManager([NotNull] ITokenClientFactory tokenClientFactory, [NotNull] ILogger logger, [NotNull] TokenManagerOptions tokenManagerOptions, [NotNull] IDateTimeProvider dateTimeProvider) { _tokenClientFactory = tokenClientFactory ?? throw new ArgumentNullException(nameof(tokenClientFactory)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _tokenManagerOptions = tokenManagerOptions ?? throw new ArgumentNullException(nameof(tokenManagerOptions)); _dateTimeProvider = dateTimeProvider ?? throw new ArgumentNullException(nameof(dateTimeProvider)); _semaphore = new SemaphoreSlim(1); }
public static IServiceCollection AddAccessTokenManager(this IServiceCollection services, IConfiguration config) { TokenManagerOptions options = new TokenManagerOptions(); config.Bind("TokenManagerOptions", options); services.TryAddSingleton(options); services.TryAddSingleton <IAccessTokenManager, AccessTokenManager>(); services.TryAddTransient <TokenManagerAuthenticationHandler>(); return(services); }
private void AddTokenManager(ServiceCollection services) { var apiClient = new TestAccessTokenApiClient(); _options = new TokenManagerOptions { ClientId = "TEST", ClientSecret = "TEST" }; _tokenManager = new AccessTokenManager(_options, apiClient); services.AddSingleton <IAccessTokenManager>(_tokenManager); services.TryAddTransient <TokenManagerAuthenticationHandler>(); }
public static IServiceCollection AddAccessTokenManager(this IServiceCollection services, IConfiguration config) { TokenManagerOptions options = new TokenManagerOptions(); config.Bind("TokenManagerOptions", options); services.TryAddSingleton(options); var apiClient = new AccessTokenApiClient(config.GetValue <string>("TokenManagerOptions:TokenEndpoint")); services.TryAddSingleton <IAccessTokenApiClient>(apiClient); services.TryAddSingleton <IAccessTokenManager, AccessTokenManager>(); services.TryAddTransient <TokenManagerAuthenticationHandler>(); return(services); }
/// <inheritdoc /> public ITokenManager Create([NotNull] TokenManagerOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } if (options.Client == null) { throw new ArgumentNullException(nameof(options.Client)); } if (string.IsNullOrWhiteSpace(options.Client.AuthorityUrl)) { throw new ArgumentException($"'{nameof(options.Client.AuthorityUrl)}' must not be null, empty or whitespace.", nameof(options.Client.AuthorityUrl)); } if (string.IsNullOrWhiteSpace(options.Client.ClientId)) { throw new ArgumentException($"'{nameof(options.Client.ClientId)}' must not be null, empty or whitespace.", nameof(options.Client.ClientId)); } return(new TokenManager(_tokenClientFactory, _loggerFactory.CreateLogger <TokenManager>(), options, _dateTimeProvider)); }
public static IServiceCollection AddAccessTokenManager(this IServiceCollection services, TokenManagerOptions options) { services.TryAddSingleton(options); services.TryAddSingleton <IAccessTokenManager, AccessTokenManager>(); services.TryAddTransient <TokenManagerAuthenticationHandler>(); return(services); }