jwtauthenticationsecurityapi
JWT Tokens Explained: Structure, Claims, and Security
Deep dive into JSON Web Tokens - how they work, what they contain, and security best practices.
February 8, 2024ยท7 min read
What is a JWT?
A JSON Web Token (JWT) is a compact, URL-safe token format for securely transmitting information between parties.
JWT Structure
A JWT has three parts separated by dots: header.payload.signature
Header
{
"alg": "HS256",
"typ": "JWT"
}
Payload (Claims)
{
"sub": "1234567890",
"name": "John Doe",
"iat": 1516239022,
"exp": 1516242622
}
Signature
The signature verifies the token hasn't been tampered with.
Common Claims
sub: Subject (user ID)iat: Issued at (timestamp)exp: Expiration timeiss: Issueraud: Audience
Security Best Practices
- Always validate the signature on the server
- Check expiration (
expclaim) - Use HTTPS - JWTs are base64-encoded, not encrypted
- Short expiration - Use refresh tokens for long-lived sessions
- Never store sensitive data in the payload
Decode and inspect JWTs with our JWT Decoder.