简体   繁体   English

将Restforce gem与SalesForce API和Oauth 2.0一起使用

[英]Using Restforce gem with SalesForce API and Oauth 2.0

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( https://github.com/ejholmes/restforce )使用Oauth 2.0设置与我的Rails应用程序与SalesForce API的集成。

Restforce describes the initialization process as follows: 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. 如果您正在构建一个应用程序,其中来自不同组织的许多用户通过oauth进行身份验证,并且您需要代表他们与组织中的数据进行交互,则应使用OAuth令牌身份验证方法。

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. 如果您正在使用gem与单个组织进行交互(也许您正在内部构建一些salesforce集成?)那么您应该使用用户名/密码身份验证方法。

OAuth token authentication OAuth令牌身份验证

 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: 虽然上述方法可行,但您可能希望通过指定刷新令牌,客户端ID和客户端密钥来利用(重新)身份验证中间件:

 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. 我有来自在SF中创建的应用程序的client_idclient_secret ,但不知道我需要将哪些其他信息放入restforce。

Does anyone have any experience with this gem? 有没有人有这个宝石的经验? How do I use it to make the original request token request to SF? 如何使用它向SF发出原始请求令牌请求?

You need to login using Oauth 2.0 first, then provide the tokens to the gem. 您需要先使用Oauth 2.0登录,然后将令牌提供给gem。 I did that using Omniauth-Salesforce and after the tokens are handed I instatiate restforce. 我使用Omniauth-Salesforce做到了这一点,并且在令牌交付后我实施了restforce。

The examples in omniauth are using sinatra, please look into this repo for an implementation using rails . omn​​iauth中的示例使用sinatra,请查看此repo以了解使用rails的实现

I've blogged about this as well . 我也在博客上写过这篇文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM