Authentication & SecurityAuth Simulation• 4 min read
How to Test Expired JWT Tokens and Session Timeout Flows
Summary: Force your authentication API to return 401 Unauthorized with token-expired payloads to verify that token refresh routines and logout modals fire properly.
Why This Rule Matters for Developers & QA
Waiting for JWT tokens to expire naturally takes minutes or hours. Forcing token expiry at the network layer verifies refresh-token rotation in seconds.
Step-by-Step Implementation Guide
1
Target Protected User Endpoints
Match authenticated resource URLs (e.g. `*/api/v1/user/profile*`).
2
Flip Status to 401 with Token Expired Body
Set response code to 401 and supply an error code `{"error": "TOKEN_EXPIRED"}`.
3
Validate Silent Refresh
Verify that your application interceptor catches the 401, issues a refresh request to `/auth/refresh`, and retries the original request.
Configuration Snippet
{
"id": "rule_force_jwt_expired",
"pattern": "*/api/v1/user/profile*",
"action": "mock-response",
"responseStatus": 401,
"responseBody": {
"success": false,
"error": "TOKEN_EXPIRED",
"message": "Access token has expired. Please refresh credentials."
},
"enabled": true
}