JWT Debugging Guide: Header, Claims, Expiration & Signature Troubleshooting
Diagnose why JSON Web Tokens fail: expired claims, clock skew, algorithm confusion, and how to safely inspect payload claims client-side.
Comprehensive engineering standards, security safeguards, and client-side processing insights. Bookmark DevKitLab for rapid, zero-login daily engineering workflows.
JSON Web Tokens (JWT) specified in RFC 7519 are the ubiquitous standard for stateless authentication in modern REST and GraphQL APIs. However, troubleshooting token rejections is one of the most frequent developer headaches.
Understanding the 3 JWT Segments
A compact JWT is a string of three Base64URL-encoded parts separated by periods (.):
[HEADER].[PAYLOAD].[SIGNATURE]- Header: Identifies the token type and cryptographic algorithm (e.g.
HS256,RS256). - Payload: Contains claims such as
sub(subject),iss(issuer),exp(expiration timestamp), andiat(issued-at timestamp). - Signature: Cryptographic hash verifying that the sender is authentic and the message was not tampered with.
Top 4 Reasons JWT Verification Fails in Production
1. Expiration (exp) Unit Confusion (Seconds vs. Milliseconds)
The most common mistake is providing the expiration timestamp in JavaScript milliseconds rather than Unix seconds:
// ❌ WRONG: Date.now() returns 13-digit milliseconds
const badExp = Date.now() + 3600000;
// ✅ CORRECT: JWT RFC 7519 requires 10-digit Unix Epoch seconds
const correctExp = Math.floor(Date.now() / 1000) + 3600;2. Clock Skew Between Microservices
If your authentication microservice and resource server have slightly unsynchronized system clocks, a newly minted token may be rejected with TokenNotYetValid or prematurely expired. Always configure a 30 to 60-second leeway in verification libraries.
3. Symmetric (HS256) vs Asymmetric (RS256) Key Mixup
In asymmetric systems (RS256), the issuing server signs with a Private Key, while consumer APIs verify using the public key certificate. Passing public keys into symmetric verifiers will fail verification immediately.
4. Safe Client-Side Inspection
When an API returns a 401 Unauthorized, developers need to quickly inspect token claims. Use DevKitLab's JWT Decoder to decode headers, payloads, and timestamps without leaking your bearer token to third-party endpoints.
Explore our 44+ instant, client-side developer formatters and decoders without accounts or subscriptions. Bookmark DevKitLab for rapid, zero-login daily engineering workflows.
Interactive Tools for This Guide
Frequently Asked Questions
Can I decode a JWT without knowing the secret key?
Yes! The header and payload are simply Base64URL-encoded JSON. Anyone who possesses the token can inspect the claims. The secret key is only required to verify or generate the cryptographic signature.
What is the difference between 'nbf', 'iat', and 'exp' claims?
'iat' is Issued At, 'exp' is Expiration Time, and 'nbf' is Not Before (the token is invalid before this timestamp). All three must be represented as Unix epoch seconds.
More Developer Guides & Tutorials
What Is an API? Complete Developer Guide with Real HTTP & Code Examples
Master Application Programming Interfaces (APIs) from first principles to production implementation: HTTP methods, endpoints, JSON payloads, status codes, authentication, and live JavaScript fetch examples.
How to Format & Beautify Sensitive JSON Without Uploading to Cloud Servers
Learn how to format, validate, and debug sensitive JSON responses locally in browser memory without sending private API data to external servers.
Complete Guide to Converting CSV to JSON Arrays: Delimiters, Quotes & Types
Master CSV to JSON data transformation: parse commas within quotes, escape special characters, and convert spreadsheet rows into typed JSON objects.
How to Merge & Reorder PDF Pages Without Acrobat: Private In-Browser Guide
Learn how to combine and reorder PDF documents in your web browser without paying for Adobe Acrobat or uploading sensitive files to cloud servers.