Exemple #1
0
        public static TokenValidator CreateTokenValidator(ITokenHandleStore tokenStore = null, IProfileService profile = null)
        {
            if (profile == null)
            {
                profile = new TestProfileService();
            }

            if (tokenStore == null)
            {
                tokenStore = new InMemoryTokenHandleStore();
            }

            var clients      = CreateClientStore();
            var idsvrContext = IdentityServerContextHelper.Create();
            var logger       = TestLogger.Create <TokenValidator>();

            var validator = new TokenValidator(
                clients: clients,
                tokenHandles: tokenStore,
                customValidator: new DefaultCustomTokenValidator(
                    profile: profile,
                    clients: clients,
                    logger: TestLogger.Create <DefaultCustomTokenValidator>()),
                keys: new[] { new InMemoryValidationKeysStore(new[] { TestCert.LoadSigningCredentials().Key }) },
                logger: logger,
                context: idsvrContext);

            return(validator);
        }
        public void Init()
        {
            _context = IdentityServerContextHelper.Create();

            _validatedAuthorizeRequest = new ValidatedAuthorizeRequest()
            {
                RedirectUri  = "http://client/callback",
                State        = "123",
                ResponseMode = "fragment",
                ClientId     = "client",
                Client       = new Client
                {
                    ClientId   = "client",
                    ClientName = "Test Client"
                },
                Raw     = _params,
                Subject = _user
            };

            _stubAuthorizeRequestValidator.Result.IsError          = false;
            _stubAuthorizeRequestValidator.Result.ValidatedRequest = _validatedAuthorizeRequest;

            _subject = new AuthorizeEndpoint(
                _mockEventService,
                _fakeLogger,
                _context,
                _stubAuthorizeRequestValidator,
                _stubInteractionGenerator,
                _stubResultFactory,
                _mockSignInResponseStore,
                _mockUserConsentResponseMessageStore);
        }
        public EndSessionRequestValidatorTests()
        {
            _user = IdentityServer4.IdentityServerPrincipal.Create("alice", "Alice");

            _context = IdentityServerContextHelper.Create();
            _subject = new EndSessionRequestValidator(
                TestLogger.Create <EndSessionRequestValidator>(),
                _context,
                _stubTokenValidator,
                _stubRedirectUriValidator);
        }
Exemple #4
0
        public static AuthorizeRequestValidator CreateAuthorizeRequestValidator(
            IdentityServerOptions options            = null,
            IScopeStore scopes                       = null,
            IClientStore clients                     = null,
            IUserService users                       = null,
            ICustomRequestValidator customValidator  = null,
            IRedirectUriValidator uriValidator       = null,
            ScopeValidator scopeValidator            = null,
            IDictionary <string, object> environment = null)
        {
            if (options == null)
            {
                options = TestIdentityServerOptions.Create();
            }

            if (scopes == null)
            {
                scopes = new InMemoryScopeStore(TestScopes.Get());
            }

            if (clients == null)
            {
                clients = new InMemoryClientStore(TestClients.Get());
            }

            if (customValidator == null)
            {
                customValidator = new DefaultCustomRequestValidator();
            }

            if (uriValidator == null)
            {
                uriValidator = new StrictRedirectUriValidator();
            }

            if (scopeValidator == null)
            {
                scopeValidator = new ScopeValidator(scopes, new LoggerFactory());
            }

            var sessionCookie = new SessionCookie(IdentityServerContextHelper.Create(null, options));

            return(new AuthorizeRequestValidator(
                       options,
                       clients,
                       customValidator,
                       uriValidator,
                       scopeValidator,
                       sessionCookie,
                       new Logger <AuthorizeRequestValidator>(new LoggerFactory())
                       ));
        }
Exemple #5
0
        public static TokenRequestValidator CreateTokenRequestValidator(
            IdentityServerOptions options = null,
            IScopeStore scopes            = null,
            IAuthorizationCodeStore authorizationCodeStore = null,
            IRefreshTokenStore refreshTokens = null,
            IResourceOwnerPasswordValidator resourceOwnerValidator = null,
            IProfileService profile = null,
            IEnumerable <ICustomGrantValidator> customGrantValidators = null,
            ICustomRequestValidator customRequestValidator            = null,
            ScopeValidator scopeValidator = null)
        {
            if (options == null)
            {
                options = TestIdentityServerOptions.Create();
            }

            if (scopes == null)
            {
                scopes = new InMemoryScopeStore(TestScopes.Get());
            }

            if (resourceOwnerValidator == null)
            {
                resourceOwnerValidator = new TestResourceOwnerPasswordValidator();
            }

            if (profile == null)
            {
                profile = new TestProfileService();
            }

            if (customRequestValidator == null)
            {
                customRequestValidator = new DefaultCustomRequestValidator();
            }

            CustomGrantValidator aggregateCustomValidator;

            if (customGrantValidators == null)
            {
                aggregateCustomValidator = new CustomGrantValidator(new [] { new TestGrantValidator() }, TestLogger.Create <CustomGrantValidator>());
            }
            else
            {
                aggregateCustomValidator = new CustomGrantValidator(customGrantValidators, TestLogger.Create <CustomGrantValidator>());
            }

            if (refreshTokens == null)
            {
                refreshTokens = new InMemoryRefreshTokenStore();
            }

            if (scopeValidator == null)
            {
                scopeValidator = new ScopeValidator(scopes, new LoggerFactory().CreateLogger <ScopeValidator>());
            }

            var idsvrContext = IdentityServerContextHelper.Create();

            return(new TokenRequestValidator(
                       options,
                       authorizationCodeStore,
                       refreshTokens,
                       resourceOwnerValidator,
                       profile,
                       aggregateCustomValidator,
                       customRequestValidator,
                       scopeValidator,
                       new TestEventService(),
                       TestLogger.Create <TokenRequestValidator>()));
        }