コード例 #1
0
        public void ProcessConsentAsync_AllowConsentSelected_SavesConsent()
        {
            RequiresConsent(true);
            var client = new Client {
                AllowRememberConsent = true
            };
            var user    = new ClaimsPrincipal();
            var request = new ValidatedAuthorizeRequest()
            {
                ResponseMode    = Constants.ResponseModes.Fragment,
                State           = "12345",
                RedirectUri     = new Uri("https://client.com/callback"),
                ValidatedScopes = new ScopeValidator(),
                Client          = client,
                Subject         = user
            };

            request.ValidatedScopes.AreScopesValid(new string[] { "read", "write" }, TestScopes.Get());
            var consent = new UserConsent
            {
                Button          = "yes",
                RememberConsent = true,
                Scopes          = new string[] { "read" }
            };
            var result = subject.ProcessConsentAsync(request, consent).Result;

            AssertUpdateConsentCalled(client, user, "read");
        }
コード例 #2
0
        public static AuthorizeRequestValidator CreateAuthorizeValidator(
            IdentityServerOptions options           = null,
            IScopeStore scopes                      = null,
            IClientStore clients                    = null,
            IUserService users                      = null,
            ICustomRequestValidator customValidator = null)
        {
            if (options == null)
            {
                options = Thinktecture.IdentityServer.Tests.TestIdentityServerOptions.Create();
            }

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

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

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

            return(new AuthorizeRequestValidator(options, scopes, clients, customValidator));
        }
コード例 #3
0
        public void ProcessConsentAsync_PromptModeConsent_ConsentGranted_ScopesSelected_ReturnsConsentResult()
        {
            RequiresConsent(true);
            var request = new ValidatedAuthorizeRequest()
            {
                ResponseMode    = Constants.ResponseModes.Fragment,
                State           = "12345",
                RedirectUri     = new Uri("https://client.com/callback"),
                ValidatedScopes = new ScopeValidator(),
                Client          = new Client {
                }
            };

            request.ValidatedScopes.AreScopesValid(new string[] { "read", "write" }, TestScopes.Get());
            var consent = new UserConsent
            {
                Button          = "yes",
                RememberConsent = false,
                Scopes          = new string[] { "read" }
            };
            var result = subject.ProcessConsentAsync(request, consent).Result;

            Assert.AreEqual(1, request.ValidatedScopes.GrantedScopes.Count);
            Assert.AreEqual(request.ValidatedScopes.GrantedScopes.First().Name, "read");
            Assert.IsTrue(request.WasConsentShown);
            Assert.IsFalse(result.IsConsent);
            AssertUpdateConsentNotCalled();
        }
コード例 #4
0
        public static AuthorizeRequestValidator CreateAuthorizeValidator(
            CoreSettings settings  = null,
            IScopeService scopes   = null,
            IClientService clients = null,
            IUserService users     = null,
            ICustomRequestValidator customValidator = null)
        {
            if (settings == null)
            {
                settings = new TestSettings();
            }

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

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

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

            if (users == null)
            {
                users = new TestUserService();
            }

            return(new AuthorizeRequestValidator(settings, scopes, clients, users, customValidator));
        }
コード例 #5
0
        public static TokenRequestValidator CreateTokenValidator(
            CoreSettings settings = null,
            IScopeService scopes  = null,
            IAuthorizationCodeStore authorizationCodeStore = null,
            IUserService userService = null,
            IAssertionGrantValidator assertionGrantValidator = null,
            ICustomRequestValidator customRequestValidator   = null)
        {
            if (settings == null)
            {
                settings = new TestSettings();
            }

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

            if (userService == null)
            {
                userService = new TestUserService();
            }

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

            if (assertionGrantValidator == null)
            {
                assertionGrantValidator = new TestAssertionValidator();
            }

            return(new TokenRequestValidator(settings, authorizationCodeStore, userService, scopes, assertionGrantValidator, customRequestValidator));
        }
