A JWT decoder is useful for seeing what an authentication token contains, but decoding is not the same as trusting or verifying it. This guide explains JWT structure, safe local inspection, claim validation, common expiration and signature failures, and a repeatable checklist for debugging tokens without exposing credentials.
Overview
JSON Web Tokens, or JWTs, are compact strings commonly used to carry identity and authorization data between an application, an API, and an identity provider. A typical token has three Base64URL-encoded sections separated by periods:
header.payload.signature
The first two sections are readable after decoding. The third is a cryptographic value that must be verified with the correct key and algorithm. Anyone who possesses a JWT can usually decode its header and payload, so a token must never contain passwords, private keys, client secrets, or other information that should remain confidential.
| Part | Usually contains | What inspection tells you |
|---|---|---|
| Header | alg, typ, and sometimes kid | Which token type and signing-key identifier the issuer declares |
| Payload | Claims such as iss, sub, aud, exp, and iat | Identity, intended audience, timestamps, scopes, and application-specific data |
| Signature | Encoded cryptographic signature | Whether the token was signed with the expected key and accepted algorithm |
Use a JWT decoder online only with deliberately non-sensitive test tokens. For production tokens, access tokens copied from a browser, refresh tokens, session credentials, and webhook secrets, prefer a local decoder or a controlled development environment. A decoder can help you inspect claims; it cannot establish that a token is authentic.
What to track
1. Token anatomy and formatting
Start by checking whether the value has exactly three non-empty sections. A malformed token may contain a missing period, copied quotation marks, a prefixed word such as Bearer, line breaks, or URL encoding that was not handled correctly.
For an HTTP request, the header normally looks like this:
Authorization: Bearer eyJhbGciOi...When decoding the value, remove only the Bearer prefix and preserve the token itself. Do not trim or transform characters casually; Base64URL uses a URL-safe alphabet and is sensitive to altered content.
2. Header values
Inspect the declared algorithm, token type, and key identifier. The alg value must be permitted by the API's verification configuration. Do not accept an algorithm merely because the token declares it. The verifier should choose an allowed algorithm and reject unexpected values.
If the header includes kid, confirm that the receiving service can find the corresponding public key or secret in its configured key set. A missing or stale key identifier can produce an invalid-signature error even when the token was issued correctly.
3. Registered claims
Claims are assertions, not automatically trusted facts. Track at least these fields during an investigation:
iss(issuer): identifies the system that issued the token. Compare it with the exact issuer configured by the API, including scheme, host, path, and trailing-slash conventions where relevant.sub(subject): identifies the user, service, or principal. Confirm that your application interprets this identifier as expected.aud(audience): identifies the intended recipient. It may be a string or an array, so validation must support the format issued by the identity provider.exp(expiration time): a numeric date, generally represented as seconds since the Unix epoch. A token should not be accepted after this time.nbf(not before): prevents use before a specified time when the issuer includes it.iat(issued at): indicates when the token was created. It can help reveal stale tokens, incorrect environments, or clock problems.jti(JWT ID): an optional identifier useful for tracing or replay controls when the application supports them.
Also record scopes, roles, permissions, tenant identifiers, and custom claims, but validate each according to the API's contract. A claim's presence alone does not prove that it is authorized or safe to use.
4. A safe local decoding workflow
For a quick local inspection, use a small script that decodes the header and payload without verifying the signature. This is an inspection step only:
const token = process.env.JWT || "";
const parts = token.split(".");
if (parts.length !== 3) {
throw new Error("Expected a JWT with three sections");
}
const decode = (value) => {
const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
const padded = normalized + "=".repeat((4 - normalized.length % 4) % 4);
return JSON.parse(Buffer.from(padded, "base64").toString("utf8"));
};
console.log({ header: decode(parts[0]), payload: decode(parts[1]) });Place the token in an environment variable rather than committing it to a source file or shell history when possible. Delete diagnostic output after the investigation and avoid sharing complete tokens in issue trackers, screenshots, chat, or logs. If a live credential has been exposed, treat it as compromised and follow the issuer's rotation or revocation procedure.
5. Verification with an application library
Use a maintained JWT library for verification instead of implementing cryptography yourself. In a Node.js service using the jose package, a simplified verification pattern might look like this:
import { jwtVerify } from "jose";
const secret = new TextEncoder().encode(process.env.JWT_SECRET);
const { payload } = await jwtVerify(token, secret, {
issuer: "https://issuer.example",
audience: "your-api"
});
console.log(payload.sub);The exact key type, issuer, audience, and allowed algorithms must match your identity system. For asymmetric signing, retrieve the issuer's trusted public keys through the integration's documented key-distribution method and configure key rotation deliberately. Do not replace verification with a check that merely reads the payload.
Cadence and checkpoints
JWT debugging is most effective when it becomes a small, repeatable operational check rather than an improvised exercise. Use these checkpoints:
- During integration: Save a redacted example containing the token shape and relevant claim names, not a live credential. Document the expected issuer, audience, algorithm family, clock assumptions, and required scopes.
- Before a release: Test valid, expired, not-yet-valid, wrong-audience, wrong-issuer, malformed, and incorrectly signed tokens. Confirm that failures return an appropriate authentication response without exposing token contents.
- Monthly or quarterly: Review identity-provider configuration, key rotation handling, algorithm allowlists, token lifetimes, logging redaction, and dependency updates. The precise interval should reflect your change rate and security process.
- After an authentication incident: Capture the error category, environment, issuer, audience, key identifier, and approximate timestamps. Avoid storing the full token. Compare the failing request with a known-good request.
- After an infrastructure or domain change: Recheck issuer URLs, discovery configuration, callback environments, TLS termination, system clocks, and secrets. A deployment can expose configuration drift without changing application code.
Maintain a small troubleshooting record with the token's environment, decoded non-sensitive claims, expected values, verification result, and the first component that rejected it. This makes recurring failures easier to distinguish from one-off copy-and-paste errors.
How to interpret changes
The table below maps common symptoms to useful next checks.
| Symptom | Likely area to inspect | Next action |
|---|---|---|
| Malformed token | Transport or copying | Confirm three sections, remove only the Bearer prefix, and inspect URL encoding or line breaks. |
| JWT expiration error | exp or system time | Compare the expiration timestamp with the verifier's current time and check clock synchronization. Do not solve the issue by broadly disabling expiration checks. |
| Not yet valid | nbf or clock skew | Compare issuer and verifier clocks. If the library supports a narrowly scoped clock-tolerance setting, document why it is needed. |
| Invalid signature | Wrong key, altered token, or algorithm mismatch | Verify that the complete token arrived unchanged, the correct secret or public key is loaded, and the configured algorithm is allowed. |
| Unknown key ID | kid or key rotation | Check key-set retrieval, caching, rotation timing, and environment-specific issuer configuration. |
| Wrong issuer | iss mismatch | Compare the token with the exact expected issuer and check that development and production settings were not mixed. |
| Audience rejected | aud mismatch | Confirm that the client requested a token for the API being called and that string-versus-array handling matches the library. |
| Unsupported algorithm | Verifier allowlist | Review the issuer's documented signing method and configure an explicit compatible allowlist. Never accept arbitrary algorithms from the token. |
Separate decoding failures from validation failures. A parser error means the value could not be read as the expected format. A validation error means the token was readable but failed a rule. A signature error means authenticity was not established. This distinction usually narrows the investigation quickly.
For related API payload problems, a JSON formatter and validator can help inspect surrounding request data. If authentication is part of a backend migration, compare provider behavior with the Firebase, Supabase, and Appwrite authentication guide.
When to revisit
Revisit this guide whenever an API integration changes its identity provider, issuer URL, audience, signing algorithm, key-distribution method, token lifetime, or claim schema. Return after dependency upgrades that affect JWT parsing or verification, after a domain or deployment migration, and whenever a new mobile, web, serverless, or webhook client is introduced.
On a monthly or quarterly schedule, ask five practical questions:
- Are production logs and error reports still redacting tokens?
- Does every verifier use an explicit algorithm, issuer, audience, and key configuration?
- Have key rotation and environment-specific settings been tested with a current token?
- Are expiration and clock-skew failures observable without exposing credentials?
- Do automated tests cover malformed, expired, wrong-audience, wrong-issuer, and invalid-signature cases?
Keep a redacted reference token for each environment only when your security process permits it, and refresh the reference whenever the identity configuration changes. When debugging a live failure, inspect locally, record claims rather than credentials, verify with the application library, and rotate any token that may have been exposed. That workflow makes a JWT decoder a useful developer utility without confusing visibility with trust.