Consume internal API on behalf of an employee ¶

This how-to guides you through the steps required to consume an API secured with Entra ID on behalf of an employee. This is also known as the on-behalf-of (OBO) 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:

app.yaml
app.yaml

Exchange token ¶

Now you can exchange the employee's subject token for a new token, targeting the API that you want to consume.

Send a HTTP POST request to the endpoint found in the NAIS_TOKEN_EXCHANGE_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.
target<environment>:<team>:<other-api-app-name>The intended audience (target API or recipient) of the new token. Use the environment, team and application name of the target API. The legacy format api://<environment>.<team>.<other-api-app-name>/.default is also accepted.
user_tokeneyJra...The user's access token from the inbound request. Token that should be exchanged.
Token request
Token request
Successful response

Your application does not need to validate this token.

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