DPoP authentication implementation for ASP.NET Core APIs

In order to safeguard ASP.NET Core APIs, bearer tokens are frequently utilised. When a client calls a protected endpoint, it gets an access token from an authorisation server and inserts it in the Authorisation header.

This method has a significant security flaw despite being practical. A valid bearer token can be used by anybody until it expires. For instance, a hacked client, an unsecured device, or application logs might unintentionally reveal a token that could be utilised 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:

  1. The client generates an asymmetric key pair.
  2. The client sends a token request with a signed DPoP proof.
  3. The authorization server validates the proof and associates the public key with the issued access token.
  4. The authorization server returns a DPoP-bound access token.
  5. The client generates a new DPoP proof for each API request.
  6. The client sends the access token using the DPoP authorization scheme and includes the proof in the DPoP HTTP header.
  7. The API validates the access token and verifies the DPoP proof.
  8. The API checks the key binding, request method, target URI, timestamp, and replay status.
  9. 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:

The payload contains claims such as:

These fields have specific purposes:

FieldPurpose
typIdentifies the JWT as a DPoP proof
algSpecifies the asymmetric signing algorithm
jwkContains the public key used to verify the signature
jtiProvides a unique identifier for replay detection
htmIdentifies the HTTP method
htuIdentifies the target HTTP URI
iatRecords when the proof was created
athContains 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.

FeatureBearer AuthenticationDPoP Authentication
Access tokenRequiredRequired
Private keyNot requiredRequired
Request proofNot requiredRequired
Token bindingUsually not sender-constrainedBound to a public key
Replay protectionDepends on token handlingIncludes proof validation and replay detection
Client implementationSimplerRequires cryptographic proof generation
Token theft protectionA stolen token can be reusedA 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:

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.

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.

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:

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:

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:

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:

ModeDescription
IssuedAtValidates the proof using its iat claim and configured clock-skew allowance
NonceUses a server-issued nonce to validate proof freshness
BothRequires 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:

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:

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

ProblemPossible causeRecommended action
Invalid DPoP proofIncorrect signature or malformed proof JWTVerify the key pair and proof structure
Access token rejectedInvalid issuer, audience, signature, or expirationReview JWT bearer validation settings
Key binding mismatchToken and proof use different public keysEnsure the client uses the key associated with the token
Invalid HTTP methodhtm does not match the requestGenerate a new proof for the actual method
Invalid target URIhtu does not match the externally visible URIReview URI generation and trusted proxy configuration
Proof replay detectedThe same jti was submitted againGenerate a unique proof for every request
Nonce validation failureMissing, expired, or invalid nonceRetry with a fresh proof containing the latest nonce
Replay detection fails across instancesCache is local to each API instanceConfigure distributed caching
Nonce fails after load balancingData Protection keys are not sharedShare 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.

Recommendation for ASP.NET 11.0 Hosting

A solid base for developing online services and applications is ASP.NET Core 11. Before creating an ASP.NET web application, you must be proficient in JavaScript, HTML, CSS, and C#. There are thousands of web hosting providers offering ASP.NET hosting on the market. However, there are relatively few web hosting providers that offer top-notch ASP.NET hosting.

ASP.NET is the best development language in Windows platform, which is released by Microsoft and widely used to build all types of dynamic Web sites and XML Web services. With this article, we’re going to help you to find the best ASP.NET Hosting solution in Europe based on reliability, features, price, performance and technical support. After we reviewed about 30+ ASP.NET hosting providers in Europe, our Best ASP.NET Hosting Award in Europe goes to HostForLIFE.eu, one of the fastest growing private companies and one of the most reliable hosting providers in Europe.

You may also like...

Popular Posts

Skip to toolbar Log Out