November 18, 2026
Difference between JWT , session based auth, apiKey,
Session-Based Authentication
By Rohith
In session-based authentication, the server maintains information about logged-in users.
1. User logs in
Username + Password
2. Server validates credentials
Creates a session and stores it in a database or Redis
3. Server sends Session ID
Usually through an HTTP-only cookie
4. Browser sends cookie with requests
Server looks up the session ID to identify the user1. User logs in
Username + Password
2. Server validates credentials
Creates a session and stores it in a database or Redis
3. Server sends Session ID
Usually through an HTTP-only cookie
4. Browser sends cookie with requests
Server looks up the session ID to identify the userJWT Authentication
JWT stands for JSON Web Token.
Unlike session authentication, the server generally doesn't need to store a session for every logged-in user.
The server generates a signed token containing information about the user.
1. User logs in
Username + Password
2. Server generates JWT
Signs the token using a secret or private key
3. Client stores the token
For example, in a secure cookie
4. Client sends JWT with requests
Authorization: Bearer token
5. Server verifies JWT signature
Checks expiration and other claims without looking up a session1. User logs in
Username + Password
2. Server generates JWT
Signs the token using a secret or private key
3. Client stores the token
For example, in a secure cookie
4. Client sends JWT with requests
Authorization: Bearer token
5. Server verifies JWT signature
Checks expiration and other claims without looking up a sessionAPI Key Authentication
API keys are commonly used when one application or service needs to communicate with another application or service.
Instead of logging in with a username and password, the client sends a predefined API key.
1. Developer generates API key
Example: sk_live_abc123xyz
2. Application stores API key securely
3. Application sends API key
With every API request
4. Server validates API key
Checks whether key is valid, active, and authorized1. Developer generates API key
Example: sk_live_abc123xyz
2. Application stores API key securely
3. Application sends API key
With every API request
4. Server validates API key
Checks whether key is valid, active, and authorized