Connecting to Salesforce using OAuth

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

Segi
Ebase User
Posts: 649
Joined: Mon Dec 09, 2013 6:37 pm

Connecting to Salesforce using OAuth

#1

Postby Segi » Fri Mar 30, 2018 5:38 pm

I have been using Salesforce integration with Verj IO using REST to read information in our Salesforce instance and use it in Verj IO.

According to this page https://developer.salesforce.com/docs/a ... cation.htm, there are 3 different ways to authenticate using OAuth:

1. Web server flow
2. User-agent flow
3. Username-password flow

The first 2 methods require a https based URL as a callback URL that is called after the user authenticates which provides the access token. Since my VerjIO instance is not publicly accessible, I don't think that the first 2 methods will work for me since I don't have a publicly accessible callback URL to provide to the endpoint.

I currently have a REST Web Service Resource that I created which uses the 3rd method and this works fine.

The web service resource is configured like this:

Endpoint URL: https://login.salesforce.com/services/oauth2/token
Method: POST

Query parameters
----------------------
grant_type: password
client_id: <my client id>
client_secret: <my client secret>
username: <my username>
password: <my password appended with my security token>

Request Headers:

Content-Type: application/x-www-form-urlencoded

This works great but I only have 1 issue with this set up. Every so often, Salesforce requires you to change your password which also generates a new security token. When this happens, I have to remember to go into the web service resource and change the password and security token.

This isn't a huge deal but its annoying to have to do because I don't like the idea of updating the service every so often.

Is anyone else here who is using Salesforce able to suggest a better approach that will overcome this issue ?
0 x

Steve
Moderator
Moderator
Posts: 414
Joined: Fri Sep 07, 2007 3:44 pm
Location: Sandy, UK
Contact:

Re: Connecting to Salesforce using OAuth

#2

Postby Steve » Tue Apr 03, 2018 8:50 am

Hi Segi,

I have not used Sales Force, but from reading their documentation the Username-password flow does not support refresh tokens. So it looks as though you do not have any choice, but to refresh the web service when required.

Kind regards

Steve
0 x

Steve
Moderator
Moderator
Posts: 414
Joined: Fri Sep 07, 2007 3:44 pm
Location: Sandy, UK
Contact:

Re: Connecting to Salesforce using OAuth

#3

Postby Steve » Tue Apr 03, 2018 9:08 am

Hi Segi,

It dawned on me that I think it is the browser that forwards the URL. I know with spotify I used a http://localhost:3030/..... callback url when I have tested the Spotify using User Flow and this works fine.

Have you tried the user-agent flow using Ebase OAuth authentication with a callback URL of something like?

http://localhost:3030/ebase/ufsreturn

Kind regards

Steve Upton
0 x

Segi
Ebase User
Posts: 649
Joined: Mon Dec 09, 2013 6:37 pm

Re: Connecting to Salesforce using OAuth

#4

Postby Segi » Tue Apr 03, 2018 2:55 pm

Steve,

I don't think that that will work since the callback URL is called after you gave tried logging in and returns a JSON payload that includes an access_token after you have successfully authenticated.

As I mentioned, my server is not publicly accessible and using a URL with localhost:3030/ebase/whatever would not work because Salesforce needs to reach that callback URL to provide the JSON payload
0 x

Steve
Moderator
Moderator
Posts: 414
Joined: Fri Sep 07, 2007 3:44 pm
Location: Sandy, UK
Contact:

Re: Connecting to Salesforce using OAuth

#5

Postby Steve » Tue Apr 03, 2018 3:13 pm

Thanks Segi,

I have tested this with other OAuth2 connectors before (Spotify and Google) and used the callback URL of http://localhost.... and this works because the "browser" does the forwarding... not the server. So I am not sure whether this would be different?

According to the Salesforce documentation from:

https://help.salesforce.com/articleView ... erview.htm

The callback URL is an endpoint in your application to which Salesforce can redirect the user’s browser with an authentication code or access token.

But this may only work with in a test scenario... I also noticed that it had to be https:// so you would need to put in the https://<name-of-server>/ebase/ufsreturn

Anyway... might be worth a try?

Steve
0 x

Segi
Ebase User
Posts: 649
Joined: Mon Dec 09, 2013 6:37 pm

Re: Connecting to Salesforce using OAuth

#6

Postby Segi » Tue Apr 03, 2018 4:16 pm

Thanks

I'll give it a shot

Segi
0 x


Who is online

Users browsing this forum: No registered users and 22 guests