Salesforce authorisation with the Salesforcer Package

I'm trying to connect to Salesforce using the salesforcer package by Steven Mortimer.
It works fine on my local machine, but can't get it to work on Posit Cloud.
Instead of getting the browser window saying authentication was successful it has an error saying localhost refused to connect. I think this is because the response is being listened for at my local machine on port 1410. I don't know how to redirect this properly to Posit Cloud? I know next to nothing about authorisation flows.

Also the Posit Cloud connector for Salesforce only takes a username and password as the authentication method which Salesforce no longer supports if I'm not mistaken?

#> Connect to salesforce using OAuth

Okay, after some researching on github, Cannot connect to UAT using sf_auth · Issue #33 · StevenMMortimer/salesforcer · GitHub, I was able to authenticate using some httr code which instead of R waiting for the response on localhost:1410 will allow you to input the code into the terminal directly.

On the browser screen where it says localhost refused to connect the URL will look something like this

I had to copy this code and input it into the R Console but I had to replace the "%3D%3D" at the end with a double equals sign == e.g. aPrxqJ8A8kLOza8QYWB1MJ37.7lD7AxUZ5nbMy9PlJ1zcYI.JkbdF5ev8h1bPg9C6mkLNKS75A==

I don't know if that %3D%3D will be there every time and at the end of the code, in my case it was. Potentially other strange URL character encodings might result?

This allowed me to authenticate and could use salesforcer like I normally would be able to on my local machine.

consumer_key <- "3MVG9CEn_O3jvv0yRMQezJ8PwesiIknRU9v9j778rv78UvJ2JTQzSG.QduxyMxYaldoNEhO0eVvw4ogCT58c5"
consumer_secret <- "3471656211653393546"
callback_url <- "http://localhost:1410/"

sf_oauth_app <- oauth_app("salesforce",
                          key = consumer_key, 
                          secret = consumer_secret,
                          redirect_uri = callback_url)

sf_oauth_endpoints <- oauth_endpoint(request = NULL,
                                     base_url = "",
                                     authorize = "authorize", access = "token", revoke = "revoke")

sf_token <- oauth2.0_token(endpoint = sf_oauth_endpoints,
                           app = sf_oauth_app, 
                           cache = ".httr-oauth-salesforcer",

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.