Skip to content

Commit 5c1a1da

Browse files
Refactor token binding validation doc for clarity
Reformatted paragraphs and lists for better readability and structure. Enhanced the DPoP validation section with a detailed step-by-step breakdown and added code examples for implementing validation using the `Duende.AspNetCore.Authentication.JwtBearer` NuGet package.
1 parent 6843853 commit 5c1a1da

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

src/content/docs/identityserver/apis/aspnetcore/confirmation.md

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@ redirect_from:
1010
- /identityserver/v7/apis/aspnetcore/confirmation/
1111
---
1212

13-
IdentityServer can [bind tokens to clients](/identityserver/tokens/pop#proof-of-possession-styles) using either mTLS or DPoP, creating a `Proof-of-Possession` (PoP) access token. When one of these mechanisms is used, APIs that use those access tokens for authorization need to validate the binding between the client and token. This document describes how to perform such validation, depending on which mechanism was used to produce a PoP token.
13+
IdentityServer can [bind tokens to clients](/identityserver/tokens/pop#proof-of-possession-styles) using either mTLS or
14+
DPoP, creating a `Proof-of-Possession` (PoP) access token. When one of these mechanisms is used, APIs that use those
15+
access tokens for authorization need to validate the binding between the client and token. This document describes how
16+
to perform such validation, depending on which mechanism was used to produce a PoP token.
1417

1518
### Validating mTLS
1619

17-
If you are using a [mutual TLS connection](/identityserver/tokens/pop#mutual-tls) to establish proof-of-possession, the resulting access token will contain a `cnf` claim containing the client's certificate thumbprint. APIs validate such tokens by comparing this thumbprint to the thumbprint of the client certificate in the mTLS connection. This validation should be performed early in the pipeline, ideally immediately after the standard validation of the access token.
20+
If you are using a [mutual TLS connection](/identityserver/tokens/pop#mutual-tls) to establish proof-of-possession, the
21+
resulting access token will contain a `cnf` claim containing the client's certificate thumbprint. APIs validate such
22+
tokens by comparing this thumbprint to the thumbprint of the client certificate in the mTLS connection. This validation
23+
should be performed early in the pipeline, ideally immediately after the standard validation of the access token.
1824

1925
You can do so with custom middleware like this:
2026

@@ -28,7 +34,8 @@ app.UseConfirmationValidation();
2834
app.UseAuthorization();
2935
```
3036

31-
Here, `UseConfirmationValidation` is an extension method that registers the middleware that performs the necessary validation:
37+
Here, `UseConfirmationValidation` is an extension method that registers the middleware that performs the necessary
38+
validation:
3239

3340
```cs
3441
public static class ConfirmationValidationExtensions
@@ -109,11 +116,31 @@ public class ConfirmationValidationMiddlewareOptions
109116
```
110117

111118
### Validating DPoP
112-
If you are using [DPoP](/identityserver/tokens/pop) for proof-of-possession, there is a non-trivial amount of work needed to validate the `cnf` claim.
113-
In addition to the normal validation mechanics of the access token itself, DPoP requires additional validation of the DPoP proof token sent in the "DPoP" HTTP request header.
114-
DPoP proof token processing involves requiring the DPoP scheme on the authorization header where the access token is sent, JWT validation of the proof token, "cnf" claim validation, HTTP method and URL validation, replay detection (which requires some storage for the replay information), nonce generation and validation, additional clock skew logic, and emitting the correct response headers in the case of the various validation errors.
115119

116-
You can use the `Duende.AspNetCore.Authentication.JwtBearer` NuGet package to implement this validation. With this package, the configuration necessary in your startup can be as simple as this:
120+
When using [DPoP](/identityserver/tokens/pop#enabling-dpop-in-identityserver) for proof-of-possession, validating the `cnf` claim requires several
121+
steps:
122+
123+
1. Validating the access token as normal
124+
2. Validating the DPoP proof token from the `DPoP` HTTP request header
125+
3. Ensuring the authorization header uses the DPoP scheme
126+
4. Validating the JWT format of the proof token
127+
5. Verifying the `cnf` claim matches between tokens
128+
6. Validating the HTTP method and URL match the request
129+
7. Detecting replay attacks using storage
130+
8. Managing nonce generation and validation
131+
9. Handling clock skew between systems
132+
10. Returning appropriate error response headers when validation fails
133+
134+
This comprehensive validation process requires careful implementation to ensure security. Luckily for
135+
developers, we've implemented these steps into an easy-to-use library.
136+
137+
You can use the `Duende.AspNetCore.Authentication.JwtBearer` NuGet package to implement this validation.
138+
139+
```bash
140+
dotnet add package Duende.AspnetCore.Authentication.JwtBearer
141+
```
142+
143+
With this package, the configuration necessary in your startup can be as simple as this:
117144

118145
```cs
119146
// adds the normal JWT bearer validation
@@ -132,8 +159,8 @@ builder.Services.ConfigureDPoPTokensForScheme("token");
132159
```
133160

134161
You will also typically need a distributed cache, used to perform replay detection of DPoP
135-
proofs. Duende.AspNetCore.Authentication.JwtBearer relies on `IDistributedCache` for this,
136-
so you can supply the cache implementation of your choice. See the
162+
proofs. `Duende.AspNetCore.Authentication.JwtBearer` relies on `IDistributedCache` for this,
163+
so you can supply the cache implementation of your choice. See the
137164
[Microsoft documentation](https://learn.microsoft.com/en-us/aspnet/core/performance/caching/distributed?view=aspnetcore-8.0)
138165
for more details on setting up distributed caches, along with many examples, including Redis, CosmosDB, and
139166
Sql Server.

0 commit comments

Comments
 (0)