Anatomy of a JSON Web Token: Header, Payload, and Signature
Every compact JWS JSON Web Token consists of three dot-separated ASCII segments: header.payload.signature. First, the Header declares metadata such as signing algorithm ("alg": "HS256" or "RS256") and token type ("typ": "JWT"). Second, the Payload holds JSON claim pairs identifying user identity, roles, issuer, and timestamps. Third, the Signature binds the Base64Url-encoded header and payload cryptographically using your server secret key or asymmetric private key so tampered tokens reject cleanly upon verification.
HS256 Signature = base64url(HMAC_SHA256(Signing_Input, Secret_Key))
Crucial security principle every engineer must enforce: Standard signed JWTs (JWS) are encoded with Base64Url, never encrypted. Anyone capturing an HTTP Bearer header can decode the middle payload segment cleanly in one second—so never store database passwords, credit card numbers, raw internal API keys, or sensitive health identifiers inside JWT claims.
Standard registered JWT claims and time-window debugging
| Claim Key | Meaning | Format / Developer Gotcha |
|---|---|---|
sub | Subject (user ID / UUID) | Prefer opaque internal IDs rather than mutable email strings |
iss / aud | Issuer & Audience | Always validate both on API servers so tokens from other apps are rejected |
exp / iat / nbf | Expiration, Issued At, Not Before | Always whole Unix epoch SECONDS (10 digits), never JS milliseconds (13 digits)! |
Accidentally setting exp: Date.now() + 3600000 in Node.js or frontend prototypes—instead of Math.floor(Date.now() / 1000) + 3600—writes millisecond timestamps interpreted by RFC 7519 libraries as expiring around the year 54,000 AD! Verify human-readable UTC/local expiry cleanly via JWT Token Inspector and Unix Timestamp Converter.
Constructing, signing, and verifying test tokens inside your browser
- Generate crisp test secrets safely: Avoid weak staging keys like
secret123that leak into brute-force dictionaries or accidentally ship to production. Create 256-bit+ random test secrets via Strong Password Generator. - Build and sign HS256 test payloads locally: Open JWT Token Builder & Signer, edit custom JSON claims cleanly (including
expand role scopes), paste your test HMAC secret, and sign locally using native Web Crypto HMAC-SHA256—zero tokens or test secrets leave your browser. - Inspect production Bearer strings safely: Never paste live user authentication tokens into random remote decoder APIs that log request payloads. Use JWT Token Inspector, which decodes Base64Url headers and claims strictly client-side in your browser and flags expired timestamps immediately.
- Cross-check raw HMAC webhook digests: Debugging custom API webhooks alongside JWT auth? Test identical raw key-and-message SHA-256 HMAC digests cleanly via HMAC Signature Generator.
Four critical JWT production pitfalls (alg=none, secret strength & revocation)
First, always pin expected algorithms explicitly in your backend verification call (e.g. algorithms: ['HS256']) so attackers cannot trick misconfigured libraries with "alg": "none" or key-confusion RS256-to-HS256 downgrades. Second, keep access token lifetimes short (5–15 minutes) paired with revocable refresh sessions so logged-out or password-reset users lose access rapidly rather than holding valid stateless tokens for weeks. Third, sanitize decoded claim fields before storing or logging, and keep tokens out of URL query strings where server access logs and browser history expose Bearer credentials.
Worked debugging walkthrough: diagnosing 401 Unauthorized API errors
When a mobile app or React frontend hits sudden 401 Unauthorized responses from staging APIs, resist guessing backend deployment glitches before inspecting the live Bearer token directly inside JWT Token Inspector. Paste the full dot-separated string from DevTools Network headers without trailing spaces and inspect four checks immediately: (1) confirm exp decoded to UTC time has not expired due to container clock drift, (2) verify iss and aud strings match the exact target environment URL rather than old localhost settings, (3) confirm user role scopes carry required permissions, and (4) generate a clean test token with JWT Token Builder & Signer using an identical trimmed UTF-8 HMAC secret to separate frontend stale-cookie caching from backend key mismatches in under two minutes.