4

I'm trying to use Restforce (https://github.com/ejholmes/restforce) to set up integration with my Rails app to SalesForce's API using Oauth 2.0.

Restforce describes the initialization process as follows:

Initialization

Which authentication method you use really depends on your use case. If you're building an application where many users from different orgs are authenticated through oauth and you need to interact with data in their org on their behalf, you should use the OAuth token authentication method.

If you're using the gem to interact with a single org (maybe you're building some salesforce integration internally?) then you should use the username/password authentication method.

OAuth token authentication

client = Restforce.new :oauth_token => 'oauth token',
  :instance_url  => 'instance url'

Although the above will work, you'll probably want to take advantage of the (re)authentication middleware by specifying a refresh token, client id and client secret:

client = Restforce.new :oauth_token => 'oauth token',
  :refresh_token => 'refresh token',
  :instance_url  => 'instance url',
  :client_id     => 'client_id',
  :client_secret => 'client_secret'

I have my client_id and client_secret from the app that was created in SF, but have no idea what other information I need to be putting into restforce.

Does anyone have any experience with this gem? How do I use it to make the original request token request to SF?

2

You need to authenticate yourself first using the "user-agent" or "web-server" flow (see here) to retrieve the parameters you need. The application you set up in Salesforce provides you with a client secret and id but the token is only retrieved after access has been granted from Salesforce.

If you authenticate with the username and password option in Restforce and then inspect the client you will see you have an instance URL and an oauth token - however if you want to re-authenticate then the refresh flow is the best way and involves less handling of passwords etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.