duendesoftware/duende-skills/identityserver-hosting-setup
Claude Code and agent skill by duendesoftware/duende-skills
- community
Checking that the SKILL.md file is still in the repository.
Setting up and hosting Duende IdentityServer in ASP.NET Core applications, including DI registration, middleware pipeline, hosting patterns, essential options, license configuration, and ASP.NET Identity integration.
Install
npx vskill@latest install duendesoftware/duende-skills/identityserver-hosting-setupSKILL.md
The same SKILL.md was published earlier as duendesoftware/duende-skills/identityserver-hosting-setup.
Setting Up and Hosting IdentityServer
When to Use This Skill
- Setting up a new Duende IdentityServer project from scratch
- Configuring the ASP.NET Core DI system and middleware pipeline for IdentityServer
- Deciding between separate vs shared hosting patterns
- Integrating IdentityServer with ASP.NET Identity for user management
- Configuring
IdentityServerOptions(issuer, key management, endpoints) - Setting up proxy/load balancer forwarded headers
- Configuring data protection for production deployments
- Understanding the IdentityServer middleware pipeline ordering
Docs: https://docs.duendesoftware.com/identityserver/fundamentals
Core Concepts
Duende IdentityServer is middleware that adds OpenID Connect and OAuth 2.0 endpoints to an ASP.NET Core host. It requires two setup steps: registering services in DI and adding middleware to the request pipeline.
Architecture Decision: Separate vs Shared Host
IdentityServer should be in its own dedicated application to minimize the attack surface. While it is technically possible to co-host IdentityServer with clients or APIs, this is not recommended.
| Hosting Pattern | Pros | Cons | |
|---|---|---|---|
| Separate host (recommended) | Minimal attack surface, independent scaling, clear security boundary | Additional deployment artifact | |
| Shared with web app | Fewer projects | Larger attack surface, coupled deployments | |
| Shared with API | Fewer projects | Security risk, conflicting middleware needs |
Step 1: Install Templates and Create a Project
The duende-is-empty template creates a minimal project with the IdentityServer NuGet package installed and basic configuration.
Step 2: Register IdentityServer Services (DI)
Call AddIdentityServer on the service collection to register all necessary services. This method also calls AddAuthentication internally.
Adding Configuration Stores
The builder object returned by AddIdentityServer provides extension methods to add configuration stores for clients, resources, and scopes:
Store options:
- In-memory stores - good for development, demos, and static configuration
- EntityFramework stores - production-ready, supports dynamic configuration
- Custom stores - implement the store interfaces for any backing store
Minimal Working Example
Step 3: Configure the Request Pipeline
Add UseIdentityServer middleware to the pipeline. Pipeline ordering is critical.
Pipeline Ordering Rules
| Order | Middleware | Notes | |
|---|---|---|---|
| 1 | UseStaticFiles() | Before IdentityServer | |
| 2 | UseRouting() | Before IdentityServer | |
| 3 | UseIdentityServer() | Includes UseAuthentication() internally | |
| 4 | UseAuthorization() | Required after IdentityServer, must not be omitted | |
| 5 | MapDefaultControllerRoute() | UI framework endpoints |
Common Pipeline Anti-Patterns
Step 4: Configure Essential IdentityServerOptions
Key Configuration Properties
| Property | Default | Purpose | |
|---|---|---|---|
IssuerUri | inferred from URL | Token issuer name in discovery and tokens | |
LowerCaseIssuerUri | true | Lowercase inferred issuer URIs | |
AccessTokenJwtType | "at+jwt" | typ header in JWT access tokens (RFC 9068) | |
EmitScopesAsSpaceDelimitedStringInJwt | false | Scope claim format in JWTs | |
EmitStaticAudienceClaim | false | Static aud claim in {issuer}/resources format | |
EmitIssuerIdentificationResponseParameter | true | iss param on authorize responses (RFC 9207) |
Step 5: Configure the License Key
Duende IdentityServer requires a valid license for production use. Without a license key, IdentityServer runs in trial/community mode and will log a warning on startup.
Set the license key via options.LicenseKey or via configuration:
Store the key in a secret manager, environment variable, or key vault — never in source-controlled appsettings.json.
Step 6: ASP.NET Identity Integration
To use ASP.NET Identity as the user store for IdentityServer, install the integration package and configure both systems:
What AddAspNetIdentity Configures
AddAspNetIdentity<TUser> registers the following IdentityServer implementations:
- `IProfileService` - uses
IUserClaimsPrincipalFactoryto add claims to tokens - `IResourceOwnerPasswordValidator` - supports the password grant type
- `IUserClaimsPrincipalFactory` - a wrapper implementation that calls through to the previously registered factory and adds extra IdentityServer-specific claims
Custom IUserClaimsPrincipalFactory
If you register a custom IUserClaimsPrincipalFactory before calling AddAspNetIdentity, the IdentityServer registration will resolve your factory and call through to it, layering additional claims on top:
Inactive User Handling
ASP.NET Identity has no built-in concept of inactive users. The default IsActiveAsync implementation returns true. To support enable/disable functionality:
Template Alternative
Use the duende-is-aspid template for a pre-configured ASP.NET Identity integration:
Production Deployment: Proxy and Load Balancer Configuration
When behind a reverse proxy or load balancer, the proxy obscures request scheme and IP address. This causes common symptoms:
- HTTPS downgraded to HTTP in discovery document
- Incorrect host names in discovery or redirects
- Cookies missing the
secureattribute
Solution: Forwarded Headers Middleware
Option 1: Environment variable (simple) Set ASPNETCORE_FORWARDEDHEADERS_ENABLED=true for cloud/Kubernetes environments.
Option 2: Explicit configuration (production)
Add UseForwardedHeaders() early in the pipeline, before UseIdentityServer().
Production Deployment: Data Protection
Data protection is critical for IdentityServer. It protects signing keys at rest, persisted grants, server-side sessions, and authentication cookies. See ASP.NET Core Data Protection for comprehensive guidance covering all Duende SDKs.
Data Protection Checklist
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-hosting-setup/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-hosting-setup)