Overview
Thetokens client provides four operations for managing grant tokens:
- Exchange an authorization code for a grant token
- Refresh a grant token using a refresh token
- Verify a grant token online via the Grantex API
- Revoke a grant token by its token ID (JTI)
client.tokens.
Exchange
Exchange an authorization code for a grant token after the user approves the consent request.ExchangeTokenParams
ExchangeTokenResponse
Exchange with PKCE
Refresh
Refresh a grant token using a refresh token while the underlying grant remains active. Returns a new grant token and a new refresh token. Thegrant_id and expires_at stay the same.
Refresh tokens are single-use and rotated on every refresh per SPEC §7.4. Refresh does not extend the grant lifetime; after expires_at, the caller must re-authorize. If the HTTP response is lost after the server commits the rotation, retry the same previous refresh token immediately. During a five-minute (300-second) replay-recovery window, Grantex returns the already-rotated refresh token instead of rotating again while the grant remains active. After that window, or once the rotated child token has been used, the previous refresh token is rejected.
RefreshTokenParams
Response
Returns anExchangeTokenResponse — same shape as exchange(). See above for field descriptions.
Verify
Verify a grant token online via the Grantex API. This sends the token to the server for validation and returns the token’s metadata.VerifyTokenResponse
For local signature-and-claim verification without the online revocation
endpoint, use
verify_grant_token(). The
standalone helper still fetches the remote JWKS on every invocation.Revoke
Revoke a grant token by its token ID (JTI claim). The token is immediately invalidated and can no longer be used.Parameters
The method returns
None. A GrantexApiError is raised if the token does not exist or has already been revoked.