JWT: how the token is built and how to read it
What a JWT is
A JSON Web Token is a compact way to pass information about a user between services. After login the server issues a token and the client attaches it to every request; the server does not need to store a session — verifying the signature is enough.
A token consists of three Base64URL-encoded parts: a header with the signing algorithm, a payload with the data, and the signature itself.
Common security mistakes
Storing confidential data in the token: the contents are readable without a key. Accepting tokens with the “none” algorithm — they are unsigned. Using a short or predictable HS256 secret that can be brute-forced. Issuing tokens with no expiry — a stolen token then works forever.
On the server, always verify the signature, the expiry and the iss and aud claims, and set the algorithm in code rather than taking it from the token header.