duendesoftware/duende-skills/aspnetcore-authentication
Claude Code and agent skill by duendesoftware/duende-skills
- community
Checking that the SKILL.md file is still in the repository.
ASP.NET Core authentication middleware configuration including OpenID Connect, JWT Bearer, cookie authentication, authentication schemes, challenge/forbid flows, and external identity provider integration.
Install
npx vskill@latest install duendesoftware/duende-skills/aspnetcore-authenticationSKILL.md
The same SKILL.md was published earlier as duendesoftware/duende-skills/aspnetcore-authentication.
ASP.NET Core Authentication
When to Use This Skill
Use this skill when:
- Configuring OIDC authentication in an ASP.NET Core web application
- Setting up JWT Bearer authentication for an API
- Managing authentication schemes (cookies, OIDC, JWT, external providers)
- Implementing challenge, sign-in, sign-out, and forbid flows
- Debugging authentication failures (401s, redirect loops, claim mapping issues)
- Integrating with Duende IdentityServer as an OpenID Connect provider
- Configuring token validation parameters
Core Principles
- Authentication ≠ Authorization — Authentication establishes who the user is. Authorization (see
aspnetcore-authorization) determines what they can do. - Scheme-Based Architecture — ASP.NET Core authentication is built around named schemes. Each scheme has a handler that knows how to authenticate, challenge, and sign out.
- Cookies for Web Apps, JWT for APIs — Web applications use cookie authentication (with OIDC for login). APIs use JWT Bearer or introspection.
- Never Roll Your Own — Use the built-in OIDC and JWT Bearer handlers. They handle nonce validation, key rotation, token validation, and dozens of edge cases.
- Claim Type Mapping Matters — The OIDC handler maps JWT claim types to .NET claim types by default. Disable this for predictable claim names.
Related Skills
aspnetcore-authorization— Policy-based authorization after authenticationidentityserver-configuration— Server-side client and resource configurationidentityserver-sessions-providers— Server-side sessions to reduce cookie size and maintain IdP-side dataoauth-oidc-protocols— Protocol fundamentals underlying these handlerstoken-management— Automatic token refresh with Duende.AccessTokenManagement
Docs: https://docs.duendesoftware.com/identityserver/apis/aspnetcore/jwt/
Pattern 1: OIDC Authentication for Web Applications
The most common pattern — a server-rendered web app authenticating users via Duende IdentityServer:
Critical Settings Explained
| Setting | Why | Default | |
|---|---|---|---|
MapInboundClaims = false | Prevents renaming sub → http://schemas.xmlsoap.org/.../nameidentifier | true (maps) | |
SaveTokens = true | Stores access/refresh tokens in the cookie for later API calls | false | |
GetClaimsFromUserInfoEndpoint = true | Fetches full profile claims from userinfo | false | |
ResponseType = "code" | Authorization code flow (PKCE is automatic in .NET 7+) | "code" (.NET 7+; was "code id_token" in earlier versions) |
Pattern 2: JWT Bearer Authentication for APIs
APIs validate access tokens issued by IdentityServer:
Multiple Audiences
When an API accepts tokens from multiple resources:
Pattern 3: Reference Token Introspection
For APIs that validate reference tokens (opaque tokens) instead of JWTs:
Install theDuende.AspNetCore.Authentication.JwtBearerpackage which supports both JWT and reference token validation, switching automatically based on the token format.
Combined JWT + Reference Token Support
Pattern 4: Understanding Authentication Schemes
ASP.NET Core uses named authentication schemes. Each scheme is handled by a specific handler.
Default Schemes
The Authentication Flow
Pattern 5: Claim Type Mapping
By default, the Microsoft OIDC handler remaps JWT claims to XML-based .NET claim types. This causes confusion:
The Mapping Problem
| JWT Claim | .NET Default Mapping | After MapInboundClaims = false | |
|---|---|---|---|
sub | http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier | sub | |
name | http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name | name | |
role | http://schemas.microsoft.com/ws/2008/06/identity/claims/role | role | |
email | http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress | email |
The Fix — Always Disable Mapping
Why this matters: Without this,User.FindFirst("sub")returnsnullbecause the claim was renamed. You'd need to use the verbose XML URI instead.
Pattern 6: OIDC Handler Events
The OIDC handler exposes events for customizing the authentication pipeline:
Common Event Use Cases
| Event | Use Case | |
|---|---|---|
OnRedirectToIdentityProvider | Add acr_values, login_hint, or custom parameters | |
OnTokenValidated | Transform claims, load additional user data | |
OnTokenResponseReceived | Inspect raw token response | |
OnRemoteFailure | Custom error handling for failed logins | |
OnSignedOutCallbackRedirect | Custom post-logout redirect |
Pattern 7: Sign-Out
Proper sign-out must clear both the local cookie and the IdentityServer session:
The Sign-Out Flow
Important: Calling onlySignOutAsync("Cookies")withoutSignOutAsync("oidc")leaves the IdentityServer session active. The user will be silently re-authenticated on the next challenge.
Pattern 8: Accessing Stored Tokens
When SaveTokens = true, the access token, refresh token, and ID token are stored in the authentication cookie:
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 reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/aspnetcore-authentication/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/aspnetcore-authentication)