A JWT decoder can show you what a token contains, but decoding alone does not prove that the token is authentic or acceptable to an API. This guide provides a repeatable workflow for reading a JWT safely, checking its claims, distinguishing inspection from cryptographic validation, and troubleshooting authentication failures without exposing live credentials.
Overview
A JSON Web Token, or JWT, is commonly represented as three dot-separated parts:
header.payload.signature
The header and payload are JSON objects encoded with base64url. The signature is used to detect whether the signed content has been altered and, depending on the signing method, may be verified with a shared secret or a public key. Encoding is not encryption: anyone who obtains a JWT can usually decode its header and payload.
That distinction is the foundation of safe JWT debugging:
- Decoding reads the header and payload. It does not establish trust.
- Validation checks token structure, required claims, timestamps, issuer, audience, and other application rules.
- Cryptographic verification checks the signature with the expected algorithm and key.
- Authorization determines whether the authenticated identity may perform a particular action.
A browser-based JWT decoder is useful for a redacted sample, a locally generated test token, or a non-sensitive fixture. Do not paste production access tokens, refresh tokens, session credentials, or tokens copied from a customer environment into an unfamiliar online tool. If you need to inspect a real token, prefer a local command-line utility, a trusted development environment, or application logging that has been designed to remove secrets.
Checklist by scenario
When you need to read a token
- Confirm that the value has three dot-separated segments. A token with a different shape may use another format or may be truncated.
- Decode the first segment as the header and the second as the payload. Treat both as readable metadata, not confidential storage.
- Record the algorithm, key identifier, token type, subject, issuer, audience, and time claims.
- Compare the decoded values with the configuration expected by the API or identity provider.
- Remove the token from browser history, shell history, screenshots, issue trackers, and chat messages after debugging.
When an API returns 401 Unauthorized
- Check whether the request includes the expected authorization scheme, usually an
Authorizationheader with a bearer value. - Check the token's
expandnbfvalues against the current server time. Small clock differences can matter near a boundary. - Compare
isswith the issuer configured by the API. Tokens from a development tenant and a production tenant are not interchangeable merely because they look similar. - Compare
audwith the API's expected audience. A token intended for a user profile service may not be valid for a reporting API. - Check the signing algorithm and key identifier against the verifier's allowed configuration.
- Determine whether the token is valid but lacks the required scope or role. That situation may produce a 403 response, although response behavior depends on the API.
For a broader response diagnosis, pair this workflow with the HTTP status codes API debugging reference.
When you are implementing verification
- Use a maintained JWT or JOSE library rather than writing signature verification and base64url handling from scratch.
- Configure an explicit allowlist of algorithms appropriate for the issuer. Do not accept an algorithm simply because it appears in the incoming header.
- Obtain verification keys through a trusted, configured source and validate key selection rather than trusting arbitrary key URLs or header values.
- Verify the signature before using identity or permission claims for authorization.
- Validate issuer, audience, expiration, not-before time, and required scopes or roles as separate checks.
- Keep access-token verification separate from refresh-token handling and session policy.
A typical server-side library workflow is conceptually similar to:
const claims = await jwtVerify(token, verificationKey, {
algorithms: ["RS256"],
issuer: expectedIssuer,
audience: expectedAudience
});
The exact API varies by language and library. The important principle is that the verifier supplies its expectations; it does not adopt them from untrusted token content.
JWT claims reference
| Claim | Purpose | What to check |
|---|---|---|
iss | Identifies the issuer | Matches the configured trusted issuer |
sub | Identifies the subject | Maps to the expected user or service identity |
aud | Identifies intended recipients | Includes the API or client that should accept the token |
exp | Expiration time | Has not passed, using a consistent clock |
nbf | Not-before time | Token is currently usable |
iat | Issued-at time | Fits the expected issuance window when relevant |
jti | Token identifier | Supports replay controls if the application uses them |
scope or roles | Permission information | Matches the endpoint's authorization requirements |
Registered claims are conventions, not a complete security policy. Custom claims should have clear ownership, documented types, and a defined effect on access decisions.
What to double-check
- Base64url versus Base64: JWT segments use base64url conventions and may omit padding. A decoder that expects ordinary Base64 can report misleading errors.
- Numeric dates: JWT time claims are generally represented as numeric timestamps rather than formatted date strings. Convert them consistently and verify the unit your tooling expects.
- Audience shape: Depending on the issuer,
audmay be a string or an array. Your validator should handle the documented form explicitly. - Key rotation: A changing
kidcan indicate that the issuer rotated signing keys. Confirm that the verifier refreshes trusted keys through its supported configuration rather than accepting an untrusted key. - Environment boundaries: Check the API host, issuer, audience, client configuration, and key set together. Mixing one environment's token with another environment's verifier is a common source of 401 responses.
- Authorization semantics: A valid signature proves integrity, not permission. The API still needs to evaluate scopes, roles, tenant boundaries, resource ownership, and endpoint policy.
If the failure occurs only after a deployment, compare the complete responses and configuration between environments rather than comparing token payloads by eye. The API response comparison guide can help organize that investigation.
Common mistakes
- Calling a decoded token valid: A readable payload only proves that the token has a recognizable structure.
- Trusting claims before verification: Never use an unverified
sub, role, or scope to select data or grant access. - Accepting any algorithm: Verification should restrict algorithms to those expected for the configured issuer and key type.
- Putting secrets in the payload: JWT payloads should not contain passwords, private keys, or other information that must remain confidential.
- Logging full bearer tokens: Request logs, error reports, proxy traces, and screenshots can become credential leaks.
- Ignoring clock skew: A correct token can fail when application servers, containers, or identity systems disagree about time. Use a narrowly defined, documented tolerance where appropriate rather than disabling time checks.
- Confusing 401 and 403: A missing, malformed, expired, or unverifiable token is different from an authenticated caller who lacks permission. Check the API's documented behavior.
For a complete investigation, follow a repeatable browser, API, and build troubleshooting process instead of changing authentication settings at random. See the frontend debugging workflow for a structured approach.
When to revisit
Return to this checklist whenever an API begins returning authentication errors, an identity provider changes its claims, a signing key rotates, or a service moves between environments. It is also worth revisiting before a major release, tenant migration, or change to scopes and roles.
During each review, confirm the issuer and audience values, algorithm allowlist, key-discovery configuration, time handling, required claims, and redaction rules in logs. Test both a valid token and controlled failure cases: an expired token, the wrong audience, a modified payload, a missing scope, and a token signed with an unsupported algorithm. Keep those tests free of production credentials.
The practical rule is simple: use a JWT decoder to understand a token, a validator to enforce expectations, cryptographic verification to establish integrity, and authorization checks to decide access. Keeping those steps separate makes 401 investigations faster and reduces the chance that a debugging shortcut becomes a security weakness.