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
The authorization code received at your
redirectUri after user consent.The ID of the agent that initiated the authorization request.
The PKCE code verifier. Required if
codeChallenge was provided in the authorize step. See PKCE.Response: ExchangeTokenResponse
The signed RS256 JWT grant token. Pass this to your agent for use in API calls.
The unique grant record ID.
The scopes granted by the user.
ISO 8601 timestamp when the grant token expires.
A refresh token for obtaining new grant tokens without re-authorization.
tokens.refresh()
Refresh a grant token using a refresh token. Returns a new grant token and a new refresh token (the old refresh token is invalidated). ThegrantId stays the same.
Refresh tokens are single-use and rotated on every refresh per SPEC §7.4.
Parameters
The refresh token from a previous
exchange() or refresh() response.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
The grant token JWT string to verify.
Response: VerifyTokenResponse
Whether the token is valid and not expired/revoked.
The grant record ID (present when
valid is true).The granted scopes.
The user (principal) who authorized the grant.
The agent DID that holds the grant.
ISO 8601 timestamp when the token expires.
For zero-latency, offline verification without calling the Grantex API, use verifyGrantToken() instead.
tokens.revoke()
Revoke a token by its token ID (thejti claim). The API responds with 204 No Content.
Parameters
The token ID (
jti claim from the JWT) to revoke.Response
Returnsvoid. The token is immediately invalidated.