/// <summary>
        /// Convenience method to create an instance of <see cref="IdentityServerServiceFactory" /> and
        /// configure it to use in-memory implementations of the <see cref="IUserService"/>, <see cref="IClientStore"/>, 
        /// and <see cref="IScopeStore"/>.
        /// </summary>
        /// <param name="users">The users.</param>
        /// <param name="clients">The clients.</param>
        /// <param name="scopes">The scopes.</param>
        /// <returns></returns>
        public static IdentityServerServiceFactory Create(
            List<InMemoryUser> users = null,
            IEnumerable<Client> clients = null,
            IEnumerable<Scope> scopes = null)
        {
            var factory = new IdentityServerServiceFactory();
            
            if (users != null)
            {
                factory.Register(new Registration<List<InMemoryUser>>(users));
                factory.UserService = new Registration<IUserService, InMemoryUserService>();
            }

            if (clients != null)
            {
                factory.Register(new Registration<IEnumerable<Client>>(clients));
                factory.ClientStore = new Registration<IClientStore>(typeof(InMemoryClientStore));
            }

            if (scopes != null)
            {
                factory.Register(new Registration<IEnumerable<Scope>>(scopes));
                factory.ScopeStore = new Registration<IScopeStore>(typeof(InMemoryScopeStore));
            }

            return factory;
        }
        public static IdentityServerServiceFactory Configure()
        {
            var factory = new IdentityServerServiceFactory();

            var scopeStore = new InMemoryScopeStore(Scopes.Get());
            factory.ScopeStore = new Registration<IScopeStore>(resolver => scopeStore);
            
            var clientStore = new InMemoryClientStore(Clients.Get());
            factory.ClientStore = new Registration<IClientStore>(resolver => clientStore);            
            //var corsPolicyService = new CorsPolicyService();
            //factory.CorsPolicyService = new Registration<ICorsPolicyService>(ressolver => corsPolicyService);

            var origns = new List<string>();
            
            origns.Add("http://thebeast.com:15831");
            origns.Add("http://localhost:15831");
            origns.Add("http://localhost:15832");
            origns.Add("http://karamaangular.azurewebsites.net");

            var defaultCorsPolicyService = new DefaultCorsPolicyService() { AllowAll = false, AllowedOrigins = origns };
            factory.CorsPolicyService = new Registration<ICorsPolicyService>(ressolver => defaultCorsPolicyService);

            /*            factory.ConfigureDefaultViewService(new DefaultViewServiceOptions(){})*/
            ;
            return factory;
        }
        public static IdentityServerServiceFactory Create(
            IEnumerable<InMemoryUser> users = null,
            IEnumerable<Client> clients = null,
            IEnumerable<Scope> scopes = null)
        {
            var factory = new IdentityServerServiceFactory();
            
            if (users != null)
            {
                var userService = new InMemoryUserService(users);
                factory.UserService = Registration.RegisterFactory<IUserService>(() => userService);
            }

            if (clients != null)
            {
                var clientStore = new InMemoryClientStore(clients);
                factory.ClientStore = Registration.RegisterFactory<IClientStore>(() => clientStore);
            }

            if (scopes != null)
            {
                var scopeStore = new InMemoryScopeStore(scopes);
                factory.ScopeStore = Registration.RegisterFactory<IScopeStore>(() => scopeStore);
            }

            return factory;
        }
        public static IdentityServerServiceFactory Configure(string connString)
        {
            var efConfig = new EntityFrameworkServiceOptions {
                ConnectionString = connString,
                //Schema = "foo"
            };

            var cleanup = new TokenCleanup(efConfig, 10);
            cleanup.Start();

            // these two calls just pre-populate the test DB from the in-memory config
            ConfigureClients(Clients.Get(), efConfig);
            ConfigureScopes(Scopes.Get(), efConfig);

            var factory = new IdentityServerServiceFactory();

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

            factory.CorsPolicyService = new ClientConfigurationCorsPolicyRegistration(efConfig);

            var userService = new Thinktecture.IdentityServer.Core.Services.InMemory.InMemoryUserService(Users.Get());
            factory.UserService = new Registration<IUserService>(resolver => userService);

            return factory;
        }
        public static IdentityServerServiceFactory Create(
            string issuerUri, string siteName, string certificateThumbprint, 
            string storageConnectionString,
            string publicHostAddress = "")
        {
            Func<IdentityServerTableContext> storageContext = () =>  new IdentityServerTableContext(
                   CloudStorageAccount.Parse(storageConnectionString));
            Func<IdentityTableContext<IdentityUser>> identityContext = () =>
                new IdentityTableContext<IdentityUser>(CloudStorageAccount.Parse(storageConnectionString));

            var settings = new AzureTableStoreCoreSettings(storageContext(),
                issuerUri, siteName, certificateThumbprint, publicHostAddress);

            var consent = new AzureTableStoreConsentService();

            var logger = new TraceLogger();

            var fact = new IdentityServerServiceFactory
            {
                Logger = () => logger,
                UserService = () => UserServiceFactory.Factory<IdentityUser>(identityContext()),
                AuthorizationCodeStore = () => new AzureTableStoreAuthorizationCodeStore(storageContext()),
                TokenHandleStore = () => new AzureTableStoreTokenHandlerStore(storageContext()),
                CoreSettings = () => settings,
                ConsentService = () => consent
            };

            return fact;
        }
        public static IdentityServerServiceFactory Configure()
        {
            var factory = new IdentityServerServiceFactory();

            var scopeStore = new InMemoryScopeStore(Scopes.Get());
            factory.ScopeStore = new Registration<IScopeStore>(scopeStore);
            var clientStore = new InMemoryClientStore(Clients.Get());
            factory.ClientStore = new Registration<IClientStore>(clientStore);

            return factory;
        }
