使用omniauth和devise重定向到当前页面 [英] redirect back to current page using omniauth and devise

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

问题描述

我想在oauth登录后重定向回到当前页面,我遵循此Devise wiki ,并执行以下操作:

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(资源)为零

request.referer http://openapi.qzone.qq.com/oauth/ [略过] (我的提供者)

所以在我的全方位登录后,我被重定向再次向提供者发送URL。

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

Wiki是否过时? omn​​iauth登录重定向到当前页面的推荐方法是什么?

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

推荐答案

我意识到我不应该覆盖 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_filter :store_current_location, :unless => :devise_controller?
  def store_current_location
    store_location_for(:user, request.url)
  end

而内置 after_sign_in_path_for 将处理其余的。

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

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