This serves as a PoC to demonstrate how Node-RED can be setup to integrate with the Salesforce REST API via the OAuth2 JWT bearer flow
- npm
- Docker
- Docker Compose CLI
- Clone repo
- Run
npm install
- Create a connected app in your Salesforce org
- Select
Enable OAuth Settings
and set the OAuth scope for your connected app to includefull
,refresh_token
, &offline_access
- The callback URL is not used during the OAuth2 JWT flow, but it's required so you can just set it to
http://localhost:8080/callback
- Create a private key and self-signed digital certificate - take note that this guide creates a cert that will expire in one year, you may wish to change the
-days
parameter for a longer or shorter lived certificate - On your connected app settings, select
Use digital signatures
and then upload theserver.crt
file created previously - Spin up the Node-RED server locally on by executing
docker-compose up --build
- Node-RED should be available by visiting
localhost:1880
- Note the
setConfig
node that injects the required settings to generate the JWT - Set
CLIENT_ID
to your connected app's consumer key - To integrate with a Salesforce sandbox change the
LOGIN_URL
value tohttps://test.salesforce.com
- Set
USERNAME
to that of the user you want to authenticate as. This user will need to first run through the OAuth2 web flow a single time by visiting LOGIN_URL/services/oauth2/authorize?response_type=token&client_id=CLIENT_ID&redirect_uri=LOGIN_URL/services/oauth2/success - note you'll need to replaceLOGIN_URL
andCLIENT_ID
in that URL - Set
PRIVATE_KEY
to that of the private key matching the self-generated SSL cert associated with your connnected app. Note you will need to wrap the key in"
and use\n
characters as opposed to literal line breaks similar to the example value - Click
Deploy
in Node-RED to save and deploy any and all changes - Verify your Salesforce auth info and user list being logged to the debug window
This project is licensed under the MIT License - see the LICENSE file for details