public static IdentityServerServiceFactory Configure(string connString) { var efConfig = new EntityFrameworkServiceOptions { ConnectionString = connString, //Schema = "dbo" }; var cleanup = new TokenCleanup(efConfig, 10); cleanup.Start(); ConfigureClients(Clients.Get(), efConfig); ConfigureScopes(Scopes.Get(), efConfig); var factory = new IdentityServerServiceFactory(); factory.RegisterConfigurationServices(efConfig); factory.RegisterOperationalServices(efConfig); factory.CorsPolicyService = new ClientConfigurationCorsPolicyRegistration(efConfig); factory.UserService = new Registration <IUserService, UserService>(); return(factory); }
public static IdentityServerServiceFactory Configure(AppConfiguration config) { var factory = new IdentityServerServiceFactory(); var scopeStore = new InMemoryScopeStore(Scopes.Get()); factory.ScopeStore = new Registration <IScopeStore>(scopeStore); var clientStore = new InMemoryClientStore(Clients.Get(config)); factory.ClientStore = new Registration <IClientStore>(clientStore); var efConfig = new EntityFrameworkServiceOptions { ConnectionString = "Iws.DefaultConnection", Schema = "Identity" }; factory.RegisterOperationalServices(efConfig); var cleanup = new TokenCleanup(efConfig); cleanup.Start(); return(factory); }
public static IdentityServerServiceFactory Configure(string connString) { var nhSessionFactory = GetNHibernateSessionFactory(); var nhSession = nhSessionFactory.OpenSession(); var tokenCleanUpSession = nhSessionFactory.OpenSession(); var cleanup = new TokenCleanup(tokenCleanUpSession, 60); cleanup.Start(); // these two calls just pre-populate the test DB from the in-memory config ConfigureClients(Clients.Get(), nhSession); ConfigureScopes(Scopes.Get(), nhSession); var factory = new IdentityServerServiceFactory(); factory.RegisterNhibernateStores(new NhibernateServiceOptions(nhSessionFactory) { RegisterOperationalServices = true, RegisterConfigurationServices = true }); factory.UseInMemoryUsers(Users.Get().ToList()); return(factory); }
public static IdentityServerServiceFactory Configure(string connString) { var efConfig = new EntityFrameworkServiceOptions { ConnectionString = connString, //Schema = "foo", //SynchronousReads = true }; 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.ConfigureClientStoreCache(); //factory.ConfigureScopeStoreCache(); factory.UseInMemoryUsers(Users.Get()); 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 void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); // Setup Databases using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()) { serviceScope.ServiceProvider.GetService <ConfigurationDbContext>().Database.Migrate(); serviceScope.ServiceProvider.GetService <PersistedGrantDbContext>().Database.Migrate(); EnsureSeedData(serviceScope.ServiceProvider.GetService <ConfigurationDbContext>()); var options = serviceScope.ServiceProvider.GetService <DbContextOptions <PersistedGrantDbContext> >(); var tokenCleanup = new TokenCleanup(new TokenCleanupOptions { DbContextOptions = options, Interval = 30000, }); tokenCleanup.Start(); } app.UseIdentity(); app.UseIdentityServer(); app.UseStaticFiles(); app.UseApiHelpUI(); app.UseMvcWithDefaultRoute(); }
public static IdentityServerServiceFactory Configure(AppConfiguration config) { var factory = new IdentityServerServiceFactory(); var scopeStore = new InMemoryScopeStore(Scopes.Get()); factory.ScopeStore = new Registration <IScopeStore>(scopeStore); var clientStore = new InMemoryClientStore(Clients.Get(config)); factory.ClientStore = new Registration <IClientStore>(clientStore); var efConfig = new EntityFrameworkServiceOptions { ConnectionString = "Weee.DefaultConnection", Schema = "Identity" }; factory.RegisterOperationalServices(efConfig); var cleanup = new TokenCleanup(efConfig); cleanup.Start(); string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Weee.DefaultConnection"].ConnectionString; var auditSecurityEventService = new SecurityEventDatabaseAuditor(connectionString); SecurityEventService eventService = new SecurityEventService(auditSecurityEventService); factory.Register <ISecurityEventAuditor>(new Registration <ISecurityEventAuditor>(auditSecurityEventService)); factory.EventService = new Registration <IEventService>(eventService); return(factory); }
public Task StartAsync(CancellationToken cancellationToken) { if (_options.EnableTokenCleanup) { _tokenCleanup.Start(cancellationToken); } return(Task.CompletedTask); }
public void Configuration(IAppBuilder app) { var efConfig = new EntityFrameworkServiceOptions { ConnectionString = IdentityServerDb }; var cleanup = new TokenCleanup(efConfig, 10); cleanup.Start(); // Add in the Clients and Scopes to the EF database IdentityServerTestData.SetUp(efConfig); MembershipTestData.SetUp(MembershipDb, MembershipApplicationName); var factory = new IdentityServerServiceFactory(); factory.RegisterOperationalServices(efConfig); factory.Register(new Registration <IClientConfigurationDbContext>(resolver => new ClientConfigurationDbContext(efConfig.ConnectionString))); factory.RegisterClientDataStore(new Registration <IClientDataStore>(resolver => new ClientDataStore(resolver.Resolve <IClientConfigurationDbContext>()))); factory.CorsPolicyService = new ClientConfigurationCorsPolicyRegistration(efConfig); factory.Register(new Registration <IScopeConfigurationDbContext>(resolver => new ScopeConfigurationDbContext(efConfig.ConnectionString))); factory.RegisterScopeDataStore(new Registration <IScopeDataStore>(resolver => new ScopeDataStore(resolver.Resolve <IScopeConfigurationDbContext>()))); factory.AddVaultClientSecretStore( new VaultClientSecretStoreAppIdOptions { AppId = Program.IdentityServerAppId, UserId = Program.IdentityServerUserId }); factory.UseMembershipService( new MembershipOptions { ConnectionString = ConfigurationManager.ConnectionStrings["Membership"].ConnectionString, ApplicationName = MembershipApplicationName }); var options = new IdentityServerOptions { Factory = factory, RequireSsl = false }; // Wire up Vault as being the X509 Certificate Signing Store options.AddVaultCertificateStore(new VaultCertificateStoreAppIdOptions { AppId = Program.IdentityServerAppId, UserId = Program.IdentityServerUserId, RoleName = RoleName, CommonName = CommonName }); app.UseIdentityServer(options); }
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(); }
public static void UseEfStore(this IdentityServerServiceFactory factory, string dbcontectionstr, bool usetokenclean = true) { var efConfig = new EntityFrameworkServiceOptions { ConnectionString = dbcontectionstr, }; if (usetokenclean) { var cleanup = new TokenCleanup(efConfig, 60 * 10); cleanup.Start(); } factory.RegisterConfigurationServices(efConfig); factory.RegisterOperationalServices(efConfig); }
public static IdentityServerServiceFactory Configure(DocumentDbServiceOptions documentDbServiceOptions) { var efConfig = documentDbServiceOptions; 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.UseInMemoryUsers(Users.Get()); return factory; }
public static IdentityServerServiceFactory Configure(DocumentDbServiceOptions documentDbServiceOptions) { var efConfig = documentDbServiceOptions; 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.UseInMemoryUsers(Users.Get()); return(factory); }
/// <inheritdoc /> public Task StartAsync(CancellationToken cancellationToken) { _tokenCleanup.Start(cancellationToken); return(Task.CompletedTask); }
public void Configuration(IAppBuilder app) { #region customer login css //var viewOPtions = new DefaultViewServiceOptions(); //viewOPtions.CustomViewDirectory = string.Format(@"{0}\Templates\", AppDomain.CurrentDomain.BaseDirectory); //viewOPtions.Stylesheets.Add("/Content/Site.css"); //options.Factory.ConfigureDefaultViewService(viewOPtions); #endregion #region Role Scope EF config //ASP.Net identity user role... + identity server3 (EF client scope) var efOptions = new EntityFrameworkServiceOptions() { ConnectionString = "AuthServer", Schema = Constants.IdentityServerSchema, }; var factory = new IdentityServerServiceFactory(); factory.RegisterClientStore(efOptions); factory.RegisterScopeStore(efOptions); //factory.UseInMemoryUsers(InMemoryUsers.GetAllUsers()); //factory.UserService = new Registration<IdentityServer3.Core.Services.IUserService>(); #endregion #region User EF config //IdentityDbContext identityDbContext = new IdentityDbContext("AuthServer"); IdentityDbContext identityDbContext = new CustomIdentityDbContext("AuthServer"); UserManager <IdentityUser> userManager = new UserManager <IdentityUser>(new UserStore <IdentityUser>(identityDbContext)); RoleManager <IdentityRole> roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(identityDbContext)); var userService = new AspNetIdentityUserService <IdentityUser, string>(userManager); factory.UserService = new Registration <IdentityServer3.Core.Services.IUserService>(userService); #endregion //factory.RegisterConfigurationServices(efOptions); #region Token and Cache config factory.RegisterOperationalServices(efOptions);//database store token factory.ConfigureClientStoreCache(); factory.ConfigureScopeStoreCache(); factory.ConfigureUserServiceCache(); var clearToken = new TokenCleanup(efOptions, 60); clearToken.Start(); #endregion #region IdentityServer config var options = new IdentityServerOptions() { Factory = factory, RequireSsl = false, AuthenticationOptions = new AuthenticationOptions { EnablePostSignOutAutoRedirect = true, IdentityProviders = IdentityProviderManager.ConfigureIdentityProviders, }, SigningCertificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(string.Format(@"{0}\certificate\server.pfx", AppDomain.CurrentDomain.BaseDirectory), "4022042"), }; #endregion //SampleDataProvider.InitClientAndScopeSampleDatas(efOptions);//init some data app.ConfigureManagerService();//for Identity Manager Pages app.UseIdentityServer(options); }
public void Configuration(IAppBuilder app) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.File(@"c:\logs\OIDC.IdentityServer.Web.txt") .CreateLogger(); var ef = new EntityFrameworkServiceOptions { ConnectionString = "IdSvr3Config", //配置的连接字符串,EF会自动生成数据库 }; var factory = new IdentityServerServiceFactory(); factory.RegisterConfigurationServices(ef); factory.RegisterOperationalServices(ef); factory.RegisterClientStore(ef); factory.RegisterScopeStore(ef); //var factory = new IdentityServerServiceFactory() // .UseInMemoryClients(Clients.Get()) // .UseInMemoryScopes(Scopes.Get()); //自定义用户认证 var userService = new EulaAtLoginUserService(); factory.UserService = new Registration <IUserService>(resolver => userService); //自定义登录视图 factory.ViewService = new Registration <IViewService, MvcViewService <LogonWorkflowController> >(); //自定义登录视图,还需要这些注册,因为这些都是使用非STA处理的。 factory.Register(new Registration <HttpContext>(resolver => HttpContext.Current)); factory.Register(new Registration <HttpContextBase>(resolver => new HttpContextWrapper(resolver.Resolve <HttpContext>()))); factory.Register(new Registration <HttpRequestBase>(resolver => resolver.Resolve <HttpContextBase>().Request)); factory.Register(new Registration <HttpResponseBase>(resolver => resolver.Resolve <HttpContextBase>().Response)); factory.Register(new Registration <HttpServerUtilityBase>(resolver => resolver.Resolve <HttpContextBase>().Server)); factory.Register(new Registration <HttpSessionStateBase>(resolver => resolver.Resolve <HttpContextBase>().Session)); var options = new IdentityServerOptions { SiteName = "认证中心", SigningCertificate = Certificate.Load(), Factory = factory, RequireSsl = false, AuthenticationOptions = new AuthenticationOptions { IdentityProviders = ConfigureAdditionalIdentityProviders, LoginPageLinks = new LoginPageLink[] { new LoginPageLink { Text = "Register", //Href = "~/localregistration" Href = "localregistration" } } }, EventsOptions = new EventsOptions { RaiseSuccessEvents = true, RaiseErrorEvents = true, RaiseFailureEvents = true, RaiseInformationEvents = true } }; //启动清除过期票据定时器 var cleanToken = new TokenCleanup(ef, 20); cleanToken.Start(); //自定义服务路径 http://localhost:44111/identity app.Map("/identity", idsrvApp => { idsrvApp.UseIdentityServer(options); }); Log.Logger.Information("程序启动成功"); }