DPoP (Demonstrating Proof of Possession)¶
OAuth 2.0 DPoP (RFC 9449) for binding tokens to a client's private key.
Key Management¶
DPoPKey(algorithm='ES256')
¶
Manages a DPoP asymmetric key pair.
Generate via :func:generate_dpop_key. The key pair is immutable
and thread-safe after construction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm
|
str
|
The signing algorithm ( |
'ES256'
|
generate_dpop_key(algorithm='ES256')
¶
Generate a new DPoP key pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm
|
str
|
Signing algorithm — |
'ES256'
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
DPoPKey
|
class: |
Proof Creation¶
create_dpop_proof(key, method, uri, access_token=None, nonce=None)
¶
Create a signed DPoP proof JWT (RFC 9449).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
DPoPKey
|
The :class: |
required |
method
|
str
|
HTTP method (e.g. |
required |
uri
|
str
|
The full HTTP URI of the request. |
required |
access_token
|
str | None
|
If provided, includes the |
None
|
nonce
|
str | None
|
Server-provided DPoP nonce (from a previous |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The signed DPoP proof JWT string. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If method or uri is empty, or uri is not absolute. |
compute_ath(access_token)
¶
Compute the access token hash (ath) claim value.
Used when sending a DPoP proof alongside a bound access token to a resource server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_token
|
str
|
The access token string. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Base64url-encoded SHA-256 hash of the access token. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If access_token is empty. |
HTTP Headers¶
build_dpop_headers(proof, access_token=None)
¶
Build HTTP headers dict with DPoP proof and optional Authorization.
For token endpoint requests, only the DPoP header is needed.
For resource server requests, both DPoP and
Authorization: DPoP <token> headers are included.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proof
|
str
|
The signed DPoP proof JWT. |
required |
access_token
|
str | None
|
If provided, adds |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dict of HTTP headers to include in the request. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If proof is empty. |