Authentication & Authorization

Authentication (AuthN) vs. Authorization (AuthZ)

These two concepts are fundamental to security but are often confused:

Authentication always comes before Authorization. You can't determine permissions if you don't know who is making the request.

Common Authentication Mechanisms

1. Basic Authentication

The client sends a username and password, typically Base64 encoded, in the Authorization: Basic HTTP header with every request.

2. Session-Based Authentication (Cookies)

After successful login, the server creates a session, stores session data (like user ID) server-side, and sends a unique session ID back to the client stored in a cookie (e.g., Set-Cookie: sessionid=xyz...). The client automatically sends this cookie with subsequent requests. The server uses the session ID to look up the user's session data.

3. Token-Based Authentication (e.g., JWT)

After successful login, the server generates a signed token (like a JSON Web Token - JWT) containing user information (claims) and sends it to the client. The client stores the token (e.g., in local storage) and sends it in the Authorization: Bearer header with subsequent requests. The server validates the token's signature and expiration, then trusts the claims inside.

4. API Keys

A unique key (string) is generated for a client application (often for server-to-server or third-party integrations). The client includes the key in requests, often via a custom header (e.g., X-API-Key: abc...) or query parameter.

Common Authorization Mechanisms

1. Role-Based Access Control (RBAC)

Access permissions are assigned to roles (e.g., "admin", "editor", "viewer"), and users are assigned one or more roles. Authorization involves checking if the user's role has the necessary permission for the requested resource or action.

(Other mechanisms like ABAC - Attribute-Based Access Control - exist, offering more fine-grained control based on user attributes, resource properties, and environmental context, but RBAC is common and easier to visualize.)

Visualize the Flow

Configure the scenario and simulate a request to see how AuthN and AuthZ are applied.

Request Flow

Client

Sends Request...

Server: AuthN Check

Pending
...

Server: AuthZ Check

Pending
...

Server: Response

Pending
...
Log messages will appear here...