duendesoftware/duende-skills/identityserver-stores

Claude Code and agent skill by duendesoftware/duende-skills

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Implement and customize Duende IdentityServer stores including configuration store, operational store, and Entity Framework Core integration. Covers the opt-in Duende Storage provider (preview, see `identityserver-duende-storage`), migrations, custom store implementations, caching strategies, server-side sessions, signing key storage, token cleanup, and multi-tenant patterns.

Install

npx vskill@latest install duendesoftware/duende-skills/identityserver-stores

SKILL.md

The same SKILL.md was published earlier as duendesoftware/duende-skills/identityserver-stores.

Duende IdentityServer Stores

When to Use This Skill

  • You are wiring up AddConfigurationStore() or AddOperationalStore() with EF Core and need correct registration, migration assembly setup, and schema configuration.
  • You are implementing a custom IClientStore, IResourceStore, IPersistedGrantStore, or ISigningKeyStore against a non-EF data source (Redis, Mongo, external API, etc.).
  • You need to enable and tune configuration store caching (AddConfigurationStoreCache(), expiration windows, distributed cache setup) to reduce database load.
  • You are managing EF Core migrations across IdentityServer versions and need to correctly handle schema drift for ConfigurationDbContext and PersistedGrantDbContext.
  • You are enabling server-side sessions (IServerSideSessionStore) and need to understand session lifecycle, cleanup, and storage integration.
  • You are troubleshooting stale client or resource data, expired token accumulation, or signing key rotation failures tied to store configuration.
  • You are designing a multi-tenant IdentityServer deployment and need to choose between database-per-tenant and shared-database store strategies.

Core Principles

Store interfaces decouple IdentityServer from persistence. All data access goes through store interfaces registered in the ASP.NET Core DI container. IdentityServer does not care what database backs them — EF Core, Redis, MongoDB, or a static in-memory collection are all equally valid.

Two independent store categories exist: configuration and operational. They can be used independently or together. Configuration data is relatively static (clients, resources, CORS); operational data is dynamic and high-write (grants, sessions, signing keys). They should be sized, cached, and maintained with those distinct access patterns in mind.

Operational data is protected at rest. The Data payload of persisted grants and serialized signing keys is encrypted using the ASP.NET Core Data Protection API. Key rotation and Data Protection configuration must be coordinated — a lost Data Protection key makes stored grants and signing keys unreadable.

Consumed grants are soft-deleted, not immediately removed. One-time-use grants (e.g., authorization codes, one-time refresh tokens) are marked with a ConsumedTime rather than deleted. This enables threat detection in custom IRefreshTokenService implementations. Do not confuse consumed with expired — the token cleanup service only removes records past their Expiration, not consumed ones (unless RemoveConsumedTokens is enabled).

Store interfaces are runtime contracts, not storage backends. IResourceStore, IClientStore etc. define how IdentityServer loads data, not where it lives. Providers: Entity Framework Core (classic ApiResources/ApiScopes/ApiResourceScopes tables, fully supported), In-Memory, Duende Storage (preview, opt-in alternative, versioned documents; it does *not* replace EF Core), and custom.

EF Core schema changes are your responsibility. Duende does not ship automatic migration scripts or schema upgrade tooling. You own migration creation, application, and data migration between IdentityServer versions.

Docs: https://docs.duendesoftware.com/identityserver/data


NuGet Package

bash
dotnet add package Duende.IdentityServer.EntityFramework

This package provides EF Core implementations for all configuration and operational store interfaces.


Store Architecture

IdentityServer's data is split into two categories, each with its own set of store interfaces:

┌─────────────────────────────────────────────────────────────┐
│ IdentityServer Runtime │
├──────────────────────────┬──────────────────────────────────┤
│ Configuration Data │ Operational Data │
│ │ │
│ • Clients │ • Authorization codes │
│ • API Resources │ • Reference tokens │
│ • API Scopes │ • Refresh tokens │
│ • Identity Resources │ • User consent │
│ • Identity Providers │ • Device codes │
│ • CORS policies │ • Pushed auth. requests │
│ │ • Signing keys │
│ │ • Server-side sessions │
├──────────────────────────┼──────────────────────────────────┤
│ ConfigurationDbContext │ PersistedGrantDbContext │
│ (IClientStore, │ (IPersistedGrantStore, │
│ IResourceStore, │ IDeviceFlowStore, │
│ IIdentityProviderStore,│ IPushedAuthorizationRequestStore,│
│ ICorsPolicyService) │ IServerSideSessionStore, │
│ │ ISigningKeyStore) │
└──────────────────────────┴──────────────────────────────────┘
Configuration Data

Stores static, rarely-changing data that describes how IdentityServer behaves:

InterfaceContents
IClientStoreOAuth/OIDC clients (grant types, redirect URIs, secrets, claims, scopes)
IResourceStoreIdentityResource, ApiResource, and ApiScope definitions
ICorsPolicyServiceCORS allowed-origin rules (derived from client configuration)
IIdentityProviderStoreDynamic external identity provider registrations
Operational Data

Stores dynamic, high-write runtime state that IdentityServer creates and manages during request processing:

InterfaceContents
IPersistedGrantStoreAuthorization codes, refresh tokens, reference tokens, user consent records
IDeviceFlowStoreDevice authorization flow codes and user codes
ISigningKeyStoreDynamically managed signing keys (used by automatic key management)
IServerSideSessionStoreServer-side authentication session data for interactive users
IPushedAuthorizationRequestStorePushed authorization request (PAR) data

EF Core Integration

