0

Trying to make a policy for getting a bearer token trough a send-request sticking it in the Authorization header and then posting JSON data to the given back-end.

But when I test it within the test tab of Azure I always receive the same error: enter image description here

Even when I add <forward-request timeout="60" follow-redirects="60"/> it does not work. I also tried it without the follow-redirects which is defaulted to false but also no effect.

I am completly new to Azure so any help would be appreciated.

Here is my policy:

<policies>
    <inbound>
        <base />
        <send-request ignore-error="true" timeout="20" response-variable-name="bearerToken" mode="new">
            <set-url>{{AuthenticationServer}}</set-url>
            <set-method>POST</set-method>
            <set-header name="Content-Type" exists-action="override">
                <value>application/x-www-form-urlencoded</value>
            </set-header>
            <set-header name="Authorization" exists-action="override">
                <value>Basic {{Base64encodedusernamepassword}}</value>
            </set-header>
            <set-body>@{
              return "grant_type=client_credentials";
           }</set-body>
        </send-request>
        <set-header name="Authorization" exists-action="override">
            <value>@("Bearer " + (String)((IResponse)context.Variables["bearerToken"]).Body.As<JObject>()["access_token"])</value>
        </set-header>
        <!--  Don't expose APIM subscription key to the backend. -->
        <!--<set-header name="Ocp-Apim-Subscription-Key" exists-action="delete" /> -->
        <set-backend-service base-url="{{BaseURI}}" />
    </inbound>
    <backend>
        <forward-request timeout="60" follow-redirects="true" />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>
spoilerd do
  • 377
  • 6
  • 20
  • 1
    Yea the issue was fixed, the company providing my account did not give me VPN access. Which was needed to test the endpoint. – spoilerd do Dec 09 '21 at 09:17
  • 1
    I don't know if it's your case but you'll also get this error if your APIM is an Internal Vnet when before it was in an External Vnet. – Joe Gurria Celimendiz Feb 12 '22 at 10:13
  • Yea I am not sure how they set the Vnet up. But I am pretty sure it is an internal now so VPN fixed the problem for me – spoilerd do Feb 14 '22 at 10:51

1 Answers1

0

The problem was that the endpoint was behind a private VNet so getting VPN access fixed the issue.

spoilerd do
  • 377
  • 6
  • 20