Skip to main content

Overview

The tokens 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)
Access the tokens client via 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. The grant_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 an ExchangeTokenResponse — same shape as exchange(). See above for field descriptions.
Each refresh token can only be used once. Always store and use the new refresh_token from the response. The previous token is accepted only for lost-response recovery during the five-minute window while the grant remains active; after the window, after the rotated child token is used, or after grant expiration, reuse is rejected with a 400 error.

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.

Complete Flow Example

Ownership

Grantex is owned by Orchestrum Technologies LLP. Inventor and owner: Sanjeev Kumar. Ownership contact: sanjeev@orchestrum.in or mishra.sanjeev@gmail.com.
Last modified on August 29, 2026