我正在尝试使用oauth ruby gem对ruby irb的2腿OAuth(1.0)系统进行身份验证,
第1步:
require 'oauth'
irb(main):038:0> consumer = OAuth::Consumer.new("key", "secret", :site => "site", :scheme => :query_string)
I got a response for this as,
=> #<OAuth::Consumer:0xba14be2c @key="{got valid key here}", @secret="{got valid secret here}", @options={:signature_method=>"HMAC-SHA1", :request_token_path=>"/oauth/request_token", :authorize_path=>"/oauth/authorize", :access_token_path=>"/oauth/access_token", :proxy=>nil, :scheme=>:query_string, :http_method=>:post, :oauth_version=>"1.0", :site=> "https://example.com/">
第2步:
irb(main):039:0> access_token = OAuth::AccessToken.new consumer
=> #<OAuth::AccessToken:0xba144b7c @token="", @secret="", @consumer=#<OAuth::Consumer:0xba147430 @key="{got valid key here}", @secret="{got valid secret here}", @options={:signature_method=>"HMAC-SHA1", :request_token_path=>"/oauth/request_token", :authorize_path=>"/oauth/authorize", :access_token_path=>"/oauth/access_token", :proxy=>nil, :scheme=>:query_string, :http_method=>:post, :oauth_version=>"1.0", :site=>"https://example.com/"}>, @params={}>
请看上面的令牌是空的。我应该在这里获得令牌?
第3步:然后我尝试了从上面获得的所有路径,
irb(main):041:0> access_token.get("/oauth/authorize")
irb(main):041:0> access_token.get("/oauth/request_token")
irb(main):041:0> access_token.get("/oauth/access_token")
但是对于所有请求我都得到了回复,
=> #<Net::HTTPNotFound 404 Not Found readbody=true>
我不知道我犯了错误,我正确地做了请求,如果不是我应该如何验证ruby中的2legged oauth系统。或者我应该要求服务提供商自行检查。
令牌字段在步骤2中为空,这就是问题??。
任何人都可以指导我吗?提前谢谢。
答案 0 :(得分:0)
也许这段代码会有所帮助:
require 'oauth'
consumer_key = <your consumer key>
consumer_secret = <your consumer secret>
end_point = "https://www.example.com"
consumer = OAuth::Consumer.new(consumer_key, consumer_secret, {
:site => end_point,
:scheme => :header
})
parameters = "user_id=1"
resp = consumer.request(:post, '/get_user/', nil, {}, parameters, { 'Content-Type' => 'application/x-www-form-urlencoded' })