RequestToken Oauth-plugin 401未经授权

时间:2011-12-26 22:33:21

标签: ruby-on-rails ruby-on-rails-3 oauth ruby-on-rails-3.1 oauth-ruby

我使用带有Rails 3.0.9的oauth-plugin gem成功实现了OAuth。但是,一旦我升级到Rails 3.1.3,我在尝试获取请求令牌时收到错误。

我一直在本地测试

Rails 3.1.3 oauth(0.4.5) oauth-plugin(0.4.0.rc2)

我已将Rails应用程序设置为提供程序

  

消费者密钥:BkdI1PnzRuvKDw2Qs1wVxtDrtvmqhUgeXLwNpNtm消费者

     

秘密:eCY7JFk4vK6IeWXVq7yS3OMVT1XKpVOWOImsy3iw

     

请求令牌网址:http://localhost:3000/oauth/request_token

在控制台中:

ruby-1.9.2-p290 :003 > @consumer = OAuth::Consumer.new 
                                   "BkdI1PnzRuvKDw2Qs1wVxtDrtvmqhUgeXLwNpNtm",
                                   "eCY7JFk4vK6IeWXVq7yS3OMVT1XKpVOWOImsy3iw", 
                                   {:site => "http://localhost:3000"}
=> #<OAuth::Consumer:0x007fe93d5bcdf8 @key="BkdI1PnzRuvKDw2Qs1wVxtDrtvmqhUgeXLwNpNtm",
   @secret="eCY7JFk4vK6IeWXVq7yS3OMVT1XKpVOWOImsy3iw", 
   @options={:signature_method=>"HMAC-SHA1", 
             :request_token_path=>"/oauth/request_token",
             :authorize_path=>"/oauth/authorize",
             :access_token_path=>"/oauth/access_token", 
             :proxy=>nil, 
             :scheme=>:header, 
             :http_method=>:post, 
             :oauth_version=>"1.0", 
             :site=>"http://localhost:3000"}>

ruby-1.9.2-p290 :004 > @consumer.get_request_token
OAuth::Unauthorized: 401 Unauthorized 
from /Users/donpottinger/.rvm/gems/ruby-1.9.2-p290@rails3_1/gems/oauth-0.4.5/lib/oauth/consumer.rb:219:in `token_request'
from /Users/donpottinger/.rvm/gems/ruby-1.9.2-p290@rails3_1/gems/oauth-0.4.5/lib/oauth/consumer.rb:139:in `get_request_token'
from (irb):4
from /Users/donpottinger/.rvm/gems/ruby-1.9.2-p290@rails3_1/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
from /Users/donpottinger/.rvm/gems/ruby-1.9.2-p290@rails3_1/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
from /Users/donpottinger/.rvm/gems/ruby-1.9.2-p290@rails3_1/gems/railties-3.1.3/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

1 个答案:

答案 0 :(得分:2)

当我的虚拟机时钟落后时,我遇到了这个问题。我刚刚纠正了时钟以匹配当前时间,之后它运行良好。

其他原因是错误的应用程序密钥/密钥