API authentication: how an API knows who is calling
API authentication (API auth for short) is the step where an API establishes who is making a request, by checking API credentials such as a key, a token or a certificate. The methods differ in what the caller sends and in how they fail. It answers "who are you?". The separate question "may you touch this object?" is authorisation, covered on BOLA. Broken authentication is API2 in the OWASP API Security Top 10 2023, and this guide to API authentication methods sits inside API security.
Quick facts
| Method | What the caller sends | Where it fits | Main weakness |
|---|---|---|---|
| API key | A static secret in a header | Server-to-server calls, simple integrations | Identifies the app, not the user; leaks easily |
| Bearer token (OAuth 2.0) | An access token | Apps acting for a user | Whoever holds the token can use it |
| JWT | A signed token carrying claims | Stateless services | Valid until its expiry unless the service adds its own check |
| Mutual TLS | A client certificate | Service-to-service calls | Certificate issuing and rotation effort |
Definitions follow OWASP API2:2023, RFC 6750 for bearer tokens and RFC 7519 for JWT; OAuth 2.0 itself is RFC 6749 and mutual TLS client authentication is RFC 8705.
Common API authentication methods
HTTP authentication sits under these. RFC 9110 defines it as a challenge-response framework: the server issues a challenge, and the client answers in the Authorization header. Delegated access has its own pitfalls: OAuth security. Keys have their own page: API key security. Different responses for known and unknown accounts leak information, see user enumeration.
API keys. An API key is a long random string the client sends with each call. Keys are easy to issue and easy to leak, so treat them as passwords. Keep them out of source code and client-side apps, rotate them, and give each integration its own key. For api key authentication between your own systems this is the simplest start.
OAuth 2.0 access tokens. A client obtains a token from an authorisation server and sends it as a bearer token. RFC 6750 states that any party in possession of a bearer token can use it, so a token has to be protected like a password. An expiry and a scope narrow what a stolen one can do.
JWT. A JSON Web Token is a signed token that carries claims. The API verifies the signature and the expiry on every call, and checks that the issuer and audience are the ones it expects. OWASP lists unsigned or weakly signed JWTs and unchecked expiry among the causes of broken authentication.
Mutual TLS. Both sides present certificates, so the connection itself proves the caller. It suits api to api authentication between services that you control on both ends.
What is OAuth 2.0?
OAuth 2.0 is an authorisation framework, defined in RFC 6749. It lets a client application obtain limited access to an HTTP service, so a person can grant an app access without handing over a password. Its four roles are the resource owner who grants access, the client app, the authorisation server that issues tokens, and the resource server, the API that accepts them.
OpenID Connect 1.0 is an identity layer on top of OAuth 2.0 that lets a client verify the identity of the end user. An access token is what the API checks on each call. A refresh token obtains a new access token when the current one becomes invalid or expires, and RFC 6749 says it is intended for use only with the authorisation server.
A client requesting access to resources under its own control can use the client credentials grant, which asks for an access token using only its client credentials. For an app acting for a person, RFC 9700, the OAuth 2.0 security best current practice, says clients should not use the implicit grant unless access token injection and leakage are prevented, and should use the authorisation code response type instead.
OAuth and JWT are not alternatives: JWT is a token format, and RFC 9068 defines a JWT profile for OAuth 2.0 access tokens.
Reading a JWT token
A JSON Web Token, or JWT token, has three parts joined by dots: header, payload of claims, and signature. Decoding one shows the claims but does not prove them; only checking the signature does. Example JWT tokens and JWT token generators are for learning; real tokens are signed by the issuing server.
Choosing a method
Match the method to who calls. The table gives a starting point for REST API authentication, and your own risk review decides the rest.
| Who calls | Method to consider |
|---|---|
| Apps acting on behalf of people | OAuth 2.0 tokens |
| A partner's server | An API key with narrow permissions, or mutual TLS |
| Your internal services | Mutual TLS, or short-lived signed tokens |
Whatever the choice, send credentials only over HTTPS. Do not put them in the URL: RFC 6750 says bearer tokens should not be passed in page URLs, and URLs end up in logs.
Common mistakes
Unprotected endpoints. A route that was meant to be internal, or an old API version, skips API authentication altogether.
Weak token handling. A bearer token or JWT with no expiry, no signature check, or no way to cancel it after a leak.
No limit on login and token endpoints. Unlimited attempts allow credential stuffing and password guessing, both named in OWASP API2.
Credentials in the wrong place. API credentials sit in mobile app code, in the URL or in a public repository.
How to find these in practice is on API security testing. The vulnerability class itself is described on authentication failures.
What a WAF and rate limits can and cannot do
A WAF does not handle API authentication: it does not authenticate callers. It does not issue, validate or revoke API keys and bearer tokens, and it has no list of who your users are. That work belongs in the API or its gateway, and a request with valid-looking API credentials passes a request filter like any other request.
Around that core, a request filter can block known attack patterns on the same endpoints, and rate limits cap how many attempts one client can make against login and token routes, which slows password guessing. Limits keyed to a user rather than an address are covered on per-IP vs per-user limits. They reduce exposure. They do not replace correct authentication.
Questions
What is API authentication?
API authentication is how an API verifies who is making a request, using a credential such as an API key, an access token or a client certificate. It comes before authorisation, which decides what the caller may do.
What is the difference between authentication and authorisation?
Authentication checks identity; authorisation checks permission. An API can authenticate a caller correctly and still fail to check whether they may access a particular object, which is BOLA.
Is an API key enough?
For low-risk server-to-server calls it can be. A key identifies the application rather than a person and is easy to leak, so it needs narrow permissions, rotation and rate limits.
Does a WAF handle API authentication?
No. A WAF does not authenticate callers or manage credentials. It can filter attack patterns and enforce request limits, while authentication stays in the API.
What is OAuth?
OAuth 2.0 is an authorisation framework, defined in RFC 6749, that lets a client app obtain limited access to an HTTP service through an access token rather than a password.
Is OAuth authentication or authorisation?
OAuth 2.0 is specified as an authorisation framework. OpenID Connect, an identity layer on top of OAuth 2.0, lets a client verify who the end user is. OAuth 2.0 authentication pairs the layers: OpenID Connect shows who the user is, and the access token is what the API checks on each call.