API Keys, JWTs, and OAuth2 Are Answering Different Questions

They all end up as a string in an Authorization header, so it's easy to treat API keys, JWTs, and OAuth2 as three flavors of the same thing. They're not — they answer three different questions, and picking based on "which one is more modern" instead of "which question am I actually answering" is how a team ends up building OAuth2's complexity for a problem an API key would have solved in ten minutes.
API keys: "is this request allowed to happen at all"
An API key is a long random string, issued once, checked by a simple lookup: does this string exist, and is it active? It doesn't identify a person — it identifies whoever holds the string, which is exactly why leaking one is bad and why they're meant to sit in a header or a config file, never a URL that ends up in server logs or browser history. Their entire value is simplicity: no token expiry logic, no refresh flow, nothing to implement beyond "generate a random string, store its hash, check it on every request." That simplicity is also the ceiling — an API key can't natively express "this key can read but not write" or "this key expires in an hour" without building that logic yourself on top of it.
JWT: "here is a claim, and here's proof nobody tampered with it"
A JWT (JSON Web Token) isn't an authentication method by itself — it's a format: a base64-encoded header, payload, and signature, where the payload carries claims ("user 4521, expires at this timestamp, has this role") and the signature proves those claims haven't been altered since whoever issued the token signed it. The useful property is that a JWT can be verified without a database lookup — anyone holding the issuer's public key (or shared secret, for HMAC-signed tokens) can check the signature and trust the claims inside, which is exactly what makes JWTs attractive for stateless auth across multiple services. It's also exactly why a stolen JWT is dangerous for its entire remaining lifetime: unlike an API key, there's often no simple "revoke this one token" switch — only "wait for it to expire" or "revoke by checking a deny-list you now have to maintain," which quietly reintroduces the database lookup JWTs were supposed to avoid.
OAuth2: "I'm letting a third app act on my behalf, without giving it my password"
OAuth2 solves a problem neither of the above touches: letting a third-party application perform actions as a user, without that app ever seeing the user's actual credentials. The user authenticates directly with the provider (Google, GitHub, whoever), the provider issues a scoped, time-limited access token to the requesting app, and that app uses the token — which can be revoked and is limited to specific permissions — instead of a password. This is meaningfully more machinery than either an API key or a bare JWT, and building it for a problem that's actually just "does this service have permission to call my API" is solving a delegation problem that was never there in the first place.
Picking the one that matches the actual question
A backend calling another backend it directly owns: an API key. A stateless claim that needs verifying across services without a shared database: a JWT. A third-party app needing to act on a user's behalf without ever holding that user's password: OAuth2. MockBase's own personal API keys and token-protected endpoints are deliberately the first, simplest option — because "can this CI job push a mock config" doesn't need a refresh-token flow, it needs a key that works until it's revoked.
Xerat02
Building MockBase.
More from the blog

Feature Flags Turn Every User Into a Different API
Every flag you add doubles the number of distinct behaviors your API can exhibit — and unlike a version number, a flag combination is invisible in the request itself.

Build the Frontend First: A Practical Guide to API-First Development
Waiting for the backend to exist before you can build the UI against it is a scheduling problem, not a technical one. Here's how teams actually break that dependency.