The Duende.IdentityServer.EntityFramework NuGet package provides EF Core-backed implementations of all store interfaces. It ships two DbContext types:

  • `ConfigurationDbContext` — backs IClientStore, IResourceStore, ICorsPolicyService, IIdentityProviderStore
  • `PersistedGrantDbContext` — backs IPersistedGrantStore, IDeviceFlowStore, ISigningKeyStore, IServerSideSessionStore
Registering Both Stores
IdentityServer 8.1 preview: starting with 8.1.0-preview.4 the EF registrations are named AddEntityFrameworkConfigurationStore and AddEntityFrameworkOperationalStore so they can't be confused with Duende Storage's AddConfigurationStorage/AddOperationalStorage. AddConfigurationStore/AddOperationalStore still work but are [Obsolete]. Examples below use the classic names that work on all versions.
csharp
// ✅ Correct: register both stores with explicit migration assembly
var migrationsAssembly = typeof(Program).Assembly.GetName().Name;
var connectionString = builder.Configuration.GetConnectionString("IdentityServer");
builder.Services.AddIdentityServer()
.AddConfigurationStore(options =>
{
options.ConfigureDbContext = b =>
b.UseSqlServer(connectionString, sql =>
sql.MigrationsAssembly(migrationsAssembly));
})
.AddOperationalStore(options =>
{
options.ConfigureDbContext = b =>
b.UseSqlServer(connectionString, sql =>
sql.MigrationsAssembly(migrationsAssembly));
options.EnableTokenCleanup = true;
options.TokenCleanupInterval = 3600; // seconds; default 1 hour
});
csharp
// ❌ Wrong: omitting MigrationsAssembly when migrations live in the host project
builder.Services.AddIdentityServer()
.AddConfigurationStore(options =>
{
options.ConfigureDbContext = b => b.UseSqlServer(connectionString);
// EF will look for migrations in Duende.IdentityServer.EntityFramework.dll
// and fail to find them
});
Separate Schemas

Isolate configuration and operational tables using DefaultSchema to avoid naming collisions and simplify backup strategies:

csharp
// ✅ Recommended for production: dedicated schemas per store
builder.Services.AddIdentityServer()
.AddConfigurationStore(options =>
{
options.DefaultSchema = "idscfg";
options.ConfigureDbContext = b =>
b.UseSqlServer(connectionString, sql =>
{
sql.MigrationsAssembly(migrationsAssembly);
sql.MigrationsHistoryTable("__ConfigMigrationsHistory", "idscfg");
});
})
.AddOperationalStore(options =>
{
options.DefaultSchema = "idsop";
options.ConfigureDbContext = b =>
b.UseSqlServer(connectionString, sql =>
{
sql.MigrationsAssembly(migrationsAssembly);
sql.MigrationsHistoryTable("__OperationalMigrationsHistory", "idsop");
});
});

Migrations

EF Core migrations must be created in the host assembly. IdentityServer does not generate or apply migrations automatically.

Creating Migrations
shell
# Configuration store migration
dotnet ef migrations add InitialIdentityServerConfigurationDb \
--context ConfigurationDbContext \
--output-dir Data/Migrations/IdentityServer/ConfigurationDb
# Operational store migration
dotnet ef migrations add InitialIdentityServerOperationalDb \
--context PersistedGrantDbContext \
--output-dir Data/Migrations/IdentityServer/OperationalDb
Applying Migrations at Startup
csharp
// ✅ Apply EF migrations on startup (suitable for dev/staging; use a deploy pipeline in production)
public static void InitializeDatabase(IApplicationBuilder app)
{
using var serviceScope = app.ApplicationServices
.GetRequiredService<IServiceScopeFactory>()
.CreateScope();
serviceScope.ServiceProvider
.GetRequiredService<PersistedGrantDbContext>()
.Database
.Migrate();
var configContext = serviceScope.ServiceProvider
.GetRequiredService<ConfigurationDbContext>();
configContext.Database.Migrate();
// Seed initial configuration data if empty
if (!configContext.Clients.Any())
{
foreach (var client in Config.Clients)
configContext.Clients.Add(client.ToEntity());
configContext.SaveChanges();
}
}
Handling Schema Updates Across Versions

When upgrading IdentityServer, always check the upgrade guide for schema changes before applying the new package version:

  1. Review the changelog for any new columns or tables in ConfigurationDbContext or PersistedGrantDbContext.
  2. Scaffold a new EF migration: dotnet ef migrations add UpgradeToV7x --context ConfigurationDbContext.
  3. Review the generated migration SQL — especially for columns with NOT NULL constraints that require backfill.
  4. Apply to a staging environment and validate before production.
csharp
// ❌ Never auto-apply migrations in production startup without a health gate
// This causes downtime on multi-instance deployments where one instance
// applies the migration while others still run against the old schema
app.ApplicationServices.GetRequiredService<ConfigurationDbContext>()
.Database.Migrate(); // Dangerous in multi-node deployments

Caching Configuration Data

Configuration data (clients, resources, CORS) is read on every token request. Without caching, every request hits the database.

EF Store Caching (Recommended)
csharp
// ✅ Enable cache for the EF configuration store (v8: uses HybridCache)
builder.Services.AddIdentityServer()
.AddConfigurationStore(options => { /* ... */ })
.AddConfigurationStoreCache(); // wraps EF stores with HybridCache

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
9
Repository forks
3
7-day trend score
0

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/duendesoftware/duende-skills/identityserver-stores/badge)](https://verified-skill.com/skills/duendesoftware/duende-skills/identityserver-stores)

Something wrong with this skill or its page? Tell us.