What it does
This example demonstrates the complete token expiry and refresh lifecycle:
- Authorize with a short-lived token (10 seconds) using the
expiresIn parameter
- Use the token successfully before it expires (local JWKS-based + online verification)
- Wait for expiry — observe the token becoming invalid
- Detect expiry — local JWKS-based verification throws, online returns
valid: false
- Refresh the token — get a new JWT with the same
grantId and fresh expiry
- Use the refreshed token — verify it works with full scope access
- Refresh token rotation — demonstrate that old refresh tokens are single-use
Prerequisites
- Node.js 18+
- 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
Source code
The full source is in examples/token-expiry-refresh/src/index.ts.Last modified on July 11, 2026