JSON web tokens (JWTs) are a standardized format for sending cryptographically signed JSON data between systems. They can theoretically contain any kind of data but are most commonly used to send information ("claims") about users as part of authentication, session handling, and access control mechanisms.
Unlike with classic session tokens, all of the data that a server needs is stored client-side within the JWT itself. This makes JWTs a popular choice for highly distributed websites where users need to interact seamlessly with multiple back-end servers.
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
is the encoding of { "alg" : "HS256", "typ" : "JWT" }
The payload section contains information about the user’s identity. This section, too, is base64url encoded before being used in the token. Here’s an
example of the payload section, which is the base64url-encoded string of { "username" : "admin" }
: eyAidXNlcm5hbWUiIDogImFkbWluIn0
The server that issues the token typically generates the signature by hashing the header and payload. In some cases, they also encrypt the resulting hash. Either way, this process involves a secret signing key. This mechanism provides a way for servers to verify that none of the data within the token has been tampered with since it was issued: