Skip to main content

What it does

This example demonstrates the complete token refresh lifecycle:
  1. Authorize an active grant using the expiresIn parameter
  2. Use the token successfully while the grant remains active (local JWKS-based + online verification)
  3. Refresh the token — get a new JWT and rotated refresh token with the same grantId and expiresAt
  4. Use the refreshed token — verify it works with full scope access
  5. Refresh response recovery — retry the previous refresh token immediately to recover the already-rotated token
  6. Refresh token rotation — demonstrate that old refresh tokens cannot keep being reused
  7. Expired grant boundary — demonstrate that an expired grant must be re-authorized rather than refreshed

Prerequisites

  • Node.js 24 LTS (the tested repository toolchain)
  • Docker (Docker Desktop or Docker Engine with Compose)

Run

Start the local Grantex stack from the repository root:
In a separate terminal, run the example:

Expected output

Environment variables

Refresh boundary

expiresIn controls the underlying grant lifetime. Refresh rotates credentials for that active grant and does not extend the grant’s expiresAt. If the refresh response is lost after the server commits rotation, retry the previous refresh token immediately; Grantex can return the already-rotated refresh token during the five-minute recovery window. After the grant expires, the caller must re-authorize.

Source code

The full source is in 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 September 7, 2026