duendesoftware/duende-skills/identityserver-token-security

Claude Code and agent skill by duendesoftware/duende-skills

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Advanced token security features in Duende IdentityServer including DPoP, mTLS certificate binding, Pushed Authorization Requests (PAR), JWT Secured Authorization Requests (JAR), and FAPI 2.0 compliance configuration.

Install

npx vskill@latest install duendesoftware/duende-skills/identityserver-token-security

SKILL.md

The same SKILL.md was published earlier as duendesoftware/duende-skills/identityserver-token-security.

Advanced Token Security (DPoP, mTLS, PAR, JAR, FAPI)

When to Use This Skill

  • Implementing Proof-of-Possession (PoP) tokens with DPoP or mTLS
  • Configuring Pushed Authorization Requests (PAR) for front-channel parameter security
  • Setting up JWT Secured Authorization Requests (JAR) for tamperproof authorize requests
  • Building FAPI 2.0 compliant authorization servers
  • Choosing between DPoP and mTLS for sender-constrained tokens
  • Configuring APIs to validate proof-of-possession tokens
  • Meeting regulatory or industry security requirements (open banking, e-health, e-government)

Docs: https://docs.duendesoftware.com/identityserver/tokens/

Proof-of-Possession Tokens: Why They Matter

Default OAuth access tokens are bearer tokens -- anyone who possesses the token can use it. If a token leaks, a malicious third party can impersonate the client/user.

Proof-of-Possession (PoP) tokens are cryptographically bound to the client that requested them via the cnf (confirmation) claim:

json
{
"iss": "https://identity.example.com",
"aud": "urn:api",
"client_id": "web_app",
"sub": "88421113",
"cnf": "confirmation_method"
}

When using reference tokens, the cnf claim is returned from the introspection endpoint.

DPoP vs mTLS: Decision Matrix

FactorDPoPmTLS
Edition requiredEnterpriseAll editions (binding); Enterprise (some features)
Minimum version6.3All versions
Key managementApplication-layer JWK (dynamic)X.509 certificate (TLS layer)
InfrastructureNo TLS changes neededRequires TLS client certificate infrastructure
Deployment complexityLowerHigher (certificate distribution, renewal)
Protocol layerHTTP headers (DPoP header)TLS channel
Public clientsSupported (mobile/SPA)Harder for public clients
FAPI 2.0AcceptedAccepted
Replay protectionNonce mechanism + iat validationTLS channel binding
RecommendationStart here for most use casesWhen TLS infrastructure already exists

Mutual TLS (mTLS)

How It Works

IdentityServer embeds the SHA-256 thumbprint of the client's X.509 certificate into the access token via the cnf claim:

json
{
"cnf": { "x5t#S256": "bwcK0esc3ACC3DB2Y5_lESsXE8o9ltc05O89jdN-dg2" }
}

The client must use the same certificate when calling APIs. APIs validate the cnf claim against the TLS client certificate thumbprint.

mTLS for Client Authentication

Configure IdentityServer to accept client certificates:

csharp
// Program.cs
var idsvrBuilder = builder.Services.AddIdentityServer(options =>
{
options.MutualTls.Enabled = true;
options.MutualTls.DomainName = "mtls"; // mTLS endpoints on mtls subdomain
options.MutualTls.ClientCertificateAuthenticationScheme = "Certificate";
});
idsvrBuilder.AddMutualTlsSecretValidators();
builder.Services.AddAuthentication()
.AddCertificate("Certificate", options =>
{
options.AllowedCertificateTypes = CertificateTypes.SelfSigned;
options.ValidateCertificateUse = true;
});

Configure the client with certificate-based secrets:

csharp
new Client
{
ClientId = "mtls.client",
AllowedGrantTypes = GrantTypes.ClientCredentials,
AllowedScopes = { "api1" },
ClientSecrets =
{
// PKI-based (by distinguished name)
new Secret(@"CN=client, OU=production, O=company", "client.dn")
{
Type = SecretTypes.X509CertificateName
},
// Self-issued (by thumbprint)
new Secret("bca0d040847f843c5ee0fa6eb494837470155868", "mtls.tb")
{
Type = SecretTypes.X509CertificateThumbprint
}
}
}

Use SecretTypes.X509CertificateName for PKI/chained certificates (matched by distinguished name) and SecretTypes.X509CertificateThumbprint for self-issued certificates (matched by thumbprint).

mTLS Endpoint URL Strategies

options.MutualTls.DomainName controls where the mTLS-protected endpoints live:

DomainName valueEndpoint layoutExample
null / emptyPath-based on the main hosthttps://host/connect/mtls/token
"mtls"Sub-domainhttps://mtls.host/connect/token
full domainSeparate dedicated domainhttps://mtls.example.com/connect/token

The mTLS endpoint URLs are published in discovery under mtls_endpoint_aliases. Clients must read them from there rather than the standard endpoints:

csharp
var tokenEndpoint = disco.MtlsEndpointAliases?.TokenEndpoint;
mTLS Deployment: Kestrel (dev) vs Reverse Proxy (production)

Development — Kestrel terminates TLS directly. Use mkcert to create a locally-trusted CA (the private key stays on your machine, unlike shared sample certificates that ship public private keys). Accept — but don't require — client certificates; IdentityServer's mTLS middleware enforces them on the mTLS endpoint:

csharp
builder.WebHost.ConfigureKestrel(kestrel =>
{
kestrel.ConfigureHttpsDefaults(https =>
{
// Accept but do not require; the mTLS endpoint enforces the certificate
https.ClientCertificateMode = ClientCertificateMode.AllowCertificate;
});
});
On .NET 10, Kestrel auto-resolves *.localhost sub-domains, so the mtls.localhost sub-domain strategy works locally with no hosts-file entry.

