public CacheAdminStore(TStore parent,
                        IFlushableCache <TEntity> entityCache,
                        IFlushableCache <PageResponse <TEntity> > responseCache,
                        ILogger <CacheAdminStore <TStore, TEntity> > logger,
                        IdentityServer4.Configuration.IdentityServerOptions options)
 {
     _parent        = parent ?? throw new ArgumentNullException(nameof(parent));
     _entityCache   = entityCache ?? throw new ArgumentNullException(nameof(entityCache));
     _responseCache = responseCache ?? throw new ArgumentNullException(nameof(responseCache));
     _logger        = logger ?? throw new ArgumentNullException(nameof(logger));
     _options       = options ?? throw new ArgumentNullException(nameof(options));
 }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WsFederationService"/> class.
 /// </summary>
 /// <param name="signinValidator">The signin validator.</param>
 /// <param name="options">The options.</param>
 /// <param name="generator">The generator.</param>
 /// <param name="userSession">The user session.</param>
 /// <param name="logger">The logger.</param>
 /// <exception cref="ArgumentNullException">
 /// signinValidator
 /// or
 /// options
 /// or
 /// generator
 /// or
 /// userSession
 /// or
 /// logger
 /// </exception>
 public WsFederationService(ISignInValidator signinValidator,
                            IdentityServer4.Configuration.IdentityServerOptions options,
                            ISignInResponseGenerator generator,
                            IUserSession userSession,
                            ILogger <WsFederationController> logger)
 {
     _signinValidator = signinValidator ?? throw new ArgumentNullException(nameof(signinValidator));
     _options         = options ?? throw new ArgumentNullException(nameof(options));
     _generator       = generator ?? throw new ArgumentNullException(nameof(generator));
     _userSession     = userSession ?? throw new ArgumentNullException(nameof(userSession));
     _logger          = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RegisterClientService" /> class.
        /// </summary>
        /// <param name="clientStore">The client store.</param>
        /// <param name="clientUriStore">The client URI store.</param>
        /// <param name="clientResourceStore">The client resource store.</param>
        /// <param name="clientGrantTypeStore">The client grant type store.</param>
        /// <param name="clientPropertyStore">The client property store.</param>
        /// <param name="discoveryResponseGenerator">The discovery response generator.</param>
        /// <param name="identityServerOptions">The options.</param>
        /// <param name="dymamicClientRegistrationOptions">The dymamic client registration options.</param>
        /// <exception cref="ArgumentNullException">options
        /// or
        /// clientStore
        /// or
        /// clientUriStore
        /// or
        /// clientResourceStore
        /// or
        /// clientPropertyStore
        /// or
        /// clientGrantTypeStore
        /// or
        /// discoveryResponseGenerator</exception>
        public RegisterClientService(IAdminStore <Client> clientStore,
                                     IAdminStore <ClientUri> clientUriStore,
                                     IAdminStore <ClientLocalizedResource> clientResourceStore,
                                     IAdminStore <ClientGrantType> clientGrantTypeStore,
                                     IAdminStore <ClientProperty> clientPropertyStore,
                                     IDiscoveryResponseGenerator discoveryResponseGenerator,
                                     IdentityServer4.Configuration.IdentityServerOptions identityServerOptions,
                                     IOptions <DynamicClientRegistrationOptions> dymamicClientRegistrationOptions)

        {
            _identityServerOptions1           = identityServerOptions ?? throw new ArgumentNullException(nameof(identityServerOptions));
            _dymamicClientRegistrationOptions = dymamicClientRegistrationOptions?.Value ?? throw new ArgumentNullException(nameof(dymamicClientRegistrationOptions));
            _clientStore                = clientStore ?? throw new ArgumentNullException(nameof(clientStore));
            _clientUriStore             = clientUriStore ?? throw new ArgumentNullException(nameof(clientUriStore));
            _clientResourceStore        = clientResourceStore ?? throw new ArgumentNullException(nameof(clientResourceStore));
            _clientPropertyStore        = clientPropertyStore ?? throw new ArgumentNullException(nameof(clientPropertyStore));
            _clientGrantTypeStore       = clientGrantTypeStore ?? throw new ArgumentNullException(nameof(clientGrantTypeStore));
            _discoveryResponseGenerator = discoveryResponseGenerator ?? throw new ArgumentNullException(nameof(discoveryResponseGenerator));
        }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CustomJwtRequestValidator" /> class.
 /// </summary>
 /// <param name="tokenValidationOptions">The token validation options.</param>
 /// <param name="contextAccessor">The context accessor.</param>
 /// <param name="options">The options.</param>
 /// <param name="logger">The logger.</param>
 /// <exception cref="ArgumentNullException">tokenValidationOptions</exception>
 public CustomJwtRequestValidator(IOptions <TokenValidationParameters> tokenValidationOptions, IHttpContextAccessor contextAccessor, IdentityServer4.Configuration.IdentityServerOptions options, ILogger <JwtRequestValidator> logger) : base(contextAccessor, options, logger)
 {
     _tokenValidationOptions = tokenValidationOptions?.Value ?? throw new ArgumentNullException(nameof(tokenValidationOptions));
 }
Beispiel #5
0
        public async Task ValidateJwtAsync_should_validate_and_return_token()
        {
            var tokenValidationOptionsMock = new Mock <IOptions <TokenValidationParameters> >();
            var contextAccessorMock        = new Mock <IHttpContextAccessor>();
            var options = new IdentityServer4.Configuration.IdentityServerOptions
            {
                IssuerUri = "http://test"
            };
            var loggerMock = new Mock <ILogger <JwtRequestValidator> >();

            Assert.Throws <ArgumentNullException>(() => new CustomJwtRequestValidator(tokenValidationOptionsMock.Object, contextAccessorMock.Object, options, loggerMock.Object));

            var tokenValidationParameters = new TokenValidationParameters();

            tokenValidationOptionsMock.SetupGet(m => m.Value).Returns(tokenValidationParameters);
            var httpContextMock = new Mock <HttpContext>();

            contextAccessorMock.SetupGet(m => m.HttpContext).Returns(httpContextMock.Object);

            var provider = new ServiceCollection().AddTransient(p => options).BuildServiceProvider();

            httpContextMock.SetupGet(m => m.RequestServices).Returns(provider);

            var sut = new CustomJwtRequestValidator(tokenValidationOptionsMock.Object, contextAccessorMock.Object, options, loggerMock.Object);

            var client = new Client
            {
                ClientId      = Guid.NewGuid().ToString(),
                ClientSecrets = new[]
                {
                    new Secret
                    {
                        Type  = IdentityServer4.IdentityServerConstants.SecretTypes.JsonWebKey,
                        Value = "{\"kty\": \"RSA\",\"e\": \"AQAB\",\"use\": \"sig\",\"alg\": \"RS256\",\"n\": \"qBulUDaYV027shwCq82LKIevXdQL2pCwXktQgf2TT3c496pxGdRuxcN_MHGKWNOGQsDLuAVk6NjxYF95obDUFrDiugMuXrvptPrTO8dzTX83k_6ngtjOtx2UrTk_7f0EYNrusykrsB-cOvCMREsfktlsavvMKBGrzpxaHlRxcSsMxzB0dddDSlH8mxlzOGcbBuvZnbNg0EUuQC4jvM9Gy6gUEcoU0S19XnUcgwLGLPfIX2dMO4FxTAsaaTYT7msxGMBNIVUTVnL0HctYr0YVYu0hD9rePnvxJ_-OwOdxIETQlR9vp61xFr4juzyyMWTrjCACxxLm-CyEQGjwx2YZaw\"}"
                    }
                }
            };

            var jwtString = "eyJhbGciOiJub25lIn0.eyJzY29wZSI6Im9wZW5pZCIsInJlc3BvbnNlX3R5cGUiOiJjb2RlIiwicmVkaXJlY3RfdXJpIjoiaHR0cHM6XC9cL3d3dy5jZXJ0aWZpY2F0aW9uLm9wZW5pZC5uZXRcL3Rlc3RcL2FcL3RoZWlkc2VydmVyXC9jYWxsYmFjayIsInN0YXRlIjoiRXBTcFc3clVmciIsIm5vbmNlIjoiaU5Ia3gyT3ltOSIsImNsaWVudF9pZCI6ImVjZjk1Y2Q3LWI4NDQtNGNkZS05OWE4LTc2N2EyNDNmOTZjYiJ9.";

            var result = await sut.ValidateAsync(client, jwtString);

            Assert.True(result.IsError);

            tokenValidationParameters.ValidateIssuerSigningKey                                 = tokenValidationParameters.ValidateIssuer
                                                                                               = tokenValidationParameters.ValidateAudience
                                                                                               = tokenValidationParameters.ValidateLifetime
                                                                                               = tokenValidationParameters.RequireAudience
                                                                                               = tokenValidationParameters.RequireSignedTokens
                                                                                               = tokenValidationParameters.RequireExpirationTime
                                                                                               = false;

            result = await sut.ValidateAsync(client, jwtString);

            Assert.False(result.IsError);

            options.StrictJarValidation = true;

            result = await sut.ValidateAsync(client, jwtString);

            Assert.True(result.IsError);
        }