Security

JWT

What a JSON Web Token is: its header, payload and signature, why an edited token gets rejected, and how to verify and store JWTs without the common mistakes.

  • 7 min read
  • 5 questions
  • +35 XP
Transcript

JWT, explained by cats. Kitty logs into her Tuna App. The server checks her password. All good. Kitty is allowed inside. But Kitty doesn’t want to log in again every time she clicks something. So the server gives Kitty a JWT.

a JSON Web Token. A little signed note that says: ‘This is Kitty. She’s verified.’ Kitty keeps this token. She sends it with every request. The server checks the signature. If it’s valid, Kitty gets her tuna. The token has three parts: Header.

Payload. Signature. The header says how the token was made. The payload has Kitty’s info. The signature proves it wasn’t changed. If a bad kitty edits the token? Signature breaks. and the Server rejects it. That's JSON web tokens, lightweight. Stateless. Easy for servers to verify. And used for authentication and access control.