Card 02/ 12

ConceptDifficulty: Beginner2 min

How an API Knows Who Is Calling: Keys, Sessions, Tokens and Certificates

Five methods prove a caller, and four questions tell them apart.

APIs authenticate callers in five common ways: an API key, a session, a bearer token, a JWT, which is one kind of bearer token, and mutual TLS. Four questions tell them apart: what proves the caller, where that proof travels in the request, which kind of client it suits, and how access is cut off when it should end. Every card on a method in this topic answers the same four, in that order.

The five methods against the four questions
MethodWhat proves the callerWhere it travelsSuitsHow access is cut off
API keyA long random secret per projectA request headerServer-to-server calls, meteringRevoke the key
SessionA random id pointing at state on the serverA cookieThe API's own browser front endDelete the session
Bearer tokenA token issued by an authorisation serverAuthorization: BearerApps acting for a userExpiry, or revocation at the issuer
JWTA token whose claims are signedAuthorization: BearerServices that verify without a lookupExpiry, unless extra checks are added
Mutual TLSA client certificate and its private keyThe TLS handshake, before any headerServices inside one systemRevoke or stop renewing the certificate

Not five rivals. Some rows combine. A session id is usually carried in a cookie, so "cookie or session" is not a choice. A JWT is a format a bearer token can take, not a separate way of sending one. Mutual TLS can run underneath a token, proving the machine while the token names the user.

What a caller is. A person, through an app acting for them; a program belonging to a partner; or one of the API's own services. The method follows from which.

The cut-off question is easy to skip. Every method gives access; the difference that matters on a bad day is how fast it can be taken away. A key is revoked at once; a JWT may stay valid until it expires.

So choose a method by answering the four questions for the caller in front of you, not by picking the most familiar one.