liveBook · Manning

API key

As explained in Software Security for Developers

An API key is a credential, usually represented as a secret token, that identifies or authorizes a client calling an application programming interface.

An API key is a unique secret string that one service places in a request so another service can identify and authorize it. A payment processor may require a key to verify that a charge request comes from the shopping application; if the key leaks, an attacker can cause financial damage. section 2.2 section 16.2.2

The usual pattern is simple: generate a key, configure the calling service with it, send it in an HTTP or message header, and reject requests whose key is missing or unrecognized. This simplicity makes API keys useful for small internal systems, but it also creates a fragile trust boundary. section 3.1.2 section 16.2.2

Validating a request

A billing service might receive `X-API-KEY: abc123-secure-token`. Application logic compares the supplied value with the expected key and returns HTTP 401 Unauthorized when they differ. In production, validation should be extracted from individual controllers so the rule is not duplicated. section 16.2.2

Treat an API key as a sensitive credential:

  • Store it in a centralized credential service rather than ordinary configuration files, which are difficult to secure, audit, synchronize, and rotate across production servers. section 2.2 section 2.4
  • Rotate it deliberately; static keys otherwise remain valid until someone changes them. section 2.2 section 16.2.2
  • Protect requests with HTTPS or mTLS, because a spoofable header is not sufficient protection on an exposed or compromised network. section 16.2.2 section 3.1.2
  • Prefer OAuth2 client credentials or mTLS when stronger identity, lifecycle management, or request context is needed. section 16.2 section 16.4
Figure 2.8 A credential vault is a centralized store of sensitive configuration values, such as passwords, API keys, digital certificates, and other secrets the application needs at run time.
figure

A credential vault illustrates where API keys can live alongside passwords, certificates, and other runtime secrets. section 2.2

How Software Security for Developers covers it

How deep it goes
Explains generation, header transmission, validation, leakage, spoofing, and rotation, but defers detailed lifecycle implementation.
Examples
Uses payment processing, billing requests, X-API-KEY headers, and a Java controller that returns HTTP 401 for invalid keys.
What it assumes
Assumes basic application and HTTP concepts while teaching service identity and request authorization directly.
What you can do after
Apply API keys to simple service calls and recognize when leakage, spoofing, static validity, or scale requires another mechanism.
How it connects
Connects API keys with service identity, mTLS, OAuth2 client credentials, API gateways, and credential services.

Also explained in

Compare how 13 books explain API key →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Software Security for Developers. The section links point to the parts of the book it draws on.