Skip to content
routebase
API Authentication11 chapters

API Authentication: Methods and Trade-offs

A map of every authentication method an API might use, what each one is actually for, where its weaknesses are, and how to choose between them.

Every API request that is not public has to answer one question before anything else happens. Who is asking, and API authentication is how the request answers it. The methods that answer it look very different from each other, and almost all of the difference comes down to three properties.

Where the credential travels, what the server has to know to validate it, and how fast you can take it away again.

This guide covers every method you are likely to meet, including the ones that predate the modern stack and the ones no tool sets up for you. Each chapter says what the method is for, where it goes wrong, and how to configure it in practice. Every security claim carries the RFC it comes from, because a confident wrong answer in an authentication guide is expensive.

Authentication is not authorization

The distinction sounds pedantic and it is the source of the most common serious flaw in APIs.

Authentication establishes identity, and its failure mode is a 401. Authorization decides what that identity may do, and its failure mode is a 403.

An endpoint that checks the first and forgets the second is the pattern behind broken object level authorization, which sits at the top of the OWASP API Security Top 10 from 2023. The caller is genuinely who they say they are, and they are reading somebody else's record.

Everything in this guide is about the first question. The second one is covered in testing authentication, because the only reliable way to know your authorization works is to send two identities at it.

Where the credential travels, and why it matters

LocationExampleWhat to know
Authorization headerBearer eyJ…The default for good reasons, because it is not logged by default and not cached
A custom headerX-API-Key: …Equivalent in practice, and it needs a CORS entry for browser callers
Query string?api_key=…Lands in access logs, browser history, referrer headers and shared URLs
CookieSet-Cookie: session=…Sent automatically by browsers, both the feature and the CSRF risk
Request body{"token": "…"}Rare, awkward to cache and awkward to proxy, and it rules out GET

The query string row is the one that causes real incidents. A credential in a URL is also in the reverse proxy log, in the browser history and in the referrer header of the next outbound link. It ends up in the support ticket where somebody pasted the URL. RFC 6750 says exactly this about bearer tokens in URIs, and the reasoning applies to keys too.

Transport is a precondition, not a method

None of these schemes protect the credential in transit. TLS does that, and without it every method here is equivalent to shouting the password.

Two specific consequences follow. Basic authentication is not "insecure" in the sense people usually mean, because it is exactly as secure as the channel underneath it. And a token that has travelled over plain HTTP once should be treated as compromised, because you have no way to know whether it was.

Three situations, and what fits each

Almost every real decision is one of these three.

A machine calling a machine. A background job, a partner integration, a service in your own estate. There is no user, so there is nothing to delegate. An API key or the client credentials grant covers it, and the grant wins where you want short-lived tokens and central revocation.

Acting on behalf of a user. A third-party application wants to read a user's data with their permission. This is what OAuth 2.0 was designed for, and authorization code with PKCE is the current answer. Add OpenID Connect when you also need to know who the user is and not only what they permitted.

A browser talking to your own API. The credential has to survive a page reload and it has to be unreachable from injected script. A cookie with HttpOnly, Secure and a sensible SameSite usually beats a token in local storage, which mutual TLS, cookies and custom HMAC covers.

The map of methods

MethodBuilt forChapter
API keysIdentifying a calling applicationAPI keys
HTTP BasicSending a username and password over TLSBasic and Digest
HTTP DigestPassword authentication without sending the passwordBasic and Digest
Bearer tokensCarrying an issued tokenBearer tokens and JWT
JSON Web TokensCarrying signed claims the server can validate without a lookupBearer tokens and JWT
OAuth 2.0Delegated access without sharing the passwordOAuth 2.0 grants
OpenID ConnectIdentity on top of OAuth 2.0OpenID Connect
OAuth 1.0, AWS SigV4, Hawk, NTLMSigning the request, not sending a tokenSignature-based and legacy
Mutual TLSCertificates as identity at the transport layerMutual TLS and friends
Session cookiesBrowser sessions against your own APIMutual TLS and friends

Two further chapters cover the practice, not the methods. Designing authentication into your OpenAPI spec is how consumers and agents learn which scheme an endpoint expects, and setting it up in Routebase is the end-to-end configuration walkthrough.

The short version of the decision

The full table lives in choosing a method, and this is the part most people need.

  • Machine to machine, inside your control: an API key, scoped and rotatable.
  • Machine to machine, where you want short-lived credentials: OAuth 2.0 client credentials.
  • On behalf of a user, any client type: OAuth 2.0 authorization code with PKCE, per RFC 7636.
  • You also need the user's identity: OpenID Connect.
  • Browser session against your own API: a cookie with HttpOnly, Secure and SameSite.
  • Very high assurance between known parties: mutual TLS, usually alongside one of the above.

What should not be on that list is a custom scheme you designed. RFC 9700 documents what the OAuth working group has learned across two decades, and a scheme written in an afternoon has not learned any of it.

In Routebase

