Overview
Thetokens sub-client handles the token lifecycle: exchanging authorization codes for grant tokens, verifying tokens via the API, and revoking tokens.
tokens.exchange()
Exchange an authorization code for a signed grant token (RS256 JWT).Parameters
string
required
The authorization code received at your
redirectUri after user consent.string
required
The ID of the agent that initiated the authorization request.
string
The PKCE code verifier. Required if
codeChallenge was provided in the authorize step. See PKCE.Response: ExchangeTokenResponse
string
The signed RS256 JWT grant token. Pass this to your agent for use in API calls.
string
The unique grant record ID.
string[]
The scopes granted by the user.
string
ISO 8601 timestamp when the underlying grant expires.
string
A refresh token for rotating credentials while the grant remains active.
tokens.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. ThegrantId and expiresAt 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 expiresAt, 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. After that window, or once the rotated child token has been used, the previous refresh token is rejected.
Parameters
string
required
The refresh token from a previous
exchange() or refresh() response.string
required
The agent ID associated with the grant.
Response: ExchangeTokenResponse
Returns the same shape as exchange() โ see above for field descriptions.
tokens.verify()
Verify a grant token online via the Grantex API. This is useful when you want server-side validation without managing JWKS yourself.Parameters
string
required
The grant token JWT string to verify.
Response: VerifyTokenResponse
boolean
Whether the token is valid and not expired/revoked.
string
The grant record ID (present when
valid is true).string[]
The granted scopes.
string
The user (principal) who authorized the grant.
string
The agent DID that holds the grant.
string
ISO 8601 timestamp when the token expires.
For local signature-and-claim verification without the online revocation
endpoint, use verifyGrantToken().
The standalone helper still resolves the remote JWKS on each call.
tokens.revoke()
Revoke a token by its token ID (thejti claim). The API responds with 204 No Content.
Parameters
string
required
The token ID (
jti claim from the JWT) to revoke.Response
Returnsvoid. The token is immediately invalidated.