Facebook Omniauth gem没有返回正确的信息

时间:2014-05-18 04:58:41

标签: ruby-on-rails facebook omniauth

因此Facebook omniauth在我的rails网站上运行得非常好。 不,它没有,并且在检查来自facebook的返回数据时,我看到了:

{
  "provider": "facebook",
  "uid": "id",
  "info": {
    "nickname": "username",
    "email": "email",
    "name": "name",
    "first_name": "first_name",
    "last_name": "last_name",
    "image": "http://graph.facebook.com/id/picture",
    "description": "bio",
    "urls": {
      "Facebook": "link",
      "Website": "website"
    },
    "verified": "verified"
  },
  "credentials": {
    "token": "CAAUfds9x8Xf3f6VABfAFf8CQXwdmGFdpNo1f3Dqh3tjxDHmFCh4BvcawcxREJEEam9U1po2mWD7ejnDmDI3ZCKT5G3oOlZAkyHV3j5vNvToCmPpW8DnSBlheAGZADxLvLwPzf8cwVCMHhes0ZBfZAkL6basAPghFG1adAZCDG6FLSUlF1pwMAZD",
    "expires_at": 1405568757,
    "expires": true
  },
  "extra": {
    "raw_info": "{a ton of info here that is correct}"
  }
}

部分在哪里说"电子邮件":"电子邮件",它字面上说,它不是我改变价值观。我收到的数据是通用的。最近Facebook改变了什么......?我该如何解决这个问题?

这是我的代码:

  if Rails.env.production?
    config.omniauth :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], {:scope => 'basic_info, email, offline_access', :client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}}} 
  else
    config.omniauth :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], {:scope => 'basic_info, email', :client_options => {:ssl => {:verify => false}}}
  end

#OmniauthCallbacksController

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def facebook
    debugger
    @user = User.find_for_facebook_oauth(request.env["omniauth.auth"])

    if @user.persisted?
      if @user.status == "inactive"
        redirect_to reactivate_user_page_path(@user) 
      else
        sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
        set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
      end
    else
      session["devise.facebook_data"] = request.env["omniauth.auth"].except("extra")
      redirect_to new_user_registration_url
    end
  end
end

编辑: 这只发生在开发中,而不是生产中。因此,Facebook应用设置可能存在问题。

1 个答案:

答案 0 :(得分:0)

以下是我的工作代码,在find_for_facebook_oauth方法中,我正在传递current_user

  def facebook        
    @user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)

    if @user.persisted?
      sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
      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