Bind tokens to a key
Make a client's tokens useless to anyone who copies them, by binding each token to a key only the client holds.
APIRFC 9449
A stolen bearer token works for whoever holds it until it expires. A token bound with DPoP works only beside a fresh proof signed by the client’s private key, which never leaves the client, so a token copied from a log, a proxy or a browser extension can’t be used. For public apps, the refresh token is bound too. This guide is for browser and mobile apps, whose tokens are the easiest to steal, and any client whose APIs check proofs.
Before you start:
- Who can do it: a realm administrator, in a group that holds
RealmOwner(Delegated administration).RealmViewercan read the settings but not change them. - Where: today this is done through the API; Call the API shows how to get
$CVYUH_SESSION. - First: have the client’s ID, and a client library that makes DPoP proofs.
Require bound tokens
Section titled “Require bound tokens”-
Require bound tokens for the client:
Terminal window curl -X PATCH 'https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client/<client-id>' \-H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \-H "Content-Type: application/json" \-d '{ "dpopBoundAccessTokens": true }'Without this, a client that sends a proof still gets a bound token; with it, sending one is compulsory and the client can never fall back to a bearer token. An agent’s client needs no change: it’s held to FAPI 2.0 by default, which binds its tokens.
-
Leave the realm’s nonces on (
oauth2Settings.dpopNonceRequired) unless a client can’t handle the retry. To turn them off:PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Settings/oauth2Settingswith{ "dpopNonceRequired": false }.
What the client does
Section titled “What the client does”-
It makes a key pair. In a browser, a non-exportable key in the browser’s key store.
-
With each token request, it sends a
DPoPheader: a small JWT signed by its key, naming the request’s method and address. -
The first request is answered
use_dpop_noncewith aDPoP-Nonceheader. It signs a new proof including the nonce and sends again. Every answer after that carries the next nonce. -
Its tokens come back with
token_type: DPoP, each naming the key. -
It calls APIs with
Authorization: DPoP <token>and a fresh proof naming the token. Each proof works once.
Check it worked
Section titled “Check it worked”- At the realm’s own APIs, such as userinfo, the bound token sent as a plain bearer token is refused.
- Introspection shows the key the token is bound to, in
cnf.jkt, for an API that checks proofs itself. - At the gateway, a bound token without a matching proof is refused
invalid_dpop_proof.
Each bound token’s TOKEN_ISSUED record names the key it is bound to, in bound. Find it in
Audit → Authentication in the dashboard.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Cause | Fix |
|---|---|---|
Every first token request is refused use_dpop_nonce | Expected: the realm hands out a nonce | Retry with a new proof carrying the DPoP-Nonce it sent |
invalid_dpop_proof | The proof names another method or address, was used before, is too old, or the clock is off | Sign a fresh proof for each request, with the exact method and address |
invalid_dpop_proof, “this client is issued DPoP-bound tokens only” | The client sent no proof, and bound tokens are now required | Have the client send a DPoP header |
| A bound token is refused at an API as a bearer token | Expected: it must be sent as DPoP with a proof | Send Authorization: DPoP <token> and a proof naming it |
Undo it
Section titled “Undo it”PATCH the client with { "dpopBoundAccessTokens": false }. Tokens already bound stay bound until they expire.
Related
Section titled “Related”- DPoP: the standard in full.
- Bound tokens at the gateway: how the gateway checks proofs.
- Hold a client to FAPI 2.0: binding and more, in one setting.
- Check a token at your API: introspection and
cnf.jkt.