问题描述
我的应用程序中有一些页面需要通过链接输入进行身份验证.如果用户尚未进行身份验证,我会在过滤器之前使用它来将用户重定向到/auth/linked_in
.我希望在身份验证后将用户重定向到需要身份验证的页面,而不是用户来自的页面.
There are some pages in my app which require authentication with linked in. I use before filter to redirect user to /auth/linked_in
if s/he is not already authenticated. I want that after authentication user should be redirected to page which required authentication instead of page from which user came from.
在过滤器看起来像之前:
Before filter looks like:
def require_linked_in!
unless current_user and current_user.linked_in_authenticated?
redirect_to "/auth/#{Authentication::LINKED_IN}"
end
end
在我的omniauth回调中,我做了一些事情,例如登录或将提供者数据与用户帐户相关联,如果一切正常,请单击redirect_to request.env['omniauth.origin'] || root_url
,但这会将用户重定向到他单击该页面的链接,然后单击该链接到需要链接的页面身份验证而不是目标页面.
In my omniauth callback I do some stuff, like logging in or associating provider data with user account and if everything was ok, redirect_to request.env['omniauth.origin'] || root_url
, but this redirects back the user to page from which he clicked the link to page requiring linked_in authentication and not the target page.
如何将用户重定向到触发身份验证的页面,而不是用户来自哪个页面?
How can I redirect the user to page which triggered authentication instead of page which user came from?
PS:用户只能使用该应用程序的注册表格进行注册,但以后可以在该处连接链接的和Facebook个人资料,也可以使用它们代替普通的电子邮件/密码登录表格.如果有什么区别.
PS: User can only sign up using the registration form for the app, but can later on connect there linked and facebook profile and also use them instead of normal email/password login form. If it makes any difference.
推荐答案
我想您需要将URL存储在会话中,并在omniauth回调后进行重定向.
I guess you need to store the url in your session and redirect after the omniauth callback.
def require_linked_in!
session[:return_to] = request.url
unless current_user and current_user.linked_in_authenticated?
redirect_to "/auth/#{Authentication::LINKED_IN}"
end
end
在回调操作中,您可以使用:
In your callback-action you can use:
redirect_to session[:return_to] || root_url
希望有帮助!
这篇关于OmniAuth:重定向到需要身份验证的页面,而不是用户来自的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!