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.
Why DPoP
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.
cnf.jkt — the thumbprint of a key pair generated on-device.jti cache before it ever reaches application logic.What it does
No hand-rolled cryptographic primitives — Django Ninja, PostgreSQL, Redis and joserfc do the heavy lifting.
S256 only — plain is refused. Redirect URIs match exactly. Login and consent are server-rendered, CSRF- and frame-protected.
Built for service-to-service calls, with the same constant-time secret checks as every other grant.
Opaque, hashed at rest, rotated on every use. Reuse of a stale token revokes the whole family.
The whole RFC 9449 §4.3 checklist: jti replay cache, server nonces, cnf.jkt binding, dpop_jkt code binding, and token_type: DPoP.
ES256-signed access tokens, keys rotating through pending → active → retired, several live at once in the JWKS.
RFC 8414 metadata, RFC 7662 introspection, RFC 7009 revocation, and RFC 9126 pushed authorization requests.
A reusable Django Ninja auth class for resource servers — validates the token, the proof and ath, with RFC-shaped WWW-Authenticate errors.
Rate limiting on /token, constant-time comparisons everywhere, and error descriptions that never say which check failed.
The DPoP flow
The client's private key never leaves the device. The server only ever sees a proof it can verify.
POST /oauth/token with a DPoP proof {htm, htu, iat, jti}.400 use_dpop_nonce with a fresh DPoP-Nonce.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.cnf.jkt is the RFC 7638 thumbprint of its public key, plus token_type: DPoP and a refresh token.Authorization: DPoP <token> and a fresh proof whose ath is SHA-256(token).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
The authorization server and the resource server never need to share code — only the same JWKS and the same proof rules.
Generates an ES256 key pair once and signs a fresh proof for every request.
Issues codes, tokens and nonces; rotates signing keys through pending → active → retired.
Short-lived jti entries make every proof usable exactly once.
Verifies the JWT, the proof and ath before any route handler runs.
Quickstart
# 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