[英]Omniauth, Twitter: OAuth::Unauthorized / 401 Unauthorized upon callback from Twitter
我的Twitter应用程序执行回调时,出现错误OAuth::Unauthorized
/ 401 Unauthorized
。
我正在使用:
gem 'omniauth' # (1.2.1) gem 'omniauth-twitter' # (1.0.1) gem 'rails', '4.1.0.rc1'
为Twitter应用程序提交的回调URL(尝试了两种解决方案):
http://127.0.0.1:3000
: http://127.0.0.1:3000
: http://127.0.0.1:3000
http://127.0.0.1:3000
: http://127.0.0.1:3000
: http://127.0.0.1:3000
调用的回调URL如下所示:
http://127.0.0.1:3000/auth/twitter/callback?oauth_token=FcU...hYFk&oauth_verifier=Dge...oJ27E
route.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'
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倍:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, 'e93Q89eW4o...DNMe9w3i8tqQ', 'owERioaRjj...jrKdotiiOeIUdd89irlA'
end
确保仅将此值设置为1x!
(如果您习惯于从以前的项目中复制配置文件,则可能会有重复的结果。)
我也遇到了同样的错误。 但是,我的解决方案有所不同,因为我仅在应用程序中声明了一次该块。
我遵循来自github的FAQ:intridea / omniauth并通过使系统时钟正确来解决了我的问题。 一旦更改为正确的时间,我就可以成功使用twitter omniauth登录。
希望它有助于回答这个问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.