What is an API key, and how is it different from an OAuth token?
An API key identifies an application; an OAuth token represents a user's authorisation for an application to act on their behalf. They answer different questions, and using one where the other is needed is a common security failure.
API key. A long string issued to a developer, sent with each request, identifying which application is calling.
What it is good for: identifying the caller for rate limiting, quota management, billing and usage analytics.
What it is not good for: authorisation of access to user data. A key is a bearer credential — anyone holding it can use it, with no expiry and no user context. It says nothing about who is using the application.
The recurring failure: keys embedded in mobile applications or front-end JavaScript, where they are trivially extractable. Keys are routinely found in public code repositories, and automated scanners locate and abuse them within minutes of publication. A key in client-side code should be assumed public.
OAuth 2.0 tokens. The flow separates three parties: the user who owns the data, the application requesting access, and the service holding it.
The user authenticates directly with the service and consents to specific access. The service issues the application an access token representing that grant.
Why this is better where user data is involved:
The application never sees the user's password.
Scoped access — the token permits only what was consented to, not everything the user can do.
Short lifetime, with refresh tokens used to obtain new ones, so a leaked access token has limited value.
Revocable by the user, per application, without changing their password.
Auditable per application.
The practical guidance:
Keys belong on the server, never in client code. Where a client must call an API directly, proxy through your own backend.
Rotate keys, and scope them to the minimum permissions and, where supported, to specific IP addresses or referrers.
Use OAuth whenever user data is involved, and never ask users for credentials to a third-party service.
Secrets belong in a secrets manager, not in configuration files committed to version control.