What is JWT
JSON Web Token for authentication
JWT (JSON Web Token) is an open standard (RFC 7519) for securely transmitting information between parties as a digitally signed JSON object.
JWT Structure
- Header — token type and signing algorithm (HS256, RS256)
- Payload — claims (sub, exp, iat, etc.)
- Signature — for verifying integrity
Benefits of JWT
- Stateless — server doesn't store sessions
- Compact — transmitted in HTTP headers
- Self-contained — contains all necessary information
- Cross-domain — works with CORS
Use Cases
- Authentication — Bearer tokens in Authorization header
- SSO (Single Sign-On) — login to multiple services
- API authorization — access to protected resources
- Microservices — passing identity between services