Omniauth-Twitter 401 Unauthorized

I provide a "log in with twitter" link to /auth/twitter , which handles gem omniauth .

On my development machine, this works fine, redirecting to the twitter login page and returning to the set of callbacks for the application on dev.twitter.com (http://127.0.0.1haps000/auth/twitter/ callback).

I have a separate application registered for our test production server, with the only difference being the access token, secret and callback. Access to the /auth/twitter path on the production server results in

 OAuth::Unauthorized (401 Unauthorized): oauth (0.4.6) lib/oauth/consumer.rb:216:in `token_request' oauth (0.4.6) lib/oauth/consumer.rb:136:in `get_request_token' ... 

I made sure that the server really uses my development key / secret by printing the ones that were used for the log, as they are installed in /config/initializers/omniauth.rb . They correspond to those indicated on the Twitter page, and the registered callback is a valid address and points to the production server.

What could be wrong here? Could this be the result of speed limits?

The following is a gemfile:

 source 'https://rubygems.org' gem 'rails', '3.2.3' gem 'mysql2','0.3.11' gem 'tweetstream' gem 'koala' group :assets do gem 'sass-rails', '~> 3.2.3' gem 'coffee-rails', '~> 3.2.1' gem 'twitter-bootstrap-rails' gem 'uglifier', '>= 1.0.3' end gem 'jquery-rails' gem 'twitter' gem 'omniauth-twitter' gem 'omniauth-facebook' gem 'thin' 

/config/initializers/omniauth.rb:

 puts "initializing twitter with #{TWITTER_KEY}, #{TWITTER_SECRET}" Rails.application.config.middleware.use OmniAuth::Builder do provider :twitter, TWITTER_KEY, TWITTER_SECRET provider :facebook, FACEBOOK_KEY, FACEBOOK_SECRET, :scope => 'read_stream,publish_stream' end 

The server registers the correct key and secret in the first line here.

+4
source share
4 answers

In my case, the problem was that the server time was about 50 minutes and requests were rejected because the timestamp was too old.

System time update fixed.

+2
source

do not forget to check the Twitter settings:

"Allow this app to log in to Twitter"

Hope this helps someone

+1
source

My solution was that you need to provide the callback URL specified in the Twitter.com application management section. https://apps.twitter.com/ This will also allow the use of localhost URLs.

0
source

My problem was that I checked Url Callback Lock. I just did not check it at work.

0
source

All Articles