A JWT (JSON Web Token) is a compact, URL-safe token used to securely transmit information between two parties (e.g., client and server). It's commonly used for authentication and authorization in modern web apps.
A JWT has three parts separated by dots:
xxxxx.yyyyy.zzzzz
Header – Contains metadata about the token, such as the algorithm (e.g., HS256) and type.
{
"alg": "HS256",
"typ": "JWT"
}
Payload – Contains the actual data (claims), like user ID, email, or expiration time.
{
"sub": "1234567890",
"name": "John Doe",
"exp": 1712345678
}
Signature – A cryptographic signature generated using the header, payload, and a secret key to verify the token’s integrity.
user_id
) and signs it with a secret key.Authorization: Bearer <token>
header).