使用 omniauth 重定向回当前页面并设计 [英] redirect back to current page using omniauth and devise

查看:31
本文介绍了使用 omniauth 重定向回当前页面并设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 oauth 登录后重定向回当前页面,我按照 此设计维基 并执行以下操作:

I want to redirect back to current page after oauth signin, and I followed this Devise wiki and did the following:

  def after_sign_in_path_for(resource)
    sign_in_url = new_user_session_url
    if request.referer == sign_in_url
      super
    else
      request.env['omniauth.origin'] || stored_location_for(resource) || request.referer || root_path
    end
  end

request.env['omniauth.origin']http://www.bubutravel.com/users/sign_in

stored_location_for(resource) 为零

request.refererhttp://openapi.qzone.qq.com/oauth/[省略](我的提供商)

因此,在我的 omniauth 登录后,我再次被重定向到提供程序的 URL.

So after my omniauth login, I get redirected to the provider urls again.

维基过时了吗?将 omniauth 登录重定向到当前页面的推荐方法是什么?

Is the wiki outdated? What's the recommended way to do omniauth login redirect to current page?

推荐答案

我意识到我不应该按照 wiki 的建议覆盖 after_sign_in_path_for.我应该在每个请求中记录路径:

I realized that I should not override after_sign_in_path_for as suggested by the wiki. I should just record the path in every request:

  before_action :store_current_location, :unless => :devise_controller?
  def store_current_location
    store_location_for(:user, request.url)
  end

而内置的 after_sign_in_path_for 将处理剩下的事情.

And the build-in after_sign_in_path_for will handle the rest.

这篇关于使用 omniauth 重定向回当前页面并设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