๐ What Is JWT (JSON Web Token)?
JWT is a compact, URL-safe token format used to represent claims securely between two parties.
✅ Key Uses:
Purpose | Description |
---|---|
Authentication | Verifies user identity (who are you?) |
Authorization | Grants access to resources (what can you do?) |
๐ง Real-World Analogy
Imagine entering a theater:
-
You show a ticket (JWT).
-
The ticket proves your identity and permissions (e.g., VIP, regular).
-
The staff doesn’t ask your name again — they just validate the ticket.
๐ JWT Flow (Authentication + Authorization)
๐ฆ JWT Structure
A JWT has three parts (Base64 encoded):
1. Header
Specifies algorithm and type:
2. Payload
Claims like username, roles, etc.:
3. Signature
Verifies token integrity using secret key:
✅ JWT Authentication in Spring Boot
๐ง Maven Dependency
๐ Typical Components
1. Login Controller
2. JWT Utility Class
3. JWT Filter (for Authorization)
4. Security Config
๐ฅ Example Request & Token
๐ Login Request
✅ Response:
๐ Authenticated Request:
๐งพ Summary
Concept | Explanation |
---|---|
Authentication | User logs in, receives JWT token |
Authorization | User sends token in headers for future requests |
Token Validation | Server verifies signature, expiry, and claims |
Stateless | No server session storage needed |
No comments:
Post a Comment