public async Task Valid_Custom_Grant_Multiple_Validator()
        {
            var validator = new CustomGrantValidator(new List<ICustomGrantValidator> 
            { 
                new TestGrantValidator(), 
                new TestGrantValidator2() 
            });

            var request = new ValidatedTokenRequest
            {
                GrantType = "custom_grant"
            };

            var result = await validator.ValidateAsync(request);

            result.IsError.Should().BeFalse();
            result.Principal.Should().NotBeNull();
            result.Principal.GetSubjectId().Should().Be("bob");
            result.Principal.GetAuthenticationMethod().Should().Be("CustomGrant");

            request.GrantType = "custom_grant2";
            result = await validator.ValidateAsync(request);

            result.IsError.Should().BeFalse();
            result.Principal.Should().NotBeNull();
            result.Principal.GetSubjectId().Should().Be("alice");
            result.Principal.GetAuthenticationMethod().Should().Be("CustomGrant2");
        }
 public DiscoveryEndpointController(IdentityServerOptions options, IScopeStore scopes, IOwinContext context, ISigningKeyService keyService, CustomGrantValidator customGrants)
 {
     _options = options;
     _scopes = scopes;
     _context = context;
     _keyService = keyService;
     _customGrants = customGrants;
 }
 public TokenRequestValidator(IdentityServerOptions options, IAuthorizationCodeStore authorizationCodes, IRefreshTokenStore refreshTokens, IUserService users, CustomGrantValidator customGrantValidator, ICustomRequestValidator customRequestValidator, ScopeValidator scopeValidator, IEventService events)
 {
     _options = options;
     _authorizationCodes = authorizationCodes;
     _refreshTokens = refreshTokens;
     _users = users;
     _customGrantValidator = customGrantValidator;
     _customRequestValidator = customRequestValidator;
     _scopeValidator = scopeValidator;
     _events = events;
 }
        public async Task Valid_Custom_Grant_Validator_Throws_Exception()
        {
            var validatorThrowingException = new Mock<ICustomGrantValidator>();
            validatorThrowingException.Setup(y => y.ValidateAsync(It.IsAny<ValidatedTokenRequest>())).Throws(new Exception("Random validation error"));
            validatorThrowingException.Setup(y => y.GrantType).Returns("custom_grant");
            var validator = new CustomGrantValidator(new[] { validatorThrowingException.Object});
            var request = new ValidatedTokenRequest
            {
                GrantType = validator.GetAvailableGrantTypes().Single()
            };

            var result = await validator.ValidateAsync(request);

            result.IsError.Should().BeTrue();
            result.Error.Should().Be("Grant validation error");
            result.Principal.Should().BeNull();
            
        }
Exemple #5
0
 public TokenRequestValidator(IdentityServerOptions options, IAuthorizationCodeStore authorizationCodes, IRefreshTokenStore refreshTokens, IBasicUserService users, CustomGrantValidator customGrantValidator,
                              ICustomRequestValidator customRequestValidator, ScopeValidator scopeValidator, IEventService events)
 {
     _options            = options;
     _authorizationCodes = authorizationCodes;
     _refreshTokens      = refreshTokens;
     _users = users;
     _customGrantValidator   = customGrantValidator;
     _customRequestValidator = customRequestValidator;
     _scopeValidator         = scopeValidator;
     _events = events;
 }
Exemple #6
0
 public TokenRequestValidator(IdentityServerOptions options, IAuthorizationCodeStore authorizationCodes, IRefreshTokenStore refreshTokens, IUserService users, CustomGrantValidator customGrantValidator,
                              ICustomRequestValidator customRequestValidator, ScopeValidator scopeValidator, IEventService events)
     : this(options, authorizationCodes, refreshTokens, (IBasicUserService)users, customGrantValidator, customRequestValidator, scopeValidator, events)
 {
 }
        public async Task Unknown_Custom_Grant_Multiple_Validator()
        {
            var validator = new CustomGrantValidator(new List<ICustomGrantValidator> 
            { 
                new TestGrantValidator(), 
                new TestGrantValidator2() 
            });

            var request = new ValidatedTokenRequest
            {
                GrantType = "unknown"
            };

            var result = await validator.ValidateAsync(request);

            result.IsError.Should().BeTrue();
        }
        public void GetAvailable_Should_Return_Expected_GrantTypes()
        {
            var validator = new CustomGrantValidator(new List<ICustomGrantValidator> 
            { 
                new TestGrantValidator(), 
                new TestGrantValidator2() 
            });

            var available = validator.GetAvailableGrantTypes();

            available.Count().Should().Be(2);
            available.First().Should().Be("custom_grant");
            available.Skip(1).First().Should().Be("custom_grant2");
        }
        public async Task Empty_Validator_List()
        {
            var validator = new CustomGrantValidator(new List<ICustomGrantValidator>());

            var request = new ValidatedTokenRequest
            {
                GrantType = "something"
            };

            var result = await validator.ValidateAsync(request);

            result.IsError.Should().BeTrue();
        }
Exemple #10
0
        //public static ClientValidator CreateClientValidator(
        //    IClientStore clients = null,
        //    IClientSecretValidator secretValidator = null)
        //{
        //    if (clients == null)
        //    {
        //        clients = new InMemoryClientStore(ClientValidationTestClients.Get());
        //    }

        //    if (secretValidator == null)
        //    {
        //        secretValidator = new HashedClientSecretValidator();
        //    }

        //    var owin = new OwinEnvironmentService(new OwinContext());

        //    return new ClientValidator(clients, secretValidator, owin);
        //}

        public static TokenRequestValidator CreateTokenRequestValidator(
            IdentityServerOptions options = null,
            IScopeStore scopes = null,
            IAuthorizationCodeStore authorizationCodeStore = null,
            IRefreshTokenStore refreshTokens = null,
            IUserService userService = 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 (userService == null)
            {
                userService = new TestUserService();
            }

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

            CustomGrantValidator aggregateCustomValidator;
            if (customGrantValidators == null)
            {
                aggregateCustomValidator = new CustomGrantValidator(new [] { new TestGrantValidator() });
            }
            else
            {
                aggregateCustomValidator = new CustomGrantValidator(customGrantValidators);
            }
                
            if (refreshTokens == null)
            {
                refreshTokens = new InMemoryRefreshTokenStore();
            }

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

            return new TokenRequestValidator(
                options, 
                authorizationCodeStore, 
                refreshTokens, 
                userService, 
                aggregateCustomValidator, 
                customRequestValidator, 
                scopeValidator, 
                new DefaultEventService());
        }