๐๏ธ JWT: cheat sheet
๐จ The analogyA festival wristband with a tamper-proof stamp that any gate can check without phoning the ticket office.
๐ The regular explanationJSON Web Tokens are compact, signed bundles of claims. Any service with the key can verify one on the spot, without a database lookup, which makes them great for APIs and hard to revoke.
- The first part of the wristband says what kind of stamp is used.
- The middle part is printed in plain ink, who you are, what you're allowed into, and when it stops working.
- The last part is a stamp made from the first two parts and a secret only the ticket office knows.
- You show your ticket at the office once, and they put a stamped wristband on you.
- At the ride, the attendant checks the stamp with the office's stamp guide. No phone call to the office needed.
- The food tent checks the same way. Any gate with the guide can check the band on the spot.
- Someone scribbles "VIP" over the plain-ink part of their wristband and walks to the VIP gate.
- The stamp no longer matches what's printed, so the gate says no.
- A real wristband from yesterday has a valid stamp, but the date on it has passed, so it's refused too.
๐งฉ Key questions
- Anyone can read the wristband's printed strip. Why can't they change it?
- Because the stamp, made with the office's secret, would no longer match. The strip is readable, so never print secrets on it; the stamp gives tampering away.
- Why can every gate check bands without phoning the ticket office?
- Because each gate has a guide to the office's stamp. So even huge crowds move quickly.
- A real band can't be taken back. What does the office do about that?
- Only gives out bands that last a short while. If a band is valid until tonight, it works until tonight.