Your API returns 401 Unauthorized and the only clue is a long string starting with eyJ. That string is a JSON Web Token (JWT), and it usually tells you exactly what is wrong, once you can read it.
This guide explains what is inside a JWT, how to decode it, how to check its times, and how to verify its signature. Everything below can be done in the free JWT Decoder & Inspector, which runs in your browser.
What a JWT looks like
A JWT is three parts separated by dots:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 . eyJzdWIiOiIxMjMiLCJleHAiOjE3OTM3MzY3ODB9 . 4pcPyMD09olPSyXnrXCjTwXyr4BsezdI1AVTmud2fU4
header payload signature- The header says which algorithm signed the token, for example
{"alg":"HS256","typ":"JWT"}. - The payload holds the claims: who the user is, who issued the token and when it expires.
- The signature proves the header and payload were created by someone with the key and have not been changed.
The header and payload are only Base64URL-encoded, not encrypted. Anyone can read them. That is why you must never put passwords or secrets in a JWT.
Step 1: decode the token
Paste the token into JWT Decoder. You can paste the bare token or a whole Authorization: Bearer … header; the prefix is removed automatically. The header and payload are shown as formatted JSON.
Step 2: read the standard claims
| Claim | Meaning | What to check |
|---|---|---|
iss | Issuer | Is it your auth server (and the right environment)? |
sub | Subject, usually the user ID | Is it the user you expected? |
aud | Audience | Does it match the API that rejected it? |
exp | Expiry time | Is it in the past? |
nbf | Not valid before | Is it in the future? |
iat | Issued at | Does it look right, or is a clock wrong? |
jti | Token ID | Useful for revocation lists. |
Times are Unix timestamps (seconds since 1 January 1970). The inspector shows them as dates in your time zone and as "3 hours ago" or "in 10 minutes", which is much easier than converting them by hand.
Step 3: check the status
The status bar shows one of three states:
- Expired:
exphas passed. The client should have refreshed the token. - Not yet valid:
nbf(oriat) is in the future. Usually a server clock is ahead. - Not expired: the times are fine, so look elsewhere.
"Not expired" does not mean "genuine". That needs the signature check.
Step 4: verify the signature
Anyone can write a token with any payload; only the signature shows it is real. Enter the key in the inspector:
- HS256, HS384, HS512 (HMAC): the shared secret your server signs with.
- RS256-512, PS256-512 (RSA) and ES256-512 (ECDSA): the public key in PEM format (
-----BEGIN PUBLIC KEY-----). Identity providers publish it, often as a JWKS; convert the key you need to PEM.
The result appears immediately: Signature verified, or Invalid signature, meaning the key is wrong or the token was changed.
The token and key are processed with your browser's Web Crypto API and never sent anywhere. Even so, use test tokens where you can, and never paste other people's live tokens into any website.
Common 401 causes, and what the token shows
- Expired token. The status says Expired. Fix the refresh logic, or check that the client uses the new token after refreshing.
- Wrong audience.
audis for a different API, for example a token for the web app sent to the orders service. - Wrong environment.
issis the staging auth server but the request went to production, or the other way round. Verification with the production key fails. - Clock skew.
iatornbfis a few minutes in the future. Sync server clocks (NTP) or allow a small leeway. - Missing permission. The token is valid, but the
scopeorroleclaim lacks what the endpoint needs. - Header format. The API expects
Authorization: Bearer, but the client sent the token without "Bearer", or in a cookie.
Security checklist for JWTs
- Always verify signatures on the server, with a fixed list of allowed algorithms.
- Reject
alg: none. The inspector flags these tokens as unsigned. - Keep access tokens short-lived (minutes) and use refresh tokens for long sessions.
- Do not store secrets in the payload. It is readable by anyone.
- Use HTTPS everywhere, so tokens cannot be read in transit.
Related tools
- Compare HMAC signatures with HMAC Generator.
- Convert timestamps with Unix Timestamp Converter.
- Decode one Base64URL part with Base64 Encode/Decode.
Summary
To debug a JWT, paste it into the JWT Decoder & Inspector, read the claims, check whether it is expired or not yet valid, and verify the signature with the secret or public key. Most 401 errors turn out to be an expired token, the wrong audience or issuer, clock skew or a missing permission, and the decoded token shows which.



