DpopAuthProvider
AuthProvider implementation that attaches DPoP proof-of-possession headers on every XRPC request and handles token refresh transparently.
On each request, produces:
Authorization: DPoP <access_token>DPoP: <signed-jwt-proof>(withath,htm,htu,nonce)
When the PDS responds with HTTP 401:
If
DPoP-Nonceheader is present → stores the nonce, retriesIf the access token is expired, or the 401 challenges it with
WWW-Authenticate: DPoP error="invalid_token"→ refreshes via the token endpoint with the DPoP-bound refresh token, retries. Any other 401 does not refresh: every rotation spends a single-use token, and a rotation whose response is lost ends the session on the next replayIf the request was sent with an access token the session has since replaced (a refresh finished while it was in flight) → retries with the current token and does not refresh again
If the refresh token is revoked (
error=invalid_grant) → clears the session, throws OAuthSessionExpiredExceptionOtherwise (network error, 5xx/429, unparseable/captive-portal body, or any non-
invalid_granterror) → throws the retryable OAuthRefreshFailedException and LEAVES THE SESSION INTACT, so a flaky connection can't sign the user out
Refresh operations are serialized with one Mutex per account (DID), shared by every provider in the process, so two clients built from the same session cannot spend the same refresh token at once.
Constructors
Refreshes by posting directly to the token endpoint with refreshClient — the behaviour of a public client. Equivalent to passing a DirectTokenEndpointTransport built from that client, so the same requirements apply to it: no silent re-sends, and a request timeout.
Functions
A 401 reported without the headers its request carried. The token that was rejected is then unknown and taken to be the session's current one. XrpcClient calls the two-argument overload; prefer it.
Called by XrpcClient on HTTP 401. Recovers every recoverable cause in one call so the single retry that XrpcClient performs always carries fresh state. Control flow: