When a JWT-based request fails, the fastest path is to separate three questions: what does the token contain, is its signature valid, and does the API accept its claims for this request? This guide provides a repeatable workflow for using a JWT decoder safely, checking expiration and issuer or audience values, verifying signatures on the server, and tracing authentication failures through client and backend logs.
Overview
A JSON Web Token usually has three dot-separated parts: a header, a payload, and a signature. The header and payload are encoded data; they are not encrypted merely because they appear in a JWT. Anyone who obtains a token may be able to decode those sections, so tokens should never contain passwords, private keys, or other secrets.
Decoding is useful for inspection, but it does not prove that a token was issued by a trusted authority. A browser-based JWT decoder can help you read claims during local testing, while cryptographic verification must happen in the API or another trusted backend component using the expected algorithm and key. Treat those as separate debugging steps:
- Decode: inspect the token’s structure and readable claims.
- Validate: check time-based and application-specific rules such as expiration, issuer, audience, and required scopes.
- Verify: confirm the signature with a trusted key and an explicitly allowed algorithm.
- Authorize: decide whether the authenticated identity may perform the requested operation.
This distinction explains many confusing reports. A token can decode correctly but fail signature verification. It can have a valid signature but be expired, intended for a different API, or missing the permission required by an endpoint.
What to track
Token structure and claims
Start by recording the request ID, endpoint, HTTP method, response status, and a redacted token fingerprint. Do not put the complete token in shared tickets or ordinary logs. For local testing, inspect the header and payload with a JWT decoder or a local script. The most useful claims commonly include:
| Claim | What it indicates | Debugging question |
|---|---|---|
alg | The signature algorithm named by the token header | Does the server allow this algorithm, and does it match the configured verifier? |
kid | A key identifier, when the issuer publishes or rotates multiple keys | Can the verifier find the corresponding trusted key? |
iss | The token issuer | Does it exactly match the issuer configured for this environment? |
aud | The intended recipient or service | Does the API’s expected audience match the token, including its data type? |
sub | The subject, often a user or service identifier | Does this identity map to an account or service in the current environment? |
exp | Expiration time, generally represented as a numeric timestamp | Has the token expired, or is the server clock substantially different? |
nbf | Not-before time, when present | Is the request arriving before the token becomes valid? |
iat | Issued-at time | Was the token issued recently enough for the application’s rules? |
scope or roles | Application permissions | Does the identity have the permission required by this route? |
Time claims are commonly expressed as seconds since the Unix epoch. Compare them with the server’s current time rather than relying only on a browser clock. A small clock tolerance may be appropriate for distributed systems, but it should be deliberate and consistent rather than used to hide a larger time-sync problem.
Verification and configuration
For a signature failure, track the environment, issuer configuration, key source, selected algorithm, and key ID. A common cause is mixing development and production settings: a token issued by one identity provider or tenant is sent to an API configured for another. Another is key rotation, where the issuer begins signing with a new key and the verifier has not refreshed its trusted key set.
Use your framework’s maintained JWT library for verification. Configure an explicit allowlist of algorithms and validate the expected issuer and audience through the library’s verification options. Do not accept the algorithm simply because the token header requests it, and do not treat a decoded payload as authenticated data.
Request flow and logs
Trace the token from acquisition to rejection. Record whether the client received it from a login response, a refresh flow, a cookie, or another service; which request attached it; and which middleware rejected it. Compare the client’s request with a known-good request, including the authorization scheme, host, path, and environment. Browser storage is often part of this investigation, so inspect cookies and storage carefully without copying sensitive values into screenshots or issue trackers. The browser storage debugging guide can help separate a missing credential from an invalid one.
Cadence and checkpoints
JWT failures are easiest to resolve when teams use the same checkpoints every time. During local development, add a small authentication test matrix covering a valid token, an expired token, an incorrect audience, an incorrect issuer, a missing scope, a malformed token, and a token signed with an untrusted key. The expected response should be documented for each case, without exposing token contents in test output.
Before a release, verify that configuration points to the intended issuer, audience, key endpoint or key store, and algorithm allowlist. Test both access-token and refresh-token paths if the application uses them. Confirm that a token for one environment cannot accidentally authorize requests in another.
On a monthly or quarterly review cadence, inspect authentication error trends by category rather than counting all failures together. Useful categories include missing credentials, malformed tokens, expiration, signature failure, issuer mismatch, audience mismatch, and insufficient permissions. Also review key-rotation behavior, clock synchronization, dependency updates, and changes to identity-provider configuration. These checks are especially valuable before planned changes to domains, tenants, API audiences, or deployment environments.
During an incident, create a timeline containing the first failing request, the affected deployment or configuration change, issuer and key identifiers, and whether failures affect all users or only a subset. If the issue involves a third-party webhook or service-to-service token, keep its signature and retry investigation separate from browser login debugging; the request flow and verification rules may differ.
How to interpret changes
A sudden increase in missing-token responses usually points to client behavior, cookie attributes, a proxy stripping the authorization header, or a changed route. Inspect the actual request at the API boundary before changing token validation.
A rise in expired-token responses may indicate a legitimate increase in stale browser sessions, a refresh flow that is not running, or clock drift. Compare the token’s exp and iat values with server time and check whether refresh requests are succeeding.
Issuer or audience mismatches commonly indicate an environment mix-up or a changed identity-provider configuration. Compare the exact claim values, including capitalization and whether the audience is represented as a string or an array. Avoid “fixing” the error by accepting every issuer or audience; that weakens the boundary the check is intended to enforce.
Signature failures require a different investigation from claim errors. Check the token’s key ID, the verifier’s key set, algorithm configuration, and key rotation timing. If only some instances fail, compare their deployed configuration and cached keys. If every instance fails immediately after a deployment, inspect configuration loading and secret or key availability.
Finally, distinguish authentication from authorization. A successfully verified token proves that the request carries an accepted identity, not that the identity may read or modify every resource. A consistent 403 response after successful verification may be the correct result of a missing role, scope, ownership check, or tenant restriction.
When to revisit
Revisit this workflow whenever an identity provider, signing key, JWT library, framework middleware, API audience, cookie policy, or deployment environment changes. It is also worth reviewing on a monthly or quarterly schedule so that authentication logs, test cases, and operational runbooks do not drift away from the running system.
Use this practical checklist when you need to debug a JWT token:
- Capture the endpoint, method, status code, request ID, environment, and a safe token fingerprint.
- Confirm that the token has the expected three-part structure and decode it only in a trusted local or approved tool.
- Inspect
exp,nbf,iss,aud,sub, and permission claims. - Verify the signature on the server with an explicit algorithm allowlist and trusted key.
- Compare issuer, audience, key ID, and configuration across the client, API, and identity provider.
- Check whether the failure is authentication, authorization, transport, storage, or refresh-related.
- Redact tokens from logs, screenshots, tickets, and chat transcripts; revoke or rotate exposed credentials according to your incident process.
- Convert the final diagnosis into a regression test and update the relevant runbook.
For a deeper pass over claim decoding, signature verification, and common authentication errors, continue with the JWT debugging guide. Keeping the checklist and test matrix current turns JWT troubleshooting from guesswork into a routine backend workflow.