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 commit, retry the same previous refresh token with the same idempotency key. During a five-minute 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 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 the new refresh_token. Retry a lost response with the same old token and idempotency_key; a new SDK process cannot reconstruct an omitted key. After five minutes, after the rotated child token is used, or after grant expiration, reuse is rejected.

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 31, 2026