public static IIdentityServerBuilder UseIdentityServerMySqlDatabase(this IIdentityServerBuilder builder,
                                                                            IServiceCollection services, IConfiguration configuration, ILogger logger)
        {
            var connectionString   = configuration.GetConnectionString("SSOConnection");
            var migrationsAssembly = "Jp.Infra.Migrations.MySql.Identity";

            // this adds the config data from DB (clients, resources)
            builder.AddConfigurationStore(options =>
            {
                options.ConfigureDbContext = b =>
                                             b.UseMySql(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly));
            })
            // this adds the operational data from DB (codes, tokens, consents)
            .AddOperationalStore(options =>
            {
                options.ConfigureDbContext = b =>
                                             b.UseMySql(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly));

                // this enables automatic token cleanup. this is optional.
                //options.EnableTokenCleanup = true;
                //options.TokenCleanupInterval = 15; // frequency in seconds to cleanup stale grants. 15 is useful during debugging
            });



            return(builder);
        }
        public static IIdentityServerBuilder AddDatabaseConfiguration(this IIdentityServerBuilder builder,
            IConfigurationSection config,
            string connectionString)
        {
            var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
            return builder.AddConfigurationStore(options =>
                {
                    options.ConfigureDbContext = b =>
                        b.UseNpgsql(connectionString,
                            sql => sql.MigrationsAssembly(migrationsAssembly));
                })
                // this adds the operational data from DB (codes, tokens, consents)
                .AddOperationalStore(options =>
                {
                    options.ConfigureDbContext = b =>
                        b.UseNpgsql(connectionString,
                            sql => sql.MigrationsAssembly(migrationsAssembly));

                    var c = config.GetSection("OperationalStore").Get<OperationalStoreConfig>();
                    if (c != null)
                    {
                        options.EnableTokenCleanup = c.EnableTokenCleanup;
                        options.TokenCleanupInterval = c.TokenCleanupInterval;
                    }
                });
        }
        public static IIdentityServerBuilder AddConfigurationStore(
            this IIdentityServerBuilder builder, IConfiguration configuration)
        {
            builder.Services.Configure <LiteDBConfiguration>(configuration);

            return(builder.AddConfigurationStore());
        }
