您可以像发送带有身份验证令牌的电子邮件链接一样执行此操作。检查以验证 cookie 是否正确example.org
,如果正确,请将它们重定向到:
http://example.com?token=<their token>
然后检查以确保令牌到达时与您在数据库中的令牌匹配。如果令牌匹配,则为example.com
域创建会话 cookie,然后更改数据库中的令牌。
这将成功地从一个域转移到另一个域,同时在新域上提供持久登录(通过 cookie)并通过更改数据库中的身份验证令牌来关闭它们背后的门。
编辑
要在下面回答您的问题,我认为您不需要中间件或任何花哨的东西。您可以在 example.org 的应用程序控制器中执行一个简单的前置过滤器,例如:
before_filter :redirect_to_dot_com
...
def redirect_to_dot_com
url = "http://example.com" + request.fullpath
url= destination + (url.include?('?') ? '&' : '?') + "token=#{current_user.token}" if signed_in?
redirect_to url, status: 301
end
这将重定向用户,如果用户在 .org 站点上登录,则将令牌附加到查询中。