Search code examples
mulemulesoft

Need Help Converting A Mule Connector From 3.9 to 4.5


We're working on converting our existing Mule connectors from version 3.9 to 4.5.0 (Community Edition) and I've found one I don't know how to convert. It makes a call to the OAuth URL for Microsoft Outlook and returns the token. The old version looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:spring="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd">
    <context:property-placeholder location="connect.properties" />
    <http:listener-config name="HTTP_Listener_Configuration"
        host="0.0.0.0" port="8081" basePath="/base" doc:name="HTTP Listener Configuration" />
    <http:request-config name="HTTP_Request_Configuration"
        protocol="HTTPS" host="login.microsoftonline.com" port="443"
        basePath="${outlook.base}" doc:name="HTTP Request Configuration" />
    <flow name="TokenProviderFlow">
        <http:listener config-ref="HTTP_Listener_Configuration"
            path="/path" doc:name="HTTP" />
        <set-payload doc:name="Set Payload"
            value="#[{'client_id':'${outlook.client.id}','client_secret':'${outlook.client.secret}','grant_type': 'client_credentials','scope':'https://outlook.office365.com/.default'}]" />
        <http:request config-ref="HTTP_Request_Configuration"
            path="/oauth2/v2.0/token" method="POST" doc:name="HTTP" />
    </flow>
</mule>

My new version (which does not work) looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
    xmlns="http://www.mulesoft.org/schema/mule/core"
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
    <configuration-properties file="connect.properties" />
    <http:listener-config name="HTTP_Listener_config" basePath="/base">
        <http:listener-connection host="0.0.0.0" port="8081" />
    </http:listener-config>
    <http:request-config name="HTTP_Request_configuration" basePath="${outlook.base}">
        <http:request-connection protocol="HTTPS" host="login.microsoftonline.com" port="443" />
    </http:request-config>
    <flow name="tokenproviderFlow">
        <http:listener config-ref="HTTP_Listener_config" path="/path" />
        <set-payload value="#[{'client_id':'${outlook.client.id}','client_secret':'${outlook.client.secret}','grant_type': 'client_credentials','scope':'https://outlook.office365.com/.default'}]" />
        <http:request config-ref="HTTP_Request_configuration" method="POST" path="/oauth2/v2.0/token" />
    </flow>
</mule>

My new version is returning an http status of 400 (Bad Request). Any suggestions on how to make this work?


Solution

  • Found the answer! I removed the set-payload component and added a body to the http:request component:

    <http:request config-ref="HTTP_Request_configuration" method="POST" path="/oauth2/v2.0/token">
        <http:body><![CDATA[#[output application/x-www-form-urlencoded --- {'client_id':'${outlook.client.id}','client_secret':'${outlook.client.secret}','grant_type': 'client_credentials','scope':'https://outlook.office365.com/.default'}]]]></http:body>
    </http:request>