0

我使用omniauth-facebook 1.4.1 来使用facebook 登录。有错误

Could not authorize you from Facebook because "Csrf detected".

似乎人们通过将omniauth-facebook 降级到1.4.0 来解决这个问题。我试过了,但现在有错误

The action 'facebook' could not be found for Devise::OmniauthCallbacksController.

我有路线

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

并且 omniauth_callbacks 位于控制器目录中:

class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
  # You need to implement the method below in your model
  @user = User.find_for_facebook_oauth(env["omniauth.auth"], current_user)  

  if @user.persisted?
    flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook"
    sign_in_and_redirect @user, :event => :authentication
  else
    session["devise.facebook_data"] = env["omniauth.auth"]
    redirect_to new_user_registration_url
  end
end
end

有什么建议么?

4

1 回答 1

0

哦,我发现了问题。在 route.rb 我有一行代码

devise_for :users, :controllers => { :registrations => :registrations }

在...前面

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

它覆盖了方法,所以它导致

The action 'facebook' could not be found for Devise::OmniauthCallbacksController.

我评论了第一行然后它起作用了。

于 2012-11-30T20:42:21.710 回答