public void AddOperationalStore(IServiceCollection services, IIdentityServerBuilder builder) { bool useRedis = Convert.ToBoolean(Configuration["appOptions:redis:useRedis"]); bool useCosmos = Convert.ToBoolean(Configuration["appOptions:cosmos:useCosmos"]); if (useCosmos) { /* * * "identityServerOperationalStore": { * "database": "identityServer", * "collection": "operational" * } */ var uri = Configuration["appOptions:cosmos:uri"]; var primaryKey = Configuration["appOptions:cosmos:primaryKey"]; var databaseName = Configuration["appOptions:cosmos:identityServerOperationalStore:database"]; var collection = Configuration["appOptions:cosmos:identityServerOperationalStore:collection"]; var cosmosStoreSettings = new CosmosStoreSettings( databaseName, uri, primaryKey, s => { s.ConnectionPolicy = _connectionPolicy; }); builder.AddOperationalStore(cosmosStoreSettings, collection); builder.AddCosmonautIdentityServerCacheStore(cosmosStoreSettings, collection); } else if (useRedis) { var redisConnectionString = Configuration["appOptions:redis:redisConnectionString"]; builder.AddOperationalStore(options => { options.RedisConnectionString = redisConnectionString; options.Db = 1; }) .AddRedisCaching(options => { options.RedisConnectionString = redisConnectionString; options.KeyPrefix = "prefix"; }); services.AddDistributedRedisCache(options => { options.Configuration = redisConnectionString; }); } else { builder.AddInMemoryCaching(); builder.AddInMemoryPersistedGrants(); services.AddDistributedMemoryCache(); } }