Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OAuth::Unauthorized 401 int twitter-omniauth gem

I have been trying to authenticate users using twitter-omniauth gem for last days, yet not successful. (Authentication with facebook works perfectly)

I'm keep getting 401 Unauthorized error.

I search through stackoverflow, but none of the answers could solve my problem.

I reach the twitter login when I try http://127.0.0.1/users/auth/twitter. I login and I'm redirected to http://127.0.0.1/users/auth/twitter/callback and unauthorized error comes.

Below callback url I have entered in twitter

http://127.0.0.1/users/auth/twitter/callback

rake routes output

new_user_session GET    /users/sign_in(.:format)               {:action=>"new", :controller=>"devise/sessions"}
                user_session POST   /users/sign_in(.:format)               {:action=>"create", :controller=>"devise/sessions"}
        destroy_user_session DELETE /users/sign_out(.:format)              {:action=>"destroy", :controller=>"devise/sessions"}
      user_omniauth_callback        /users/auth/:action/callback(.:format) {:action=>/twitter|facebook/, :controller=>"users/omniauth_callbacks"}
               user_password POST   /users/password(.:format)              {:action=>"create", :controller=>"devise/passwords"}
           new_user_password GET    /users/password/new(.:format)          {:action=>"new", :controller=>"devise/passwords"}
          edit_user_password GET    /users/password/edit(.:format)         {:action=>"edit", :controller=>"devise/passwords"}
                             PUT    /users/password(.:format)              {:action=>"update", :controller=>"devise/passwords"}
    cancel_user_registration GET    /users/cancel(.:format)                {:action=>"cancel", :controller=>"devise/registrations"}
           user_registration POST   /users(.:format)                       {:action=>"create", :controller=>"devise/registrations"}
       new_user_registration GET    /users/sign_up(.:format)               {:action=>"new", :controller=>"devise/registrations"}
      edit_user_registration GET    /users/edit(.:format)                  {:action=>"edit", :controller=>"devise/registrations"}
                             PUT    /users(.:format)                       {:action=>"update", :controller=>"devise/registrations"}
                             DELETE /users(.:format)                       {:action=>"destroy", :controller=>"devise/registrations"}
                       login        /login(.:format)                       {:action=>"login", :controller=>"home"}
                        root        /                                      {:controller=>"home", :action=>"index"}

If you need anymore info, I'll provide. Please help me to solve this.

like image 519
robert Avatar asked Dec 06 '11 16:12

robert


2 Answers

I had this issue today and found that I had to set a callback URL in the settings at dev.twitter.com under my application. So check that you have set a callback URL settings, I set it to my intended production address and when running in dev mode locally it redirected fine.

It mentions under the callback url input box that if left blank it will restrict the app from using callback urls.

like image 110
Kalvir Sandhu Avatar answered Sep 23 '22 22:09

Kalvir Sandhu


I'm pretty sure I ran into issues with this when it was coming from localhost...

This article says they allow it, but if memory serves me correctly, I had to use an externally accessible URL. When I was testing my oauth stuff, I used DynDns and opened a port in my router.

like image 22
ejlevin1 Avatar answered Sep 24 '22 22:09

ejlevin1