I get the error OAuth::Unauthorized
/ 401 Unauthorized
when my Twitter app does the callback.
I'm using:
gem 'omniauth' # (1.2.1) gem 'omniauth-twitter' # (1.0.1) gem 'rails', '4.1.0.rc1'
The callback URL submitted for the Twitter app (tried both solutions):
http://127.0.0.1:3000
http://127.0.0.1:3000
The called callback URL looks like:
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('/')
my machine's time is OK, as explained here: https://github.com/intridea/omniauth/wiki/FAQ
my initializers/omniauth.rb looks like this:
Rails.application.config.middleware.use OmniAuth::Builder do provider :twitter, 'e93Q89eW4o...DNMe9w3i8tqQ', 'owERioaRjj...jrKdotiiOeIUdd89irlA' end
What am I missing?
EDIT - Some trace: 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'
I finally found the issue:
This block was defined 2x inside my app:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, 'e93Q89eW4o...DNMe9w3i8tqQ', 'owERioaRjj...jrKdotiiOeIUdd89irlA'
end
Make sure you set this only 1x !
(If you have the habit of copying over config files from previous projects, you risk ending up with duplicates.)
I also faced same error. However, my solution is different since I only declared the block once in my app.
I follow FAQ from github: intridea/omniauth and solved my problem by making the system clock correct. Once i changed to the correct time, I can succesfully using twitter omniauth login.
Hope it contributes to answer this question
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.