本文介绍了将 Restforce gem 与 SalesForce API 和 Oauth 2.0 结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 描述初始化过程如下:

Restforce describes the initialization process as follows:

初始化

您使用哪种身份验证方法实际上取决于您的用例.如果您正在构建一个应用程序,其中来自不同组织的许多用户通过 oauth 进行身份验证,您需要与中的数据进行交互代表他们的组织,您应该使用 OAuth 令牌身份验证方法.

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.

如果您使用 gem 与单个组织进行交互(也许您是在内部构建一些 Salesforce 集成?)然后你应该使用用户名/密码验证方法.

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 令牌认证

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

虽然上述方法可行,但您可能想利用通过指定刷新令牌的(重新)身份验证中间件,客户端 ID 和客户端密码:

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.

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.

有人对这个宝石有任何经验吗?如何使用它向SF发出原始请求令牌请求?

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

推荐答案

您需要先使用 Oauth 2.0 登录,然后将令牌提供给 gem.我使用 Omniauth-Salesforce 做到了这一点,在传递令牌后,我设置了 restforce.

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.

omniauth 中的示例正在使用 sinatra,请查看此 repo 以使用 Rails 的实现.

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

我也在博客上写过这件事.

这篇关于将 Restforce gem 与 SalesForce API 和 Oauth 2.0 结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 08:05