Example #4
0
 public static IIdentityServerBuilder AddConfigurationAndOperationStores(this IIdentityServerBuilder builder,
                                                                         IConfiguration cfg, string assembly)
 {
     builder
     .AddConfigurationStore(options =>
     {
         options.ConfigureDbContext = builder => builder.UseSqlServer(
             cfg["ConnectionString"],
             sql =>
         {
             sql.MigrationsAssembly(assembly);
             sql.EnableRetryOnFailure(
                 cfg.GetValue("SQLDB_MAX_RETRY_COUNT", 2),
                 TimeSpan.FromSeconds(cfg.GetValue("SQLDB_MAX_RETRY_DELAY_IN_SECONDS", 10)),
                 null);
         });
     })
     .AddOperationalStore(options =>
     {
         options.ConfigureDbContext = builder => builder.UseSqlServer(
             cfg["ConnectionString"],
             sql =>
         {
             sql.MigrationsAssembly(assembly);
             sql.EnableRetryOnFailure(
                 cfg.GetValue("SQLDB_MAX_RETRY_COUNT", 2),
                 TimeSpan.FromSeconds(cfg.GetValue("SQLDB_MAX_RETRY_DELAY_IN_SECONDS", 10)),
                 null);
         });
     });
     return(builder);
 }
        /// <summary>
        /// Add SQL Support database
        /// </summary>
        /// <param name="connectionString">Connection String</param>
        /// <returns></returns>
        public static IIdentityServerBuilder WithMySql(
            this IIdentityServerBuilder builder,
            string connectionString)
        {
            var migrationsAssembly = typeof(IdentityServerConfig).GetTypeInfo().Assembly.GetName().Name;

            // this adds the config data from DB (clients, resources)
            builder.AddConfigurationStore(options =>
            {
                options.ConfigureDbContext = b =>
                                             b.UseMySql(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly));
            })
            // this adds the operational data from DB (codes, tokens, consents)
            .AddOperationalStore(options =>
            {
                options.ConfigureDbContext = b =>
                                             b.UseMySql(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly));

                // this enables automatic token cleanup. this is optional.
                options.EnableTokenCleanup = true;
                //options.TokenCleanupInterval = 15; // frequency in seconds to cleanup stale grants. 15 is useful during debugging
            });


            return(builder);
        }
        public static IIdentityServerBuilder AddIdentityServerDb(this IIdentityServerBuilder identityServerBuilder,
                                                                 IConfiguration configuration,
                                                                 IHostingEnvironment environment,
                                                                 string @namespace,
                                                                 Assembly assembly
                                                                 )
        {
            var connectionString = configuration.GetConnectionString("Main");

            identityServerBuilder
            .AddConfigurationStore(options =>
            {
                options.ConfigureDbContext = builder =>
                                             builder.UseSqlServer(connectionString,
                                                                  sql => sql.MigrationsAssembly(typeof(Configuration).GetTypeInfo().Assembly.GetName().Name));
            })
            .AddOperationalStore(options =>
            {
                options.ConfigureDbContext = builder =>
                                             builder.UseSqlServer(connectionString,
                                                                  sql => sql.MigrationsAssembly(typeof(Configuration).GetTypeInfo().Assembly.GetName().Name));
            })
            ;

            var services = identityServerBuilder.Services;

            services
            .AddSeedServices(environment, @namespace, assembly, ApiResourcesSeeder.CreateSeeder)
            .AddSeedServices(environment, @namespace, assembly, IdentityResourcesSeeder.CreateSeeder)
            .AddSeedServices(environment, @namespace, assembly, ClientsDatabaseSeeder.CreateSeeder)
            ;

            return(identityServerBuilder);
        }
        public static IIdentityServerBuilder UseIdentityServerSqlDatabase(this IIdentityServerBuilder builder,
                                                                          IServiceCollection services, IConfiguration configuration, ILogger logger)
        {
            var connectionString   = Environment.GetEnvironmentVariable("CUSTOMCONNSTR_DATABASE_CONNECTION") ?? configuration.GetConnectionString("SSOConnection");
            var migrationsAssembly = typeof(IdentityServerSqlConfig).GetTypeInfo().Assembly.GetName().Name;

            services.AddDbContext <JpContext>(options => options.UseSqlServer(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly)));
            // this adds the config data from DB (clients, resources)
            builder.AddConfigurationStore(options =>
            {
                options.ConfigureDbContext = b =>
                                             b.UseSqlServer(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly));
            })
            // this adds the operational data from DB (codes, tokens, consents)
            .AddOperationalStore(options =>
            {
                options.ConfigureDbContext = b =>
                                             b.UseSqlServer(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly));

                // this enables automatic token cleanup. this is optional.
                options.EnableTokenCleanup   = true;
                options.TokenCleanupInterval = 15;     // frequency in seconds to cleanup stale grants. 15 is useful during debugging
            });



            return(builder);
        }
        /// <summary>
        /// Register DbContexts and configure stores for IdentityServer4
        /// </summary>
        /// <typeparam name="TConfigurationDbContext"></typeparam>
        /// <typeparam name="TPersistedGrantDbContext"></typeparam>
        /// <param name="builder"></param>
        /// <param name="configuration"></param>
        public static IIdentityServerBuilder AddIdentityServerStoresWithDbContexts <TConfigurationDbContext, TPersistedGrantDbContext>(this IIdentityServerBuilder builder, IConfiguration configuration)
            where TPersistedGrantDbContext : DbContext, IPersistedGrantDbContext
            where TConfigurationDbContext : DbContext, IConfigurationDbContext
        {
            // Config DB from existing connection
            builder.AddConfigurationStore <TConfigurationDbContext>(options =>
            {
                options.ConfigureDbContext = b =>
                                             b.UseSqlServer(configuration.GetConnectionString(ConfigurationConsts.ConfigurationDbConnectionStringKey),
                                                            sql => sql.MigrationsAssembly(configuration.GetConnectionString(ConfigurationConsts.ConfigurationDbMigrationsAssemblyKey)));
            });

            // Operational DB from existing connection
            builder.AddOperationalStore <TPersistedGrantDbContext>(options =>
            {
                options.EnableTokenCleanup = true;
#if DEBUG
                options.TokenCleanupInterval = 15;
#endif
                options.ConfigureDbContext = b =>
                                             b.UseSqlServer(configuration.GetConnectionString(ConfigurationConsts.PersistedGrantDbConnectionStringKey),
                                                            sql => sql.MigrationsAssembly(configuration.GetConnectionString(ConfigurationConsts.PersistedGrantDbMigrationsAssemblyKey)));
            });

            return(builder);
        }
        public static IIdentityServerBuilder AddIdServerPersistence(this IIdentityServerBuilder services, string connectionString, string migrationsAssembly = "")
        {
            services.AddConfigurationStore(options =>
            {
                options.ConfigureDbContext = builder =>
                                             builder.UseSqlServer(connectionString,
                                                                  sql =>
                {
                    if (!string.IsNullOrEmpty(migrationsAssembly))
                    {
                        sql.MigrationsAssembly(migrationsAssembly);
                    }
                });
                options.DefaultSchema = "idsv";
            })
            .AddOperationalStore(options =>
            {
                options.ConfigureDbContext = builder =>
                                             builder.UseSqlServer(connectionString,
                                                                  sql =>
                {
                    if (!string.IsNullOrEmpty(migrationsAssembly))
                    {
                        sql.MigrationsAssembly(migrationsAssembly);
                    }
                });
                options.DefaultSchema = "idsv";

                // this enables automatic token cleanup. this is optional.
                options.EnableTokenCleanup   = true;
                options.TokenCleanupInterval = 30;     // interval in seconds
            });
            return(services);
        }
        public static IIdentityServerBuilder UseIdentityServerPermentStore(this IIdentityServerBuilder builder)
        {
            builder.AddConfigurationStore <ConfigurationDbContext>()
            .AddOperationalStore <PersistedGrantDbContext>();

            return(builder);
        }
