// companion to "what is an api?"

API Auth
who gets in
and how

API keys, tokens, OAuth, sessions, JWTs — you've heard all these terms used interchangeably. They're not the same thing. Here's what each one actually is, why it exists, and how they fit together.

T1 / Beginner March 2026
tl;dr
Most people confuse API auth terms because they're actually describing different kinds of things — some are how you prove who you are, some are formats for storing that proof, some are full protocols. API keys identify your app. Bearer tokens are access passes anyone can use. OAuth is what powers "Sign in with Google." Access tokens expire quickly on purpose. Once the categories click, the individual terms follow naturally.

Why the door needs a lock

In the previous guide, we established that an API is a messenger between two systems. But here's something we glossed over: most APIs aren't open to the public. If any app or person could call any API without restriction, the weather service's servers would be overwhelmed, payment systems would be chaos, and private data would be freely accessible to anyone who asked.

This is where authentication comes in. Authentication is the process of proving who — or what — you are before you're allowed to use an API. Think of it as the bouncer at the door: before you get access to the resource inside, you have to show some form of ID.

There's also a related concept worth knowing: authorisation (sometimes spelled "authorization"). Authentication asks "who are you?" Authorisation asks "what are you allowed to do?" They often happen together, but they're distinct steps. You might be authenticated as a valid user but not authorised to access certain parts of the system.

💡 Mental Model

Authentication = proving your identity. Authorisation = confirming your permissions. Getting into a building requires authentication (the key card says who you are). Going to a restricted floor requires authorisation (your keycard also needs permission for that floor).

First: these terms aren't all the same kind of thing

The reason API auth vocabulary feels so confusing is that people use all these terms in the same breath — as if they're interchangeable alternatives. They're not. They're describing different layers of the same problem.

How you send credentials
API keys, Bearer tokens, Basic auth
These describe the mechanism for carrying your proof of identity in an HTTP request.
How login state is managed
Sessions, Cookies
These describe where and how the server remembers that you've already logged in.
Token formats
JWT
These describe the structure of the token itself — what information it contains and how it's signed.
Full identity protocols
OAuth 2.0, OpenID Connect, SSO
These describe complete systems for handling identity across multiple apps and services.

Keep this grid in mind as we walk through each method. The moment you know which category something belongs to, the definition becomes obvious.

The methods, from simplest to most sophisticated

Authentication has evolved over decades as the web got more complex. Walking through that evolution is the fastest way to make each method make sense.

🔑
API Keys
how you send credentials
An API key is a unique string — a long code — assigned to a developer or application. Think of it like a loyalty card: it's tied to you, and you show it every time you use the service. When your app sends a request to a weather API, it includes the key in that request. The server reads it, recognises which app is calling, and either grants or refuses access.

API keys are simple and very common, especially for public APIs like maps, weather services, and payment integrations. One important nuance: an API key usually identifies the application, not an individual user. If you build a weather app using an API key, the key proves that your app is calling the weather service — not which specific person opened your app.
🍪
Sessions & Cookies
how login state is managed
When you log into a website, something has to remember that you're logged in — otherwise you'd have to re-enter your password on every click. Session authentication is the traditional solution: when you log in successfully, the server creates a session (a record that says "this user is authenticated") and sends your browser a cookie containing a session ID.

Think of the cookie like a hotel key card: the hotel made it, the hotel recognises it, and the hotel can deactivate it at any time. Your browser automatically sends that cookie back with every subsequent request, and the server checks its session records to confirm you're still logged in. This works well for websites, but it requires the server to store session data — which gets complicated when millions of users are logging in across hundreds of servers.
🎟️
Bearer Tokens
how you send credentials
Bearer tokens are how most modern APIs handle authentication. The word bearer literally means "whoever holds this." A bearer token is an access pass: whoever presents it is allowed in, regardless of how they obtained it — like a festival wristband. No one checks your ID at the gate; they just check that you have the band.

Technically, you send a bearer token in a request header: Authorization: Bearer <token>. The server verifies the token and grants access if it's valid. Because the token itself carries all the information needed, the server doesn't need to store session data — it just checks the token. This is far easier to scale.

