🔴 Advanced · Lesson 38
JWT Authentication
JWT Authentication
What is JWT?
JWT (JSON Web Token) is a secure token used for API logins. After login, the server gives a token; the client sends it with each request to prove identity — no sessions needed.
How JWT Works
- User logs in with email/password.
- Server verifies and returns a signed JWT token.
- Client sends the token in the
Authorizationheader on each request. - Server verifies the token signature and allows access.
Token Structure
header.payload.signature
// example (3 parts separated by dots)
eyJhbGc... . eyJ1c2Vy... . SflKxwRJ...
Use a Library
Do not build JWT by hand — use a trusted library like firebase/php-jwt via Composer to create and verify tokens safely.
Summary
- JWT is a signed token proving identity on each API request.
- Login returns a token; client sends it in the Authorization header.
JWT क्या है?
JWT (JSON Web Token) API logins के लिए secure token है। Login के बाद server token देता है; client हर request के साथ भेजता है पहचान साबित करने को — sessions की ज़रूरत नहीं।
JWT कैसे काम करता है
- User email/password से login करता है।
- Server verify करके signed JWT token लौटाता है।
- Client हर request में token
Authorizationheader में भेजता है। - Server token signature verify करके access देता है।
Token Structure
header.payload.signature
// example (dots से अलग 3 parts)
eyJhbGc... . eyJ1c2Vy... . SflKxwRJ...
Library Use करें
JWT हाथ से न बनाएं — firebase/php-jwt जैसी trusted library Composer से use करें tokens safely बनाने/verify करने को।
सारांश
- JWT हर API request पर पहचान साबित करने वाला signed token है।
- Login token लौटाता है; client उसे Authorization header में भेजता है।