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 TokenCleanup(EntityFrameworkServiceOptions options, int interval = 60)
        {
            if (options == null) throw new ArgumentNullException("options");
            if (interval < 1) throw new ArgumentException("interval must be more than 1 second");

            this.options = options;
            this.interval = TimeSpan.FromSeconds(interval);
        }
        public static void RegisterScopeStore(this IdentityServerServiceFactory factory, EntityFrameworkServiceOptions options)
        {
            if (factory == null) throw new ArgumentNullException("factory");
            if (options == null) throw new ArgumentNullException("options");

            factory.Register(new Registration<ScopeConfigurationDbContext>(resolver => new ScopeConfigurationDbContext(options.ConnectionString, options.Schema)));
            factory.ScopeStore = new Registration<IScopeStore, ScopeStore>();
        }
Пример #4
0
        public ClientConfigurationCorsPolicyRegistration(EntityFrameworkServiceOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            this.AdditionalRegistrations.Add(new Registration <ClientConfigurationDbContext>(resolver => new ClientConfigurationDbContext(options.ConnectionString, options.Schema)));
        }
        public static void RegisterOperationalServices(this IdentityServerServiceFactory factory, EntityFrameworkServiceOptions options)
        {
            if (factory == null) throw new ArgumentNullException("factory");
            if (options == null) throw new ArgumentNullException("options");

            factory.Register(new Registration<OperationalDbContext>(resolver => new OperationalDbContext(options.ConnectionString, options.Schema)));
            factory.AuthorizationCodeStore = new Registration<IAuthorizationCodeStore, AuthorizationCodeStore>();
            factory.TokenHandleStore = new Registration<ITokenHandleStore, TokenHandleStore>();
            factory.ConsentStore = new Registration<IConsentStore, ConsentStore>();
            factory.RefreshTokenStore = new Registration<IRefreshTokenStore, RefreshTokenStore>();
        }
Пример #6
0
        public TokenCleanup(EntityFrameworkServiceOptions options, int interval = 60)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            if (interval < 1)
            {
                throw new ArgumentException("interval must be more than 1 second");
            }

            this.options  = options;
            this.interval = TimeSpan.FromSeconds(interval);
        }
 public static void ConfigureScopes(IEnumerable<Scope> scopes, EntityFrameworkServiceOptions options)
 {
     using (var db = new ScopeConfigurationDbContext(options.ConnectionString, options.Schema))
     {
         if (!db.Scopes.Any())
         {
             foreach (var s in scopes)
             {
                 var e = s.ToEntity();
                 db.Scopes.Add(e);
             }
             db.SaveChanges();
         }
     }
 }
 public static void ConfigureClients(IEnumerable<Client> clients, EntityFrameworkServiceOptions options)
 {
     using (var db = new ClientConfigurationDbContext(options.ConnectionString, options.Schema))
     {
         if (!db.Clients.Any())
         {
             foreach (var c in clients)
             {
                 var e = c.ToEntity();
                 db.Clients.Add(e);
             }
             db.SaveChanges();
         }
     }
 }
 public static void RegisterConfigurationServices(this IdentityServerServiceFactory factory, EntityFrameworkServiceOptions options)
 {
     factory.RegisterClientStore(options);
     factory.RegisterScopeStore(options);
 }