Omniauth,Twitter:OAuth :: Unauthorized / 401在Twitter回拨时未经授权

时间:2014-03-04 18:32:00

标签: ruby-on-rails twitter oauth omniauth

当我的Twitter应用程序执行回调时,我收到错误OAuth::Unauthorized / 401 Unauthorized

  • 我正在使用:

    gem 'omniauth'         # (1.2.1)
    gem 'omniauth-twitter' # (1.0.1)
    gem 'rails', '4.1.0.rc1'
    
  • 为Twitter应用程序提交的回调网址(尝试了两种解决方案):

    • 指向http://127.0.0.1:3000
    • 的bit.ly网址
    • 或:直接网址:http://127.0.0.1:3000
  • 被叫回调网址如下所示:

    http://127.0.0.1:3000/auth/twitter/callback?oauth_token=FcU...hYFk&oauth_verifier=Dge...oJ27E
    
  • routes.rb中:

    get '/auth/:provider/callback', to: 'mycontroller#create'
    get '/auth/failure', to: redirect('/')
    
  • 我的机器时间没问题,如下所示:https://github.com/intridea/omniauth/wiki/FAQ

  • 我的初始化程序/ omniauth.rb看起来像这样:

    Rails.application.config.middleware.use OmniAuth::Builder do
      provider :twitter, 'e93Q89eW4o...DNMe9w3i8tqQ', 'owERioaRjj...jrKdotiiOeIUdd89irlA'
    end
    

我错过了什么?

编辑 - 一些痕迹: OAuth::Unauthorized (401 Unauthorized): oauth (0.4.7) lib/oauth/consumer.rb:216:in `token_request' oauth (0.4.7) lib/oauth/tokens/request_token.rb:18:in `get_access_token' omniauth-oauth (1.0.1) lib/omniauth/strategies/oauth.rb:57:in `callback_phase' omniauth (1.2.1) lib/omniauth/strategy.rb:227:in `callback_call' omniauth (1.2.1) lib/omniauth/strategy.rb:184:in `call!' omniauth (1.2.1) lib/omniauth/strategy.rb:164:in `call' omniauth (1.2.1) lib/omniauth/builder.rb:59:in `call' warden (1.2.3) lib/warden/manager.rb:35:in `block in call' warden (1.2.3) lib/warden/manager.rb:34:in `catch' warden (1.2.3) lib/warden/manager.rb:34:in `call' rack (1.5.2) lib/rack/etag.rb:23:in `call' rack (1.5.2) lib/rack/conditionalget.rb:25:in `call' rack (1.5.2) lib/rack/head.rb:11:in `call' actionpack (4.1.0.rc1) lib/action_dispatch/middleware/params_parser.rb:27:in `call'

2 个答案:

答案 0 :(得分:0)

我终于找到了问题:

此块在我的应用程序中定义为2x:

Rails.application.config.middleware.use OmniAuth::Builder do

  provider :twitter, 'e93Q89eW4o...DNMe9w3i8tqQ', 'owERioaRjj...jrKdotiiOeIUdd89irlA'

end

确保只将其设置为1x!

(如果您习惯于复制先前项目中的配置文件,则可能会出现重复的风险。)

答案 1 :(得分:0)

我也遇到了同样的错误。但是,我的解决方案不同,因为我只在我的应用程序中声明了一次块。

我从github跟踪FAQ:intridea / omniauth并通过使系统时钟正确解决了我的问题。一旦我改变到正确的时间,我就可以成功使用twitter omniauth登录。

希望它有助于回答这个问题