Klevr Product Documentation logo

API Authentication Options

The authentication options supported by outbound stages that call a remote API.

There are a number of API-based outbound stages in Integration Hub, which result in a call to a remote API:

All of these stages support the same authentication options for the remote API being called by the stage.

Secrets

The secret values in the authentication section are stored in Key Vault, and API Management reads them through named values. Each secret value must have a secret token:

  • An $env: token for an Azure DevOps variable. The deployment writes the variable's value to Key Vault.
  • A $kv: token for a Key Vault secret that you have created.

A token can be part of a longer value, for example Bearer $kv:partner-api-token.

The secret values are basic.userName and basic.password, and authenticationUrl and body in the oauth2 and custom options. A header value, in the authentication section or in the stage's own header, can be a literal value, or can use an $env: or $kv: token to read a secret from Key Vault, for example an API key. Other values, for example method and accessTokenFieldName, are deployed as they are.

No Authentication

When the remote API being called by the stage does not require authentication, simply omit the authentication option from the stage definition file.

HTTP Basic

When the remote API being called requires HTTP Basic authentication, this can be configured by setting the authentication option in the stage definition file with the required username and password details:

"authentication": {
  "basic": {
    "userName": "$env:HTTP_BASIC_USER_NAME_DEVOPS_VARIABLE",
    "password": "$env:HTTP_BASIC_PASSWORD_DEVOPS_VARIABLE"
  }
}
PropertyDescription
userNameThe HTTP Basic authentication username. See Secrets.
passwordThe HTTP Basic authentication password. See Secrets.

Managed Identity

When the remote API being called by the stage is protected by Microsoft Entra ID and accepts OAuth 2.0 bearer access tokens, the API Management service's system-assigned managed identity may be able to be used to authenticate, if the remote API supports this.

When supported, managed identity authentication is preferred over manually configuring OAuth 2.0, as Azure manages the identity's credentials so no client secret, token endpoint, certificate, or other credential needs to be configured or stored.

This can be configured by setting the authentication option in the stage definition file with the Microsoft Entra resource of the remote API being called:

"authentication": {
  "managedIdentity": {
    "resource": "$env:REMOTE_API_RESOURCE"
  }
}
PropertyDescription
resourceThe Microsoft Entra resource identifier or application ID URI (e.g. api://<application-id>) requested as the access-token audience when acquiring the token. This is the token audience, not the remote API URL or a scope ending in /.default. Generally set via an Azure DevOps variable.

OAuth 2.0

When the remote API being called requires OAuth 2.0 authentication, this can be configured by setting the authentication option in the stage definition file with the required OAuth 2.0 details:

"authentication": {
  "oauth2": {
    "authenticationUrl": "$env:AUTHENTICATION_URL__DEVOPS_VARIABLE",
    "method": "POST",
    "header": {
      "contentType": "application/x-www-form-urlencoded",
      "Authorization": "$env:BasicAuth"
    },
    "body": "$env:AUTHENTICATION_FORM_DATA_DEVOPS_VARIABLE",
    "accessTokenFieldName": "access_token",
    "tokenExpirationFieldName": "expires_in"
  }
}
PropertySub-PropertyDescription
authenticationUrlThe full URL of the OAuth 2.0 authentication endpoint that needs to be called in order to obtain the token required for calling the remote API.
methodThe HTTP method used when calling the OAuth 2.0 authentication endpoint. Only POST is supported.
headerMandatory section for defining headers that need to be used when calling the OAuth 2.0 authentication endpoint.
contentTypeMandatory section for setting the "Content-Type" header when calling the OAuth 2.0 authentication endpoint. Generally, this will need to be set to application/x-www-form-urlencoded.
AuthorizationOptional. If needed, a string of format Basic {encoded_string}, where {encoded_string} is a Base64 encoded string of username:password, can be set for HTTP Basic authentication when calling the OAuth 2.0 authentication endpoint. (This is not normally required - most OAuth 2.0 authentication endpoints do not require HTTP Basic authentication to call, but it is sometimes needed.)
bodyThe body required for calling the OAuth 2.0 authentication endpoint.
accessTokenFieldNameThe field in the response from the OAuth 2.0 authentication endpoint that contains the access token to be used when calling the interface's external API.
tokenExpirationFieldNameOptional value defining the field in the response from the OAuth 2.0 authentication endpoint that contains how many seconds the token will remain valid for. If not supplied, Integration Hub will not cache the OAuth 2.0 token, and authenticate on every call to the interface's external API.

Custom

The custom authentication option should be used when the remote API being called by the stage uses a bespoke authentication mechanism (i.e. neither HTTP Basic nor OAuth 2.0).

This option deploys a policy into the API Management service so that when outbound calls to the remote API are made via API Management, the service calls the provided authentication URL, and performs a POST of the defined body, along with any headers set. The authentication URL is expected to return a string which will then be used as the Authorization header when calling the external API.

No caching of the string used for the Authorization header when calling the remote API is performed - the custom authentication URL is called for every call to the remote API.

It is generally intended that the custom authentication URL will be a custom Azure Function deployed outside of the Integration Hub service that is responsible for generating the Authorization header, based on the custom requirements of the remote API.

"authentication": {
  "custom": {
    "authenticationUrl": "$env:AuthenticationURL",
    "method": "POST",
    "header": {
        "contentType": "application/json"
    },
    "body": "$env:AuthenticationPayload"
  }
}
PropertySub-PropertyDescription
authenticationUrlThe full URL of the custom authentication endpoint that needs to be called in order to obtain the token required for calling the remote API.
methodThe HTTP method used when calling the custom authentication endpoint. Only POST is supported.
headerSection for defining headers to be used when calling the custom authentication endpoint.
contentTypeThe content type used when calling the custom authentication endpoint.
bodyThe body required for calling the custom authentication endpoint.

Last updated on