JWT Internals, Token Relay & Spring Security 6
Deconstruct JSON Web Tokens (JWT), configure asymmetric RS256 signature verification, and propagate user context across microservices using the Token Relay pattern.
In modern microservices, the standard carrier of security context is the JSON Web Token (JWT) (RFC 7519).
Unlike opaque tokens that require calling an authorization server on every single HTTP request to check validity, a JWT is stateless and self-contained: it packs the user identity, roles, and cryptographic signature directly inside the token string.
01JWT Internals: Header, Payload & Signature
A JWT consists of three distinct Base64URL-encoded strings separated by dots (.):
header.payload.signature
1. Header (Red)
Contains metadata about the token and the cryptographic algorithm:
{
"alg": "RS256",
"typ": "JWT",
"kid": "auth-key-2026-01"
}2. Payload / Claims (Purple)
Contains the actual statement of identity and authorization permissions:
{
"sub": "usr_99182",
"name": "Jane Doe",
"roles": ["ROLE_CUSTOMER", "ROLE_PREMIUM"],
"scope": "order:write payment:write",
"iss": "https://auth.example.com/realms/production",
"exp": 1761892800,
"iat": 1761889200
}3. Signature (Blue)
Calculated by hashing the encoded header and payload using a secret or private key:
Signature = RSA-SHA256(Base64Url(Header) + "." + Base64Url(Payload), Private Key)
Loading the rest of the lesson…