Resources / Guides

API authentication methods: API keys vs OAuth 2.0 vs JWT vs HMAC

The main ways to authenticate API requests — API keys, OAuth 2.0, JWTs, HMAC signatures and mTLS — how each works, and which to choose.

Every API needs to answer two questions on each request: who is calling (authentication) and are they allowed to do this (authorization). These are the common ways to answer the first one.

API keys

A long random string the client sends with every request, usually in a header:

Authorization: Bearer sk_live_51Hx...
x-api-key: sk_live_51Hx...

OAuth 2.0

A framework where a user delegates access to an app without giving it their password. The app gets an access token (short-lived) and often a refresh token.

JWT (JSON Web Tokens)

A signed token format: header.payload.signature. The server can verify it without a database lookup, because the signature proves who issued it.

JWT is a format, not a method — OAuth often uses JWTs as access tokens.

HMAC request signatures

The client signs each request (usually timestamp + body) with a shared secret, and sends the signature. The server recomputes it.

Mutual TLS (mTLS)

Both sides present certificates. Strong, but heavy to operate — mostly for regulated industries and service meshes.

Which one to choose

ScenarioUse
Customers' servers call your APIAPI keys (per customer, scoped, revocable)
Your app acts on behalf of users of another serviceOAuth 2.0
Users sign in to your own appSessions or OAuth/OIDC via an identity provider
Services you own call each otherShort-lived JWTs or mTLS
Receiving events from another serviceHMAC signature verification
AI agents calling your toolsAPI keys or OAuth, scoped per tool

Whatever you pick: always use HTTPS, rate-limit per credential (see API rate limit best practices), log which credential made each call, and make revocation instant.

Authentication on Wisp

Each Wisp project can require API keys — one per customer or app, optionally limited to some endpoints and with an expiry. Callers send Authorization: Bearer … or x-api-key; requests without a valid key get 401, and your code sees which key called in req.apiKey. For anything else — sessions, JWTs from your identity provider, HMAC-signed webhooks — describe it and Wisp writes it as a before function that runs ahead of every HTTP function.

Try it: curl to fetch / Python converter

Build it with Wisp — describe an API, get it live.

Related