duendesoftware/duende-skills/claims-authorization
Claude Code and agent skill by duendesoftware/duende-skills
- community
Checking that the SKILL.md file is still in the repository.
Claims transformation and profile service patterns for Duende IdentityServer — IProfileService, IClaimsTransformation, claim type mapping, token claim filtering, extension grant validators, and dynamic claims loading.
Install
npx vskill@latest install duendesoftware/duende-skills/claims-authorizationSKILL.md
The same SKILL.md was published earlier as duendesoftware/duende-skills/claims-authorization.
Claims Transformation & Profile Service
When to Use This Skill
- You are implementing or customizing
IProfileServiceto control which claims are emitted into identity tokens, access tokens, or the userinfo endpoint. - You need to map claims from an external identity provider (Google, Azure AD, SAML, etc.) into your IdentityServer user principal during login callback processing.
- You are configuring
IdentityResource,ApiScope, orApiResourceUserClaimscollections and need to understand how requested scopes driveProfileDataRequestContext.RequestedClaimTypes. - You are troubleshooting missing claims — claims are defined on resources but not appearing in tokens or on the userinfo endpoint.
- You need to load claims dynamically from a database or downstream service at token issuance time.
- You are implementing an
IExtensionGrantValidatorand need to emit custom claims into the resulting access token. - You are consuming tokens in an ASP.NET Core API or web app and need to handle claim type mapping (
MapInboundClaims,JwtClaimTypesvs. MicrosoftClaimTypes).
Core Principles
- Claims are opt-in by scope. IdentityServer only asks your profile service for claims that have been declared on a requested
IdentityResource,ApiScope, orApiResource. Declaring a claim on your user store is not enough — it must be listed in a resource'sUserClaimscollection and the client must request that resource's scope. - `IProfileService` is the single authoritative extension point for controlling which user claims enter tokens. Do not use
IClaimsTransformationon the IdentityServer host to modify token claims — that interface runs during cookie authentication, not token issuance. - Identity tokens are for the client; access tokens are for APIs. Keep identity tokens small. Use
AlwaysIncludeUserClaimsInIdTokensparingly. Prefer the userinfo endpoint for full profile data. - `AddRequestedClaims` respects consent. Use
context.AddRequestedClaims(claims)rather thancontext.IssuedClaims.AddRange(claims)when you want IdentityServer to filter your claims down to only those that were requested and consented to by the user. - Claim serialization is type-aware. Set
ClaimValueTypecorrectly (e.g.ClaimValueTypes.Integer64,IdentityServerConstants.ClaimValueTypes.Json) so numeric and structured values arrive in tokens as the right JSON type rather than strings. - `MapInboundClaims = false` is required in consuming APIs and web apps. Without it, the JWT bearer handler silently renames standard OIDC claims (e.g.
sub→http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier), breakingUser.FindFirst(JwtClaimTypes.Subject)lookups.
Docs: https://docs.duendesoftware.com/identityserver/apis/aspnetcore/authorization/
Sub-Documents
| Document | Description | When to Load | |
|---|---|---|---|
| docs/extension-grant-claims.md | IExtensionGrantValidator implementation for custom grant types with claim propagation | Extension grants, token exchange, custom grant type, IExtensionGrantValidator, GrantValidationResult | |
| docs/external-provider-claims.md | External provider login callback with claim mapping, Google/AAD normalization, and ClaimActions | External provider, Google, Azure AD, OIDC callback, claim mapping, ExternalCookieAuthenticationScheme |
Claims Pipeline Overview
Claims travel through several distinct stages between the user's identity and an API's authorization check. Understanding where each transformation occurs prevents duplicate work and subtle bugs.
Stage 1 — Login callback: Claims from the external provider (or local user store) are incorporated into the IdentityServerUser and persisted in the session cookie. This is where you map external IdP claims to internal claim types.
Stage 2 — Token issuance: When a client requests a token, IdentityServer calls IProfileService.GetProfileDataAsync. The ProfileDataRequestContext tells you which claims are requested (derived from scopes/resources) and what token type is being built. This is where you load dynamic claims from your database.
Stage 3 — Token consumption: APIs receive the JWT and validate it. IClaimsTransformation can augment the ClaimsPrincipal after validation — useful for adding application-specific roles or denormalized data that doesn't belong in the token itself.
IProfileService
IProfileService is the primary extensibility point for claims in Duende IdentityServer. Register your implementation with AddProfileService<T>() during startup.
Interface Contract
ProfileDataRequestContext Key Members
| Member | Description | |
|---|---|---|
Subject | The ClaimsPrincipal from the authentication session (or from the access token for userinfo calls). | |
Client | The Client making the request — use for per-client filtering. | |
Caller | What triggered this call: ClaimsProviderAccessToken, ClaimsProviderIdentityToken, UserInfoEndpoint. | |
RequestedClaimTypes | Claim types requested by the client, built from the UserClaims of the resources (IdentityResource/ApiScope/ApiResource) resolved for the request. | |
IssuedClaims | Populate this collection with claims to include in the token. | |
AddRequestedClaims(IEnumerable<Claim>) | Helper that filters your claims to only those in RequestedClaimTypes. |
Minimal Implementation
`ProfileIsActiveCallers`:IsActiveContext.Calleris aProfileIsActiveCallersconstant indicating why the check is being made — e.g.AuthorizeEndpoint,Token,RefreshTokenValidation,UserInfoRequestValidation. Use it to apply different strictness levels; for example, you might allow a soft-disabled account to complete an in-flight refresh but deny new interactive logins.
Emitting Claims Unconditionally
Use context.IssuedClaims.AddRange(...) when a claim must always appear regardless of requested scopes — for example, a mandatory tenant_id that APIs rely on for multi-tenancy:
Differentiating by Caller
The Caller property lets you tailor claims for each token type:
Detecting Userinfo Endpoint Calls
When called for the userinfo endpoint, Subject is populated from the access token rather than the session principal. Guard against assuming session-only data is available:
Profile Service Invocation Count (Lifecycle)
For an authorization-code + userinfo flow, GetProfileDataAsync can be called up to three times per login, distinguished by context.Caller:
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/claims-authorization/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/claims-authorization)