Skip to main content

JWT Token Management

Deep dive into JWT-based authentication.

Token Types​

TokenPurposeLifetime
Access TokenAPI authentication15 min-1hr
Refresh TokenRenew access token7-30 days

Token Structure​

{
"header": { "alg": "HS256", "typ": "JWT" },
"payload": {
"id": "user-uuid",
"tenantId": "tenant-uuid",
"role": "ADMIN",
"iat": 1709635260,
"exp": 1709638860
}
}

Configuration​

JWT_SECRET=your-secret-key-min-32-chars
JWT_TOKEN_EXPIRATION_TIME=3600
JWT_REFRESH_TOKEN_SECRET=your-refresh-secret
JWT_REFRESH_TOKEN_EXPIRATION_TIME=604800

Token Flow​

Security Best Practices​

PracticeImplementation
Strong secretMin 256-bit secret key
Short expirationAccess: 15-60 min
Refresh rotationIssue new refresh on use
HTTPS onlyPrevent token interception
HttpOnly cookiesPrevent XSS access
Token blacklistingInvalidate on logout