JWT Decoder · Tutorial

How to find out why an API rejects your JWT

7 min readintermediateUpdated

Your request returns 401 Unauthorized even though you're sending a token. Before digging through server logs, look inside the token itself. Most rejections come from a handful of claims. This tutorial checks them one by one, using a sample token that has expired, and shows how to confirm the signature.

What you need

  • The JWT Decoder
  • The token your app sends, for example from the Authorization header in your browser's Network tab (the Try it button loads a sample)

Steps

  1. Copy the token

    In your browser's developer tools, open the failing request and find the Authorization header. Copy everything after Bearer , or the whole value, since the prefix is removed automatically. Paste it into the decoder.

  2. Check the expiry badge first

    The sample shows a red Expired badge. Its iat (issued at) is 30 October 2026 at 09:00 UTC, and exp is exactly one hour later. An expired token is the most common cause of a 401. The app should refresh it or ask the user to sign in again.

  3. Check the audience and issuer

    Look at Audience (aud) and Issuer (iss). The sample's audience is orders-api and its issuer is https://auth.example.com. If the API you're calling expects a different audience, or tokens from a different auth server (for example production instead of staging), it will reject the token even if it hasn't expired.

  4. Check roles and scopes

    If the error is 403 Forbidden rather than 401, the token is accepted but lacks permission. Look for claims like role, roles, scope or permissions. The sample user is an editor, so an admin-only endpoint would refuse them.

  5. Verify the signature

    Open Verify the signature, enter the secret bentools-demo-secret and press Verify. A green badge confirms the token was signed with that secret and not altered. A red badge with the right secret means the token was changed, or the server uses a different key than you think.

Try it yourself

Opens the JWT Decoder with this tutorial's sample loaded.

Try it now

Common mistakes

Ignoring clock differences
Expiry is checked against the server's clock. If your device's clock is off, the status here can differ from what the server sees. Some servers also allow a small grace period.
Sending the ID token instead of the access token
Sign-in flows often return both. ID tokens usually have your app as their audience, not the API. Check the aud claim to tell them apart.
Pasting tokens into chat or tickets
A token that hasn't expired lets anyone act as that user. Share only expired tokens, or copy just the claims you need.

Next steps

Go back to the JWT Decoder, or keep going with one of these:

FAQ

Can I make the token valid again by editing exp?

No. Changing any part of the payload invalidates the signature, and a correctly configured server will reject it.