Beispiel #7
0
        public static IdentityServerServiceFactory Configure(string connString)
        {
            var factory = new IdentityServerServiceFactory();

            factory.ScopeStore = new Registration<IScopeStore, CustomScopeStore>();
            factory.ClientStore = new Registration<IClientStore, CustomClientStore>();

            factory.Register(new Registration<List<User>>(Users.Get()));
            factory.UserService = new Registration<IUserService, CustomUserService>();

            return factory;
        }
        public static IdentityServerServiceFactory Configure(string connString)
        {
            var factory = new IdentityServerServiceFactory();

            factory.UserService = Registration<IUserService>.RegisterFactory(()=>MembershipRebootUserServiceFactory.Factory(connString));

            var scopeStore = new InMemoryScopeStore(Scopes.Get());
            factory.ScopeStore = Registration.RegisterFactory<IScopeStore>(() => scopeStore);
            var clientStore = new InMemoryClientStore(Clients.Get());
            factory.ClientStore = Registration.RegisterFactory<IClientStore>(() => clientStore);

            return factory;
        }
        public static IdentityServerServiceFactory Create()
        {
            var scopes = new InMemoryScopeStore(TestScopes.Get());
            var clients = new InMemoryClientStore(TestClients.Get());
            
            var fact = new IdentityServerServiceFactory
            {
                ScopeStore = new Registration<IScopeStore>((resolver) => scopes),
                ClientStore = new Registration<IClientStore>((resolver) => clients)
            };

            return fact;
        }
