Esempio n. 1
0
        public JwtSigningKeyResolver(IMemoryCache cache, IOptions <DelegationOptions> options, HttpMessageHandler handler, ILogger <JwtSigningKeyResolver> logger)
        {
            if (cache == null)
            {
                throw new ArgumentNullException(nameof(cache), $"{nameof(cache)} cannot be null");
            }
            if (options == null || options.Value == null)
            {
                throw new ArgumentNullException(nameof(options), $"{nameof(options)} cannot be null");
            }
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler), $"{nameof(handler)} cannot be null");
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger), $"{nameof(logger)} cannot be null");
            }

            _cache   = cache;
            _options = options.Value;
            _client  = new HttpClient(handler, true);
            _logger  = logger;

            if (_options.JwtSigningKeyCacheDuration > 0)
            {
                _cachingEnabled = true;
                _cacheOptions   = new MemoryCacheEntryOptions {
                    AbsoluteExpirationRelativeToNow = new TimeSpan(0, _options.JwtSigningKeyCacheDuration, 0)
                };
            }
        }
Esempio n. 2
0
        public TokenValidationParametersFactory(IOptions <DelegationOptions> options,
                                                IJwtSigningKeyResolver jwtSigningKeyProvider,
                                                IHostingEnvironment hostingEnvironment)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options), $"{nameof(options)} cannot be null");
            }
            if (jwtSigningKeyProvider == null)
            {
                throw new ArgumentNullException(nameof(jwtSigningKeyProvider), $"{nameof(jwtSigningKeyProvider)} cannot be null");
            }
            if (hostingEnvironment == null)
            {
                throw new ArgumentNullException(nameof(hostingEnvironment), $"{nameof(hostingEnvironment)} cannot be null");
            }

            _options = options.Value;
            _jwtSigningKeyProvider = jwtSigningKeyProvider;
            _hostingEnvironment    = hostingEnvironment;
        }