ruby-on-rails - 将 Restforce gem 与 SalesForce API 和 Oauth 2.0 结合使用

标签 ruby-on-rails api gem oauth-2.0 salesforce

我正在尝试使用 Restforce ( https://github.com/ejholmes/restforce ) 使用 Oauth 2.0 将我的 Rails 应用程序集成到 SalesForce 的 API。

Restforce 对初始化过程的描述如下:

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'


我有我的 client_idclient_secret来自在SF中创建的应用程序,但不知道我需要将哪些其他信息放入restforce。

有没有人对这个 gem 有任何经验?如何使用它向SF发出原始请求 token 请求?

最佳答案

您需要先使用 Oauth 2.0 登录,然后将 token 提供给 gem。
我是用 Omniauth-Salesforce 做到的并在传递 token 后,我恢复了restforce。

omn​​iauth 中的例子使用的是sinatra,请查看this repo for an implementation using rails .

我已经 blogged about this as well .

关于ruby-on-rails - 将 Restforce gem 与 SalesForce API 和 Oauth 2.0 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22899617/

相关文章:

ruby-on-rails - 自定义中间件中未捕获的异常后类重新加载停止

ruby-on-rails - 版本 Rails 3 API 的正确方法

c++ - Windows API 建立事件

ruby - 在 OSX 10.8.4 上使用无法识别的选项 '-arch' 安装 json-1.8.0 时 make 失败

ruby-on-rails - 无法批量分配 protected 属性

html - 使 Bootstrap 样式覆盖原生 Rails 样式

JSON 和 Cygwin - 如何解析、获取字段等

ruby-on-rails - "bundle install"导致每个 gem 上的 Gem::RemoteFetcher::FetchError

ruby - 我可以在 Opal 中使用 Ruby gems 吗?

javascript - Rails select_tag - jQuery/JavaScript 在更改事件上隐藏/显示