Example #11
0
        RegisterIdentityServerStoresWithDbContexts <TConfigurationDbContext, TPersistedGrantDbContext>(
            IIdentityServerBuilder builder, IConfiguration configuration)
            where TPersistedGrantDbContext : DbContext, IPersistedGrantDbContext
            where TConfigurationDbContext : DbContext, IConfigurationDbContext
        {
            var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

            // Config DB from existing connection
            builder.AddConfigurationStore <TConfigurationDbContext>(options =>
            {
                options.ConfigureDbContext = b =>
                                             b.UseSqlite(
                    configuration.GetConnectionString(ConfigurationConsts.ConfigurationDbConnectionStringKey),
                    sql => sql.MigrationsAssembly(migrationsAssembly));
            });

            // Operational DB from existing connection
            builder.AddOperationalStore <TPersistedGrantDbContext>(options =>
            {
                options.EnableTokenCleanup = true;
#if DEBUG
                options.TokenCleanupInterval = 15;
#endif
                options.ConfigureDbContext = b =>
                                             b.UseSqlite(
                    configuration.GetConnectionString(ConfigurationConsts.PersistedGrantDbConnectionStringKey),
                    sql => sql.MigrationsAssembly(migrationsAssembly));
            });

            return(builder);
        }
        public static IIdentityServerBuilder AddConfigurationStore(
            this IIdentityServerBuilder builder, Action <MongoDBConfiguration> setupAction)
        {
            builder.Services.Configure(setupAction);

            return(builder.AddConfigurationStore());
        }
        public static IIdentityServerBuilder AddIdentityServerStorage(this IIdentityServerBuilder builder,
                                                                      String connectionString)
        {
            builder.AddConfigurationStore(connectionString);
            builder.AddOperationalStore(connectionString);

            return(builder);
        }
Example #14
0
 public static IIdentityServerBuilder AddConfigurationStoreMSSQL(
     this IIdentityServerBuilder builderScope,
     string connectionString
     )
 {
     builderScope.AddConfigurationStore(builder => builder.UseSqlServer(connectionString, b => b.MigrationsAssembly("coremanage.Data.Storage.MSSQL")));
     return(builderScope);
 }
Example #15
0
        public static IIdentityServerBuilder AddConfigurationStore(
            this IIdentityServerBuilder builder, IConfiguration configuration)
        {
            // Add Store Configuration
            builder.Services.Configure <MongoDbRepositoryConfiguration>(configuration);

            return(builder.AddConfigurationStore());
        }
 private static IIdentityServerBuilder  AddSqlConfigurationStore(this IIdentityServerBuilder services, ConnectionSettings settings)
 {
     return(services.AddConfigurationStore(options =>
     {
         options.ConfigureDbContext =
             builder => builder.UseSqlServer(settings.ConfigurationDb,
                                             ef => ef.MigrationsAssembly(typeof(Program).Assembly.GetName().Name));
     }));
 }
