コード例 #1
0
ファイル: TokenManager.cs プロジェクト: fossabot/GiG.Core
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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>();
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        /// <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));
        }
コード例 #6
0
        public static IServiceCollection AddAccessTokenManager(this IServiceCollection services, TokenManagerOptions options)
        {
            services.TryAddSingleton(options);

            services.TryAddSingleton <IAccessTokenManager, AccessTokenManager>();
            services.TryAddTransient <TokenManagerAuthenticationHandler>();

            return(services);
        }