Lesson 1 of 9 · 20m
JWT Anatomy: Three Parts, One Contract
What the header, payload, and signature actually are, what 'signed not encrypted' means in practice, and the claims that make a token safe to consume.
A JWT is the most misunderstood artifact in modern auth. New hires paste them into jwt.io, see readable JSON, and conclude they're "encrypted tokens." They are not. A JWT is signed, not encrypted — anyone holding one can read every claim inside. The signature's only promise is integrity: the payload hasn't been modified since the issuer signed it.
The three segments
eyJhbGciOiJSUzI1NiIsImtpZCI6ImtleTEifQ.eyJzdWIiOiJ1c2VyXzEyMyIsImV4cCI6MTczNTAwMDAwMH0.c2lnbmF0dXJlBase64url-decode the three dot-separated parts and you get:
// header
{"alg": "RS256", "kid": "key1", "typ": "JWT"}
// payload
{"iss": "https://auth.example.io", "sub": "user_123", "aud": "api",
"exp": 1735000000, "iat": 1734996400, "jti": "01JABC..."}Header describes how the token was signed. Payload is the claims. Signature is computed over the exact bytes of header.payload — tamper with one character of either and verification fails.
Signed ≠ encrypted — the rule you enforce on others
Never put anything in a token you wouldn't print on a postcard. I've reviewed codebases that put password-reset codes, internal role names like can_see_salary_data, even full user objects with hashed passwords into JWTs "because they're encrypted." They're not. If you need confidentiality, you need JWE (encrypted tokens) — which almost nobody needs. Just don't put secrets in claims.
The claims that make verification meaningful
A valid signature alone proves nothing — it proves someone with the key signed this. You must validate:
iss— is this from your issuer? A token from another tenant's IdP has a perfectly valid signature.aud— is this token meant for your service? Tokens for the billing API shouldn't work on the admin API.exp/nbf/iat— expiry with clock skew (usually ±60s leeway).sub— the principal. Never trustemailorusernameas identity; emails change,subdoesn't.
# pyjwt — validation done properly
jwt.decode(token, key, algorithms=["RS256"],
issuer="https://auth.example.io",
audience="api", leeway=60)Opaque tokens vs JWTs
A JWT is self-contained — the API validates without calling home. An opaque token is a random string the API must introspect. JWTs win on latency and scale; opaque tokens win on revocation (a JWT is valid until exp no matter what). That trade-off drives everything in the refresh-token lessons later.
Field notes
kidin the header picks which public key verifies the signature — attacker-controlled input to your key lookup, remember that for the key-confusion lesson.- jwt.io is fine for debugging but it's a website — don't paste production tokens bearing real user data into it. Use
jq+ base64 locally. - Keep tokens small. They ride in every
Authorizationheader; a 4KB token can blow through HTTP header size limits at proxies (nginx defaults to 8k total). typ: "at+jwt"on access tokens vsJWTon ID tokens — mixing them up is how ID tokens end up accepted as API authorization.
Was this lesson helpful?