Devise + Omniauth call action passthru on login Facebook

你离开我真会死。 提交于 2019-12-06 08:14:21

问题


When I try to login with Facebook using Omniauth and Devise, passthru is called instead of facebook. How do I pass in the link_to:

user_omniauth_authorize_path(:facebook)

I've revised the code many times and tried to use this route:

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

and

  devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } 

But the error is same. I have the action facebook in my users/omniauth_callbacks_controller.rb


回答1:


I just flailed with the exact same problem for hours, trying everything including doing the exact same process on a different branch with github oauth, which worked without a problem. What finally worked for me was changing the hash of arguments I was passing to config.omniauth in devise.rb after the app token and secret. It was name: 'google' that was doing it. Commented it out and it works:

config.omniauth :google_oauth2, 'ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"],
   {
    # name: 'google',
    scope: 'calendar, plus.login plus.me'
  }

Whether the id and secret are hard coded in has no effect. I didn't try it, but :name seems like it is used as an alias for the provider to use elsewhere in the code in place of :google_oauth2. Uncommenting it and changing it (redundantly) to name: google_oauth2 works. I'm sure you've either solved it or moved on after a year but I hope this helps someone in the future.

onmiauth-google-oauth2 0.2.5

devise 3.4.0

rails 4.1.6




回答2:


The passthru route is an old relic from the omniauth past.

Just set your routes like this:

devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }



回答3:


Did you add the configuration in devise.rb ?
you need to declare the provider in your (config/initializers/devise.rb) and require it

require "omniauth-facebook" 
config.omniauth :facebook, "APP_ID", "APP_SECRET"

You will need to restart the server also.




回答4:


In my case, we added the gem omniauth-rails_csrf_protection but we were still trying to access the authorize endpoints using GET methods. Replacing those GET calls by POST requests (with the CSRF token) solved it.



来源:https://stackoverflow.com/questions/17513829/devise-omniauth-call-action-passthru-on-login-facebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!