Skip to content
HTTP

Authentication

Basic, Bearer, and challenge responses.

By EZ4Code Team
authbasicbearer

Code

# Basic Auth
GET /secure HTTP/1.1
Host: example.com
Authorization: Basic dXNlcjpwYXNz

---

# Bearer Token (JWT)
GET /api/me HTTP/1.1
Host: example.com
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.payload.signature

---

# Server challenge
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="api", error="invalid_token"

Explanation

Basic authentication base64-encodes user:pass in the Authorization header and should only be used over HTTPS. Bearer authentication carries an opaque or JWT token that the server validates per request. When a request lacks valid credentials, the server returns 401 with a WWW-Authenticate header describing the scheme and realm.

More HTTP Snippets