Production — a reverse proxy terminates TLS and forwards the client certificate to Kestrel via a request header. Kestrel itself does not negotiate the certificate (ClientCertificateMode.NoCertificate); use certificate forwarding:

csharp
// Kestrel: the proxy terminates TLS, so Kestrel never asks for a certificate
builder.WebHost.ConfigureKestrel(k =>
k.ConfigureHttpsDefaults(h => h.ClientCertificateMode = ClientCertificateMode.NoCertificate));
builder.Services.AddCertificateForwarding(options =>
{
options.CertificateHeader = "X-SSL-CERT"; // match your proxy
options.HeaderConverter = headerValue =>
{
if (string.IsNullOrWhiteSpace(headerValue)) return null!;
// e.g. Nginx sends URL-encoded PEM; IIS sends base64 DER — decode accordingly
var pem = Uri.UnescapeDataString(headerValue);
return X509Certificate2.CreateFromPem(pem);
};
});
builder.Services.AddAuthentication()
.AddCertificate("Certificate", options =>
{
// Production PKI certificates are chained, not self-signed
options.AllowedCertificateTypes = CertificateTypes.Chained;
});
// ...
app.UseCertificateForwarding(); // MUST come before UseAuthentication()
app.UseAuthentication();
app.UseAuthorization();

Proxy header conventions:

ProxyHeaderValue format
IISX-ARR-ClientCertbase64 DER
NginxX-SSL-CERT$ssl_client_escaped_cert (URL-encoded PEM)
ApacheX-SSL-CERT%{SSL_CLIENT_CERT}s (PEM)
Security: the proxy must strip or overwrite the certificate header on all inbound requests so a client cannot spoof a certificate by sending the header directly.
mTLS without Client Authentication

You can bind tokens to a client certificate without using the certificate for client authentication. This works with any authentication method, including public clients:

csharp
// Program.cs
var idsvrBuilder = builder.Services.AddIdentityServer(options =>
{
options.MutualTls.AlwaysEmitConfirmationClaim = true;
});

The client creates a certificate on the fly and uses it to establish the TLS channel:

csharp
static X509Certificate2 CreateClientCertificate(string name)
{
X500DistinguishedName distinguishedName = new X500DistinguishedName($"CN={name}");
using (RSA rsa = RSA.Create(2048))
{
var request = new CertificateRequest(distinguishedName, rsa, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
request.CertificateExtensions.Add(
new X509KeyUsageExtension(
X509KeyUsageFlags.DataEncipherment |
X509KeyUsageFlags.KeyEncipherment |
X509KeyUsageFlags.DigitalSignature, false));
request.CertificateExtensions.Add(
new X509EnhancedKeyUsageExtension(
new OidCollection { new Oid("1.3.6.1.5.5.7.3.2") }, false));
return request.CreateSelfSigned(
new DateTimeOffset(DateTime.UtcNow.AddDays(-1)),
new DateTimeOffset(DateTime.UtcNow.AddDays(10)));
}
}
.NET Client Requesting mTLS Token
csharp
static async Task<TokenResponse> RequestTokenAsync()
{
var handler = new SocketsHttpHandler();
var cert = new X509Certificate2("client.p12", "password");
handler.SslOptions.ClientCertificates = new X509CertificateCollection { cert };
var client = new HttpClient(handler);
var disco = await client.GetDiscoveryDocumentAsync(Constants.Authority);
if (disco.IsError) throw new Exception(disco.Error);
var response = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
{
Address = disco.MtlsEndpointAliases.TokenEndpoint,
ClientCredentialStyle = ClientCredentialStyle.PostBody,
ClientId = "mtls.client",
Scope = "api1"
});
if (response.IsError) throw new Exception(response.Error);
return response;
}
Validating mTLS in APIs

Add custom middleware to compare the cnf claim against the TLS client certificate:

csharp
// API middleware pipeline
app.UseAuthentication();
app.UseConfirmationValidation(); // custom middleware
app.UseAuthorization();

The middleware validates the x5t#S256 value in the cnf claim against the SHA-256 thumbprint of the client certificate on the TLS channel.

DPoP (Demonstrating Proof-of-Possession at the Application Layer)

Version: >= 6.3 (Enterprise Edition)

DPoP binds an asymmetric key (stored as a JWK) to an access token via the cnf claim:

json
{
"cnf": {
"jkt": "JGSVlE73oKtQQI1dypYg8_JNat0xJjsQNyOI5oxaZf4"
}
}

The client proves possession of the private key by sending a signed JWT (proof token) via the DPoP HTTP header on every request.

Enabling DPoP in IdentityServer

DPoP can be used dynamically with no server configuration, or enforced per-client:

csharp
new Client
{
ClientId = "dpop_client",
RequireDPoP = true,
// Optional: control DPoP proof token expiration validation
// DPoPValidationMode = DPoPTokenExpirationValidationMode.Iat (default)
// DPoPClockSkew = TimeSpan.FromMinutes(5) (default)
}
Client-Side DPoP Configuration

Use Duende.AccessTokenManagement for automatic DPoP proof token handling.

Client credentials flow:

csharp
// Program.cs
builder.Services.AddClientCredentialsTokenManagement()
.AddClient("demo_dpop_client", client =>
{
client.TokenEndpoint = "https://identity.example.com/connect/token";
client.DPoPJsonWebKey = "..."; // JWK string
});

Authorization code flow:

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

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
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/duendesoftware/duende-skills/identityserver-token-security/badge)](https://verified-skill.com/skills/duendesoftware/duende-skills/identityserver-token-security)

Something wrong with this skill or its page? Tell us.