A JWT decoder can quickly reveal a token’s header and claims, but decoding is not the same as verifying authentication. This guide explains how to inspect a JWT safely, interpret expiration, audience, and issuer values, validate signatures with application libraries, and troubleshoot failures without exposing secrets or production credentials.
Overview
JSON Web Tokens (JWTs) are compact strings commonly used to carry authentication and authorization data between an identity provider, an API, and a client. A token usually has three Base64URL-encoded parts separated by periods:
header.payload.signature
Conceptually, the structure looks like this:
┌──────────────┐ . ┌───────────────┐ . ┌────────────────┐
│ Header │ │ Payload │ │ Signature │
│ alg, typ, kid│ │ sub, iss, exp │ │ Integrity proof │
└──────────────┘ └───────────────┘ └────────────────┘
metadata claims verification
A JWT decoder reads the first two sections and converts them into JSON. That is useful for debugging an API request, checking which claims an identity provider issued, or confirming whether a token is already expired. It does not prove that the token came from a trusted issuer or that its contents are authentic. Anyone can create a string with readable JSON in the header and payload.
For that reason, use an online JWT token decoder only with a deliberately non-sensitive sample. Do not paste live access tokens, refresh tokens, API credentials, private keys, or shared signing secrets into an untrusted browser tool. A local decoder or a trusted development environment is safer for real debugging.
What to track
When inspecting a token, record the values that affect the API’s acceptance decision. Registered claims have common meanings, although an application may impose additional rules.
| Field | Purpose | Typical troubleshooting question |
|---|---|---|
iss | Identifies the token issuer. | Does it match the issuer configured by the API? |
sub | Identifies the subject, often a user or service. | Is this the expected identity or principal? |
aud | Identifies the intended recipient or audience. | Does it include the API’s expected audience? |
exp | Expiration time, represented as a numeric date. | Has the token expired, including clock-skew considerations? |
nbf | “Not before” time. | Is the token being used before it becomes valid? |
iat | Time at which the token was issued. | Was it issued when expected, or is it unexpectedly old? |
jti | A token identifier when supplied. | Can this token be correlated with logs or a denylist? |
Also inspect the header. The alg value identifies the intended signing algorithm, while kid can identify which public key should be used when a key set contains several keys. Treat both as input to a strict verification policy, not as instructions to trust automatically. The server should allow only algorithms and keys configured for that issuer and endpoint.
Reading a token in code
For a quick local inspection, decoding is enough. The following JavaScript example reads the payload without claiming that it is valid:
function decodeJwtPayload(token) {
const parts = token.split('.');
if (parts.length !== 3) throw new Error('Expected a JWT with three parts');
const base64 = parts[1].replace(/-/g, '+').replace(/_/g, '/');
const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, '=');
return JSON.parse(atob(padded));
}
const payload = decodeJwtPayload(token);
console.log(payload.exp, payload.aud);
In Python, a JWT library may expose an explicit unverified decode operation for inspection. Use that operation only for diagnostics; use the library’s normal verification API, configured with the trusted key, issuer, audience, and permitted algorithms, before accepting a token.
Decode versus verify
Keep these steps separate in your notes and code:
- Decode: parse the header and payload to view their contents.
- Validate claims: check times, issuer, audience, subject requirements, and application-specific permissions.
- Verify the signature: use the trusted secret for a shared-key algorithm or the trusted public key for a public-key algorithm.
- Authorize: determine whether the verified identity may perform the requested action.
Cadence and checkpoints
JWT troubleshooting is usually event-driven, but teams benefit from a recurring review of their token configuration. A monthly or quarterly checkpoint can catch drift between identity-provider settings, API middleware, and client behavior.
- Confirm that each API has an explicit issuer, audience, and permitted-algorithm configuration.
- Review signing-key rotation behavior, including how the application discovers and caches public keys.
- Check access-token and refresh-token lifetimes against the intended user experience and threat model.
- Verify that logs record useful failure categories without recording complete tokens or secrets.
- Test expired, not-yet-valid, wrong-audience, wrong-issuer, and invalid-signature cases in a non-production environment.
When a library or identity provider changes its JWT API, review verification calls rather than copying an old decoding snippet. Names and defaults vary across JavaScript, Python, Go, Java, and other ecosystems. The durable requirement is the same: verification must be explicit and bound to trusted configuration.
How to interpret changes
An authentication error becomes easier to isolate when you compare the token’s claims with the API’s expected configuration. An exp failure points toward token lifetime, client caching, or clock differences. An nbf failure can indicate a clock mismatch or a token intentionally issued for later use. An audience failure generally means the client requested a token for one resource while sending it to another. An issuer failure often means the token came from a different tenant, environment, or identity-provider configuration.
A signature failure is different from a claim failure. Check that the API selected the correct key, that the key identifier is available, that the configured algorithm matches the issuer’s algorithm, and that the token was not altered or truncated in transit. Do not “fix” a signature error by disabling verification or accepting every algorithm. That changes a debugging problem into a security vulnerability.
Also inspect the request itself. Confirm the token is sent in the expected Authorization: Bearer header, that a proxy has not removed or rewritten it, and that the client is not sending an old token after a login or refresh operation. For a broader request-level investigation, see the API debugging workflow for HTTP errors, headers, CORS, and request bodies.
When to revisit
Return to this guide whenever authentication behavior changes, not just when a login fails. Revisit it after rotating signing keys, changing token lifetimes, adding an audience, moving between development and production issuers, upgrading a JWT library, or introducing a new gateway or API service.
For a practical checkpoint, save a redacted diagnostic record containing the token’s header, non-sensitive claim values, request timestamp, expected issuer and audience, verification result, and error category. Never save the complete bearer token in tickets or chat. Then work through this checklist:
- Is the token structurally a three-part JWT?
- Can the header and payload be decoded as valid JSON?
- Are
iss,aud,exp, andnbfconsistent with the API configuration and current time? - Did the server verify the signature with the expected key and an allowed algorithm?
- Did the request transport the intended token without proxy or client substitution?
- After authentication succeeds, does authorization permit the requested operation?
A JWT decoder is valuable as an inspection tool, but it is only the first checkpoint. Treat decoded data as untrusted until cryptographic verification and claim validation succeed. That distinction keeps token debugging useful while preserving the security boundary around your APIs.