Example #17
0
        public static IIdentityServerBuilder AddCloudscribeCoreNoDbIdentityServerStorage(
            this IIdentityServerBuilder builder
            )
        {
            builder.AddConfigurationStore();
            builder.AddOperationalStore();

            return(builder);
        }
Example #18
0
        public static IIdentityServerBuilder AddConfigurationStoreUsingAppSettings(this IIdentityServerBuilder builder)
        {
            var configuration    = OptionSettingsReader.GetConfigurationRoot();
            var connectionString = OptionSettingsReader.GetConnectionString(configuration);
            var options          = OptionSettingsReader.GetConfigurationStoreOptions(configuration);

            builder.AddConfigurationStore(options, (_) => new ConfigurationDbContext(connectionString, options));

            return(builder);
        }
Example #19
0
 private static IIdentityServerBuilder AddConfiguration(this IIdentityServerBuilder builder, IdentityServerConfig config) =>
 config.UseConfigurationStore
                         ? builder
 .AddConfigurationStore(options =>
 {
     options.ConfigureDbContext = b => b.UseSqlServer(config.ConfigurationStoreConnectionString,
                                                      sql => sql.MigrationsAssembly(migrationsAssembly));
 })
                         : builder
 .AddInMemoryClients(Config.Clients)
 .AddInMemoryApiResources(Config.Apis)
 .AddInMemoryIdentityResources(Config.Ids);
Example #20
0
        public static IIdentityServerBuilder AddCloudscribeCoreNoDbIdentityServerStorage(
            this IIdentityServerBuilder builder,
            bool useSingletons = false
            )
        {
            builder.AddConfigurationStore(useSingletons);
            builder.AddOperationalStore(useSingletons);

            builder.Services.AddScoped <IStorageInfo, StorageInfo>();

            return(builder);
        }
Example #21
0
        public static IIdentityServerBuilder AddCustomIdentityServer(this IIdentityServerBuilder identityServerBuilder, string connectionString)
        {
            var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

            identityServerBuilder.AddConfigurationStore(builder => builder.UseSqlServer(connectionString, options => options.MigrationsAssembly(migrationsAssembly)))
            .AddOperationalStore(builder => builder.UseSqlServer(connectionString, options => options.MigrationsAssembly(migrationsAssembly)));

            identityServerBuilder.Services.AddTransient <IProfileService, AspNetIdentityProfileService>();
            identityServerBuilder.Services.AddTransient <IClientStore, ClientStore>();
            identityServerBuilder.Services.AddTransient <IScopeStore, ScopeStore>();
            identityServerBuilder.Services.AddTransient <IPersistedGrantStore, PersistedGrantStore>();

            return(identityServerBuilder);
        }
        public static IIdentityServerBuilder AddEFConfigurationStore(
            this IIdentityServerBuilder builder, string connectionString)
        {
            string assemblyNamespace = typeof(AppConfigurationDbContext).Namespace;

            builder.AddConfigurationStore <AppConfigurationDbContext>(options =>
                                                                      options.ConfigureDbContext = b =>
                                                                                                   b.UseSqlServer(connectionString, optionsBuilder =>
                                                                                                                  optionsBuilder.MigrationsAssembly(assemblyNamespace)
                                                                                                                  )
                                                                      );

            return(builder);
        }
Example #23
0
        public static IIdentityServerBuilder AddIdentityServerStores(this IIdentityServerBuilder builder, IConfiguration configuration)
        => builder.AddConfigurationStore(options =>
        {
            options.ConfigureDbContext = x => GetDbContextOptions <ApplicationDbContext>(x, configuration);
        })
        .AddOperationalStore(options =>
        {
            options.ConfigureDbContext = x => GetDbContextOptions <ApplicationDbContext>(x, configuration);

            // this enables automatic token cleanup. this is optional.
            options.EnableTokenCleanup = true;

            options.TokenCleanupInterval = 3600;     //In Seconds 1 hour
        });
