How JWT authentication works

An animated explainer of JSON Web Tokens: what is inside a JWT, how the signature is checked on every request, and what happens when it expires.

Chapters

  1. Log in & check the hash: Maya logs in with her email and password. The server hashes what she typed and compares it with the stored hash. Wrong: 401. Right: it creates a JWT.
  2. Minting the JWT: A JWT has three parts: a header, a payload with user id, role and expiry, and a signature made with HMAC and the server secret.
  3. Bearer on every request: The browser stores the token and sends it in the Authorization: Bearer header. On every request the server re-checks signature and expiry, with no database lookup.
  4. Expired or tampered?: A tampered or expired token gets a 401, and the client refreshes it. A valid one is served. One login, then fast, stateless checks.

Make an animated explainer of your own topic →

More explainers

← All explainers

Try AI Flowchart free →