Emil
Emil

Reputation: 21

Devise & omniauth Facebook authentication in Rails 3.1

I've followed this guide for getting Devise Facebook authentication to work and I've now come to a point where I can't understand and I would like some help.

I get the Sign in with Facebook link but clicking on it I get the following error, telling me there's something wrong with the routes

Unknown action

Could not find devise mapping for path "/users/auth/facebook". Maybe you forgot to wrap your route inside the scope block? For example: devise_scope :user do match "/some/route" => "some_devise_controller" end

Here is my routes file

  devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
  get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
  root :to => 'home#index'

Edit:

Solved that issue by changing the routes to

devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } do
  get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
end
root :to => 'home#index'

Now I got the next error getting the Facebook auth to work but when coming back from the "Allow app screen" ruby throws...

undefined method `closed?' for nil:NilClass

activesupport (3.1.0.rc8) lib/active_support/whiny_nil.rb:48:in method_missing' /opt/local/lib/ruby/1.8/net/http.rb:1060:inrequest' faraday (0.6.1) lib/faraday/adapter/net_http.rb:51:in call' faraday (0.6.1) lib/faraday/request/url_encoded.rb:14:incall' faraday (0.6.1) lib/faraday/request.rb:88:in run' faraday (0.6.1) lib/faraday/request.rb:28:inrun' faraday (0.6.1) lib/faraday/connection.rb:170:in run_request' oauth2 (0.4.1) lib/oauth2/client.rb:63:inrequest'

...

This is using Rails 3.1.0rc8 and ruby 1.9.2

Upvotes: 2

Views: 5263

Answers (1)

Andrei S
Andrei S

Reputation: 6516

I just finished yesterday my omniauth login for my app, using exactly the same guide and rails 3.1 final

Not sure you did your routes ok, mine look like this:

devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } do
  get 'sign_in', :to => 'users/sessions#new', :as => :new_user_session
  get 'sign_out', :to => 'users/sessions#destroy', :as => :destroy_user_session
end

devise_scope :user do
  get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
end

In my devise_for :users block I put the sign in and sign out because I'm using OmniAuth without other authentications

The guide also sais that the get '/users/auth/:provider' line should be in a devise_scope :user

Not sure this will fix your problem, but at least I wanted to state out these points, which don't fit in a comment

Upvotes: 2

Related Questions