Mรณdulo 13 ยท Auth & Security โ Lecciรณn 2 de 3 ยท ~8 min
JWT tokens
What's inside a JWT
A JWT (JSON Web Token) is a compact, signed string with three parts joined by dots: header.payload.signature.
- Header โ which algorithm signed it.
- Payload โ the claims: who this token is for (
sub, short for subject) plus timing (iatissued-at,expexpiry). Anyone can read the payload โ it's only base64, not encrypted. - Signature โ the server signs
header + payloadwith a secret key. Change one character of the payload and the signature no longer matches, so tampering is detectable.
This is the exact string Part I's iOS app received from /auth/signup and /auth/login and stored in the Keychain. Every request after that sent it back in an Authorization: Bearer <token> header โ that token came from exactly the function below.