Identity and access API keys 3 min read
What is an API key?
Your server calls a maps API with a key in the request. If that key appears in a public code repository, what can the finder do with it?
-
The key is a credential in the request
A service gives your application a key, often a long random string. Your code includes it when calling the API, commonly in a header such as
X-API-Key.The service checks the key and applies its own rules. Some keys identify a project for quotas and billing; others grant access directly. The name “API key” alone doesn’t tell you how much authority it carries.
An application sends a request and its API key to a service. The service checks which project or permissions the key represents before responding.
The service defines what possession of this key means. In short An API key is a credential; its actual authority depends on the service.
-
A secret key can be copied
If a key is embedded in a public repository, shipped in a browser bundle, or printed in logs, someone else can copy it. A key that grants access works for whoever presents it; the service cannot tell that the request came from your original server just because the string matches.
A public identifier intended for browser use is different from a secret key. Follow the provider’s guidance about which keys can be exposed and restrict them to the sites, APIs, and operations that need them.
In short Assume a leaked secret can be reused until it expires or you revoke it.
-
Limit what a key can do
Keep server-side secrets in a secret manager or protected environment variable, not in source control or frontend code. Give each integration its own key, limit its permissions and usage, and set an expiry where the provider supports it.
If a key may have leaked, revoke or rotate it and review its usage. Don’t rely on obscuring the key’s name or splitting the string in client code.
In short Make keys narrow, replaceable, and easy to revoke.
What an API key doesn’t tell you by itself
A key doesn’t automatically prove which human is making a request, and it doesn’t guarantee fine-grained authorization. Those properties depend on how the provider binds the credential and checks permissions.
When an app needs to act on a user’s behalf, OAuth can provide a delegated, scoped grant instead of sharing a long-lived key.
Keep this
Treat a secret API key like a password for software.
Know what the key permits in that specific API. Keep secret keys out of source code and browser apps, grant the minimum access, and revoke a key that may have leaked.- Presents
- The client sends the key with an API request.
- Means
- The service uses it to identify a project, a caller, or an access grant, depending on its design.
- Risk
- A leaked secret key can be copied and used by someone else.
- Reduce harm
- Restrict permissions, store server-side, rotate, and revoke.
Questions worth carrying
Is every API key a user identity?
No. Some keys identify a project or application, while other API credentials can act with the permissions of a user or service account. Check what the provider binds the key to and what each endpoint authorizes.
Is a GitHub personal access token just an API key?
It is an API credential, but it is tied to the account that created it and its granted permissions. For automated integrations, consider whether a GitHub App is a better fit than a personal token.