Mulesoft and Slack Integration Using OAuth
This tutorial explains the steps to integrate Slack and Mulesoft with Oauth 2 authentication so that you can post a message from Slack to Mulesoft.
Join the DZone community and get the full member experience.Join For Free
The Mulesoft Slack Connector enables organizations to connect directly with the Slack API, permitting users access to the Slack functionality with seamless integration.
The lack of documentation to configure OAuth authentication for Slack connector makes it difficult for developers to use the connector with this security configuration. This article will guide developers to perform seamless integration with OAuth security.
Anypoint Studio 7.6 , Mule Runtime 4.3.0, Slack Account Workspace
In order to connect with Slack via Mulesoft, first, an app needs to created in https://api.slack.com/apps.
Click on Create an App, enter the App Name, and select your Development Slack Workspace from the dropdown.
Once the app is created, go under Basic Information and copy the Client ID and Client Secret. These will be used in the Mulesoft Slack connector configuration.
Go to OAuth & Permission and add a Bot Token Scope as per your requirement. For this tutorial, I am adding a
chat:write scope, which is used for posting messages to Slack.
Once the scope is added click Install to Workspace:
Once Oauth Token is installed to workspace, log into your Slack account. You should see the newly created app in your workspace.
Open Anypoint Studio and add Slack Connector in the project. In this tutorial, I will be using the Chat - Post Message operation for demonstration. In the Slack Config, select OAuth 2 Connection and enter the Client ID and Client secret copied earlier to Consumer key and Consumer secret respectively.
Under outhCallbackConfig, enter the details as below. Here, Authorize path will initiate the OAuth dance and the Call URL will return the access token which will be saved in the object store. Also, copy the External callback url; this needs to be in the Slack app.
Run the application, go to the Slack app, and add the Redirect URL as below:
To initiate the OAuth dance, go to the browser and enter the authorize URL http://localhost:8081/authorize. The below pop up will appear; click on Allow. The token will be retuned and saved to the object store of you application automatically.
Open Postman and hit the POST request to your Mule application listener with any payload as below:
Congratulations! You have successfully posted a chat message from Mulesoft to Slack using OAuth 2 as shown above.
Opinions expressed by DZone contributors are their own.