duendesoftware/duende-skills/identityserver-aspire
Claude Code and agent skill by duendesoftware/duende-skills
- community
Checking that the SKILL.md file is still in the repository.
Orchestrate Duende IdentityServer in .NET Aspire AppHost — dependency graphs, authority URL wiring, health checks, and multi-instance.
Install
npx vskill@latest install duendesoftware/duende-skills/identityserver-aspireSKILL.md
The same SKILL.md was published earlier as duendesoftware/duende-skills/identityserver-aspire.
Orchestrating IdentityServer with .NET Aspire
When to Use This Skill
Use this skill when:
- Adding Duende IdentityServer to an Aspire-orchestrated solution
- Configuring service dependencies so clients and APIs wait for IdentityServer
- Passing IdentityServer's authority URL to dependent services via Aspire
- Wiring database resources for IdentityServer configuration and operational stores
- Ensuring IdentityServer exposes health checks for Aspire startup ordering
- Adding IdentityServer telemetry sources to Aspire service defaults
- Running multiple IdentityServer replicas in Aspire
- Integration testing an Aspire solution that includes IdentityServer
Core Principles
- IdentityServer is a startup dependency — Every client app and API depends on IdentityServer being available for discovery, token validation, and OIDC flows. Model this with
WithReference()+WaitFor(). - Explicit configuration over service discovery — Pass the authority URL, client IDs, and scopes as explicit environment variables. App code reads
IConfiguration/IOptions<T>, never Aspire service discovery. - Health checks enable startup ordering — Aspire's
WaitFor()requires the target to expose a healthy health check endpoint. IdentityServer must be configured with health checks for startup ordering to work. - Cross-reference, don't duplicate — General Aspire and IdentityServer patterns are covered by existing skills. This skill covers only the unique orchestration intersection.
Related Skills
identityserver-hosting-setup— IdentityServer DI and middleware pipelineidentityserver-deployment— production deployment, data protection, health check implementationsidentityserver-data-storage— EF Core stores for configuration and operational data
Docs: https://docs.duendesoftware.com/identityserver/deployment/
Pattern 1: AppHost Orchestration Basics
IdentityServer is added to an Aspire AppHost like any ASP.NET Core project. The key addition is wiring its database dependency so the database is ready before IdentityServer starts.
WaitFor(sqlServer) ensures the database is accepting connections before IdentityServer starts. This matters because IdentityServer connects to EF Core stores on startup for configuration and operational data.
Important: The IdentityServer project itself is a standard ASP.NET Core application.Seeidentityserver-hosting-setupfor DI registration and middleware pipeline setup.This skill focuses only on how the AppHost orchestrates it.
Pattern 2: Service Dependency Graph
This is the most critical pattern. Clients and APIs must depend on IdentityServer because:
- Clients download the discovery document (
.well-known/openid-configuration) at
startup to configure OIDC flows
- APIs configured with JWT Bearer authentication download JWKS (signing keys) from
IdentityServer at startup to validate tokens
- OIDC login redirects fail if IdentityServer isn't running when a user tries to
sign in
Without explicit dependency ordering, services start in parallel and fail with cryptic "unable to obtain configuration" errors.
Full dependency graph
What each call does
| Call | Effect | |
|---|---|---|
.WithReference(identityServer) | Makes the IdentityServer endpoint URL available to the dependent service via service discovery | |
.WaitFor(identityServer) | Holds the dependent service from starting until IdentityServer's health check returns healthy |
Both are needed. WithReference alone provides the URL but doesn't prevent premature startup. WaitFor alone doesn't expose the endpoint URL.
Dependency flow
Important: WithoutWaitFor(identityServer), the API and web app may start beforeIdentityServer is ready, causingHttpRequestExceptionwhen fetching the discoverydocument or JWKS. This leads to `InvalidOperationException: IDX20803: Unable to obtainconfiguration from 'https://.../.well-known/openid-configuration'` errors at startup.
Pattern 3: Authority URL and OIDC Configuration
WithReference(identityServer) makes the endpoint available via Aspire service discovery, but client applications need explicit configuration for the OIDC authority URL, client ID, and scopes. Use WithEnvironment to pass these as standard configuration values.
Web application (OIDC client)
API (JWT Bearer)
Issuer URI consideration
By default, IdentityServer infers the issuer URI from incoming requests, which works correctly within Aspire's network. Only override if the internal URL differs from what clients see:
Important: Do NOT setIssuerUriunless the internal Aspire URL differs from whatclients see. Mismatched issuer URIs cause token validation failures — theissclaim intokens won't match the expected authority.
See aspire-configuration for the general pattern of reading these values via IOptions<T> in the app project.
When generating app code: The environment variables above map to standardIConfigurationkeys (Authentication:Authority,Authentication:ClientId,Authentication:Scopes:0, etc.). When scaffolding the web app, configureAddOpenIdConnectto readAuthorityandClientIdfrombuilder.Configuration["Authentication:Authority"]andbuilder.Configuration["Authentication:ClientId"]. Bind scopes from theAuthentication:Scopesconfiguration section. For the API, configureAddJwtBearerwithoptions.Authorityfrombuilder.Configuration["Authentication:Authority"].Seeaspnetcore-authenticationfor full OIDC and JWT Bearer middleware setup.Seeaspire-configurationfor the generalIOptions<T>binding pattern.
Pattern 4: Database and Store Wiring
IdentityServer typically needs its own database for configuration and operational stores. Other services in the solution use separate databases for application data.
Separate databases per service
WithReference(identityDb) sets ConnectionStrings__identitydb automatically. The IdentityServer project's EF stores must use this connection string name:
Migration strategies
- Option A: Startup migration — Call
Database.MigrateAsync()inProgram.cs. Simple
and suitable for development.
- Option B: Dedicated migration service — Add a separate migration runner project that
runs before IdentityServer:
See identityserver-data-storage for EF Core store configuration details and migration patterns.
Pattern 5: Health Checks for Startup Readiness
Aspire's WaitFor() polls the target's /health endpoint. If IdentityServer doesn't expose a health check, WaitFor() has no readiness signal and dependent services may start too early or the AppHost may time out waiting.
Minimal health check setup
Enhanced health checks with readiness validation
For production-grade startup ordering, add checks that validate IdentityServer can actually serve discovery documents and signing keys:
The DiscoveryDocumentHealthCheck and DiscoveryKeysHealthCheck verify that IdentityServer can serve its discovery document and signing keys. These checks catch configuration errors (missing signing credentials, database connection failures) before dependent services try to connect.
Important: TheDiscoveryDocumentHealthCheckandDiscoveryKeysHealthCheckimplementations are covered in theidentityserver-deploymentskill. Use them to ensureIdentityServer is fully operational before dependent services start.
If using AddServiceDefaults() from the Aspire service defaults project, the /health and /alive endpoints are already mapped. You still need to register the IdentityServer-specific health checks in the DI container.
Pattern 6: Service Defaults Integration
IdentityServer emits OpenTelemetry traces and metrics under specific source names. To see them in the Aspire dashboard, add these sources in the shared service defaults project.
Tracing sources
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/identityserver-aspire/SKILL.md
Popularity
- 7-day trend score
- 0
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-aspire)