Repository navigation
Description
Part of #6886. Needed by #6897.
Problem: refresh tokens issued by token exchange need state that fosite's refresh-token storage cannot hold: one grant per subject-token jti, written atomically with the replay marker; a parent link checked on every use; and revocation that leaves a record. They must also stay apart from ordinary refresh tokens, so grant_type=refresh_token can never redeem them.
Change: an optional storage capability, ExchangeGrantStorage, found the same way as DeviceCodeStorage. Startup fails when a client enables token-exchange refresh tokens and the storage lacks it. Memory and Redis backends.
Record (ExchangeGrant):
Signature: the refresh token's HMAC signature, also the grant's internal ID; never exposed;ParentSignature: empty for a top-level grant;ClientID,Subject,SubjectIdentifier(thesub_idJSON, if present), andUpstreamSubject(the subject token'shttps://toolhive.dev/upstream_subjectclaim: issuer, claim, and value, if present). A child copies both from its parent;SourceJTI,SourceExpiresAt: the subject access token'sjtiandexp; empty for child grants;IssuableTokenTypes: exactly one token type URN;ExpiresAt,CreatedAt,RevokedAt(zero while live).
Operations:
CreateExchangeGrant: atomic. Refuses a reused (issuer,SourceJTI) withfosite.ErrJTIKnownand a duplicate signature withErrAlreadyExists, and writes nothing on failure. Thejtimarker holds the grant's signature.GetExchangeGrant: returns revoked grants too;ErrNotFoundonce the record has expired.RevokeExchangeGrant: setsRevokedAtonce; idempotent.
Rules:
- A child is usable only while it is live and its parent exists and is live. A missing parent counts as revoked. Revocation marks one record: no children index, no cascade walk.
- Depth is 1: a child cannot be a parent.
- Record TTL is
ExpiresAt; thejtimarker TTL isSourceExpiresAtplus a margin. Time decisions are made in code (Live(now)); Redis TTL is only garbage collection. - Redis: one hash per record under the existing hash-tagged prefix. One Lua script creates a grant, running all checks before writing and touching only declared keys. Revoke is a single conditional write. No error is swallowed.
No user index, session key, owner, tombstone, or stored revocation reason: the client keeps those.
Acceptance, on both backends:
- concurrent creates with one
jtileave one grant; - revoking a child leaves its parent and siblings usable;
- revoking a parent makes its children unusable;
- an expired grant reads as not found;
- store errors are returned, not logged and dropped;
- a decorator that hides the capability makes startup fail.
Activity
Support authorization_details on token exchange
Support authorization_details on token exchange (#6921)
[-]Storage for refresh tokens issued by token exchange[/-][+]Storage for grants issued by token exchange[/+]jhrozek commentedon Oct 30, 2026
The storage capability, the memory and Redis backends and their contract tests are on main. The last pieces, the UpstreamSubject field on the grant record and the startup failure when a client enables the feature on a store without the capability, are in #7003. Closing here; the rest of this work is tracked in #6897.