1

I successfully implemented OAuth using the oauth-plugin gem with Rails 3.0.9. However, once I upgraded to Rails 3.1.3, I'm receiving an error when attempting to get the request token.

I've been testing locally

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

I've setup the Rails app as a provider

Consumer Key: BkdI1PnzRuvKDw2Qs1wVxtDrtvmqhUgeXLwNpNtm Consumer

Secret: eCY7JFk4vK6IeWXVq7yS3OMVT1XKpVOWOImsy3iw

Request Token URL: http://localhost:3000/oauth/request_token

In the console:

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
    That means invalid OAuth request,can you verify that everything is correct like the secret/api key and client token – Umesh Awasthi Dec 27 '11 at 01:11
  • Do check the the reasons for a 401 http://oauth.net/core/1.0a/#http_codes – Jesvin Jose Dec 27 '11 at 10:08
  • I've double-checked the key and secret and tried it on multiple accounts. I have this implemented on the Rails 3.0.9 version of the same app, and it works as expected. I read that if the server time is off that it could cause the 401 error. The error message doesn't give the reason for the 401 error though. – strukturedkaos Dec 27 '11 at 18:08
  • The only thing I can think of is that something changed between Rails 3.0.9 and 3.1 that is causing this error. – strukturedkaos Dec 27 '11 at 18:32
  • 1
    Bump, anyone have any idea what could be going on? – strukturedkaos Jan 29 '12 at 23:07

1 Answers1

2

I had this issue when my Virtual Machine's clock was behind. I just corrected the clock to match the current time and it worked fine after that.

Other causes are wrong application secret/key

mvilrokx
  • 1,588
  • 1
  • 16
  • 23