我正在尝试使用omniauth-facebook gem 对我的Rails 4.0.1 应用程序实施Facebook 身份验证。这是我用来帮助我完成此任务的指南,https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
我已按照所有说明进行操作,但我收到了 facebook 错误。我认为错误来自处理 facebook omniauth 回调的方法之一。
Facebook 显示的错误是“应用程序未设置:此应用程序的开发人员尚未正确设置此应用程序以进行 Facebook 登录”
omniauth_callbacks_controller.rb
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
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
end
用户.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable,
:omniauthable, :omniauth_providers => [:facebook]
def self.new_with_session(params, session)
super.tap do |user|
if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"]
user.email = data["email"] if user.email.blank?
end
end
end
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.email = auth.info.email
user.password = Devise.friendly_token[0,20]
user.profile_name = auth.info.name # assuming the user model has a name
end
end
def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
user = User.where(:provider => auth.provider, :uid => auth.uid).first
if user
return user
else
registered_user = User.where(:email => auth.info.email).first
if registered_user
return registered_user
else
user = User.create(profile_name:auth.extra.raw_info.name,
provider:auth.provider,
uid:auth.uid,
email:auth.info.email,
password:Devise.friendly_token[0,20],
)
end
end
end
end
当我第一次完成 OmniAuth 概述页面中的指南时,它起作用了。我用我的个人 Facebook 注册了我的应用程序。我的帐户成功登出。当我开始注册其他 Facebook 帐户时,它坏了,我收到“App Not Setup”错误。
在此先感谢,非常感谢任何帮助。