duendesoftware/duende-skills/identityserver-sessions-providers

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.

Guide for configuring server-side sessions, session management and querying, inactivity timeout, dynamic identity providers, and CIBA (Client Initiated Backchannel Authentication) in Duende IdentityServer.

Install

npx vskill@latest install duendesoftware/duende-skills/identityserver-sessions-providers

SKILL.md

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

IdentityServer Sessions, Dynamic Providers, and CIBA

When to Use This Skill

  • Enabling and configuring server-side sessions for authentication state management
  • Implementing session querying, revocation, and administrative tooling via ISessionManagementService
  • Configuring inactivity timeout across IdentityServer and client applications
  • Setting up the Entity Framework Core session store or implementing a custom IServerSideSessionStore
  • Adding dynamic identity providers loaded from a database at runtime
  • Implementing custom non-OIDC dynamic provider types (Google, SAML, etc.)
  • Building a CIBA (Client Initiated Backchannel Authentication) flow
  • Understanding edition requirements (Business vs Enterprise) for these features

Docs: https://docs.duendesoftware.com/identityserver/ui/server-side-sessions/

Server-Side Sessions

What Problem Do They Solve?

By default, ASP.NET Core stores all authentication session state in a self-contained cookie. This creates several challenges:

ProblemImpact
Cookie size growthAs clients are tracked, the cookie grows; large cookies can exceed browser limits
No session visibilityCannot query how many active sessions exist
No administrative revocationCannot terminate a session from outside the user's browser
No server-side coordinationCannot detect inactivity or synchronize session expiration across clients

Server-side sessions store authentication state on the server, keeping only a session reference in the cookie.

Edition Requirements

Server-side sessions are part of the Duende IdentityServer Business and Enterprise Edition.

Enabling Server-Side Sessions
csharp
// Program.cs
builder.Services.AddIdentityServer()
.AddServerSideSessions();

Important: This call must come after any custom IRefreshTokenService implementation registration. Order matters in the ASP.NET Core service provider.

By default, sessions are stored in-memory. For production, use Entity Framework Core or a custom store.

Using Entity Framework Core Store
csharp
// Program.cs
builder.Services.AddIdentityServer()
.AddServerSideSessions()
.AddOperationalStore(options =>
{
options.ConfigureDbContext = builder =>
builder.UseSqlServer(connectionString,
sql => sql.MigrationsAssembly(migrationsAssembly));
});

The EF Core implementation is included in the operational store and supports the IServerSideSessionStore interface automatically.

Custom Session Store

Implement IServerSideSessionStore and register it:

csharp
// Program.cs — two-step registration
builder.Services.AddIdentityServer()
.AddServerSideSessions()
.AddServerSideSessionStore<YourCustomStore>();
// Or one-step registration
builder.Services.AddIdentityServer()
.AddServerSideSessions<YourCustomStore>();
Data Stored Server-Side

The session stores the serialized ASP.NET Core AuthenticationTicket (all claims + AuthenticationProperties.Items). The data is protected using ASP.NET Core's Data Protection API.

Queryable indices extracted from the session:

IndexSource
Subject IDsub claim value
Session IDsid claim value
Display NameConfigurable claim type (e.g., name or email)

Configure the display name claim. Note: UserDisplayNameClaimType is unset (null) by default due to PII concerns. You must explicitly set it if you want display names stored in the session index:

csharp
// Program.cs
builder.Services.AddIdentityServer(options => {
options.ServerSideSessions.UserDisplayNameClaimType = "name";
}).AddServerSideSessions();

Session Management with ISessionManagementService

Querying Sessions
csharp
var userSessions = await _sessionManagementService.QuerySessionsAsync(new SessionQuery
{
CountRequested = 10,
SubjectId = "12345",
DisplayName = "Bob",
});
Paging Through Results
csharp
// First page
var userSessions = await _sessionManagementService.QuerySessionsAsync(new SessionQuery
{
CountRequested = 10,
});
// Next page
userSessions = await _sessionManagementService.QuerySessionsAsync(new SessionQuery
{
ResultsToken = userSessions.ResultsToken,
CountRequested = 10,
});
// Previous page
userSessions = await _sessionManagementService.QuerySessionsAsync(new SessionQuery
{
ResultsToken = userSessions.ResultsToken,
RequestPriorResults = true,
CountRequested = 10,
});
Performance Note on Querying

When listing sessions, prefer GetSessionsAsync over QuerySessionsAsync. The QuerySessionsAsync method performs a full-text search and may be slower. Use QuerySessionsAsync only when advanced filtering is needed.

Terminating Sessions

Terminate sessions and optionally revoke tokens, consents, and send back-channel logout notifications:

csharp
// Revoke everything for a user
await _sessionManagementService.RemoveSessionsAsync(new RemoveSessionsContext
{
SubjectId = "12345"
});

Selective revocation (filtering by SessionId or ClientIds is also supported):

