我一直得到“未找到。身份验证passthru”for Facebook连接登录与Devise - 需要调试建议

时间:2013-05-26 03:11:37

标签: ruby-on-rails facebook devise

我见过几个人问过类似的问题,但我真的需要有关如何调试此问题的建议。我正在尝试使用Devise使用以下文章设置facebook连接:https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview

每次我点击带有facebook链接的登录信息,我都会得到一个空白页面,上面写着:未找到。身份验证passthru。显然,在前一页上没有设置JavaScript / ajax来提取facebook登录界面。

我知道这可以在我的系统上运行,因为我使用上面链接中完全相同的代码创建了一个空白项目并且它可以工作。当然,我的项目有很多代码,所以我试图弄清楚我的项目中是什么原因导致这个问题无法解决。

对于如何调试的任何帮助表示赞赏。

谢谢!

2 个答案:

答案 0 :(得分:0)

这是来自设计源的#passthru代码。

def passthru
    render :status => 404, :text => "Not found. Authentication passthru."
end

这意味着设计无法识别您的Facebook回调。确保正确设置回调控制器或发布用户控制器代码。

答案 1 :(得分:0)

我遇到了同样的错误。我错过了Facebook回调控制器(app / controllers / users / omniauth_callbacks_controller.rb):

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController

  # ...

  def facebook
    respond_to do |format|
      format.html {
        @user = User.find_for_facebook(request.env["omniauth.auth"])

        if @user.persisted?
          sign_in_and_redirect @user
          set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
        else
          session["devise.facebook_data"] = request.env["omniauth.auth"]
          redirect_to new_user_registration_url
        end
      }
    end
  end
end

此代码引用方法&#34; find_for_facebook&#34;在我的用户模型(app / models / user.rb)中:

class User < ActiveRecord::Base

  # ...

  def self.find_for_facebook(auth_hash)
    user = User.where(:email => auth_hash.info["email"]).first

    unless user
      user = User.create(
        username: auth_hash.info["nickname"],
        email: auth_hash.info["email"],
        password: Devise.friendly_token[0,20])
    end

    user.provider = auth_hash["provider"]
    user.uid = auth_hash["uid"]
    user
  end
end

确保重新启动开发服务器,以便获取所有更改。