Skip to main content

Secure an API

Require every caller of an API to authenticate, with tokens issued by the platform.

Use this guide when an API is published and must only answer callers you know.

Choose the method​

The right authentication method depends on who calls the API. Pick the row that matches the caller.

CallerMethodPage
Applications, service to serviceJWT with OAuth 2.0 client credentialsThis guide
People in a browserOIDC authorization code flowOIDC authentication
A few known partners, simple toolingAPI keyAPI key authentication
Decision taken by your own serviceExternal authorizationExternal authorization

Secure an API with JWT and client credentials​

  1. Identity provider: in API Manager, Auth Gateways, create an auth gateway on an HTTPS access point. Its address is the issuer.
  2. Audience: open the API instance and copy its audience ID.
  3. Client: in a client list attached to the auth gateway, register the application and add the audience ID to the APIs its tokens are for.
  4. Policy: on the API instance, add a JWT authentication rule issued by the auth gateway, with the audience check on.

Verification​

Token request
TOKEN=$(curl -s https://auth.example.com/api/oidc/token \
-u "$CLIENT_ID:$CLIENT_SECRET" \
-d grant_type=client_credentials | jq -r .access_token)
Calls
curl -i https://orders.example.com/orders # 401
curl -i https://orders.example.com/orders -H "Authorization: Bearer $TOKEN" # 200
Never put the client secret in a URL or a repository

Read it from a stored configuration or from the secret store of the calling application. A secret that reached a log or a commit must be regenerated.

Who may manage the API​

Calling an API and managing it are separate: the first is decided by tokens, the second by roles in Access Manager.

Refused calls: Tokens and sign-in.