RFC 9449 · DPoP everywhere

Stolen tokens
should be worthless.

A small, standards-exact OAuth 2.1 authorization server whose every access token is sender-constrained with DPoP. A token lifted from a log, a proxy, or a browser extension is inert without the private key it's bound to.

Python 3.12+ Django 5.2 / 6.1 PostgreSQL 16 Redis 7 RFC 9449 DPoP AGPL-3.0

Why DPoP

A bearer token trusts whoever holds it. DPoP doesn't.

Plain OAuth access tokens are bearer tokens — anyone who has the string can use it. RFC 9449 binds the token to a private key that never leaves the client.

Bearer tokens

  • ✕ A token copied from a log or a misconfigured proxy works anywhere, for anyone.
  • ✕ XSS or a malicious dependency that reads memory can exfiltrate a token and replay it off-device.
  • ✕ Revoking access means waiting out the token's lifetime or invalidating it server-side.
  • ✕ The resource server has no way to tell the legitimate client from the thief.

DPoP-bound tokens

  • ✓ Every token carries cnf.jkt — the thumbprint of a key pair generated on-device.
  • ✓ Using it requires a fresh signed proof; a copied token without the private key is inert.
  • ✓ A replayed proof is caught by the jti cache before it ever reaches application logic.
  • ✓ Resource servers verify possession on every request, not just at issuance.

What it does

Every grant, every token, sender-constrained.

No hand-rolled cryptographic primitives — Django Ninja, PostgreSQL, Redis and joserfc do the heavy lifting.

01

Authorization Code + PKCE

S256 only — plain is refused. Redirect URIs match exactly. Login and consent are server-rendered, CSRF- and frame-protected.

02

Client Credentials

Built for service-to-service calls, with the same constant-time secret checks as every other grant.

03

Rotated refresh tokens

Opaque, hashed at rest, rotated on every use. Reuse of a stale token revokes the whole family.

04

DPoP, fully

The whole RFC 9449 §4.3 checklist: jti replay cache, server nonces, cnf.jkt binding, dpop_jkt code binding, and token_type: DPoP.

05

RFC 9068 JWTs

ES256-signed access tokens, keys rotating through pending → active → retired, several live at once in the JWKS.

06

Metadata & lifecycle

RFC 8414 metadata, RFC 7662 introspection, RFC 7009 revocation, and RFC 9126 pushed authorization requests.

07

ninja_dpop

A reusable Django Ninja auth class for resource servers — validates the token, the proof and ath, with RFC-shaped WWW-Authenticate errors.

08

Hardened by default

Rate limiting on /token, constant-time comparisons everywhere, and error descriptions that never say which check failed.

The DPoP flow

A stolen token fails at the proof step.

The client's private key never leaves the device. The server only ever sees a proof it can verify.

1
Client generates an ES256 key pair once and sends POST /oauth/token with a DPoP proof {htm, htu, iat, jti}.
2
Server has no current nonce for this client yet → 400 use_dpop_nonce with a fresh DPoP-Nonce.
3
Client retries with the nonce embedded in a new proof.
4
Server verifies typ, alg, that the jwk is public, the signature, htm/htu, the iat window, and the nonce — then records jti in Redis to block replay.
5
Client receives 200 with an access token whose cnf.jkt is the RFC 7638 thumbprint of its public key, plus token_type: DPoP and a refresh token.
6
Client calls the resource server with Authorization: DPoP <token> and a fresh proof whose ath is SHA-256(token).
7
Resource server (ninja_dpop) checks the token against the JWKS, then checks the proof's key against cnf.jkt, its ath, and its htm/htu — and also guards against replay.

Architecture

Four pieces, one proof format.

The authorization server and the resource server never need to share code — only the same JWKS and the same proof rules.

Client

dpop_client

Generates an ES256 key pair once and signs a fresh proof for every request.

→
Django + Ninja

Authorization server

Issues codes, tokens and nonces; rotates signing keys through pending → active → retired.

→
Redis

Nonce & replay cache

Short-lived jti entries make every proof usable exactly once.

→
ninja_dpop

Resource server

Verifies the JWT, the proof and ath before any route handler runs.

Quickstart

Up and running in two commands.

# with Docker
docker compose up --build -d
docker compose exec web python manage.py createsuperuser
docker compose exec web python manage.py create_client "My service" \
    --grant client_credentials --scope orders:read --scope orders:write

# or locally, with uv and a Redis on localhost:6379
make install
make run               # migrations, then runserver on :8000 (SQLite)

Built with

DjangoDjango NinjajoserfcPostgreSQLRedisDocker Compose