Decode a JWT to find out whether a 401 is caused by expiry, the signature or aud
When an API returns 401 Unauthorized, I read the access token (JWT) in a browser-based JWT decoder and checked, in order, the header and payload, whether exp has passed, whether the signature matches the public key, and whether aud and iss line up. I also tested a tampered token, the default 120-second clock skew, what goes wrong when an HS256 shared secret is entered as Base64, and how to create test tokens.
I called an API and got 401 Unauthorized back. The request carries a long string in Authorization: Bearer eyJhbGciOi.... Staring at that string won’t tell you whether the token has expired, was issued in a different environment, or was meant for a different API.
A token in this format is a JWT (JSON Web Token), and its contents are JSON encoded with Base64URL. Anyone can read it by decoding it. Even so, I hesitate to paste a production token into whichever online decoder comes up first in a search. An access token that hasn’t expired yet is a “key”: whoever holds it can call the API with it.
The JWT Decoder / Encoder decodes and verifies signatures entirely inside the browser and never sends the token or keys anywhere. Using an expired token as the example, this article walks through reading its contents, then checking the signature, the expiry, and aud and iss. The second half covers the places where verification tends to trip you up, and how to create tokens for testing.
A JWT is three parts joined by dots
A JWT is a string of three parts, header.payload.signature, joined with . (RFC 7519; the signature format is defined in RFC 7515).
- Header: JSON that states the signing algorithm (
alg), the token type (typ), an ID showing which key signed it (kid), and so on. - Payload: JSON holding claims such as the issuer (
iss), the subject (sub), the audience (aud), the issued-at time (iat) and the expiration time (exp). - Signature: the header and payload parts signed with the issuer’s key.
The header and payload are not encrypted. Base64URL is Base64 with + replaced by -, / replaced by _ and the trailing = dropped; it is only a way of converting strings. What the signature guarantees is that “nothing has been changed since the issuer created it”, not that the contents are hidden. That is why you must not put anything secret in the payload.
The token used for testing
I assumed an access token signed with RS256 by the authorization server https://auth.example.com/ for the order API orders-api. The signing key is a 2048-bit RSA key pair generated with Node.js crypto. The token was issued at 9:00 on November 20, 2026, Japan time (UTC+9), which is 00:00 UTC, and expires one hour later. Save the files below and you can follow the same steps.
- expired-token.txt: the JWT used for testing (already expired)
- public.pem: the public key for checking the signature
Reading the contents
Paste the token into “JWT token” in the tool’s “Decode a token” section and press “Decode”. Pressing Enter also decodes it. It’s fine to leave Bearer or Authorization: Bearer at the start; line breaks and spaces are stripped before the token is parsed.
The header and payload are shown as indented JSON, and the Japanese name 「山田太郎」 (Taro Yamada) in the payload is displayed as is, non-ASCII characters included. The “Copy” button on each field copies the formatted JSON to the clipboard.
From the payload, we learn the following about this token.
| Claim | Value | Meaning |
|---|---|---|
iss |
https://auth.example.com/ |
The authorization server that issued it |
sub |
user-1024 |
The user the token was issued to |
aud |
orders-api |
The API that should accept this token |
scope |
orders:read |
The permitted operation (reading orders) |
iat |
1795132800 |
Issued-at time |
exp |
1795136400 |
Expiration time |
iat and exp are seconds since 00:00 UTC on January 1, 1970, and the decoded result shows them as plain numbers. To turn them into dates, paste them into the Unix Timestamp Converter. 1795136400 is 10:00:00 on November 20, 2026, Japan time (01:00:00 UTC). How to tell seconds from milliseconds and how time zones are handled is covered in detail in “Read Unix timestamps in JST and set the start of a log search”.
When you’re hunting for the cause of a 401, this is often enough to form a hypothesis. If exp is in the past, the token has expired; if aud differs from the API you’re calling, the token is for another API; if iss is the staging authorization server, you’ve mixed up environments. But decoding only tells you “what the token says”, not whether it’s genuine. That is what the signature check in the next step confirms.
Checking the signature and the expiry
The “Signature verification” section shows the decoded token’s alg and the length of the string being signed (the header and payload parts). Here it was alg: RS256, with a 265-character signing input. Below that, the current time is shown both in UTC and in the browser’s local time.
Which options you can pick under “Key type” depends on alg. RS and PS algorithms such as RS256 allow “Public key PEM” or “Certificate PEM”, ES algorithms allow “Public key PEM”, EdDSA allows “Public key PEM” or “Raw/Base64”, and HS algorithms allow “Shared secret”. Types that don’t fit are disabled.
I pasted the contents of public.pem (from -----BEGIN PUBLIC KEY----- to -----END PUBLIC KEY-----) into “Public key PEM” and pressed “Verify signature”.
The result was “⚠️ Signature valid” with the message “Signature is valid. Review the claim results.”, and the claims list showed “❌ exp: Expired”. The token is genuine, issued by this authorization server and not modified, but its lifetime is over. The diagnosis: the 401 is caused by expiry, and the client fixes it by obtaining a new token.
The exp checkbox under “Claim validation” is ticked from the start. For a token without exp, the tool shows “exp is missing” and the result is “⚠️ Signature valid”. Only when the signature matches and every checked claim passes does it show “✅ Valid”.
A different key, or a tampered token
When I verified the same token with the public key from a separately generated key pair, the result was “❌ Invalid” with the message “Signature does not match.” This is what you’ll see if you mix up tokens from environments with different keys, such as staging and production.
I also tried a token in which I changed scope in the payload from orders:read to orders:write and reattached the original signature part. Decoding succeeds without complaint, and the payload shows orders:write. In other words, anyone can rewrite the contents. Verify it with the correct public key, though, and it comes out “❌ Invalid”. The signature is computed over the header and payload strings, so changing a single character breaks the match.
Where to get the public key
Authorization servers usually publish the public keys used to check signatures as a JSON document called a JWKS (JSON Web Key Set). This tool doesn’t fetch JWKS, and it can’t read keys in JWK format either. Picking the right key based on the kid in the header is also up to you. Prepare the public key as a PEM starting with -----BEGIN PUBLIC KEY-----, or as a certificate PEM starting with -----BEGIN CERTIFICATE-----. For a certificate, choose “Certificate PEM” and the tool extracts the public key from it before verifying. You can check who issued a certificate you have and when it expires with the X.509 / CSR Decoder.
Matching aud and iss
Claims other than exp are only compared when you tick them and enter an expected value. To check a token sent to the wrong audience, I unticked exp, ticked aud and entered payments-api in “Expected aud”. This is the situation where you meant to call the payments API but sent a token for the order API.
The result was “❌ aud: aud=orders-api does not match the expected values”. You can enter several expected values separated by commas. If the token’s aud is an array, it counts as a match when any one of its entries is among the expected values.
iss is compared as an exact string match. When I entered https://auth.example.com (no trailing slash) as the expected value, it was reported as not matching the token’s https://auth.example.com/. Whether an issuer URL ends with a slash depends on the authorization server, and this one character in the API server’s configuration can make verification fail. The safest way is to copy the value from the token and compare.
Expiry checks have a 120-second grace period
The default for “Allowed clock skew (seconds)” is 120. The clocks on the issuing server and the verifying server never agree perfectly, so the comparisons for exp, nbf and iat allow this many seconds of leeway. RFC 7519 also says implementers may provide a small leeway, usually no more than a few minutes, to account for clock skew.
To see the effect, I created a token that had expired one minute earlier and verified it. With the default of 120 seconds it came out “✅ Valid”, and the claim result showed the exp value followed by “(remaining 0 seconds)”. A token that had expired three minutes earlier was reported as “Expired”. With the allowed skew set to 0, the token that had expired one minute earlier was also “Expired”.
If your API server verifies with no leeway, a token the tool calls “Valid” may still be treated as expired by the server. When you investigate the boundary of the expiry, set the allowed skew to the same value as the server.
HS256 shared secrets are treated as strings
HS256, HS384 and HS512 are schemes in which the issuer and the verifier hold the same shared secret. The tool uses the string entered in “Shared secret” directly as UTF-8 bytes for the key.
Some environments store the shared secret Base64-encoded in a configuration file or environment variable. For a token signed with the bytes obtained by Base64-decoding the secret, entering the Base64 string from the configuration file as is gave “❌ Invalid”. The key I tested decodes to the string secret-key-for-demo-0123456789abc, and entering that gave “✅ Valid”.
Check the issuer’s library settings to find out whether the key is Base64 or a raw string. If Base64-decoding the key produces bytes that can’t be read as text, you can’t enter it in the tool’s shared secret field. To turn Base64 back into a string, use the Base64 Converter.
Creating test tokens
While developing an API, you’ll want tokens that haven’t expired, or tokens with a different aud. The “Encode / Sign” section lets you edit the JSON and create a signed JWT.
Here I took the decoded token and created one with a later expiry.
- Press “Import decoded data”. The header and payload JSON go into the editors, and “Signing algorithm” is set to RS256 to match the header’s
alg. - Under “Quick helpers”, press “iat=now” and “exp=+1h”.
iatis rewritten to the current time andexpto one hour later, in UNIX seconds. There are alsoexp=+24h,exp=+7d,nbf=now, and “Generate jti”, which inserts a randomjti. - Under “Key input method”, choose “Private key PEM” and paste the signing private key.
- Press “Generate token”. “✅ Generated successfully” appears and the token is shown in “Generated JWT”.
Pressing “Load into decoder” loads the generated token into the decode section. Leaving the public key as the same public.pem and pressing “Verify signature” now gave “✅ Valid”, and the claim result showed “remaining 3599 seconds”.
For the signing private key, the tool accepts PKCS#8 keys starting with -----BEGIN PRIVATE KEY-----, and for RSA also the -----BEGIN RSA PRIVATE KEY----- format. If you paste a -----BEGIN EC PRIVATE KEY----- key for ES256 or similar, it shows “Convert EC PRIVATE KEY (SEC1) to PKCS#8 before using it”. In that case, convert the key with OpenSSL first.
openssl pkcs8 -topk8 -nocrypt -in ec-key.pem -out ec-key-pkcs8.pem
If you choose “none (no signature)” as the signing algorithm, a confirmation dialog appears before the token is generated. This is only for testing whether a system accepts unsigned tokens, and the result is shown as “⚠️ Unsigned”.
If you need a certificate and key for development, the X.509 Certificate Generator creates a self-signed certificate and private key. How to extract the private key and certificate PEM from a PFX file exported on Windows is covered in “Using a Windows PFX with Nginx”.
Sample buttons and cleanup
Even without a token of your own, you can see how the tool behaves with “HS256 sample”, “RS256 sample”, “ES256 sample” and “EdDSA sample” in the decode section. The HS256 sample is a fixed token signed with the shared secret secret; it has no exp, so verification shows “⚠️ Signature valid” along with “exp is missing”. Each of the other three generates a key pair in the browser every time you press it, fills the input fields with a token valid for one hour and its public key, and runs the verification. The EdDSA sample and EdDSA verification only work in browsers that support Ed25519.
When “Clear on exit” in the decode section is ticked, the token, key and generated-token fields are emptied when you leave the page. It is ticked by default.
Note that this tool reads signed JWTs (JWS). An encrypted JWT (JWE), which has five parts, can’t be decoded because its payload is encrypted, and the tool reports an error.
Test environment
- JWT Decoder / Encoder (operated in the English version; messages also checked in the Japanese version), Chromium (via Playwright)
- The test key pairs and tokens were created with
cryptoin Node.js 22, and I also confirmed withcrypto.verifythat the signatures match