Example #24
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddIdentity <ApplicationUser, IdentityRole>().AddDefaultTokenProviders();
            var migrationsAssembly     = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
            IIdentityServerBuilder isb = services.AddIdentityServer(options =>
            {
                // TODO: set authority and PublicOrigin
                options.IssuerUri    = DebugConstants.IdentityServer.Authority;
                options.PublicOrigin = DebugConstants.IdentityServer.Authority;
                this.Configuration.Bind(nameof(IdentityServerOptions), options);
            });

            //TODO: use recommended approach for signing credentials
            isb.AddDeveloperSigningCredential();

            isb.AddConfigurationStore(options =>
            {
                //TODO: use real connection sting
                options.ConfigureDbContext = builder =>
                                             builder.UseSqlServer(DebugConstants.ConnectionStrings.IdentityServerConfStore,
                                                                  sql => sql.MigrationsAssembly(migrationsAssembly));
            });

            // this adds the operational data from DB (codes, tokens, consents)
            isb.AddOperationalStore(options =>
            {
                //TODO: use real connection sting
                options.ConfigureDbContext = builder =>
                                             builder.UseSqlServer(DebugConstants.ConnectionStrings.IdentityServerOperationalStore,
                                                                  sql => sql.MigrationsAssembly(migrationsAssembly));
            });

            isb.AddAspNetIdentity <ApplicationUser>();

            isb.AddInMemoryCaching().AddConfigurationStoreCache();

            services.AddCors(options =>
            {
                // this defines a CORS policy called "default"
                options.AddPolicy("default", policy =>
                {
                    // TODO: set correct CORS policy
                    policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().AllowCredentials();
                });

                options.DefaultPolicyName = "default";
            });

            MigrateDatabase(services);
        }
Example #25
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSerilogWithInsights <Startup>(Configuration);

            services.AddInfrastructure(Configuration);

            IHealthChecksBuilder healthCheckBuilder = services.AddHealthChecks()
                                                      .AddDbContextCheck <ApplicationDbContext>();

            IIdentityServerBuilder builder = services.AddIdentityServer()
                                             .AddAspNetIdentity <ApplicationUser>()
                                             .AddProfileService <RolesProfileService>()
                                             .AddResourceOwnerValidator <ResourceOwnerPasswordValidator <ApplicationUser> >();

            if (Environment.IsDevelopment())
            {
                builder.AddDeveloperSigningCredential();

                builder.AddInMemoryIdentityResources(Config.Ids)
                .AddInMemoryApiResources(Config.Apis)
                .AddInMemoryClients(Config.Clients);
            }
            else
            {
                healthCheckBuilder
                .AddDbContextCheck <ISConfigurationDbContext>()
                .AddDbContextCheck <ISPersistedGrantDbContext>();

                builder.AddSigningCredential(GetCertificateAsync(Configuration).Result);

                var identityServerConnectionString = Configuration.GetConnectionString("IdentityServerConnectionString");

                builder
                .AddConfigurationStore <ISConfigurationDbContext>(options =>
                {
                    options.ConfigureDbContext = configurationDbBuilder =>
                                                 configurationDbBuilder.UseNpgsql(identityServerConnectionString);
                })
                .AddOperationalStore <ISPersistedGrantDbContext>(options =>
                {
                    options.ConfigureDbContext = operationalDbBuilder =>
                                                 operationalDbBuilder.UseNpgsql(identityServerConnectionString);

                    options.EnableTokenCleanup   = true;
                    options.TokenCleanupInterval = (int)TimeSpan.FromDays(1).TotalSeconds;
                });
            }
        }
        RegisterIdentityServerStoresWithDbContexts <TConfigurationDbContext, TPersistedGrantDbContext>(
            IIdentityServerBuilder builder, IConfiguration configuration)
            where TPersistedGrantDbContext : DbContext, IPersistedGrantDbContext
            where TConfigurationDbContext : DbContext, IConfigurationDbContext
        {
            var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

            // Config DB from existing connection
            builder.AddConfigurationStore <TConfigurationDbContext>(options =>
            {
                options.ConfigureDbContext = b => {
                    var provider         = configuration.GetValue <string>(ConfigurationConsts.DatabaseProvider);
                    var connectionString = configuration.GetConnectionString(ConfigurationConsts.ConfigurationDbConnectionStringKey);
                    if ("Sqlite".Equals(provider, StringComparison.OrdinalIgnoreCase))
                    {
                        b.UseSqlite(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly));
                    }
                    else
                    {
                        b.UseSqlServer(connectionString,
                                       sql => sql.MigrationsAssembly(migrationsAssembly));
                    }
                };
            });


            // Operational DB from existing connection
            builder.AddOperationalStore <TPersistedGrantDbContext>(options =>
            {
                options.ConfigureDbContext = b =>
                {
                    var provider         = configuration.GetValue <string>(ConfigurationConsts.DatabaseProvider);
                    var connectionString = configuration.GetConnectionString(ConfigurationConsts.PersistedGrantDbConnectionStringKey);
                    if ("Sqlite".Equals(provider, StringComparison.OrdinalIgnoreCase))
                    {
                        b.UseSqlite(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly));
                    }
                    else
                    {
                        b.UseSqlServer(connectionString,
                                       sql => sql.MigrationsAssembly(migrationsAssembly));
                    }
                };
            });

            return(builder);
        }
