Documentation Index
Fetch the complete documentation index at: https://docs.grantex.dev/llms.txt
Use this file to discover all available pages before exploring further.
What it does
This example demonstrates the complete token expiry and refresh lifecycle:- Authorize with a short-lived token (10 seconds) using the
expiresInparameter - Use the token successfully before it expires (offline + online verification)
- Wait for expiry — observe the token becoming invalid
- Detect expiry — offline verification throws, online returns
valid: false - Refresh the token — get a new JWT with the same
grantIdand 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:Expected output
Environment variables
| Variable | Default | Description |
|---|---|---|
GRANTEX_URL | http://localhost:3001 | Base URL of the Grantex auth service |
GRANTEX_API_KEY | sandbox-api-key-local | API key. Use a sandbox key for auto-approval |
TOKEN_TTL | 10s | Grant token time-to-live (e.g. 10s, 1m, 1h) |
Source code
The full source is inexamples/token-expiry-refresh/src/index.ts.