devise icon indicating copy to clipboard operation
devise copied to clipboard

Integrating Omniauth/Facebook: Auth route not set

Open MSeifert opened this issue 15 years ago • 19 comments

Hi,

I've followed the tutorial on how to integrate Openauth, but the authentication route simply doesn't exist - Omniauth doesn't intercept it, it just returns a 404 / No route matches error.

  • I've used Devise from Github, master branch, like this (in my Gemfile):

gem 'devise', :git => "git://github.com/plataformatec/devise.git"

  • Also, I've used Omniauth 0.2.0 beta5:

gem 'oa-oauth', '0.2.0.beta5', :require => "omniauth/oauth"

  • In my config/initializers/devise.rb, Omniauth is initialized:

config.omniauth :facebook, "APP ID", "APP SECRET"

  • In my user model, I've added

devise [...], :omniauthable

  • In my routes.rb I've added the callback routing, and I've implemented the callback controller, but that shouldn't even matter, because the problem is not with devise, it's with Omniauth. It simply doesn't generate the auth route!
  • When I run "rake middleware" it does show:

use OmniAuth::Strategies::Facebook

  • Yes, I've restarted the server, multiple times.
  • I'm trying to get this to run on my Webrick development server, but I've also tried on the production Apache and it doesn't work either.

The routes I've tried are:

http://localhost:3000/auth/facebook

http://localhost:3000/users/auth/facebook

They both return 404 errors.

Unfortunately I've never worked with Rack applications and they're kind of a mystery to me, so I'm not sure what Omniauth is or isn't supposed to do and how to debug it.

Anybody who might know what the issue is? It seems your tutorial isn't clear enough, since I've read it 100 times and followed the steps but it doesn't work. Actually, I've been working on this one issue for 10 hours now, taking apart every single file in the Devise and Omniauth gems, but I simply can't find the issue... Any help or suggestions would be MUCH appreciated!

MSeifert avatar Mar 14 '11 15:03 MSeifert

I can't see the issue also. Can you post also the result of rake routes?

josevalim avatar Mar 14 '11 15:03 josevalim

rake routes shows the callback route, of course:

user_omniauth_callback (/:locale)/auth/:action/callback(.:format) {:action=>/facebook/, :controller=>"omniauth_callbacks"}

...but the auth route doesn't show up at all.

MSeifert avatar Mar 14 '11 15:03 MSeifert

Sorry I accidentally closed the issue. Pls reopen.

MSeifert avatar Mar 14 '11 15:03 MSeifert

Something is wrong with your route... It doesn't have the /users at the beginning... probably a conflict with the locale... i will investigate.

josevalim avatar Mar 14 '11 16:03 josevalim

One last thing, how are you calling devise_for in your routes? Which parameters? It is inside a scope?

josevalim avatar Mar 14 '11 16:03 josevalim

Yes, like this:

scope "(:locale)" do
  devise_for :users, 
    :controllers => { 
      :sessions           => 'internal/sessions', 
      :registrations      => 'internal/registrations', 
      :confirmations      => 'devise/confirmations', 
      :passwords          => 'internal/passwords',
      :omniauth_callbacks => 'omniauth_callbacks'
    },
    :path => '',
    :path_names => {:sign_in => 'sign_in', :sign_out => 'sign_out', :sign_up => 'sign_up'}
end

MSeifert avatar Mar 14 '11 16:03 MSeifert

I have fixed on Devise master. Could you please try it? Tks!

josevalim avatar Mar 14 '11 17:03 josevalim

Umm..thank you, but actually the callback route wasn't my problem. It was the "/facebook/auth" which didn't work, and which doesn't even come from devise, but from Omniauth as I understand.

It still doesn't work.

MSeifert avatar Mar 14 '11 17:03 MSeifert

rake routes result from master please?

josevalim avatar Mar 14 '11 17:03 josevalim

user_omniauth_callback        /auth/:action/callback(.:format)                          {:action=>/facebook/, :controller=>"omniauth_callbacks"}

The auth route doesn't show up.

MSeifert avatar Mar 14 '11 17:03 MSeifert

Hrm, this is weird. Final test, please try on rails console: "puts Omniauth.config.path_prefix"

josevalim avatar Mar 14 '11 17:03 josevalim

NameError: uninitialized constant Omniauth

MSeifert avatar Mar 14 '11 17:03 MSeifert

Ugh, my bad! Please try: "::OmniAuth.config.path_prefix"

josevalim avatar Mar 14 '11 17:03 josevalim

The result is: //auth

MSeifert avatar Mar 14 '11 18:03 MSeifert

A-ha. That is the issue. One sec.

josevalim avatar Mar 14 '11 18:03 josevalim

Please try again on master. :D

josevalim avatar Mar 14 '11 18:03 josevalim

It works, finally! Thanks a lot man, you saved my day.

MSeifert avatar Mar 14 '11 18:03 MSeifert

Today you, tomorrow me: http://www.reddit.com/r/AskReddit/comments/elal2/have_you_ever_picked_up_a_hitchhiker/c18z0z2

:D

josevalim avatar Mar 14 '11 18:03 josevalim

Thanks, saved my day!

pavanagrawal avatar Jun 11 '12 08:06 pavanagrawal