Using Restforce gem with SalesForce API and Oauth 2.0
Asked Answered
D

1

6

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?

Darlinedarling answered 6/4, 2014 at 20:29 Comment(0)
U
8

You need to login using Oauth 2.0 first, then provide the tokens to the gem. I did that using Omniauth-Salesforce and after the tokens are handed I instatiate restforce.

The examples in omniauth are using sinatra, please look into this repo for an implementation using rails.

I've blogged about this as well.

Untraveled answered 7/4, 2014 at 19:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.