Beispiel #10
0
        public static IdentityServerServiceFactory Configure(string connString)
        {
            var factory = new IdentityServerServiceFactory();

            //var scopeStore = new InMemoryScopeStore(Config.Scopes.Get());
            //factory.ScopeStore = new Registration<IScopeStore>(scopeStore);
            var scopeStore = new clientMgr.Stores.ScopeStore(connString);
            factory.ScopeStore = new Registration<IScopeStore>(scopeStore);

            //var clientStore = new InMemoryClientStore(Config.Clients.Get());
            //factory.ClientStore = new Registration<IClientStore>(clientStore);
            var clientStore = new clientMgr.Stores.ClientStore(connString);
            factory.ClientStore = new Registration<IClientStore>(clientStore);

            return factory;
        }
        public static IdentityServerServiceFactory Create(
                    string issuerUri, string siteName, string publicHostAddress = "")
        {
            var settings = new TestSettings(issuerUri, siteName, publicHostAddress);
            var scopes = new InMemoryScopeService(TestScopes.Get());
            var clients = new InMemoryClientService(TestClients.Get());
            
            var fact = new IdentityServerServiceFactory
            {
                CoreSettings = Registration.RegisterFactory<CoreSettings>(() => settings),
                ScopeService = Registration.RegisterFactory<IScopeService>(() => scopes),
                ClientService = Registration.RegisterFactory<IClientService>(() => clients)
            };

            return fact;
        }
        public static IdentityServerServiceFactory Create(
                    string issuerUri, string siteName, string publicHostAddress = "")
        {
            var settings = new LocalTestCoreSettings(issuerUri, siteName, publicHostAddress);
            
            var codeStore = new InMemoryAuthorizationCodeStore();
            var tokenStore = new InMemoryTokenHandleStore();
            var consent = new InMemoryConsentService();
            var scopes = new InMemoryScopeService(LocalTestScopes.Get());
            var clients = new InMemoryClientService(LocalTestClients.Get());
            var logger = new TraceLogger();

            var users = new InMemoryUser[]
            {
                new InMemoryUser{Subject = "alice", Username = "******", Password = "******", 
                    Claims = new Claim[]
                    {
                        new Claim(Constants.ClaimTypes.GivenName, "Alice"),
                        new Claim(Constants.ClaimTypes.FamilyName, "Smith"),
                        new Claim(Constants.ClaimTypes.Email, "*****@*****.**"),
                    }
                },
                new InMemoryUser{Subject = "bob", Username = "******", Password = "******", 
                    Claims = new Claim[]
                    {
                        new Claim(Constants.ClaimTypes.GivenName, "Bob"),
                        new Claim(Constants.ClaimTypes.FamilyName, "Smith"),
                        new Claim(Constants.ClaimTypes.Email, "*****@*****.**"),
                    }
                },
            };
            var userSvc = new InMemoryUserService(users);

            var fact = new IdentityServerServiceFactory
            {
                Logger = () => logger,
                UserService = () => userSvc,
                AuthorizationCodeStore = () => codeStore,
                TokenHandleStore = () => tokenStore,
                CoreSettings = () => settings,
                ConsentService = () => consent,
                ScopeService = () => scopes,
                ClientService = () => clients
            };

            return fact;
        }
        public static IdentityServerServiceFactory Create(string issuerUri, string siteName, string publicHostAddress = "")
        {
            var settings = new TestCoreSettings(issuerUri, siteName, publicHostAddress);
            var codeStore = new TestAuthorizationCodeStore();
            var tokenStore = new TestTokenHandleStore();
            var consent = new TestConsentService();
            var logger = new TraceLogger();
            
            var fact = new IdentityServerServiceFactory
            {
                Logger = () => logger,
                UserService = () => new TestUserService(),
                AuthorizationCodeStore = () => codeStore,
                TokenHandleStore = () => tokenStore,
                CoreSettings = () => settings,
                ConsentService = () => consent
            };

            return fact;
        }
        public static IdentityServerServiceFactory Configure(string connString)
        {
            var svcFactory = new ServiceFactory(connString);
            svcFactory.ConfigureClients(Clients.Get());
            svcFactory.ConfigureScopes(Scopes.Get());

            var factory = new IdentityServerServiceFactory();

            var userService = new Thinktecture.IdentityServer.Core.Services.InMemory.InMemoryUserService(Users.Get());
            factory.UserService = Registration.RegisterFactory<IUserService>(() => userService);

            factory.ScopeStore = Registration.RegisterFactory<IScopeStore>(() => svcFactory.CreateScopeStore());
            factory.ClientStore = Registration.RegisterFactory<IClientStore>(() => svcFactory.CreateClientStore());
            
            factory.AuthorizationCodeStore = Registration.RegisterFactory<IAuthorizationCodeStore>(() => svcFactory.CreateAuthorizationCodeStore());
            factory.TokenHandleStore = Registration.RegisterFactory<ITokenHandleStore>(() => svcFactory.CreateTokenHandleStore());
            factory.ConsentService = Registration.RegisterFactory<IConsentService>(() => svcFactory.CreateConsentService());
            factory.RefreshTokenStore = Registration.RegisterFactory<IRefreshTokenStore>(() => svcFactory.CreateRefreshTokenStore());

            return factory;
        }
        public IdentityServerHost()
        {
            var clientStore = new InMemoryClientStore(Clients);
            var scopeStore = new InMemoryScopeStore(Scopes);
            var userService = new InMemoryUserService(Users);

            var factory = new IdentityServerServiceFactory
            {
                ScopeStore = new Registration<IScopeStore>(scopeStore),
                ClientStore = new Registration<IClientStore>(clientStore),
                UserService = new Registration<IUserService>(userService),
                ClientSecretValidator = new Registration<IClientSecretValidator, PlainTextClientSecretValidator>(),
            };

            Options = new IdentityServerOptions
            {
                Factory = factory,
                DataProtector = new NoDataProtector(),
                SiteName = "Thinktecture IdentityServer3 Host",
                SigningCertificate = SigningCertificate
            };
        }
        public static IdentityServerServiceFactory Create(
                    string issuerUri, string siteName, string publicHostAddress = "")
        {
            var users = new InMemoryUser[]
            {
                new InMemoryUser{Subject = "818727", Username = "******", Password = "******", 
                    Claims = new Claim[]
                    {
                        new Claim(Constants.ClaimTypes.GivenName, "Alice"),
                        new Claim(Constants.ClaimTypes.FamilyName, "Smith"),
                        new Claim(Constants.ClaimTypes.Email, "*****@*****.**"),
                    }
                },
                new InMemoryUser{Subject = "88421113", Username = "******", Password = "******", 
                    Claims = new Claim[]
                    {
                        new Claim(Constants.ClaimTypes.GivenName, "Bob"),
                        new Claim(Constants.ClaimTypes.FamilyName, "Smith"),
                        new Claim(Constants.ClaimTypes.Email, "*****@*****.**"),
                    }
                },
            };

            var settings = new Settings(issuerUri, siteName, publicHostAddress);
            var scopes = new InMemoryScopeService(Scopes.Get());
            var clients = new InMemoryClientService(Clients.Get());
            var userSvc = new InMemoryUserService(users);

            var fact = new IdentityServerServiceFactory
            {
                UserService = Registration.RegisterFactory<IUserService>(() => userSvc),
                CoreSettings = Registration.RegisterFactory<CoreSettings>(() => settings),
                ScopeService = Registration.RegisterFactory<IScopeService>(() => scopes),
                ClientService = Registration.RegisterFactory<IClientService>(() => clients)
            };

            return fact;
        }
        public void Configuration(IAppBuilder app)
        {
            //var factory2 = new IdentityServerServiceFactory();

            //LogProvider.SetCurrentLogProvider(new DiagnosticsTraceLogProvider());
            //var factory = InMemoryFactory.Create(
            //    scopes: Scopes.Get(),
            //    clients: Clients.Get(),
            //    users: Users2.Get()
            //    );
            var factory = new IdentityServerServiceFactory();
            var scopeStore = new InMemoryScopeStore(Scopes.Get());
            factory.ScopeStore = new Registration<IScopeStore>(scopeStore);
            var clientStore = new InMemoryClientStore(Clients.Get());
            factory.ClientStore = new Registration<IClientStore>(clientStore);
            factory.TokenService = new Registration<ITokenService>(typeof(MyCustomTokenService));
            factory.RefreshTokenStore = new Registration<IRefreshTokenStore>(typeof(MyCustomRefreshTokenStore));
            factory.CustomTokenValidator = new Registration<ICustomTokenValidator>(new MyCustomTokenValidator());
            factory.TokenHandleStore = new Registration<ITokenHandleStore>(new MyCustomTokenHandleStore());
            factory.ConfigureUserService("AspId");
            LogProvider.SetCurrentLogProvider(new NLogLogProvider());
            //LogProvider.SetCurrentLogProvider(new DiagnosticsTraceLogProvider());
            //factory.TokenHandleStore = new Registration<ITokenHandleStore>();
            //factory.RefreshTokenStore = new Registration<IRefreshTokenStore>();
            //factory.CustomTokenValidator = new Registration<ICustomTokenValidator>(new MyCustomTokenValidator());
            //factory.Register(new Registration<IUserService, MyCustomUserService>());
            //factory.Register(new Registration<IMyCustomLogger, MyCustomLogger>());
            //factory.UserService = new Registration<IUserService>(typeof(IUserService));
            var options = new IdentityServerOptions
            {
                Factory = factory,
                //IssuerUri = "https://idsrv3.com",
                SiteName = "Thinktecture IdentityServer3 Halo",
                SigningCertificate = Certificate.Get(),
                RequireSsl = false,
                CspOptions = new CspOptions
                {
                    Enabled =true,
                },
                Endpoints = new EndpointOptions
                {
                    EnableAccessTokenValidationEndpoint = true,
                    EnableTokenEndpoint = true,
                    EnableTokenRevocationEndpoint = true,
                    EnableIdentityTokenValidationEndpoint = true,

                    //remove in production
                    EnableDiscoveryEndpoint = true,

                    EnableAuthorizeEndpoint= false,
                    EnableClientPermissionsEndpoint= false,
                    EnableCspReportEndpoint= false,

                    EnableEndSessionEndpoint=false,
                    EnableCheckSessionEndpoint = false,
                    EnableUserInfoEndpoint = false
                },
                AuthenticationOptions = new AuthenticationOptions
                {
                    EnableLocalLogin = true,
                    EnableLoginHint = false,
                },
                LoggingOptions = new LoggingOptions
                {
                    EnableHttpLogging=true,
                    EnableWebApiDiagnostics=true,
                    IncludeSensitiveDataInLogs=true,
                    WebApiDiagnosticsIsVerbose=true
                },
                EnableWelcomePage = false,
                IssuerUri = "https://HFL0100:44333"

            };
            options.CorsPolicy.AllowedOrigins.Add("http://localhost:14869/");

            app.UseHsts();
            app.UseIdentityServer(options);
        }
