On this page
API keys, JSON Web Tokens, and mutual TLS solve different parts of the identity problem. They are not three interchangeable security levels, and choosing one does not remove the need for authorization. A good design starts with the caller: a human using a browser, a partner integration, a backend workload, or an automated agent acting with delegated authority.
This guide compares the roles of these mechanisms through an example reporting API. The purpose is to help you define a credential lifecycle and a verification contract. It is not a prescription to combine every mechanism on every endpoint or to replace a supported identity library with handwritten cryptography.
Start by identifying the principal
Write down what the API needs to know about the caller. A browser request may represent a signed-in user inside an organization. A scheduled integration may represent a service installation with access to a specific project. A backend connection may represent a workload, while the operation still needs the authority of the user who initiated it.
Keep these identities distinct in your model. A service’s ability to establish a trusted connection should not imply permission to export every tenant’s reports. For the example API, record the integration identity, the tenant it belongs to, and the permitted operations separately. This prevents the transport credential from quietly becoming an all-purpose administrator identity when new routes are added.
Use API keys with a deliberate scope
An API key can identify a client integration or serve as a bearer credential, depending on the service design. The essential question is what possession of the key permits. Give each integration its own credential, limit its scope, and provide a way to revoke it without disabling unrelated clients. Avoid putting long-lived secret keys into browser-delivered code.
For the reporting example, a partner integration could receive permission to request a particular report type for one organization. Keep key metadata such as owner, creation time, last use, and permitted scope separate from the secret value. Do not display the secret in ordinary logs or error responses. Where a lookup-only key design permits it, consider storing a secure verifier rather than a recoverable copy, with the details reviewed for your implementation.
Treat JWT verification as a complete contract
A JWT is a token format, not an automatic trust decision. The IETF JSON Web Token Best Current Practices, RFC 8725 discusses issues such as algorithm verification, issuer and audience validation, and preventing confusion between token types. Use a maintained library and configure the expected verification rules rather than trusting token-supplied choices.
Define the trusted issuer, acceptable algorithms, required audience, applicable time claims, and intended token type for each consumer. An access token for one API should not become valid for another merely because both trust the same signing infrastructure. Keep authentication failures separate from permission failures in your internal decision model. Successful verification establishes a trusted set of claims; it does not answer whether the actor may export this particular report.
Understand the role of mutual TLS
Mutual TLS adds certificate-based client authentication to the connection when configured and verified appropriately. In an application design, that can help establish which workload or managed client is connecting. It does not inherently describe the human user’s current permissions or the business action being requested.
For the example reporting system, a backend worker might use mutual TLS when contacting the export service, while the export request carries a separately verified job authorization context. Document where TLS terminates and how the verified client identity reaches the application. If a proxy forwards certificate information in headers, ensure clients cannot supply equivalent trusted headers themselves. Review certificate issuance, rotation, expiration, and revocation as operational processes, not just initial installation steps.
Avoid confusing connection identity with delegation
A trusted service can act on behalf of many users. That makes delegation an explicit design problem. Decide whether the downstream API receives an audience-specific user token, a constrained job authorization, or another supported delegation mechanism. Do not let a generic service credential erase the restrictions of the initiating user.
Imagine an employee starting a report export and losing project access before the worker executes it. Your policy must decide which permissions apply at execution and at download. Record that choice and test it. A useful job context includes the intended operation and resource scope without exposing unnecessary credentials. The worker should not be able to change the target organization simply because it possesses a valid connection credential.
Build rotation and revocation before an incident
Credential rotation should be a routine, testable workflow. Identify how a replacement is issued, how clients adopt it, whether a bounded overlap is permitted, and how the old credential stops working. Keep the overlap short enough for the risk and long enough for the supported migration process. A forgotten fallback credential defeats the point of rotation.
Revocation deserves a separate test. Some verification arrangements can continue accepting a credential until expiry unless they consult additional state. Document the expected delay and the mechanism available for urgent containment. For partner keys, rehearse disabling one integration while preserving others. For signing keys and certificates, test the effect on caches and already running workloads. Operators should know which action contains the incident rather than merely changing a value in a dashboard.
Protect credentials across the development lifecycle
Inspect source repositories, build logs, test fixtures, deployment manifests, error reporting, and support workflows. A carefully designed authentication scheme can still be undermined when a secret is pasted into an issue or bundled into a client asset. Use workload-appropriate secret distribution and avoid creating unnecessary copies during deployment.
In the reporting example, test credentials should access only synthetic data and should not share privileges with production integrations. Redact authorization headers in observability pipelines and check failure paths as well as successful requests. Give support staff identifiers they can use to locate a credential record without requesting its secret value. If a key is exposed, removing it from the visible page is not a substitute for revoking or replacing the underlying credential.
Write a negative verification test matrix
Test more than a valid credential. Include missing credentials, malformed tokens, unsupported algorithms, unexpected issuers, incorrect audiences, expired claims, and revoked integrations where the mechanism supports revocation. Then test valid credentials with insufficient permission. That last group proves the application does not confuse identity with authority.
Exercise configuration changes too. A signing-key update, a certificate rollover, or an issuer migration can reveal assumptions that ordinary request tests miss. Keep expected outcomes and the verification configuration beside the fixtures. Do not use production secrets in the test suite. For each failure, verify the response, the absence of protected side effects, and the minimized log record needed for diagnosis. A generic “authentication test passed” leaves too much ambiguity.
Choose combinations only when they add a clear boundary
Using mutual TLS alongside an access token can make sense when you need both workload identity and delegated user context. Adding a second credential merely because it sounds stronger can create unnecessary operational complexity. Write down what each mechanism proves, who issues it, how it expires, and how it is revoked. Remove any layer whose purpose the team cannot explain or test.
Conclusion: credentials are only the beginning
Select authentication mechanisms by caller type, trust boundary, and lifecycle needs. Keep verification explicit, delegation constrained, and resource authorization independent. The most useful credential is one your team can issue safely, validate consistently, rotate routinely, and revoke when circumstances change.
The API security overview places identity inside a broader protection model. Continue with the API shield architecture guide to connect credential verification with contracts, permissions, resource budgets, and response handling. No token format replaces those other decisions.



