Ruby:获得salesforce oauth_token

时间:2013-04-25 12:29:03

标签: ruby-on-rails salesforce databasedotcom-gem

我有client_idclient_secret但要进行身份验证,我需要oauth_token。如何使用Ruby on Rails获取此令牌?我尝试了几个选项,但无法解决。

使用宝石:databasedotcom

我尝试了以下选项,但它没有响应 https://gist.github.com/undees/300175

require 'oauth'

consumer_key    = '...' # from SalesForce
consumer_secret = '...' # from SalesForce

oauth_options = {
:site               => 'https://login.salesforce.com',
:scheme             => :body,
:request_token_path => '/_nc_external/system/security/oauth/RequestTokenHandler',
:authorize_path     => '/setup/secur/RemoteAccessAuthorizationPage.apexp',
:access_token_path  => '/_nc_external/system/security/oauth/AccessTokenHandler',
}
consumer = OAuth::Consumer.new consumer_key, consumer_secret, oauth_options
# consumer.http.set_debug_output STDERR # if you're curious 
request       = consumer.get_request_token
authorize_url = request.authorize_url :oauth_consumer_key => consumer_key 
puts "Go to #{authorize_url} in your browser, then enter the verification code:"
verification_code = gets.strip 
access = request.get_access_token :oauth_verifier => verification_code

puts "Access Token:  " + access.token
puts "Access Secret: " + access.secret

1 个答案:

答案 0 :(得分:0)

解决方案:databasedotcom-oAuth2 gem为我工作。它需要客户端密钥和秘密,并与salesforce进行交互。细节在这里给出。 点击此处http://wiki.developerforce.com/page/Introduction_to_the_databasedotcom-oauth2_Gem