Example #27
0
 public static IIdentityServerBuilder AddIdentityServerStores(this IIdentityServerBuilder identityServerBuilder, string connectionString = null)
 {
     connectionString = string.IsNullOrEmpty(connectionString) ?
                        AppConfig.DbConnectionString : connectionString;
     identityServerBuilder.AddConfigurationStore(options =>
     {
         options.ConfigureDbContext = builder => builder.UseNpgsql(connectionString,
                                                                   sql => sql.MigrationsAssembly(AppConfig.MigrationsAssembly));
     })
     .AddOperationalStore(options =>
     {
         options.ConfigureDbContext = builder => builder.UseNpgsql(connectionString,
                                                                   sql => sql.MigrationsAssembly(AppConfig.MigrationsAssembly));
         options.EnableTokenCleanup = true;
     });
     return(identityServerBuilder);
 }
Example #28
0
        public static IIdentityServerBuilder AddEFConfigurationStore(
            this IIdentityServerBuilder builder, string connectionString)
        {
            string assemblyNamespace = typeof(IdentityServerBuilderExtensions)
                                       .GetTypeInfo()
                                       .Assembly
                                       .GetName()
                                       .Name;

            builder.AddConfigurationStore(options =>
                                          options.ConfigureDbContext = b =>
                                                                       b.UseSqlServer(connectionString, optionsBuilder =>
                                                                                      optionsBuilder.MigrationsAssembly(assemblyNamespace)
                                                                                      )
                                          );
            return(builder);
        }
        /// <summary>
        /// IdentityServer4 context config
        /// </summary>
        public static IIdentityServerBuilder OAuth2Store(this IIdentityServerBuilder builder, Action <DbContextOptionsBuilder> databaseConfig)
        {
            builder.AddConfigurationStore(options =>
            {
                options.ConfigureDbContext = databaseConfig;
            })
            // this adds the operational data from DB (codes, tokens, consents)
            .AddOperationalStore(options =>
            {
                options.ConfigureDbContext = databaseConfig;
                // this enables automatic token cleanup. this is optional.
                options.EnableTokenCleanup = true;
                //options.TokenCleanupInterval = 15; // frequency in seconds to cleanup stale grants. 15 is useful during debugging
            });

            return(builder);
        }
Example #30
0
        private static IIdentityServerBuilder RegisterIdentityServerStoresWithDbContexts
        <TConfigurationDbContext, TPersistedGrantDbContext>
            (IIdentityServerBuilder builder, IConfiguration configuration, ILogger logger,
            Action <ConfigurationStoreOptions> configurationStoreOptions, Action <OperationalStoreOptions> operationalStoreOptions)
            where TPersistedGrantDbContext : DbContext, IPersistedGrantDbContext
            where TConfigurationDbContext : DbContext, IConfigurationDbContext
        {
            // Config DB from existing connection
            builder.AddConfigurationStore <TConfigurationDbContext>(configurationStoreOptions);

            // Operational DB from existing connection
            builder.AddOperationalStore <TPersistedGrantDbContext>(operationalStoreOptions);

            builder.AddCustomSigningCredential(configuration, logger);
            builder.AddCustomValidationKey(configuration, logger);

            return(builder);
        }