Track 07 · Lesson 4 of 18Identity and login

Track 07 · Identity and login

Inside a JWT

Lesson 4 of 18· 7 min

A JSON Web Token is three Base64URL pieces joined by dots: a header, a payload of “claims”, and a signature. Anyone can decode the first two. Only the server, which knows the secret, can produce a matching signature.

Make yourself an admin

Real HMAC-SHA256, computed in your browser

The token, as the browser stores it

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..

Header · payload · signature

Header (decoded)

{
  "alg": "HS256",
  "typ": "JWT"
}

What the claims mean

Encoded, not encrypted#

Base64URL is an encoding: it turns bytes into URL-safe text, and anyone can turn it back. So never put passwords, card numbers or secrets in a JWT. The payload is a postcard, not a sealed letter.

What the server must check#

On every request: the signature, with a pinned algorithm (never the one the token’s header asks for, which is how alg: none attacks work), then the claims: iss (issued by the server it trusts), aud (issued for this API), and exp (not expired, with a little allowance for clock skew). Only then are claims like role trusted, and even then, sensitive actions should be checked against the server’s own data.

Who holds the secret#

The signing secret or private key must never reach the browser. If it ships in your frontend bundle, or sits behind a public env prefix like NEXT_PUBLIC_, anyone can mint admin tokens, as the “Re-sign” button showed.

Decode a token of your own

Runs only on this page

Decoding runs only on this page. Nothing is sent anywhere.

Paste a token above. Most issuers include iss, sub, aud, iat and exp.

Check yourself

Anyone who holds a JWT can…