Routebase carries a catalogue of ten authentication schemes plus none, and the same catalogue appears everywhere authentication is configured. That means environments, test suites, individual test cases and security personas all use the identical editor, so a scheme you set up once behaves the same wherever you apply it.

Authentication type dropdown grouped into common, OAuth, token and other, listing eleven schemes.
The catalogue groups the schemes by family, and every entry configures the same way at environment, suite, case and persona level.

The catalogue covers Basic, Bearer and API Key, where the key travels in a header or a query parameter under a name you choose. It also covers OAuth 2.0 with four grant types, OAuth 1.0, JWT Bearer signed from a secret or a private key, Digest, AWS Signature V4, Hawk and NTLM. Every credential field accepts a {{VARIABLE}} placeholder resolved from the environment's variables, so the scheme lives in the configuration and the secret lives in a secret variable.

Read on for the method you need, or jump straight to setting up authentication in Routebase. The product documentation for the configuration surface is Project Auth. What happens after the token is valid, meaning whether this caller may have this object, is the subject of the API security guide.

Frequently asked questions

What is API authentication?

API authentication is how a request proves who or what is making it. It answers the question of identity, and that is separate from authorization, since authorization decides what the identity is then allowed to do. Most of the methods in use today differ in only three respects. Those are where the credential travels, whether the server has to store anything to validate it, and how quickly a compromised credential can be withdrawn.

What are the main API authentication methods?

API keys identify a calling application, HTTP Basic and Digest send a username and password, and bearer tokens carry a token that the server validates. JSON Web Tokens are bearer tokens that carry signed claims, so the server can validate them without a lookup. OAuth 2.0 issues those tokens through several grant flows, OpenID Connect adds identity on top of it, and signature-based schemes such as AWS Signature V4 sign the request itself instead of sending a token.

What is the difference between authentication and authorization?

Authentication establishes who is calling, and authorization decides what that caller may do. A request can be perfectly authenticated and still be refused, and that is the difference between a 401 and a 403. Confusing the two is how endpoints end up checking that somebody is logged in without checking that the object they asked for is theirs, and that is the most common serious API flaw there is.

Which API authentication method should I choose?

For machine-to-machine calls between services you control, an API key or the OAuth 2.0 client credentials grant covers it, with the grant preferred where you want short-lived tokens and central revocation. For acting on behalf of a user, use OAuth 2.0 authorization code with PKCE, and add OpenID Connect when you also need to know who the user is. For browser-facing sessions, a cookie with the right attributes usually beats a token in storage.

Last reviewed by The Routebase Team.

Chapters in this guide

  1. Chapter 01

    API Keys: What They Are and What They Are Not

    How an API key differs from a user credential, why the query string is the wrong place for one, and what scoping, rotation and per-key rate limits buy you.

  2. Chapter 02

    HTTP Basic Authentication and Digest, Explained

    Why Base64 is not encryption, what Digest was designed to solve, where both still make sense, and the challenge-response mechanics behind them.

  3. Chapter 03

    Bearer Tokens and JWT

    Opaque tokens against self-contained ones, what a JWT actually guarantees, the validation mistakes that keep recurring, and what RFC 8725 says about them.

  4. Chapter 04

    OAuth 2.0: The Grant Types, Explained

    The four roles, the grants that matter today, why PKCE is now required for every authorization code flow, and what RFC 9700 has retired.

  5. Chapter 05

    OpenID Connect

    The identity layer on top of OAuth 2.0, why an ID token is not an access token, what discovery buys you, and when plain OAuth is the right answer instead.

  6. Chapter 06

    Request Signing: OAuth 1.0, AWS SigV4 and Hawk

    What request signing buys you over a bearer token, how nonces and timestamps stop replay, and where each of these four schemes still turns up.

  7. Chapter 07

    Mutual TLS, Cookies and Custom HMAC Schemes

    Certificates as identity at the transport layer, cookies and CSRF, and why a home-grown signing scheme is usually a worse version of one that already exists.

  8. Chapter 08

    OpenAPI Security Schemes and Per-Endpoint Auth

    Security schemes, per-operation requirements, scopes, and what consumers and agents can only learn from a specification that documents its authentication.

  9. Chapter 09

    Setting Up API Authentication in Routebase, End to End

    Configure credentials once per environment, inherit them everywhere, keep secrets in variables, and cover the pipeline, scans and agents from one setup.

  10. Chapter 10

    API Authentication Testing: The Negative Cases

    The negative cases worth writing, why 401 and 403 mean different things, and how two identities prove what a single-user suite structurally cannot.

  11. Chapter 11

    Choosing an API Authentication Method

    A decision table across complexity, revocation, rotation, delegation, browser exposure and maturity, plus the four questions that usually settle it first.

The guide that follows this one is API Security.

Ready to ship on it?

Routebase is live. Design your API once — docs, mocks, tests, and monitoring all follow from the same source.

14-day Pro trial — no credit card required.