duendesoftware/duende-skills/identityserver-token-lifecycle
Claude Code and agent skill by duendesoftware/duende-skills
- community
Checking that the SKILL.md file is still in the repository.
Guide for implementing token types, refresh token management, token exchange (RFC 8693), extension grants, IProfileService claims customization, and token lifetime best practices in Duende IdentityServer.
Install
npx vskill@latest install duendesoftware/duende-skills/identityserver-token-lifecycleSKILL.md
The same SKILL.md was published earlier as duendesoftware/duende-skills/identityserver-token-lifecycle.
IdentityServer Token Types, Refresh Tokens, and Token Exchange
When to Use This Skill
- Choosing between JWT and reference access tokens for a client
- Configuring refresh token rotation, sliding expiration, or replay detection
- Implementing token exchange (RFC 8693) for impersonation or delegation
- Building an extension grant validator (
IExtensionGrantValidator) - Customizing which claims appear in identity tokens, access tokens, or userinfo responses via
IProfileService - Setting token lifetime policies for access tokens and refresh tokens
- Issuing internal tokens from extensibility code via
IIdentityServerTools - Understanding identity tokens vs access tokens and their intended audiences
Docs: https://docs.duendesoftware.com/identityserver/tokens
Token Types Overview
Duende IdentityServer issues three primary token types:
| Token Type | Purpose | Audience | Format | |
|---|---|---|---|---|
| Identity Token | Communicates authentication event to the client | Client application only (aud claim) | Always JWT | |
| Access Token | Authorizes access to a protected resource (API) | API / Resource Server | JWT or Reference | |
| Refresh Token | Obtains new access tokens without user interaction | Token endpoint only | Opaque handle |
Key Principles
- Identity tokens are solely for the client application that initiated the authentication. Never send an identity token to an API.
- Access tokens are for APIs. They contain client ID, scopes, expiration, and optionally user claims.
- Refresh tokens enable long-lived API access by allowing the client to request new access tokens silently.
Identity Tokens
Identity tokens are JWTs that describe "what happened at the token service". They contain:
iss— the issuer (your IdentityServer URL)sub— the authenticated user's unique identifieraud— the client that requested authenticationauth_time— when the user authenticatedamr— authentication method (e.g.,pwd)idp— identity provider used (e.g.,local)sid— the session IDnonce— ensures the token is consumed only once at the client
Access Tokens: JWT vs Reference
JWT Access Tokens
All claims are embedded in the token. The API validates the token by checking the signature using the issuer's public keys (from the JWKS endpoint). JWTs cannot be revoked before their expiration — the only invalidation mechanism is waiting for exp.
Reference Access Tokens
Reference tokens are pointers to token data stored in the persisted grant store. The API must call the introspection endpoint to validate the token. Reference tokens support immediate revocation by deleting the stored data.
Trade-off — immediate revocation vs network dependency: because claims live in the persisted grant store, an API cannot validate a reference token on its own; it must call introspection (or hit its introspection cache). Deleting the record revokes immediately (JWTs stay valid until exp), but the API needs a live connection to IdentityServer, which is a poor fit for offline/air-gapped/intermittently connected APIs. Reference tokens are not tied to the user session by default: set CoordinateLifetimeWithUserSession (client) or Authentication.CoordinateClientLifetimesWithUserSession to revoke them at logout / session expiry (see identityserver-sessions-providers).
The API consuming reference tokens must have a secret configured on the ApiResource:
Decision Matrix: JWT vs Reference Tokens
| Criterion | JWT | Reference | |
|---|---|---|---|
| Revocability | No (expires naturally) | Yes (immediate, delete from store) | |
| API call to validate | No (self-contained) | Yes (introspection endpoint) | |
| Network dependency | None at validation time | Requires IdentityServer availability | |
| Token size | Larger (contains all claims) | Small (just a handle) | |
| Performance at scale | Better (no server call) | Introspection adds latency | |
| Best for | High-throughput APIs, microservices | Sensitive APIs needing revocation |
Token Revocation (RFC 7009)
Revocation via the /connect/revocation endpoint applies only to reference access tokens and refresh tokens — the tokens that are persisted in the operational (persisted grant) store. A JWT access token is stateless and is not stored server-side by default, so there is no revocation state to deactivate: a JWT simply remains valid until its exp. If you need to invalidate access tokens immediately (logout, compromise, entitlement change), issue reference tokens (AccessTokenType.Reference).
Controlling Token Format Per Client
Refresh Tokens
Refresh tokens allow clients to obtain new access tokens without user interaction. They are supported for authorization code, hybrid, and resource owner password credential flows.
Requesting Refresh Tokens
The client must:
- Have
AllowOfflineAccess = trueon its configuration - Request the
offline_accessscope in the authorize request
Using Duende.IdentityModel:
Refresh Token Lifetime Settings
| Setting | Description | Recommendation | |
|---|---|---|---|
AbsoluteRefreshTokenLifetime | Maximum lifetime regardless of activity (seconds) | Set based on security policy (e.g., 30 days) | |
SlidingRefreshTokenLifetime | Extends token life on each use, up to the absolute limit | Use for "remember me" scenarios (e.g., 1 day sliding) | |
RefreshTokenExpiration | Absolute or Sliding | Use Sliding with a reasonable absolute cap |
Rotation (OneTime vs ReUse)
Configured via RefreshTokenUsage on the client:
| Mode | Behavior | Trade-offs | |
|---|---|---|---|
ReUse (default since v7.0) | Same refresh token is reused across requests | Robust to network failures, lower DB pressure | |
OneTime | New refresh token issued on each use; old one consumed | Limited security benefit, risk of losing token on network failure |
Why `ReUse` is the default: Rotating tokens on every use has limited security benefits regardless of client type. Reusable tokens are robust to network failures — if a one-time-use token is used but the response is lost, the client cannot recover without forcing a new login. Reusable tokens also have better performance since they avoid extra writes to the persisted grant store.
Accepting Consumed Tokens (Network Failure Resilience)
To make one-time-use tokens more resilient, subclass DefaultRefreshTokenService and override AcceptConsumedTokenAsync:
Register it:
Important: For this to work, PersistentGrantOptions.DeleteOneTimeOnlyRefreshTokensOnUse must be false so consumed tokens are marked rather than deleted.
Replay Detection
If a consumed refresh token is reused, it could indicate a replay attack. You can extend AcceptConsumedTokenAsync to revoke all access for the user/client:
- Delete all refresh tokens for the user/client
- Revoke reference access tokens
- End the user's server-side session
- Send back-channel logout notifications
- Alert the user
Caution: This is disruptive and can produce false positives from network failures or client bugs.
Token Cleanup Configuration
Token Exchange (RFC 8693)
Token exchange allows translating between token types. Common use cases: impersonation, delegation, SAML-to-JWT conversion.
Implementing Token Exchange
Implement IExtensionGrantValidator:
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
- SKILL.md in the repositoryCheckingskills/identityserver-token-lifecycle/SKILL.md
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
[](https://verified-skill.com/skills/duendesoftware/duende-skills/identityserver-token-lifecycle)