JWT failures are usually caused by a small mismatch in claims, keys, algorithms, timestamps, or request formatting. This JWT debugging guide gives you a reusable workflow for decoding a token, validating it safely, identifying why an API rejected it, and separating client-side symptoms from server-side authentication problems.
Overview
A JSON Web Token (JWT) is commonly used to carry claims between an identity provider, an application, and an API. A compact JWT normally contains three Base64URL-encoded sections separated by periods:
header.payload.signature
The header describes the token type and signing algorithm. The payload contains claims such as the subject, issuer, audience, and expiration time. The signature helps the recipient detect whether the signed content was changed and whether it was produced by a trusted key.
A decoder can read the header and payload, but decoding does not prove that a token is authentic or acceptable. Verification requires checking the signature with the expected key and applying the receiving service's rules for issuer, audience, time limits, scopes, and other claims. Treat every decoded claim as untrusted until validation succeeds.
| Operation | What it tells you | What it does not prove |
|---|---|---|
| Decode | What data is present in the header and payload | That the token is genuine, unmodified, or authorized |
| Signature verification | Whether the token was signed by a matching trusted key | That every application policy requirement is satisfied |
| Claim validation | Whether issuer, audience, time, and other rules match expectations | That the user should receive every possible permission |
| Authorization check | Whether the validated identity has access to a specific resource | That the token was correctly issued if earlier checks were skipped |
When investigating a JWT invalid token error, keep these stages separate. A token can have a valid signature but the wrong audience. It can contain plausible claims but use an expired timestamp. It can be perfectly valid in one environment and rejected by another because the environments use different issuers or signing keys.
Checklist by scenario
When the token is rejected immediately
- Inspect the authorization header. Confirm that the request contains
Authorization: Bearer <token>, with one space afterBearerand no surrounding quotation marks. - Check token structure. A signed JWT generally has three dot-separated sections. A missing section, copied newline, truncated value, or extra prefix can cause parsing to fail.
- Compare environments. Confirm that the token was issued for the same staging, development, or production environment as the API receiving it.
- Review the server's error category. Distinguish malformed-token, signature, expiration, issuer, audience, and permission errors instead of treating every response as a generic authentication failure.
When the token is expired
- Read the
expclaim as a NumericDate, normally represented as seconds since the Unix epoch. - Compare it with the server's current time, not only the time on your development machine.
- Check
nbf, if present. A token can be rejected because it is not valid yet. - Consider limited clock skew between systems. Configure an explicit, small tolerance only where the identity and API libraries support it; do not use a large tolerance to conceal time synchronization problems.
- Obtain a fresh token through the intended authentication flow. Do not edit the payload to extend its lifetime.
When signature verification fails
- Confirm that the API is using the correct public key or shared secret for the token's issuer and environment.
- Check whether signing keys recently rotated. A verifier may need access to the current key set as well as a still-valid previous key during a planned transition.
- Compare the token header's
algvalue with the algorithms explicitly allowed by the verifier. - Do not select a verification algorithm solely from untrusted token input. Configure an allowlist in application code.
- Make sure the token was not altered by copying, logging, URL encoding, whitespace insertion, or a proxy that changed the request value.
When issuer or audience validation fails
- Compare the token's
issclaim with the exact issuer configured by the API. Differences in scheme, hostname, path, or trailing slash can matter. - Compare
audwith the API's expected audience. A token intended for a different service may be correctly signed but still unsuitable. - Check whether your identity provider uses a string or an array for the audience claim, and confirm that the selected library handles the expected form.
- Verify that the client requested a token for the intended resource or scope rather than for a related management or user-information endpoint.
When authorization fails after authentication succeeds
- Confirm that signature, issuer, audience, and time checks have passed.
- Inspect the claims used by the application for roles, scopes, groups, or permissions.
- Check naming and casing. For example, an API expecting
read:ordersmay not treatorders.readas equivalent. - Review the resource-level policy. A valid identity token does not automatically grant access to every endpoint.
What to double-check
Header and payload claims
Common header fields include typ and alg. Common payload claims include:
iss: the issuer that created the token.sub: the subject or principal represented by the token.aud: the intended recipient or service.exp: the expiration time.nbf: the time before which the token must not be accepted.iat: the time at which the token was issued.jti: a token identifier, when supplied.scope,roles, or similar fields: application-specific authorization data.
Do not assume that a claim has the same meaning across every identity provider. The API's configuration and documentation define which claims are required and how they are interpreted.
Safe debugging workflow
- Capture the request method, URL path, environment, response status, and correlation ID without recording the full token in a shared ticket.
- Decode the token locally or with a trusted internal utility to inspect its shape and non-sensitive debugging fields.
- Verify the signature using the issuer's configured key material and an explicit algorithm allowlist.
- Validate issuer, audience, expiration, not-before time, and any required token type or scope.
- Reproduce the request with a newly issued token and compare only the relevant differences.
- After debugging, revoke or rotate exposed credentials according to your organization's incident process.
A JWT decoder online can be useful for examining a token during development, but avoid pasting production access tokens into a public website. Tokens may contain personal data, internal identifiers, or credentials that remain usable until they expire or are revoked. Prefer local tooling, redacted samples, or a controlled developer utility.
Minimal validation design
Use your framework's maintained JWT middleware or a well-reviewed library rather than implementing cryptographic verification yourself. A sound validation configuration should explicitly define the trusted issuer, expected audience, permitted algorithms, key source, clock-skew policy, and required claims. Keep authentication and authorization as separate steps so that a successfully verified identity is still checked against the requested resource.
Common mistakes
- Confusing decoding with validation: readable JSON only proves that the token was parseable.
- Trusting payload roles before verification: claims must not drive access decisions until the token passes every required validation step.
- Using the wrong token: an identity token, access token, refresh token, and service token may have different audiences and intended uses.
- Ignoring environment configuration: copied development secrets, issuer URLs, or API audiences are frequent causes of staging and production failures.
- Accepting every algorithm: permit only the algorithms your application actually supports and expects.
- Logging complete tokens: access logs, exception traces, browser history, and monitoring systems can turn debugging data into a credential leak.
- Changing the payload manually: editing a claim invalidates the signature and does not create a legitimate token.
- Blaming the API too early: inspect the outgoing request, proxy behavior, server time, key selection, and configuration before changing application code.
For a repeatable engineering process, record the validation failure category and environment rather than storing sensitive token contents. Add automated tests for expired tokens, wrong audiences, unknown issuers, invalid signatures, missing scopes, malformed headers, and small clock differences. This turns one-off JWT debugging into an authentication regression suite.
When to revisit
Revisit this JWT debugging checklist whenever you integrate a new API, change identity providers, rotate signing keys, introduce a new environment, update authentication middleware, or change scopes and authorization rules. It is also worth reviewing before a seasonal planning cycle or a major release, when configuration drift and undocumented assumptions are more likely to surface.
Before closing an incident, run this practical sequence:
- Save a redacted example and the exact environment details.
- Confirm the authorization header and token structure.
- Decode for inspection, then verify the signature independently.
- Check algorithm, key, issuer, audience, expiration, not-before time, and scopes.
- Retest with a fresh token and a minimal request.
- Add a regression test or configuration check for the failure you found.
- Remove exposed tokens from tickets and logs, and rotate credentials if disclosure is possible.
Authentication tooling and library APIs change over time, so compare this workflow with the current documentation for your identity provider and framework when you update dependencies. The core rule remains stable: decode to inspect, verify to trust, validate claims to accept, and authorize access separately.