The catch: because anyone who has the token can use it, bearer tokens must be protected carefully. This is why they're kept out of URLs, never logged, and — critically — why they expire. A stolen token that expires in 15 minutes is far less dangerous than one that lasts forever.
📋
JWT — JSON Web Token
a token format — not a protocol
Here's a clarification that trips a lot of people up: JWT is not an authentication method. It's a format — a specific way of packaging a bearer token. A JWT is a digitally signed parcel of information. It contains a payload (data about the user, their permissions, when the token expires) and a cryptographic signature that proves the server issued it and that no one has tampered with it.

Because a JWT is self-contained — the user information is inside the token — the server can verify requests without looking anything up in a database every time. It reads the token, checks the signature, and knows who you are. This is why JWTs are popular in distributed systems where many servers need to verify the same tokens.
🔑
OAuth 2.0
a full authorisation protocol
OAuth 2.0 is the system behind "Sign in with Google," "Connect with GitHub," and any time one app asks permission to access your data in another app. The key insight: OAuth lets an application act on your behalf without ever seeing your password.

Think of it like valet parking. You hand the valet a special key that only unlocks the ignition — not the boot, not the glovebox. The valet can drive the car, but only within those limits. OAuth works the same way: you grant an app limited access to a specific resource (your Google Drive files, your GitHub repos) and that's all it can touch.

Technically, OAuth is an authorisation framework — it's about granting permissions, not verifying identity. It answers "what is this app allowed to do?" but on its own, it doesn't definitively answer "who is this user?"
🪪
OpenID Connect (OIDC)
identity layer on top of OAuth
OpenID Connect builds on top of OAuth 2.0 and adds the identity piece that OAuth is missing. While OAuth grants access, OIDC also tells the application who the authenticated user actually is. It introduces an ID token — a verified package of user information (name, email, profile picture) that comes back alongside the access token.

When you click "Sign in with Google" on a website, OIDC is almost certainly what's running under the hood. Google authenticates you, confirms your identity to the third-party site, and the site logs you in — without ever storing your Google password.
🏢
Single Sign-On (SSO)
a user experience — not a protocol
SSO is not a specific technology. It's a user experience: sign in once, access everything. When you log into your work account and immediately have access to email, dashboards, internal tools, and video calls without logging in again — that's SSO.

Behind the scenes, SSO is usually implemented using protocols like OpenID Connect or SAML. The user experience feels seamless because those protocols are quietly passing your verified identity between systems. You don't see any of that — you just don't have to log in seven times.

Why there are two kinds of token

In most modern systems using bearer tokens, you'll encounter two tokens working together. This pairing is a deliberate security design — not an accident or an overcomplicated solution.

Short-lived
Access Token
Used to actually access a protected API. Intentionally short-lived — often just minutes or hours. If it's stolen, the attacker's window to abuse it is small before it expires and becomes useless.
Long-lived
Refresh Token
Used to get a new access token when the old one expires — without making you log in again. Stored more securely than access tokens. If you've ever stayed logged into an app for weeks, a refresh token is why.

The logic: anything you use constantly (the access token, sent with every request) is exposed more often, so it should expire quickly. The refresh token is used rarely — just to renew — so it can live longer while being stored more carefully.

⚠ Watch Out — the three golden rules

1. Never expose API keys or tokens publicly. That means not in frontend JavaScript, not in GitHub repos, not in URLs. Treat them like passwords. 2. Always use HTTPS. Early auth methods that sent credentials without encryption (like basic authentication) were vulnerable to anyone intercepting the connection — HTTPS prevents this. 3. Tokens expire for a reason. If your code breaks because a token expired, that's the security model working correctly — not a bug to route around.

Quick reference

Seven terms, plain English:

// key terms
API Key
A unique code that identifies your app to an API. Show it with every request, like a loyalty card. Keep it secret.
Bearer Token
An access pass sent in the request header. Whoever holds it can use it — so protect it, and let it expire.
Session / Cookie
Server-side login memory. The server creates a session; the browser carries the session ID in a cookie on every request.
JWT
A token format — not a protocol. A self-contained, signed parcel of user info that servers can verify without a database lookup.
OAuth 2.0
A protocol for granting limited permissions across apps — without sharing passwords. Powers "Sign in with Google."
Access / Refresh Token
A pair: access tokens are short-lived (used constantly); refresh tokens are long-lived (used only to renew the access token).
SSO
Single Sign-On — a user experience, not a technology. Sign in once, access everything. Usually built on OAuth or SAML behind the scenes.