JWT is a secure method to transmit authentication tokens between a client and a server.
A JSON Web Token (JWT) is a compact, URL-safe way to transmit information between parties as a JSON object. It's primarily used for authentication and secure information exchange in web applications.
When you log into a web application, the server verifies your credentials and issues a JWT containing your user information. Your browser stores this token and includes it with every subsequent request, allowing the server to identify you without checking the database each time.
Think of it like a concert wristband - once security checks your ticket at the entrance and gives you a wristband, you can move around freely without showing your ticket again. Guards can verify you belong there just by checking the wristband.
A JWT consists of three parts separated by dots:
Header: Specifies the token type (JWT) and signing algorithm (like HMAC SHA256).
Payload: Contains the claims (user data) - who the user is, when the token expires, what permissions they have.
Signature: Ensures the token hasn't been tampered with by signing it with a secret key only the server knows.
The signature prevents forgery. Even if someone intercepts your token and tries to modify it (like changing their user ID to an admin), the signature won't match, and the server will reject it.
However, JWT tokens should always be transmitted over HTTPS to prevent interception, and should have reasonable expiration times.
No related topics found.
Single Sign-On (SSO): Log in once and access multiple services without re-authenticating.
Microservices Authentication: Pass user context between services without centralized session storage.
Mobile APIs: Stateless authentication perfect for mobile apps that need to stay logged in.
When you use Google OAuth to log into a third-party app, that app receives a JWT from Google containing your basic profile information and permissions. The app can verify this token came from Google and trust the information inside without directly accessing Google's databases.