使用像facebook这样的omniauth提供程序时,Devise不会正确地重定向到存储位置

我在我的应用程序中有一些受保护的操作,需要用户身份validation。 因为我正在使用devise,所以我使用authenticate_user! 在过滤之前保护它们。 每当用户点击受保护的页面时,设计要求用户登录,然后重定向回受保护的页面。 这部分很完美。

问题是,当用户尝试通过我的应用程序登录Facebook时,设计在登录后不会将用户重定向到受保护的页面。 它总是将用户返回到根URL。 使用标准身份validation,这不是问题

我怀疑它与passthru方法有关 – 设计 – omniauth集成需要。 任何帮助将不胜感激

这是我的omniauth回调的代码片段:

def facebook # You need to implement the method below in your model omniauth = request.env["omniauth.auth"] @user = User.find_for_facebook_oauth(omniauth, 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 def passthru render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false end 

我们使用Facebook JS获取访问代码,然后返回omniauth_callback_controller.rb并签署用户。

我发现原始URL保存在请求中。 为我们工作了一种享受。

application_controller.rb中

 def after_sign_in_path_for(resource_or_scope) if request.env['omniauth.origin'] request.env['omniauth.origin'] end end