Key takeaway
- Compare API keys, Basic, OAuth 2.0, JWT, mTLS and agent identities. Pick the right method using RFC 6749, RFC 7519 and the OWASP API Top 10 2023.
The main API authentication methods are API keys, HTTP Basic, OAuth 2.0 access tokens, JSON Web Tokens (JWT) and mutual TLS (mTLS). They answer different questions: an API key identifies the calling application, Basic sends a user name and password, OAuth 2.0 issues scoped and expiring tokens, a JWT is a signed container for claims, and mTLS proves possession of a certificate. For most enterprise APIs the sound default is OAuth 2.0 with short-lived tokens, with mTLS added where the client must be provably the same machine, and API keys kept for low-risk client identification only.
This guide is about choosing and governing the method, not about designing endpoints. For resource modelling and naming, read our companion guide on API design best practices and principles; for the delivery lifecycle, see API development best practices. Standards claims here come from the IETF RFCs, the OWASP API Security Top 10 (2023) and NIST SP 800-63.
Which API authentication method should you choose?
Choose by what you need to prove and who the caller is. The table sets out each method with the situation where it fits and its current standing in the primary sources.
| Method | What it proves | When it fits | Current status |
|---|---|---|---|
| API key | Which client application is calling | Low-risk, read-only or metered access where no user identity is needed | OWASP advises against using API keys for user authentication; they are only for authenticating API clients |
| HTTP Basic | A user name and password pair, Base64 encoded | Legacy or internal endpoints, only over TLS | RFC 7617: not a secure method of user authentication unless used with something such as TLS |
| OAuth 2.0 access token | Delegated, scoped access issued by an authorization server | User-delegated access and most service access | RFC 6749 (Proposed Standard), updated by the RFC 9700 best current practice of January 2025 |
| JWT | A set of claims, signed or encrypted, that a resource server can check itself | As the token format when APIs validate tokens locally | RFC 7519, with RFC 8725 (BCP 225) on safe handling |
| Mutual TLS | Possession of a client certificate; tokens can be bound to it | High-assurance service-to-service and regulated traffic | RFC 8705 defines client authentication and certificate-bound access tokens |
| Agent or service identity | Which workload or agent is acting, and on whose behalf | Autonomous agents and automated pipelines | Built from OAuth 2.0 client credentials and RFC 8693 token exchange |
What is the difference between authentication and authorization?
Authentication establishes who or what is calling. Authorization decides what that caller may do. An API can authenticate a caller correctly and still fail by letting it reach objects or functions it should not. OWASP lists these as separate risks in the 2023 Top 10: API2:2023 is broken authentication, while API1, API3 and API5 cover object-level, property-level and function-level access control failures. Treat them as two controls with two sets of tests.
How do API keys work, and when are they enough?
An API key is a secret string issued to a client application. It tells the provider which application is calling, which makes it useful for metering, quotas and revoking one integration. It does not identify a person. OWASP states that API keys should not be used for user authentication and are meant only for authenticating API clients.
Send keys in a header, never in the query string. RFC 6750 explains why for tokens in general: URLs are highly likely to be logged, so a secret in the URL leaks into proxies, browser history and analytics. Give each key an owner, an expiry and a rotation date, and store it in a secrets manager rather than in code or configuration files.
Is HTTP Basic authentication still acceptable?
Rarely. Basic joins the user name and password with a colon and Base64 encodes the result. Base64 is an encoding, not encryption, so anyone who sees the header can read the password. RFC 7617 says the scheme is not considered a secure method of user authentication unless used with an external secure system such as TLS, and it calls cleartext password transmission the most serious flaw. If Basic must stay for a legacy integration, require TLS, use a dedicated service account with narrow rights, and plan its replacement.
How do OAuth 2.0 and bearer tokens work?
OAuth 2.0 lets a client obtain an access token from an authorization server, then present it to the API. RFC 6749 describes access tokens as credentials used to access protected resources, and refresh tokens as credentials used to obtain new access tokens; refresh tokens are never sent to resource servers. The token endpoint must use TLS. The usual way to present a token is the Bearer scheme in RFC 6750: whoever holds the token can use it, without proving possession of a key, so it must be protected and sent in the Authorization header.
OAuth 2.0 is an authorization framework. OWASP is explicit that OAuth is not authentication, so a sign-in flow for people should use an established identity layer rather than a home-built check.
Which OAuth 2.0 grant should you use today?
RFC 6749 defines four grants. RFC 9700, published in January 2025 as BCP 240, changes the advice for two of them.
| Grant | Typical use | Current guidance |
|---|---|---|
| Authorization code | User signs in to a web or mobile app | The main interactive flow. RFC 9700: public clients must use PKCE, and authorization servers must support it |
| Client credentials | A service acts on its own behalf | RFC 6749: used when the client is acting on its own behalf. The standard choice for server-to-server access |
| Implicit | Older browser apps | RFC 9700: clients should not use it |
| Resource owner password credentials | Client collects the user's password | RFC 9700: must not be used |
RFC 9700 also requires exact matching of redirect URIs, with a narrow exception for localhost in native apps, and says refresh tokens for public clients must be sender-constrained or rotated. Older articles that recommend the implicit flow or the password grant are out of date.
What does a JWT prove, and how should you validate it?
A JWT is, in the words of RFC 7519, a compact, URL-safe means of representing claims between two parties. The claims can be signed (JWS) or encrypted (JWE). Registered claims include iss (issuer), sub (subject), aud (audience), exp (expiry), nbf (not before), iat (issued at) and jti (a unique identifier that can help prevent replay). A JWT is a token format, not a login method, and OAuth 2.0 does not require access tokens to be JWTs.
The failures are in validation. RFC 8725 (BCP 225, February 2020) says libraries must let the caller fix the set of accepted algorithms, that the "none" algorithm should only be used when the token is protected by other means, that an application must reject a token whose keys do not belong to the stated issuer, and that a recipient must reject a token whose audience is missing or does not match. OWASP separately flags unsigned or weakly signed tokens and unchecked expiry as authentication weaknesses. Check signature, algorithm, iss, aud and exp on every request, and keep tokens short-lived because a JWT cannot be recalled once issued unless you add a revocation check.
When should you use mutual TLS?
Mutual TLS has both sides present certificates, so the server knows which client machine it is talking to. RFC 8705 defines two uses in OAuth 2.0: clients authenticating to the authorization server with a certificate, and access tokens bound to the client's certificate so that only the client that was issued the token can use it. That second use removes the main weakness of bearer tokens, which is that a stolen token works anywhere.
The cost is operational: certificate issuance, rotation and revocation across every client. It fits payment, healthcare and partner integrations where the client is a known system, and it is a poor fit for public mobile or browser apps.
How should AI agents and services authenticate to APIs?
Give every agent and service its own identity. Do not let agents share a human user's session or one long-lived key. Use the OAuth 2.0 client credentials grant for an agent acting on its own behalf, with narrow scopes and short token lifetimes. When an agent acts for a person, RFC 8693 token exchange supports delegation: the token identifies both parties, and the act (actor) claim records that delegation has occurred. RFC 8693 distinguishes this from impersonation, in which the acting party is treated as the other party and receives all its rights. Prefer delegation, so audit logs show which agent did what for whom.
Authentication alone does not make an agent safe. The agent still needs a policy decision on each action, and a record of why. ElixirData Context OS keeps governed context, versioned policy and decision traces in one decision layer above AI agents, and AgentGRC keeps autonomous agent actions inside policy, with the audit trail risk teams need. For building and orchestrating the agents themselves, ElixirClaw is an agentic OS platform to build, orchestrate and govern AI agents and automation workflows while keeping humans in control.
What does OWASP say about API authentication failures?
OWASP ranks broken authentication second in its API Security Top 10 (2023), as API2:2023, noting that the authentication mechanism is an easy target because it is exposed to everyone. Its prevention advice is practical:
- Use established standards. Do not build your own authentication, token generation or password storage.
- Apply anti-brute-force controls stricter than general rate limiting, such as lockout or captcha, and treat password-reset endpoints like login endpoints.
- Require re-authentication for sensitive changes such as an email address, and use multi-factor authentication where possible.
- Do not use API keys for user authentication.
For people signing in, NIST SP 800-63B (part of the SP 800-63-4 suite) defines authentication assurance levels. AAL3 requires proof of possession of a key through a public-key protocol with a phishing-resistant authenticator. These levels apply to human subjects, so use them for staff and customer sign-in rather than for workload identities.
What are the trade-offs, and when is each method the wrong choice?
| Method | Main trade-off | Avoid when |
|---|---|---|
| API key | Simple to issue, but one leaked string gives full access until rotated | You need to know which person acted, or the data is sensitive |
| HTTP Basic | Easy everywhere, but sends the password on every request | Traffic is not on TLS, or the user is a person with a shared password |
| OAuth 2.0 | Scopes and expiry, but needs an authorization server and careful flow choice | The API is a single internal script with no growth planned |
| JWT | Local validation, but hard to revoke before expiry | You cannot manage signing keys, or need instant revocation without a check |
| mTLS | Strong client binding, but heavy certificate lifecycle work | Clients are public browsers or mobile apps |
In what order should an enterprise adopt these controls?
- Inventory every API and record its current method, owner and data sensitivity.
- Require TLS everywhere and remove credentials from query strings.
- Move interactive access to the authorization code flow with PKCE, and retire implicit and password grants.
- Move service access to client credentials with short-lived tokens and scoped permissions.
- Add certificate-bound tokens or mTLS for the highest-risk service paths.
- Test authentication paths in your pipeline; our guide to API testing workflow, tools and best practices covers how, and our note on API latency versus response time helps you budget the overhead that token checks add.
In our own security reviews of platform code, the recurring findings are the ones OWASP and the RFCs describe: unvalidated token claims, weak handling of the OAuth state parameter and redirect URIs, and credentials held in configuration instead of referenced from a secrets store.
To map one authentication or authorisation decision your agents should make, and the context and policy it depends on, book a Context Workshop. See what happens in the workshop.
Frequently asked questions
What is the most secure API authentication method?
No single method is the most secure for every case. OAuth 2.0 with short-lived, scoped tokens is the usual enterprise default, and mutual TLS with certificate-bound tokens (RFC 8705) adds stronger client binding for high-risk service traffic.
Is an API key enough to secure an API?
Only for low-risk use. OWASP says API keys are for authenticating API clients, not users, so they do not show who performed an action.
Is Base64 in Basic authentication a form of encryption?
No. Base64 is an encoding. RFC 7617 says Basic is not a secure method of user authentication unless used with something such as TLS.
Which OAuth 2.0 grants should no longer be used?
RFC 9700 says clients should not use the implicit grant and that the resource owner password credentials grant must not be used. Public clients must use PKCE with the authorization code grant.
Is a JWT the same as OAuth 2.0?
No. A JWT is a token format defined in RFC 7519. OAuth 2.0 is an authorization framework that may issue JWTs or opaque tokens, and every JWT must still be validated for algorithm, issuer, audience and expiry.
How should an AI agent authenticate to an API?
Give the agent its own identity and use the client credentials grant with narrow scopes. When it acts for a person, use RFC 8693 token exchange so the token records delegation through the act claim.
Explore the XenonStack platform family: ElixirData · ElixirClaw · ElixirHub · NexaStack · MetaSecure · Neural AI · AgentGRC · AgentSRE · AgentAnalyst · AgentInstruct · AgentRAI · AgentScrum · AgentSearch · AgentForce · AI Aviator · SAIF Aviator · CohortIQ · XenonStack AI · XenonStack UAE