Beispiel #18
0
        public static IContainer Configure(IdentityServerCoreOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            if (options.Factory == null)
            {
                throw new InvalidOperationException("null factory");
            }

            IdentityServerServiceFactory fact = options.Factory;

            fact.Validate();

            var builder = new ContainerBuilder();

            // mandatory from factory
            builder.Register(ctx => fact.AuthorizationCodeStore()).As <IAuthorizationCodeStore>();
            builder.Register(ctx => fact.CoreSettings()).As <ICoreSettings>();
            builder.Register(ctx => fact.Logger()).As <ILogger>();
            builder.Register(ctx => fact.TokenHandleStore()).As <ITokenHandleStore>();
            builder.Register(ctx => fact.UserService()).As <IUserService>();
            builder.Register(ctx => fact.ConsentService()).As <IConsentService>();

            // optional from factory
            if (fact.ClaimsProvider != null)
            {
                builder.Register(ctx => fact.ClaimsProvider()).As <IClaimsProvider>();
            }
            else
            {
                builder.RegisterType <DefaultClaimsProvider>().As <IClaimsProvider>();
            }

            if (fact.TokenService != null)
            {
                builder.Register(ctx => fact.TokenService()).As <ITokenService>();
            }
            else
            {
                builder.RegisterType <DefaultTokenService>().As <ITokenService>();
            }

            if (fact.CustomRequestValidator != null)
            {
                builder.Register(ctx => fact.CustomRequestValidator()).As <ICustomRequestValidator>();
            }
            else
            {
                builder.RegisterType <DefaultCustomRequestValidator>().As <ICustomRequestValidator>();
            }

            if (fact.AssertionGrantValidator != null)
            {
                builder.Register(ctx => fact.AssertionGrantValidator()).As <IAssertionGrantValidator>();
            }
            else
            {
                builder.RegisterType <DefaultAssertionGrantValidator>().As <IAssertionGrantValidator>();
            }

            if (fact.ExternalClaimsFilter != null)
            {
                builder.Register(ctx => fact.ExternalClaimsFilter()).As <IExternalClaimsFilter>();
            }
            else
            {
                builder.RegisterType <DefaultExternalClaimsFilter>().As <IExternalClaimsFilter>();
            }

            // validators
            builder.RegisterType <TokenRequestValidator>();
            builder.RegisterType <AuthorizeRequestValidator>();
            builder.RegisterType <ClientValidator>();
            builder.RegisterType <TokenValidator>();

            // processors
            builder.RegisterType <TokenResponseGenerator>();
            builder.RegisterType <AuthorizeResponseGenerator>();
            builder.RegisterType <AuthorizeInteractionResponseGenerator>();
            builder.RegisterType <UserInfoResponseGenerator>();

            // for authentication
            var authenticationOptions = options.AuthenticationOptions ?? new AuthenticationOptions();

            builder.RegisterInstance(authenticationOptions).AsSelf();

            // controller
            builder.RegisterApiControllers(typeof(AuthorizeEndpointController).Assembly);

            return(builder.Build());
        }
        public static IContainer Configure(IdentityServerCoreOptions options, InternalConfiguration internalConfig)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            if (options.Factory == null)
            {
                throw new InvalidOperationException("null factory");
            }
            if (internalConfig == null)
            {
                throw new ArgumentNullException("internalConfig");
            }

            IdentityServerServiceFactory fact = options.Factory;

            fact.Validate();

            var builder = new ContainerBuilder();

            builder.RegisterInstance(internalConfig).AsSelf();

            // mandatory from factory
            builder.Register(ctx => fact.AuthorizationCodeStore()).As <IAuthorizationCodeStore>();
            builder.Register(ctx => fact.CoreSettings()).As <CoreSettings>();
            builder.Register(ctx => fact.TokenHandleStore()).As <ITokenHandleStore>();
            builder.Register(ctx => fact.UserService()).As <IUserService>();
            builder.Register(ctx => fact.ScopeService()).As <IScopeService>();
            builder.Register(ctx => fact.ClientService()).As <IClientService>();
            builder.Register(ctx => fact.ConsentService()).As <IConsentService>();

            // optional from factory
            if (fact.Logger != null)
            {
                builder.Register(ctx => fact.Logger()).As <ILogger>();
            }
            else
            {
                builder.RegisterType <TraceLogger>().As <ILogger>();
            }

            if (fact.ClaimsProvider != null)
            {
                builder.Register(ctx => fact.ClaimsProvider()).As <IClaimsProvider>();
            }
            else
            {
                builder.RegisterType <DefaultClaimsProvider>().As <IClaimsProvider>();
            }

            if (fact.TokenService != null)
            {
                builder.Register(ctx => fact.TokenService()).As <ITokenService>();
            }
            else
            {
                builder.RegisterType <DefaultTokenService>().As <ITokenService>();
            }

            if (fact.CustomRequestValidator != null)
            {
                builder.Register(ctx => fact.CustomRequestValidator()).As <ICustomRequestValidator>();
            }
            else
            {
                builder.RegisterType <DefaultCustomRequestValidator>().As <ICustomRequestValidator>();
            }

            if (fact.AssertionGrantValidator != null)
            {
                builder.Register(ctx => fact.AssertionGrantValidator()).As <IAssertionGrantValidator>();
            }
            else
            {
                builder.RegisterType <DefaultAssertionGrantValidator>().As <IAssertionGrantValidator>();
            }

            if (fact.ExternalClaimsFilter != null)
            {
                builder.Register(ctx => fact.ExternalClaimsFilter()).As <IExternalClaimsFilter>();
            }
            else
            {
                builder.RegisterType <DefaultExternalClaimsFilter>().As <IExternalClaimsFilter>();
            }

            // validators
            builder.RegisterType <TokenRequestValidator>();
            builder.RegisterType <AuthorizeRequestValidator>();
            builder.RegisterType <ClientValidator>();
            builder.RegisterType <TokenValidator>();

            // processors
            builder.RegisterType <TokenResponseGenerator>();
            builder.RegisterType <AuthorizeResponseGenerator>();
            builder.RegisterType <AuthorizeInteractionResponseGenerator>();
            builder.RegisterType <UserInfoResponseGenerator>();

            // for authentication
            var authenticationOptions = options.AuthenticationOptions ?? new AuthenticationOptions();

            builder.RegisterInstance(authenticationOptions).AsSelf();

            // load core controller
            builder.RegisterApiControllers(typeof(AuthorizeEndpointController).Assembly);

            // plugin configuration
            var pluginDepencies = internalConfig.PluginDependencies;

            if (pluginDepencies != null)
            {
                if (pluginDepencies.ApiControllerAssemblies != null)
                {
                    foreach (var asm in pluginDepencies.ApiControllerAssemblies)
                    {
                        builder.RegisterApiControllers(asm);
                    }
                }

                if (pluginDepencies.Types != null)
                {
                    foreach (var type in pluginDepencies.Types)
                    {
                        if (type.Value == null)
                        {
                            builder.RegisterType(type.Key);
                        }
                        else
                        {
                            builder.RegisterType(type.Key).As(type.Value);
                        }
                    }
                }

                if (pluginDepencies.Factories != null)
                {
                    foreach (var factory in pluginDepencies.Factories)
                    {
                        builder.Register(ctx => factory.Value()).As(factory.Key);
                    }
                }
            }

            return(builder.Build());
        }
 public static void RegisterConfigurationServices(this IdentityServerServiceFactory factory, EntityFrameworkServiceOptions options)
 {
     factory.RegisterClientStore(options);
     factory.RegisterScopeStore(options);
 }
        public static IContainer Configure(IdentityServerOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            if (options.Factory == null)
            {
                throw new InvalidOperationException("null factory");
            }

            IdentityServerServiceFactory fact = options.Factory;

            fact.Validate();

            var builder = new ContainerBuilder();

            builder.RegisterInstance(options).AsSelf();

            // mandatory from factory
            builder.Register(fact.UserService);
            builder.Register(fact.ScopeStore);
            builder.Register(fact.ClientStore);

            // optional from factory
            if (fact.AuthorizationCodeStore != null)
            {
                builder.Register(fact.AuthorizationCodeStore);
            }
            else
            {
                var inmemCodeStore = new InMemoryAuthorizationCodeStore();
                builder.RegisterInstance(inmemCodeStore).As <IAuthorizationCodeStore>();
            }

            if (fact.TokenHandleStore != null)
            {
                builder.Register(fact.TokenHandleStore);
            }
            else
            {
                var inmemTokenHandleStore = new InMemoryTokenHandleStore();
                builder.RegisterInstance(inmemTokenHandleStore).As <ITokenHandleStore>();
            }

            if (fact.RefreshTokenStore != null)
            {
                builder.Register(fact.RefreshTokenStore);
            }
            else
            {
                var inmemRefreshTokenStore = new InMemoryRefreshTokenStore();
                builder.RegisterInstance(inmemRefreshTokenStore).As <IRefreshTokenStore>();
            }

            if (fact.ConsentStore != null)
            {
                builder.Register(fact.ConsentStore);
            }
            else
            {
                var inmemConsentStore = new InMemoryConsentStore();
                builder.RegisterInstance(inmemConsentStore).As <IConsentStore>();
            }

            if (fact.ClaimsProvider != null)
            {
                builder.Register(fact.ClaimsProvider);
            }
            else
            {
                builder.RegisterType <DefaultClaimsProvider>().As <IClaimsProvider>();
            }

            if (fact.TokenService != null)
            {
                builder.Register(fact.TokenService);
            }
            else
            {
                builder.RegisterType <DefaultTokenService>().As <ITokenService>();
            }

            if (fact.RefreshTokenService != null)
            {
                builder.Register(fact.RefreshTokenService);
            }
            else
            {
                builder.RegisterType <DefaultRefreshTokenService>().As <IRefreshTokenService>();
            }

            if (fact.TokenSigningService != null)
            {
                builder.Register(fact.TokenSigningService);
            }
            else
            {
                builder.RegisterType <DefaultTokenSigningService>().As <ITokenSigningService>();
            }

            if (fact.CustomRequestValidator != null)
            {
                builder.Register(fact.CustomRequestValidator);
            }
            else
            {
                builder.RegisterType <DefaultCustomRequestValidator>().As <ICustomRequestValidator>();
            }

            if (fact.AssertionGrantValidator != null)
            {
                builder.Register(fact.AssertionGrantValidator);
            }
            else
            {
                builder.RegisterType <DefaultAssertionGrantValidator>().As <IAssertionGrantValidator>();
            }

            if (fact.ExternalClaimsFilter != null)
            {
                builder.Register(fact.ExternalClaimsFilter);
            }
            else
            {
                builder.RegisterType <DefaultExternalClaimsFilter>().As <IExternalClaimsFilter>();
            }

            if (fact.CustomTokenValidator != null)
            {
                builder.Register(fact.CustomTokenValidator);
            }
            else
            {
                builder.RegisterType <DefaultCustomTokenValidator>().As <ICustomTokenValidator>();
            }

            if (fact.ConsentService != null)
            {
                builder.Register(fact.ConsentService);
            }
            else
            {
                builder.RegisterType <DefaultConsentService>().As <IConsentService>();
            }

            if (fact.ViewService != null)
            {
                builder.Register(fact.ViewService);
            }
            else
            {
                builder.RegisterType <EmbeddedAssetsViewService>().As <IViewService>();
            }

            // validators
            builder.RegisterType <TokenRequestValidator>();
            builder.RegisterType <AuthorizeRequestValidator>();
            builder.RegisterType <ClientValidator>();
            builder.RegisterType <TokenValidator>();

            // processors
            builder.RegisterType <TokenResponseGenerator>();
            builder.RegisterType <AuthorizeResponseGenerator>();
            builder.RegisterType <AuthorizeInteractionResponseGenerator>();
            builder.RegisterType <UserInfoResponseGenerator>();

            // general services
            builder.RegisterType <CookieMiddlewareTrackingCookieService>().As <ITrackingCookieService>();

            // for authentication
            var authenticationOptions = options.AuthenticationOptions ?? new AuthenticationOptions();

            builder.RegisterInstance(authenticationOptions).AsSelf();

            // load core controller
            builder.RegisterApiControllers(typeof(AuthorizeEndpointController).Assembly);

            // add any additional dependencies from hosting application
            foreach (var registration in fact.Registrations)
            {
                builder.Register(registration);
            }

            return(builder.Build());
        }