csharp
// Only revoke refresh tokens, keep session and consents
await _sessionManagementService.RemoveSessionsAsync(new RemoveSessionsContext
{
SubjectId = "12345",
SessionId = "abc123", // optional: target a specific session
ClientIds = { "my_app" }, // optional: target specific clients
RevokeTokens = true,
RemoveServerSideSession = false,
RevokeConsents = false,
SendBackchannelLogoutNotification = false,
});
What Gets Cleaned Up
FlagEffect
RemoveServerSideSession (default: true)Deletes the session record from the store
RevokeTokens (default: true)Revokes refresh tokens and reference access tokens
RevokeConsents (default: true)Removes persisted consent grants
SendBackchannelLogoutNotification (default: true)Sends back-channel logout to clients with BackChannelLogoutUri

Internally, this uses IServerSideTicketStore, IPersistedGrantStore, and IBackChannelLogoutService.

What Logout Does and Doesn't Clean Up

SignOutAsync removes the IdentityServer cookie (and the server-side session record when enabled). By default it does not sign out of the external IdP, notify clients, or revoke tokens:

ArtifactDefault at logoutHow to clean up
IdentityServer cookieRemoved by SignOutAsync-
Server-side session recordRemoved automatically when enabled-
External IdP sessionNot signed outExternal logout flow
Client app sessionsNot cleaned unless notifiedFront/back-channel notification
Refresh tokens & reference access tokensKeptCoordinateLifetimeWithUserSession on the client, or global Authentication.CoordinateClientLifetimesWithUserSession (a client's own value wins; no server-side sessions required)
JWT access tokensNever revoked, expire on their ownKeep lifetime short
Consents / other grantsKeptISessionManagementService / IPersistedGrantService (coordination does not revoke consents)
BFF session + refresh tokenRefresh token revoked by default on BFF logout-

When a server-side session expires (no explicit logout), clients with a coordinated lifetime have tokens revoked and get a back-channel logout; other clients are only notified when ExpiredSessionsTriggerBackchannelLogout = true (default false). ISessionManagementService.RemoveSessionsAsync (admin-initiated termination) removes the session, sends back-channel logout, revokes tokens and consents by default; each step can be turned off.

Server-Side Session Custom Metadata

Store per-sign-in metadata (device name, auth method, region) in the AuthenticationTicket's AuthenticationProperties.Items. It stays inside IdentityServer and is NOT issued as claims.

Writing Metadata
csharp
var properties = new AuthenticationProperties();
properties.Items["device_name"] = "Bob's iPhone";
properties.Items["region"] = "eu-west";
await HttpContext.SignInAsync(identityServerUser, properties);

With ASP.NET Identity, pass properties to SignInWithClaimsAsync:

csharp
await _signInManager.SignInWithClaimsAsync(user, properties, additionalClaims: []);

If you use PasswordSignInAsync (which does not accept properties), override SignInWithClaimsAsync in a custom SignInManager to inject the metadata.

Reading Metadata
csharp
var sessions = await _sessionManagementService.QuerySessionsAsync(
new SessionQuery { SubjectId = "12345" });
foreach (var session in sessions.Results)
{
if (session.AuthenticationTicket.Properties.Items
.TryGetValue("device_name", out var deviceName))
{
// use deviceName
}
}

Limitation: custom metadata is not indexed by the built-in store — you cannot filter SessionQuery by it. Query by subject id, session id, or display name first, then inspect the tickets.

Inactivity Timeout

The Challenge

OpenID Connect does not natively provide distributed session management based on user inactivity. Multiple artifacts (cookies, refresh tokens, access tokens) have independent lifetimes controlled by different entities. Coordinating their expiration is non-trivial.

Design: Centralized Session Tracking

Server-side sessions at IdentityServer provide the central record for monitoring user activity:

  1. Activity signals: As the user's client uses refresh tokens, introspection, or userinfo, these protocol calls extend the server-side session automatically via an internal ISessionCoordinationService (this is an implementation detail, not a public API for consumers).
  2. Inactivity detection: When no activity occurs within the session timeout, the session expires and cleanup is triggered (back-channel logout, token revocation).
Configuration at IdentityServer

Three features must be enabled:

csharp
// Program.cs
builder.Services.AddIdentityServer(options =>
{
// 1. Enable server-side sessions
// (done separately via .AddServerSideSessions())
// 2. Coordinate client token lifetimes with the user session
options.Authentication.CoordinateClientLifetimesWithUserSession = true;
// 3. Also notify clients WITHOUT coordinated lifetimes when sessions expire
// Defaults to false. Clients with a coordinated token lifetime are always
// notified on expiry, regardless of this flag.
options.ServerSideSessions.ExpiredSessionsTriggerBackchannelLogout = true;
}).AddServerSideSessions();

Note: ExpiredSessionsTriggerBackchannelLogout defaults to false. When a server-side session expires, IdentityServer always revokes refresh/reference tokens and sends a back-channel logout notification to clients with a coordinated token lifetime (CoordinateLifetimeWithUserSession, or the global CoordinateClientLifetimesWithUserSession). Other clients in the session are only notified when you set the flag to true.

Alternatively, enable coordination per-client:

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-sessions-providers/badge)](https://verified-skill.com/skills/duendesoftware/duende-skills/identityserver-sessions-providers)

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