Consume internal API as an application ΒΆ

This how-to guides you through the steps required to consume an API secured with Entra ID as an application (or a machine user). This is also known as the machine-to-machine (M2M) or client credentials flow.

Prerequisites ΒΆ

Configure your application ΒΆ

Enable Entra ID in your application:

app.yaml

Depending on how you communicate with the API you're consuming, configure the appropriate outbound access policies.

Acquire token ΒΆ

Now you can request a new token for the API that you want to consume.

Send a HTTP POST request to the endpoint found in the NAIS_TOKEN_ENDPOINT environment variable. The request must have a Content-Type header set to either:

  • application/json or
  • application/x-www-form-urlencoded

The body of the request should contain the following parameters:

ParameterExample ValueDescription
identity_providerentra_idAlways entra_id.
targetapi://<cluster>.<namespace>.<other-api-app-name>/.defaultThe intended audience (target API or recipient) of the new token.
Token request
Token request
Successful response

Your application does not need to validate this token.

Tokens are automatically cached by default

The endpoint will always return a cached token, if available. The endpoint will never return an expired token.

To forcibly get a new token, set the skip_cache property to true in the request. This is only necessary if the token is denied by the target API, for example if permissions have changed since the token was issued.

Consume API ΒΆ

Once you have acquired a new token, you can finally consume the target API by using the token as a Bearer token:

http

πŸ“š Entra ID reference