REST API authentication methods
Six ways to prove who's calling your API — and what each one costs you.
REST APIs authenticate callers along a spectrum from simple to strong: HTTP Basic auth, static API keys, bearer tokens and JWTs, delegated OAuth 2.0, HMAC request signing, and mutual TLS. Each trades ease of use against security, statelessness and revocability, and mature systems mix them by context.
HTTP Basic auth
The client sends the username and password, base64-encoded, in the Authorization header of every request. It is dead simple and universally supported, but the credentials travel on each call and base64 is encoding, not encryption, so it is only safe over HTTPS. There is no expiry and no scoping, which makes it a poor fit for anything beyond internal tools.
API keys
The server issues a long, random string that the client attaches to each request to identify the calling application. Keys are easy to hand out and great for tracking usage and enforcing quotas, but they are typically long-lived, coarse-grained, and identify an app rather than a user. If a key leaks it stays valid until someone manually rotates it, so keys need careful storage and rotation.
Bearer tokens / JWT
The client presents a token — often a signed JWT — in the Authorization header, and whoever bears it is granted access. A JWT packs claims like the user, scopes and an expiry into a signed payload the server can verify without a database lookup, which keeps auth stateless and scalable. The catch is that a bearer token is valid until it expires, so short lifetimes and refresh tokens are essential.
OAuth 2.0 (delegated)
OAuth solves a different problem: letting a third-party app act on a user's behalf without ever seeing their password. The user authorizes at the provider, which issues the app a scoped, expiring access token. This delegated model powers 'Sign in with Google' style flows and fine-grained consent, at the cost of a more involved multi-party handshake to set up.
HMAC / request signing
Instead of sending a secret, the client uses a shared secret key to compute a hash (HMAC) over the request — method, path, body, timestamp — and sends that signature. The server recomputes the same hash and compares, proving both authenticity and that the request was not tampered with, without the secret ever crossing the wire. It resists replay when a timestamp or nonce is included, but is more complex to implement correctly.
Mutual TLS
In mutual TLS both sides present X.509 certificates during the handshake, so the server verifies the client and the client verifies the server before any request flows. This is the strongest option and common between backend services and in zero-trust networks, because identity is proven cryptographically at the transport layer. The price is heavy operational overhead: issuing, distributing, rotating and revoking certificates for every client.
The one question every method answers
Every authentication method for a REST API exists to answer a single question at the door: "who is making this request, and can I trust that claim?" REST itself is stateless — each request stands alone, carrying no memory of the last — so the proof of identity has to travel *with* every call. That constraint is why API auth looks different from a stateful web login, and it is the thread connecting all six methods below.
The methods form a spectrum from simple-but-weak to strong-but-heavy. As you move along it you generally gain security, revocability, granularity and the ability to delegate, and you pay in setup complexity and operational overhead. There is no single "best" — the right choice depends on who the caller is (a human, an app, another service), how sensitive the data is, and how much machinery you can afford to run. Mature systems deliberately use several at once.
Basic auth and API keys — the simple end
HTTP Basic authentication is the oldest and plainest: the client concatenates username:password, base64-encodes it, and sends it in the Authorization header on every request. Its virtue is that it is trivial and supported everywhere. Its problem is that base64 is *encoding, not encryption* — anyone who sees the header sees the password — so it is only acceptable over HTTPS, and even then it offers no expiry, no scoping, and no way to revoke one client without changing the password. It suits internal tools and quick scripts, not public APIs.
API keys are the next step: the server generates a long random string and gives it to a developer, who attaches it to each request. The key's job is to identify the *calling application* and to let you meter usage, enforce quotas, and cut off abusers. Keys are wonderfully easy to adopt, which is exactly why so many public APIs start here. Their weaknesses are that they are typically long-lived, coarse-grained (a key usually means "this app, all its permissions"), and identify an app rather than a specific user. A leaked key stays valid until a human rotates it, so keys demand secure storage, scoping where possible, and a rotation plan.
Tokens, JWT, and delegated OAuth
Bearer tokens move from "who owns this key" to "whoever holds this token, right now, may act." The client sends the token in the Authorization: Bearer … header, and very often that token is a JWT — a JSON payload of claims (the user id, granted scopes, an expiry time) that is cryptographically signed. Because the signature lets any server *verify* the token without a central database lookup, JWTs keep authentication stateless and horizontally scalable, which is why they dominate modern APIs. The trade-off is intrinsic to "bearer": possession equals access, and a signed token generally cannot be un-issued, so it must be short-lived and paired with refresh tokens to limit the blast radius of a leak.
OAuth 2.0 is not really a login method but a *delegation framework*, and it solves a distinct problem: how can you let a third-party app do something on your behalf without handing it your password? The user authenticates directly with the provider and consents to specific scopes; the provider then issues the app a scoped, expiring access token. This is the machinery behind "Sign in with Google" and behind any integration where you grant an app limited access to your account. The power is fine-grained, revocable, password-free delegation; the cost is a genuinely multi-party handshake with more moving pieces to configure and secure.
HMAC signing and mutual TLS — the strong end
HMAC / request signing attacks a weakness shared by every method above: they all *transmit* a secret (a password, a key, a token) that an interceptor could reuse. With HMAC, the client and server share a secret key that is *never sent*. For each request the client computes a keyed hash (an HMAC) over the request's contents — method, path, body, and a timestamp — and sends that signature alongside the request. The server, knowing the same secret, recomputes the hash and compares. A match proves two things at once: the caller holds the secret (authenticity) and the request was not altered in flight (integrity). Including a timestamp or nonce defends against replay. AWS's request signing works this way. The price is implementation complexity — signing and canonicalization are fiddly and easy to get subtly wrong.
Mutual TLS (mTLS) pushes authentication down to the transport layer and makes it symmetric. In ordinary HTTPS only the server proves its identity with a certificate; in mTLS the *client* also presents an X.509 certificate, so during the handshake each side cryptographically verifies the other before a single byte of the request is exchanged. This is the strongest option and the natural fit for service-to-service traffic and zero-trust networks, where identities are certificates rather than passwords. What you pay is a full certificate lifecycle: issuing, distributing, renewing and revoking certs for every client, which is real operational weight.
Choosing and combining them
In practice these methods are layered by context rather than chosen once. A public developer API might hand out API keys for identification and quotas while requiring OAuth for any action taken on a user's behalf. A single-page app talks to its backend with short-lived JWT bearer tokens. Internal microservices authenticate to each other with mTLS. A payments or webhook integration signs its requests with HMAC so neither side can forge or tamper.
The decision rules are worth memorizing. If the caller is an *application* and you mainly need identification and rate limiting, an API key is enough. If it is a *user* and you need scoped, expiring, revocable access, reach for tokens/JWT. If a *third party* must act for a user, that is OAuth's job by definition. If you need per-request tamper-proofing without transmitting a secret, use HMAC. And if you need the strongest mutual identity between machines, accept the overhead of mTLS. Always layer whichever you pick on top of HTTPS, keep lifetimes short, scope narrowly, and make revocation possible — the method is only as good as the discipline around it.
Basic auth sends username:password (base64) on every request — trivial but weak, HTTPS-only.
API keys identify an application with a long-lived string — simple, coarse, hard to scope and rotate.
Bearer tokens / JWTs carry signed, expiring claims — stateless and scoped, but valid until they expire.
OAuth 2.0 delegates access so a third party acts for a user without seeing their password.
HMAC / request signing proves integrity and authenticity per request without sending a shared secret.
Mutual TLS authenticates both client and server by certificate — strongest, heaviest to operate.
Quick quiz
What problem does OAuth 2.0 specifically solve?
Why can HMAC request signing prove authenticity without sending the secret?
Top tips for API security
An API is a door into your data — these are the locks every one of them needs.
Tokens vs API keys
One names an application, the other names a session — and that difference decides everything.
JWT explained
A signed, self-describing token that lets a server trust a request without looking anything up.
Sessions, cookies, JWT & OAuth 2.0
How a server remembers who you are — and who let you in.