βœ… What is a JWT (JSON Web Token)?

JWTΒ Β is a compact, URL-safe token format used to securely transmit information between parties, especially in OAuth 2.0 and OpenID Connect authentication flows.


πŸ” JWT Structure

A JWT is made of three parts, separated by dots:

<Header>.<Payload>.<Signature>
Β 

Example:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
eyJzdWIiOiIxMjM0NTYiLCJyb2xlIjoiYWRtaW4ifQ.
abc123signaturexyz
Β 

🧩 JWT Parts Explained

Part What It Contains
Header Algorithm & token type (HS256, JWT)
Payload Claims: user ID, roles, expiration, etc.
Signature Signed hash (verifies token integrity)

πŸ”„ JWT in OAuth 2.0

In OAuth 2.0, JWT is often used as the Access Token or ID Token, especially in OpenID Connect.

OAuth 2.0 Flow with JWT:

  1. User logs in via OAuth 2.0
  2. Auth server returns JWT token (access token or ID token)
  3. Client sends JWT with each request:
Authorization: Bearer <jwt_token>
  1. Resource server verifies JWT (signature + expiry)
  2. If valid β†’ grant access to protected resource

βœ… Benefits of JWT

Benefit Description
πŸ” Self-contained Includes all required info (user, role, exp)
⚑ Fast No DB call needed to verify user session
πŸ“¦ Compact Easily fits in headers, cookies
πŸ”„ Stateless No session storage on server

⚠️ Important Tips

  • Validate signature using a secret key or public/private key pair
  • Check expiration (exp claim) to avoid using stale tokens
  • Do not store sensitive data (like passwords) in JWT

βœ… Summary

Term Meaning
JWT JSON Web Token – self-contained token used in OAuth 2.0
Use Case Secure API access, user sessions, authorization
Not JOT JOT is just a mispronunciation of JWT πŸ˜„
Back to blog

Leave a comment