Пример #1
0
        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();
        }