2

Stage:

I have a Rails app, it should authenticate users using their twitter account, so I use Omniauth-Twitter gem.

I have configured one app in dev.twitter.com enabling Sign in with twitter flag and getting consumer_key and consumer_secret.

I was following this guide https://github.com/arunagw/omniauth-twitter#readme

In Rails app, I have configured some files:

  • config/initializers/omniauth.rb:

    Rails.application.config.middleware.use OmniAuth::Builder do
      # Twitter consumer data
      CONSUMER_KEY='xxxxxxxxxxxxxxxxx'
      CONSUMER_SECRET='yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'
      provider :twitter, CONSUMER_KEY, CONSUMER_SECRET
    end
    
  • sessions_controller.rb looks like:

    class SessionsController < ApplicationController
      def create
        raise request.env["omniauth.auth"].to_yaml
      end
    end
    
  • applications.html.erb layout:

    <div id="user_nav">
      <%= link_to "Sign in with Twitter", "/auth/twitter" %>
    </div>
    

    So I except that when I clic on Sign in with Twitter link, I raises an exception showing me authentication data or requesting me Twitter autorization.

Problem:

Instead of this, it returns back this:

OAuth::Unauthorized (401 Unauthorized):
oauth (0.4.7) lib/oauth/consumer.rb:216:in `token_request'
oauth (0.4.7) lib/oauth/consumer.rb:136:in `get_request_token'
omniauth-oauth (1.0.1) lib/omniauth/strategies/oauth.rb:29:in `request_phase'
omniauth-twitter (0.0.15) lib/omniauth/strategies/twitter.rb:63:in `request_phase'
omniauth (1.1.3) lib/omniauth/strategy.rb:207:in `request_call'
omniauth (1.1.3) lib/omniauth/strategy.rb:174:in `call!'
omniauth (1.1.3) lib/omniauth/strategy.rb:157:in `call'
omniauth (1.1.3) lib/omniauth/builder.rb:48:in `call'

What is wrong here?

Israel
  • 3,252
  • 4
  • 36
  • 54
  • did you setup your callback URl right?. You gotta fix it if working from production and development envs. – shayonj Mar 30 '13 at 18:33
  • @shayonj, Which URL should be right if I want to develop in localhost? – Israel Mar 30 '13 at 18:40
  • 1
    which ever shows up in your browser , along with :3000 :) – shayonj Mar 30 '13 at 18:43
  • @shayonj, I have tried to put: `http://localhost:3000/`, `http://localhost:3000`, `localhost:3000/` , `localhost:3000`. But Twitter says that it is not a valid URL format. – Israel Mar 30 '13 at 18:46
  • 3
    @shayonj Hey! I have tried with `http://120.0.0.1:3000/auth/twitter/callback/` and it works. Thank you – Israel Mar 30 '13 at 18:51
  • try `http://127.0.0.1:3000` or `http://127.0.0.0:3000` . which ever points right to your localhost – shayonj Mar 30 '13 at 18:51

0 Answers0