Beispiel #22
0
        public void Configuration(IAppBuilder app)
        {
            #if DEBUG
            const string serverName = "devservername";
            #else
               const string serverName = "prodservername";
            #endif

            LogProvider.SetCurrentLogProvider(new TraceSourceLogProvider());

            const string connectionName = "AspId";

            var factory = new IdentityServerServiceFactory();
            factory.ConfigureClientService(connectionName);
            factory.ConfigureScopeService(connectionName);
            factory.ConfigureUserService(connectionName);
            //factory.ConfigureClientStoreCache();
            //factory.ConfigureScopeStoreCache();
            //factory.ConfigureUserServiceCache();

            app.Map("/core1", coreApp =>
            {
                var options = new IdentityServerOptions
                {
                    IssuerUri = "https://" + serverName + "/identityserver",
                    SiteName = "Identity Server Name",
                    SigningCertificate = Cert.Load(serverName),
                    Factory = factory,
                    CorsPolicy = CorsPolicy.AllowAll,
                    RequireSsl = true,
                    EnableWelcomePage = true,
                    AuthenticationOptions = new AuthenticationOptions
                    {
                        EnableLoginHint = true,
                        EnableSignOutPrompt = false,
                        EnableLocalLogin = false,
                        EnablePostSignOutAutoRedirect = true,
                        PostSignOutAutoRedirectDelay = 0,
                        RequireAuthenticatedUserForSignOutMessage = false,
                        RememberLastUsername = false,
                        SignInMessageThreshold = 3,
                        IdentityProviders = ConfigureAdditionalIdentityProviders1,
                        CookieOptions = new Thinktecture.IdentityServer.Core.Configuration.CookieOptions()
                        {
                            Prefix = "Core1",
                            SecureMode = CookieSecureMode.Always
                        }
                    },
                    LoggingOptions = new LoggingOptions
                    {
                        EnableHttpLogging = true,
                        EnableWebApiDiagnostics = true,
                        IncludeSensitiveDataInLogs = true,
                        WebApiDiagnosticsIsVerbose = false
                    },
                    EventsOptions = new EventsOptions
                    {
                        RaiseSuccessEvents = true,
                        RaiseErrorEvents = true,
                        RaiseFailureEvents = true,
                        RaiseInformationEvents = true
                    }
                };

                coreApp.UseIdentityServer(options);
            });

            app.Map("/core2", coreApp =>
            {
                var options = new IdentityServerOptions
                {
                    IssuerUri = "https://" + serverName + "/identityserver",
                    SiteName = "Identity Server Name",
                    SigningCertificate = Cert.Load(serverName),
                    Factory = factory,
                    CorsPolicy = CorsPolicy.AllowAll,
                    RequireSsl = true,
                    EnableWelcomePage = false,
                    AuthenticationOptions = new AuthenticationOptions
                    {
                        EnableLoginHint = true,
                        EnableSignOutPrompt = false,
                        EnableLocalLogin = false,
                        EnablePostSignOutAutoRedirect = true,
                        PostSignOutAutoRedirectDelay = 0,
                        RequireAuthenticatedUserForSignOutMessage = false,
                        RememberLastUsername = false,
                        SignInMessageThreshold = 3,
                        IdentityProviders = ConfigureAdditionalIdentityProviders2,
                        CookieOptions = new Thinktecture.IdentityServer.Core.Configuration.CookieOptions()
                        {
                            Prefix = "Core2",
                            SecureMode = CookieSecureMode.Always
                        }
                    },
                    LoggingOptions = new LoggingOptions
                    {
                        EnableHttpLogging = true,
                        EnableWebApiDiagnostics = true,
                        IncludeSensitiveDataInLogs = true
                    },
                    EventsOptions = new EventsOptions
                    {
                        RaiseSuccessEvents = true,
                        RaiseErrorEvents = true,
                        RaiseFailureEvents = true,
                        RaiseInformationEvents = true
                    }
                };
                coreApp.UseIdentityServer(options);
            });
        }