Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise/OmniAuth/Twitter - OAuth::Unauthorized (401)

I'm trying to set up a Twitter login using Devise/OmniAuth, following the latest RailsCast for this. I've registered the Twitter developer app, using the callback url of: myiphere:port/users/auth/twitter.

I've followed everything to the T on the RailsCast, but each time I click the Sign In With Twitter link, I immediately get OAuth::Unauthorized 401 Unauthorized on the myiphere:port/users/auth/twitter page.

I think I've defined the key correctly using export TWITTER_CONSUMER_KEY=MYKEYINSERTEDHERE export TWITTWR_CONSUMER_SECRET=MYSECRETINSERTEDHERE rails server. I've tried most every solution I can find on the internet, all to no avail. Almost all of the answers are for returning back to their site once logged in, I can't get to any kind of Twitter screen, just the 401 error on the /users/auth/twitter page.

like image 928
Midnightly Coder Avatar asked Aug 02 '12 22:08

Midnightly Coder


2 Answers

I had this same issue; in my case, I had the API keys set up correctly, but had not set a callback URL in the Twitter setup at https://dev.twitter.com/apps/, under the "Settings" tab.

Oddly, it doesn't appear that the callback URL needs to point anywhere useful; Twitter apparently just uses its existence as a signal of some sort.

The debugging information provided by omniauth-twitter leaves something to be desired.

like image 100
dpassage Avatar answered Sep 27 '22 19:09

dpassage


I got it to work by removing the brackets and ENV from the initializer DEVISE.RB:

config.omniauth :twitter, "APP_ID", "APP_SECRET"

my callback specified in DEV Twitter settings:

http://www.mysite.com/users/auth/twitter/callback

In routes.rb

devise_for :users, controllers: {omniauth_callbacks: "omniauth_callbacks"}

My LogIn link:

<%= link_to "Log in with Twitter", user_omniauth_authorize_path(:twitter) %>
like image 29
Joe Ritchey Avatar answered Sep 27 '22 21:09

Joe Ritchey