我已经开始将facebook身份验证集成到我的Rails 3.1站点中,但当我单击fb身份验证对话框上的取消按钮时遇到了一个问题。当我单击cancel时,我会被重定向回我的站点/auth/facebook/callback,然后被重定向到/login页面(我正在使用Devise)。
我想做的是将取消的身份验证重定向到一个页面,该页面允许用户以标准方式(电子邮件、用户名、密码等)创建帐户。如何覆盖到/login页面的重定向?
顺便说一句,我使用的是omniauth-facebook gem。
谢谢!
发布于 2014-03-12 12:09:09
在omniauth回调控制器中添加失败方法,并定义您的自定义行为。
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
def failure
redirect_to root_path // here
end
end发布于 2012-07-12 05:09:43
我想你可以在你的omniauth配置中覆盖默认的on_failure行为,我不是在使用devise,而是在使用omniauth-facebook gem,并且已经成功地使用了以下变体:
OmniAuth.config.on_failure = Proc.new { |env|
OmniAuth::FailureEndpoint.new(env).redirect_to_failure
} 或者更定制的东西,比如:
OmniAuth.config.on_failure do |env|
new_path = "#{env['SCRIPT_NAME']}#{OmniAuth.config.path_prefix}/failure?message=#{error_type}"
[302, {'Location' => new_path, 'Content-Type'=> 'text/html'}, []]
endhttps://stackoverflow.com/questions/10526408
复制相似问题