A user says they are logged in but get a 403 on the admin page. Before you read any server code, look at the token they are sending. A JWT's payload is only Base64URL-encoded, so you can read the claims without a secret and often find the cause in a minute.
JWT Decoder FREE online toolRuns in your browser. No sign-up, nothing to install. Open the tool →What a JWT contains
A token has three dot-separated parts: header, payload and signature. The header names the signing algorithm, such as HS256 or RS256. The payload holds claims. The signature proves the token was not altered, but verifying it needs the key, so decoding alone tells you what the token says, not whether it is genuine.
Step by step: reading a failing token
- Copy the token from the Authorization header (the part after "Bearer ") or from the browser's cookies or storage.
- Paste it into the JWT Decoder and read the header and payload.
- Check exp against the current time. Dates are in Unix seconds, so 1700000000 is not a millisecond value.
- Compare iss and aud with what your API expects.
- Look at the roles, scope or permissions claim for the exact value the protected route demands.
The claims that cause most failures
- exp: the token expired. Clients that cache tokens past their lifetime are the usual cause of sudden 401 errors.
- nbf or iat in the future: caused by clock drift between the issuer and the API server.
- aud: the token was issued for a different API than the one rejecting it.
- iss: a staging token sent to production, or the reverse.
- roles or scope: the claim exists but uses a different name or case, such as Admin versus admin.
A realistic example
Suppose the payload shows sub of 4821, role of editor and exp one hour in the past. The 403 is not a permission problem at all; the token is stale and the refresh logic failed. Alternatively, if exp is fine but the scope claim reads read:reports while the endpoint needs write:reports, the user simply was not granted that scope when the token was minted. Logging out and back in will not fix that; their account or the identity provider's configuration must change.
Short-lived tokens and refresh flows
Many apps issue access tokens that last 5 to 15 minutes and rely on a refresh token to get a new one. If users report being logged out at odd moments, decode a fresh token and subtract iat from exp to see the real lifetime. A 900 second gap means 15 minutes, which may be shorter than your front end assumes.
Also compare tokens before and after the failure. If the new token after login carries the right roles but the old one does not, the problem is not the permissions system; the client is simply continuing to send an outdated token from storage. Clearing that cache is the quickest fix, and fixing the refresh logic is the lasting one.
Handle tokens with care
Treat a real token like a password. Anyone holding a valid one can act as that user until it expires. A browser-based decoder is a sensible choice since nothing needs to be sent to a server, but you should still avoid pasting production tokens into tools you do not trust, and never into public chats or tickets. For shared bug reports, redact the signature or use a test account.
Remember that decoding does not validate. A forged token will decode just as nicely as a real one. Verification belongs in your server, using the correct key and algorithm.
Comments (0)
No comments yet. Be the first to share a thought.