WK Integration Services Ltd

Seamless Solutions, Tailored Integration

APIM Policy to Retrieve D365 Bearer Token

APIM Policy to Retrieve D365 Bearer Token

The policy below adds the “Authorization” header to the backend request.  All token request parameters are added to APIM as Named values.  The “D365-secret” named value points to a secret in the key vault so that it is kept private.  A retry policy is also added in case there is an issue retrieving the bearer token.

        <base />
        <retry condition=“@(context.Variables[“bearerToken“] == null ||
((IResponse)context.Variables[“bearerToken”]).StatusCode >= 500)”
count=”5″ interval=”10″ max-interval=”50″ delta=”10″ first-fast-retry=”true”>
            <send-request mode=“new” response-variable-name=“bearerToken” timeout=“20” ignore-error=“true”>
                <set-header name=“Content-Type” exists-action=“override”>
        <set-header name=“Authorization” exists-action=“override”>
@(“Bearer ” + (String)((IResponse)context.Variables[“bearerToken”]).Body.As<JObject>()[“access_token”])
        <base />
        <base />
        <base />

Leave a Reply

Your email address will not be published. Required fields are marked *