Anypoint Exchange

Home to the complete listing of connectors, templates, examples and APIs.
Discover and use proven assets built by the MuleSoft ecosystem, or add assets to a private
tenant of Anypoint Exchange for collaboration and sharing of internal best practices.

Learn more
Sign up
Authenticating Salesforce using OAuth 2.0

Authenticating Salesforce using OAuth 2.0

(0 reviews)

This example shows how to connect to Salesforce using OAuth as the security protocol.

screenshot from Anypoint Studio

Example

This application employs the Salesforce OAuth connector to enable OAuth authentication before performing the integration process. Salesforce is queried to retrieve all contacts from the Salesforce account. To keep it simple, the Process Records Phase only prints the contacts to the log.

Set Up and Run the Example

  1. Open the example application in Anypoint Studio. Do not run the application.
  2. Log in to your Salesforce account. From your account menu (your account is labeled with your name), select Setup.
  3. In the left navigation bar, under the Build heading, click to expand the Create folder.
  4. Click Apps. Under Connected Apps click New.
  5. Fill in all the required fields. Check Enable OAuth Settings. Set Callback URL to http://localhost:8081/oauth2callback. Move Full Access (full) to Selected OAuth scopes. Click Save. Stay on this page.
  6. In your application in Studio, click the Global Elements tab and add Salesforce (OAuth) connector, if does not already exist.
  7. Now, paste the Consumer Key and Consumer Secret in the common.properties file under src/main/resources. ( Another option is to Double-click the Salesforce (OAuth) global element to open its Global Element Properties panel. In the Consumer Key and Consumer Secret fields, paste the values from Salesforce App form. Alternatively, configure the global element in the XML Editor. Then click OK to save your changes.)
  8. In the Package Explorer, right-click the authenticating-salesforce-using-oauth2 project name, then select Run As > Mule Application. Studio runs the application on the embedded server.
  9. Open your browser and put http://localhost:8081 in the address bar. You are redirected to Salesforce Login page and asked for your credentials. Allow access for this app.
  10. Go back to Anypoint Studio and the console log should contain lines like these:

     INFO  2017-10-27 12:49:25,779 [[authenticating-salesforce-using-oauth2].connector.http.mule.default.receiver.02] org.mule.examples.LoggerIterator: contact: {LastModifiedDate=2017-08-25T13:21:00.000Z, Id=0032000001INNfoAAH, LastName=Pickwick, type=Contact}
     INFO  2017-10-27 12:49:25,779 [[authenticating-salesforce-using-oauth2].connector.http.mule.default.receiver.02] org.mule.examples.LoggerIterator: contact: {LastModifiedDate=2017-08-25T13:21:00.000Z, Id=0032000001INGnuAAH, LastName=GaultThe, type=Contact}
     INFO  2017-10-27 12:49:25,780 [[authenticating-salesforce-using-oauth2].connector.http.mule.default.receiver.02] org.mule.examples.LoggerIterator: contact: {LastModifiedDate=2017-08-25T13:21:00.000Z, Id=0032000001IOBe4AAH, LastName=Hobbit, type=Contact}
     INFO  2017-10-27 12:49:25,780 [[authenticating-salesforce-using-oauth2].connector.http.mule.default.receiver.02] org.mule.examples.LoggerIterator: contact: {LastModifiedDate=2017-08-29T15:48:11.000Z, Id=0032000001IOuBtAAL, LastName=Darko, type=Contact}
     INFO  2017-10-27 12:49:25,780 [[authenticating-salesforce-using-oauth2].connector.http.mule.default.receiver.02] org.mule.examples.LoggerIterator: contact: {LastModifiedDate=2017-09-11T19:19:58.000Z, Id=0032000001IP8uiAAD, LastName=Burke, type=Contact}

Documentation

Read full documentation in GitHub


Reviews

Download
Log into Anypoint Platform to download this asset

Overview

Type
Example
Created By
MO
MuleSoft Organization
Published On
Oct 9, 2017

Versions

Version
1.5.0
1.4.0
1.3.3
1.2.0
Show more