本文介绍了将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'

我从SF中创建的应用程序中获取了我的client_idclient_secret,但是不知道我还需要将哪些其他信息添加到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 做到了这一点,并且在将令牌交给我之后,我无效化了RESTFOR.

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,请查看此回购以了解使用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