A JWT decoder can quickly reveal a token's header and claims, but readable data is not proof that a token is authentic. This guide provides a reusable workflow for decoding test tokens, checking expiration and audience errors, validating signatures safely, and avoiding common debugging and security mistakes.
Overview
JSON Web Tokens (JWTs) are compact strings commonly used to carry claims between an issuer, an application, and an API. A typical signed JWT has three Base64URL-encoded parts separated by periods:
header.payload.signature
The structure looks like this:
eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9
.eyJzdWIiOiIxMjMiLCJhdWQiOiJhcGkifQ
.signature-bytes
The header identifies details such as the token type and signing algorithm. The payload contains claims, which are statements about the token or its subject. The signature is used by a verifier to determine whether the signed content was produced by a trusted issuer and has not been changed.
A JWT decoder performs the first inspection step: it splits the token, decodes the header and payload, and displays their JSON values. It does not automatically verify the signature, confirm the issuer, check the intended audience, or prove that the token is safe to use. Treat decoding and validation as separate activities.
For production tokens, prefer local inspection or a trusted development environment. Do not paste live access tokens, refresh tokens, session tokens, or customer data into an unfamiliar online tool. A decoded payload may contain identifiers, email addresses, roles, scopes, or other sensitive information, and a token may remain usable until it expires or is revoked.
Common JWT claims
| Claim | Meaning | What to check |
|---|---|---|
iss | Issuer of the token | Matches the identity provider or configured trusted issuer |
sub | Subject identified by the token | Maps to the expected user, service, or principal |
aud | Intended audience | Matches the API or service receiving the token |
exp | Expiration time | Current time is before the Unix timestamp, with only deliberate clock tolerance |
nbf | Not-before time | Token is not being used before its allowed start time |
iat | Issued-at time | Timestamp is plausible for the request and issuer |
jti | Token identifier | Useful for tracing or replay controls when the system supports them |
scope or roles | Application-specific permissions | Authorization logic interprets them according to documented rules |
Checklist by scenario
When you need to decode a JWT
- Work with a test token or a redacted copy whenever possible.
- Confirm that the value has exactly three dot-separated sections.
- Decode the header and payload as Base64URL, not ordinary Base64 with assumptions about padding.
- Parse both sections as JSON and record the algorithm, key identifier, issuer, audience, and time claims.
- Compare the decoded values with the environment configuration that created or receives the token.
Malformed input often points to a copied prefix such as Bearer , a line break inserted into the token, URL encoding applied to the whole value, or a token that is not a JWT at all.
When an API reports an authorization failure
- Inspect the HTTP request first: confirm the header is
Authorization: Bearer <token>and that the token was sent to the intended host. - Decode the token without treating the result as trusted.
- Check
expandnbfagainst the server's clock, not only your local clock. - Compare
issandaudwith the API's expected values, including exact spelling and environment-specific URLs. - Review scopes or roles separately from authentication. A valid identity does not necessarily have permission for every endpoint.
- Use server logs or an authorized validation trace to distinguish an expired, malformed, unverifiable, or insufficiently privileged token.
For a broader request-level investigation, pair this workflow with a practical HTTP status codes and API error handling guide.
When you need to validate a JWT in JavaScript
Use a maintained JOSE-compatible library rather than implementing cryptographic verification yourself. The exact API varies by library, but the validation process should explicitly constrain the expected issuer, audience, and algorithms. A conceptual example using a library with a jwtVerify-style API looks like this:
import { jwtVerify, createRemoteJWKSet } from "jose";
const jwks = createRemoteJWKSet(new URL("https://issuer.example/.well-known/jwks.json"));
const { payload, protectedHeader } = await jwtVerify(token, jwks, {
issuer: "https://issuer.example/",
audience: "my-api",
algorithms: ["RS256"]
});
console.log({ payload, protectedHeader });
Use the issuer's documented key endpoint and configuration for your environment. Do not accept an algorithm merely because the token header requests it, and do not use a decoded claim as an authorization decision before verification succeeds.
When you need to validate a JWT in Python
Python applications should likewise use a reputable JWT or JOSE library and obtain the verification key through a controlled configuration or trusted key-distribution process. The following illustrates the checks conceptually; adapt the function names and key-loading method to the library and identity provider you use:
import jwt
claims = jwt.decode(
token,
verification_key,
algorithms=["RS256"],
audience="my-api",
issuer="https://issuer.example/",
options={"require": ["exp", "iss", "aud"]},
)
print(claims)
Keep verification keys separate from untrusted token data. If keys rotate, make sure the application can select the correct trusted key by its key identifier while still enforcing the expected issuer and algorithm.
What to double-check
- Decoding versus verification: Anyone can usually decode the readable portions of a JWT. Only successful verification against a trusted key and expected validation rules establishes authenticity.
- Time handling:
exp,nbf, andiatare generally represented as NumericDate values. Check units, time zones, and small clock differences. Add clock tolerance deliberately and keep it narrow; do not hide a broad synchronization problem with a large leeway. - Audience: A token issued for one service may not be valid for another. A familiar issuer does not make every token from that issuer appropriate for every API.
- Algorithm constraints: Configure allowed algorithms in the verifier. Never let an untrusted header alone determine whether the application uses a symmetric or asymmetric verification method.
- Key selection: Treat a header value such as
kidas a lookup hint, not as permission to fetch arbitrary files or URLs. Key retrieval should be restricted to trusted sources. - Authorization: After authentication succeeds, apply the application's authorization rules. Verify that scopes, roles, tenant identifiers, and resource ownership are interpreted consistently.
- Logging: Avoid logging complete tokens. Log a request identifier, token hash or carefully chosen fingerprint, issuer, key identifier, and validation error category where appropriate.
If you are checking a request containing encoded values or an opaque token, an API testing helpers workflow can help separate URL encoding, Base64 conversion, headers, and JWT inspection without conflating them.
Common mistakes
- Assuming readable means trustworthy: A payload can be decoded even when the signature is invalid or missing.
- Checking only expiration: A non-expired token can still have the wrong issuer, audience, signature, scope, or subject.
- Copying the Bearer prefix into a decoder: Remove the authentication-scheme prefix before parsing the token.
- Using the wrong environment: Development and production issuers, audiences, keys, and callback settings may differ.
- Hard-coding one signing key forever: Key rotation requires a planned way to discover and trust current keys while retiring old ones safely.
- Returning overly specific errors: Detailed token failures are useful in controlled server logs, but exposing internal validation details to an external client can make troubleshooting information available to attackers.
- Putting sensitive data in claims: JWT payloads are commonly readable by whoever possesses the token. Do not treat them as encrypted storage.
When to revisit
Revisit this checklist whenever an authorization failure appears, an identity provider changes, signing keys rotate, a new API audience is introduced, or authentication middleware is upgraded. It is also worth reviewing before a seasonal planning or release cycle when environments, domains, and deployment workflows may change.
During a review, create a non-sensitive test token for each supported environment and confirm:
- The token has the expected issuer, audience, algorithm, and key identifier.
- Expired and not-yet-valid tokens are rejected predictably.
- Signature verification fails when any signed portion is modified.
- Tokens for another audience or issuer are rejected.
- Insufficient scopes or roles do not become successful authorization decisions.
- Logs and error responses do not expose complete credentials or unnecessary claims.
Keep the validation rules close to the service configuration and test them as part of the application's normal change process. When the workflow changes, update the decoder procedure, library usage, key-discovery assumptions, and operational runbook together. For related payload inspection, see the JSON formatting and validation guide.
Practical final check: before acting on any decoded JWT, ask three questions: Did I protect the token while inspecting it? Was its signature verified with a trusted key? Were issuer, audience, time, and authorization requirements checked independently? If any answer is no, the token is only data to investigate—not credentials to trust.