Skip to main content

Overview

The example takes one grant through its refresh lifecycle and lets a second grant expire:
  1. Authorize a grant with an expiresIn lifetime (GRANT_TTL, default 5m).
  2. Verify the grant token locally against the JWKS and with the service.
  3. Refresh. The new grant token keeps the grantId; the grant’s expiresAt stays the same.
  4. Verify again with the refreshed token.
  5. Retry a lost response. Sending the first refresh token again at once returns the refresh token it was already rotated to.
  6. Rotation. After the rotated refresh token is used, the first one is refused.
  7. Expiry. A second grant with a short lifetime (EXPIRED_GRANT_TTL, default 3s) lapses; its token stops verifying and refresh is refused, so a new authorization is required.

Prerequisites

  • Node.js 24 LTS
  • Docker with Compose

Run

From the repository root, start the local stack:
Then, in another terminal:

Sample output

Configuration

Retrying a lost refresh response

If the service commits a rotation but the client never receives the reply, the client can send the same refresh token again, with the same Idempotency-Key, within five minutes and receive the refresh token it was rotated to. Recent SDK releases reuse the key for such a retry automatically. Once the rotated refresh token has been used, the earlier one is refused. Refresh never extends the grant: after expiresAt the agent needs a new authorization.

Source code

See examples/token-expiry-refresh/src/index.ts.

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 October 21, 2026