コード例 #6
0
        public async Task ProcessConsentAsync_PromptModeConsent_ConsentGranted_ScopesSelected_ReturnsConsentResult()
        {
            RequiresConsent(true);
            var request = new ValidatedAuthorizeRequest()
            {
                ResponseMode    = Constants.ResponseModes.Fragment,
                State           = "12345",
                RedirectUri     = "https://client.com/callback",
                ValidatedScopes = new ScopeValidator(new InMemoryScopeStore(TestScopes.Get())),
                Client          = new Client {
                }
            };
            await request.ValidatedScopes.AreScopesValidAsync(new string[] { "read", "write" });

            var consent = new UserConsent
            {
                Button          = "yes",
                RememberConsent = false,
                Scopes          = new string[] { "read" }
            };
            var result = subject.ProcessConsentAsync(request, consent).Result;

            request.ValidatedScopes.GrantedScopes.Count.Should().Be(1);
            "read".Should().Be(request.ValidatedScopes.GrantedScopes.First().Name);
            request.WasConsentShown.Should().BeTrue();
            result.IsConsent.Should().BeFalse();
            AssertUpdateConsentNotCalled();
        }
コード例 #7
0
ファイル: Startup.cs プロジェクト: n8wachT/IdentityServerTest
        public void Configuration(IAppBuilder app)
        {
            //Log.Logger = new LoggerConfiguration()
            //    .WriteTo.RollingFile("log-{Date}.txt")
            //    .CreateLogger();
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .WriteTo.Trace()
                         .CreateLogger();

            var efConfig = new EntityFrameworkServiceOptions
            {
                ConnectionString = "DefaultConnection"
            };

#if DEBUG
            Database.SetInitializer(new DropCreateDatabaseIfModelChanges <ApplicationDbContext>());
#endif

            app.Map("/admin", adminApp =>
            {
                var imgrFactory = new IdentityManagerServiceFactory();
                imgrFactory.ConfigureSimpleIdentityManagerService();

                adminApp.UseIdentityManager(new IdentityManagerOptions()
                {
                    Factory = imgrFactory
                });
            });

            var factory = new IdentityServerServiceFactory();

            factory.RegisterConfigurationServices(efConfig);
            factory.RegisterOperationalServices(efConfig);
            factory.ConfigureUserService();

#if DEBUG
            // these two calls just pre-populate the test DB from the in-memory config
            TestClients.ConfigureClients(TestClients.Get(), efConfig);
            TestScopes.ConfigureScopes(TestScopes.Get(), efConfig);
#endif

            var options = new IdentityServerOptions
            {
                SiteName           = "MyIdentityServer - Server",
                Factory            = factory,
                RequireSsl         = false,
                SigningCertificate = Certificate.Get(),
            };
            app.UseIdentityServer(options);

            var cleanup = new TokenCleanup(efConfig, 10);
            cleanup.Start();
        }
コード例 #8
0
        public static TokenRequestValidator CreateTokenValidator(
            IdentityServerOptions options = null,
            IScopeStore scopes            = null,
            IAuthorizationCodeStore authorizationCodeStore = null,
            IRefreshTokenStore refreshTokens = null,
            IUserService userService         = null,
            IAssertionGrantValidator assertionGrantValidator = null,
            ICustomRequestValidator customRequestValidator   = null)
        {
            if (options == null)
            {
                options = Thinktecture.IdentityServer.Tests.TestIdentityServerOptions.Create();
            }

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

            if (userService == null)
            {
                userService = new TestUserService();
            }

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

            if (assertionGrantValidator == null)
            {
                assertionGrantValidator = new TestAssertionValidator();
            }

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

            return(new TokenRequestValidator(options, authorizationCodeStore, refreshTokens, userService, scopes, assertionGrantValidator, customRequestValidator));
        }
コード例 #9
0
 public ScopeStoreTests()
 {
     Factory.ConfigureScope(RavenOptions);
     TestScopes.Get().LoadTo(Store);
     WaitForIndexing(Store);
 }