Bearer tokens are widely used to secure ASP.NET Core APIs. A client obtains an access token from an authorization server and includes it in the Authorization header when calling a protected endpoint.
Although this approach is convenient, it has an important security limitation. Anyone who obtains a valid bearer token may be able to use it until the token expires. For example, a token accidentally exposed through application logs, an insecure device, or a compromised client could be reused by another party.
Demonstrating Proof of Possession (DPoP) helps address this problem. Instead of relying only on possession of an access token, DPoP requires the client to prove that it controls a private cryptographic key associated with that token.
ASP.NET Core APIs can use DPoP alongside standard JWT bearer authentication. In this article, we will explore how DPoP works, understand the request flow, configure DPoP validation in an ASP.NET Core API, and review important security considerations.
What Is DPoP Authentication?
DPoP stands for Demonstrating Proof of Possession. It is an OAuth 2.0 security mechanism standardized in RFC 9449.
Traditional bearer authentication works on a simple principle: whoever possesses a valid access token can use it. DPoP introduces an additional requirement. The client must prove possession of a private key before the API accepts a DPoP-bound access token.
The client generates an asymmetric key pair containing:
- A private key, which remains with the client and signs proof tokens.
- A public key, which can be shared with the authorization server and resource server.
The authorization server associates the public key with the access token. When the client calls an API, it sends the access token along with a signed DPoP proof.
The API validates the access token, verifies the proof, and checks that the public key in the proof matches the key associated with the access token.
If someone steals only the access token, they cannot normally use it without also possessing the corresponding private key.
DPoP is particularly useful for public clients such as mobile applications, desktop applications, and single-page applications that cannot safely store a traditional client secret.
How DPoP Authentication Works
DPoP adds a proof-generation and validation step to the normal OAuth access-token flow.
The process involves the client, authorization server, and protected API.
<AsyncImage query="OAuth 2.0 DPoP authentication flow client authorization server resource API proof of possession sequence diagram" aspectRatio="16:9" width="100%" />
The typical authentication flow works as follows:
- The client generates an asymmetric key pair.
- The client sends a token request with a signed DPoP proof.
- The authorization server validates the proof and associates the public key with the issued access token.
- The authorization server returns a DPoP-bound access token.
- The client generates a new DPoP proof for each API request.
- The client sends the access token using the DPoP authorization scheme and includes the proof in the DPoP HTTP header.
- The API validates the access token and verifies the DPoP proof.
- The API checks the key binding, request method, target URI, timestamp, and replay status.
- The API processes the request only when all required checks succeed.
The important point is that a DPoP proof is specific to an HTTP request. A proof generated for one request should not be reused for another request.
Understanding the DPoP Proof JWT
A DPoP proof is a signed JSON Web Token (JWT). It contains information that connects the proof to the client key and the HTTP request.
A typical decoded proof contains the following JOSE header:
{
"typ": "dpop+jwt",
"alg": "ES256",
"jwk": {
"kty": "EC",
"crv": "P-256",
"x": "PUBLIC_KEY_X",
"y": "PUBLIC_KEY_Y"
}
}
The payload contains claims such as:
{
"jti": "unique-proof-identifier",
"htm": "GET",
"htu": "https://api.example.com/orders",
"iat": 1796200000,
"ath": "BASE64URL_SHA256_ACCESS_TOKEN_HASH"
}
These fields have specific purposes:
Field | Purpose |
typ | Identifies the JWT as a DPoP proof |
alg | Specifies the asymmetric signing algorithm |
jwk | Contains the public key used to verify the signature |
jti | Provides a unique identifier for replay detection |
htm | Identifies the HTTP method |
htu | Identifies the target HTTP URI |
iat | Records when the proof was created |
ath | Contains the SHA-256 hash of the associated access token |
The ath claim is required when a DPoP proof accompanies an access token in a protected resource request. It prevents a proof created for one access token from being substituted alongside another token.
The public key in the proof is also compared with the key binding stored in the access token. JWT access tokens commonly represent this binding through the cnf.jkt claim, which contains the public key's JWK thumbprint.
DPoP Versus Traditional Bearer Authentication
Both mechanisms use access tokens, but they provide different levels of protection against token theft.
Feature | Bearer Authentication | DPoP Authentication |
Access token | Required | Required |
Private key | Not required | Required |
Request proof | Not required | Required |
Token binding | Usually not sender-constrained | Bound to a public key |
Replay protection | Depends on token handling | Includes proof validation and replay detection |
Client implementation | Simpler | Requires cryptographic proof generation |
Token theft protection | A stolen token can be reused | A stolen token alone is insufficient |
DPoP does not replace TLS. It provides application-level sender constraint, while HTTPS protects communication between the client and server.
It also does not sign the entire HTTP request body or every request header. Applications must continue using HTTPS and appropriate request-integrity protections.
Configuring DPoP in an ASP.NET Core API
A DPoP implementation must validate both the access token and the proof JWT. Writing this validation manually requires careful handling of cryptographic signatures, key binding, URI normalization, timestamps, replay detection, and optional server-issued nonces.
For production applications, using a maintained implementation is generally safer than creating a custom JWT validation pipeline.
One available integration is the Duende.AspNetCore.Authentication.JwtBearer package. It extends the standard ASP.NET Core JWT bearer authentication handler with DPoP proof validation.
This package is separate from Microsoft's standard Microsoft.AspNetCore.Authentication.JwtBearer package. It builds on the regular JWT bearer handler rather than replacing it.
Installing the package
Add the package to the ASP.NET Core API project:
dotnet add package Duende.AspNetCore.Authentication.JwtBearer
The package and its licensing requirements should be reviewed before selecting it for a commercial application.
Configuring JWT bearer authentication
Open Program.cs and configure the standard JWT bearer authentication scheme.
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Duende.AspNetCore.Authentication.JwtBearer.DPoP;
var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddAuthentication("token")
.AddJwtBearer("token", options =>
{
options.Authority =
"https://identity.example.com";
options.Audience = "orders-api";
options.MapInboundClaims = false;
options.TokenValidationParameters.ValidTypes =
["at+jwt"];
});
The configuration identifies the authorization server and the intended API audience.
The ValidTypes setting restricts the accepted access-token type to at+jwt. The authorization server must issue tokens using a compatible format and type.
In a real application, configure the authority and audience using application settings rather than hardcoding environment-specific values.
Enabling DPoP validation
After configuring JWT bearer authentication, enable DPoP processing for the same authentication scheme.
builder.Services.ConfigureDPoPTokensForScheme("token");
This connects the DPoP validation functionality to the existing JWT bearer scheme.
The authentication handler performs the additional proof checks when a request presents a DPoP-bound access token.
Registering replay detection
A DPoP proof includes a unique jti claim. The API must prevent an already accepted proof from being reused within its validity period.
The Duende integration provides replay detection through a keyed HybridCache registration.
Add the following configuration:
using Microsoft.Extensions.Caching.Hybrid;
using Duende.AspNetCore.Authentication.JwtBearer.DPoP;
builder.Services.AddKeyedHybridCache(
ServiceProviderKeys.ProofTokenReplayHybridCache);
Replay detection is enabled by default in the integration. The cache stores proof identifiers and rejects previously accepted identifiers during the relevant validity window.
For a single-instance development environment, the default in-memory cache can be useful. For a production API running on multiple instances, configure a distributed cache such as Redis so replay detection is shared across instances.
Completing the middleware configuration
Register authorization and map the API endpoints:
var app = builder.Build();
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();
Authentication must execute before authorization so that the API can establish the authenticated user before evaluating endpoint permissions.
The complete configuration also needs the appropriate distributed cache registration when the application runs across multiple instances.
Configuring DPoP Validation Options
The DPoP integration provides options for controlling how proof tokens are validated.
For example:
builder.Services.ConfigureDPoPTokensForScheme(
"token",
options =>
{
options.AllowBearerTokens = false;
options.ProofTokenLifetime =
TimeSpan.FromSeconds(10);
options.EnableReplayDetection = true;
});
The options shown above make three important decisions.
AllowBearerTokens controls whether the authentication scheme accepts ordinary bearer tokens alongside DPoP tokens. Keeping this disabled is appropriate when the API requires DPoP authentication.
ProofTokenLifetime controls how long a proof remains valid. A short lifetime reduces the opportunity for an intercepted proof to be reused.
EnableReplayDetection controls whether previously accepted proof identifiers are rejected. Disabling replay detection removes an important protection and should not be done casually.
The integration also supports different proof expiration modes:
Mode | Description |
IssuedAt | Validates the proof using its iat claim and configured clock-skew allowance |
Nonce | Uses a server-issued nonce to validate proof freshness |
Both | Requires both timestamp and server-issued nonce validation |
The IssuedAt mode avoids an additional nonce challenge round trip but depends on reasonably synchronized client clocks.
The Nonce mode reduces dependence on the client's clock but requires the client to handle nonce challenges and retry requests with a new proof.
Calling an API With a DPoP-Bound Access Token
After receiving a DPoP-bound access token, the client must generate a fresh proof for every protected API request.
A request generally looks like this:
GET /orders HTTP/1.1
Host: api.example.com
Authorization: DPoP ACCESS_TOKEN_VALUE
DPoP: SIGNED_DPOP_PROOF_JWT
Notice that the authorization scheme is DPoP, not Bearer.
The proof must contain the correct HTTP method and target URI. It must also contain the ath claim calculated from the access token.
For example, if the client calls a different endpoint or uses a different HTTP method, it must generate a new proof with the corresponding values.
The private key must remain protected on the client. Mobile applications should use appropriate platform security facilities for private-key storage, such as Keychain on iOS or Android Keystore on Android, where supported.
Handling DPoP Nonce Challenges
An API or authorization server can issue a server-generated nonce to improve proof freshness.
When a request requires a nonce that the client has not supplied, the server can respond with a nonce challenge.
For example:
HTTP/1.1 401 Unauthorized
DPoP-Nonce: SERVER_GENERATED_NONCE
WWW-Authenticate: DPoP error="use_dpop_nonce"
The client must generate a new DPoP proof containing the supplied nonce and retry the request.
The nonce is opaque to the client. It should be treated as a value supplied by the server rather than a value that the client creates or interprets.
When an API uses multiple instances, nonce validation must work consistently across those instances. For the Duende implementation, its default nonce mechanism uses ASP.NET Core Data Protection. Share Data Protection keys across instances so that a nonce generated by one instance can be validated by another.
Important Security Considerations
Validate the access token and proof independently
A valid DPoP proof does not make an invalid access token acceptable. The API must validate the token's signature, issuer, audience, lifetime, and other applicable requirements.
It must also validate the DPoP proof and confirm that the token is bound to the public key contained in that proof.
Prevent proof replay
The jti value must be unique for each proof. Store accepted identifiers for the period in which the proof could still be accepted.
For a distributed API, use shared replay-detection storage. An in-memory cache on each server cannot reliably detect a proof replayed against another instance.
Validate the request method and URI
The htm claim must match the actual HTTP method.
The htu claim must match the target URI according to RFC 9449 comparison rules. Query and fragment components are ignored, while path matching and default-port normalization must be handled correctly.
Reverse proxies require additional attention. The API must validate the externally visible request URI, not blindly trust arbitrary forwarded headers. Configure trusted proxies and forwarded-header handling correctly.
Restrict signing algorithms
Only supported asymmetric signing algorithms should be accepted. Never allow the none algorithm or symmetric signing algorithms for DPoP proof validation.
Restrict the accepted algorithms according to the security requirements of the application.
Keep private keys secure
DPoP relies on the client protecting its private key. If an attacker can execute malicious code in the client context or extract the private key, DPoP cannot provide its intended protection.
Use platform-backed key storage where possible and avoid logging private keys or complete proof tokens.
Continue using HTTPS
DPoP does not provide full HTTP message integrity. It binds the proof to the request method and target URI, but it does not sign the entire request body.
HTTPS remains necessary to protect request and response data in transit.
Common DPoP Implementation Problems
Problem | Possible cause | Recommended action |
Invalid DPoP proof | Incorrect signature or malformed proof JWT | Verify the key pair and proof structure |
Access token rejected | Invalid issuer, audience, signature, or expiration | Review JWT bearer validation settings |
Key binding mismatch | Token and proof use different public keys | Ensure the client uses the key associated with the token |
Invalid HTTP method | htm does not match the request
| Generate a new proof for the actual method |
Invalid target URI | htu does not match the externally visible URI
| Review URI generation and trusted proxy configuration |
Proof replay detected | The same jti was submitted again | Generate a unique proof for every request |
Nonce validation failure | Missing, expired, or invalid nonce | Retry with a fresh proof containing the latest nonce |
Replay detection fails across instances | Cache is local to each API instance | Configure distributed caching |
Nonce fails after load balancing | Data Protection keys are not shared | Share the Data Protection key ring |
Advantages and Disadvantages of DPoP
Advantages
- Reduces the usefulness of stolen access tokens.
- Binds access tokens to a client's asymmetric key.
- Supports public clients that cannot securely store client secrets.
- Provides request-specific proof validation.
- Includes mechanisms for proof freshness and replay detection.
- Works alongside standard OAuth 2.0 access-token flows.
Disadvantages
- Requires additional cryptographic operations on the client and server.
- Makes client implementation more complex.
- Requires secure private-key storage.
- Introduces replay-detection and nonce-management requirements.
- Requires careful configuration in distributed environments.
- Does not replace HTTPS or protect the complete HTTP request body.
Conclusion
DPoP strengthens OAuth 2.0 authentication by binding access tokens to a client's cryptographic key. Instead of accepting a token based only on possession, the API also requires a valid proof signed by the associated private key.
ASP.NET Core developers can integrate DPoP with JWT bearer authentication using a dedicated validation library. The Duende integration provides support for proof validation, token binding, nonce handling, and replay detection without requiring developers to build every cryptographic check themselves.
For production applications, pay particular attention to distributed replay detection, secure private-key storage, nonce handling, reverse-proxy configuration, and HTTPS. These details are essential to getting the security benefits that DPoP is designed to provide.
Join the conversation! Your thoughts help the community grow.