Search code examples
resthttpsmulebasic-authentication

External HTTPS REST call with Basic Auth isn't working in Mule


I'm trying to make an external HTTPS call in Mule with Basic Authentication. Below is an extract of my application:

<http:request-config name="HTTPS_Request_Configuration" protocol="HTTPS" doc:name="HTTP Request Configuration">
    <http:basic-authentication username="username" password="password"/>
    <tls:context>
        <tls:key-store type="jks" path="keystore.jks" alias="mule" keyPassword="password" password="password"/>
    </tls:context>
</http:request-config>

<flow name="get:/clients/{clientId}:api-config">
    <logger message="#['Retrieving client with ID: ' + flowVars['clientId']]" level="INFO" doc:name="Logger"/>
    <http:request config-ref="HTTPS_Request_Configuration" path="/api/clients/{clientId}" method="GET" host="host.com" port="443" doc:name="HTTP">
        <http:request-builder>
            <http:uri-param paramName="clientId" value="#[flowVars['clientId']]"/>
        </http:request-builder>
        <http:success-status-code-validator values="0..599"/>
    </http:request>
    <logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>

Using the above configurations I'm consistnetly getting 401 responses from the API I'm trying to call. Making calls via Postman with the exact same details work fine.

I have imported the certificate of the target host into my keystore. I'm using Mule version 3.7.3.

Any thoughts around what mightbe missing / what I'm doing wrong?


Solution

  • Add preemptive="true" to the http:basic-authentication element:

    <http:basic-authentication username="username"
                               password="password"
                               preemptive="true"  />