Configure IdentityServer4 ConfigurationStore and OperationalStore in a Multi-Tenant Environment

Viewed 184

We have a web API that used IdentityServer4 for authentication. I am trying to change the authentication service to support multi-tenancy by keeping existing DBs. So there are separate DB for each tenant.

I am currently struggling to configure ConfigurationStore and OperationalStore.

Option 01: Since we have separate DB for each tenant, ConfigurationDb and PersistedGrantDb related tables can be added to those DBs.

Option 02: Use common DB to keep ConfigurationDb and PersistedGrantDb related tables.

What would be the best approach?

services.AddIdentityServer()
    // this adds the config data from DB (clients, resources, CORS)
    .AddConfigurationStore(options =>
    {
        options.ConfigureDbContext = builder =>
            builder.UseSqlServer(connectionString,
                sql => sql.MigrationsAssembly(migrationsAssembly));
    })
    .AddOperationalStore(options =>
    {
        options.ConfigureDbContext = builder =>
            builder.UseSqlServer(connectionString,
                sql => sql.MigrationsAssembly(migrationsAssembly));

        // this enables automatic token cleanup. this is optional.
        options.EnableTokenCleanup = true;
        options.TokenCleanupInterval = 30; // interval in seconds
    });
1 Answers

We couldn't find a way to configure ConfigurationStore and OperationalStore in separate DBs. Since that we have configured them in our common DB. So final DB structure is like following.

  • TenantDB: Common DB to all the tenants. Holds tenant configurations like tenant name, host/domain details, connection strings. And ConfigurationStore and OperationalStore configurations.
  • Tenant01DB : Tenant 01 Data
  • Tenant02DB : Tenant 02 Data
  • Tenant03DB : Tenant 03 Data
Related