跨子域的表单身份验证
当身份验证在子域而不是父域进行时,是否可以跨子域对用户进行身份验证?
例如:
用户登录site1.parent.com,然后我们需要将它们发送到reporting.parent.com。
即使登录是在子域中进行的,我是否可以向报告站点验证它们的身份?
到目前为止,我所做的所有研究都是用户首先登录父域,然后每个子域都可以访问身份验证 cookie。
Is it possible to authenticate users across sub-domains when the authentication takes place at a sub-domain instead of the parent domain?
For example:
User logs into site1.parent.com, and then we need to send them to reporting.parent.com.
Can I authenticate them to the reporting site even though the log-in occured at a sub-domain?
So far all of the research I have done has users logging into the parent domain first and then each sub-domain has access to the authentication cookie.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
当您对用户进行身份验证时,将身份验证cookie的域设置为二级域,即parent.com。 每个子域都会根据请求接收父域的 cookie,因此可以对每个子域进行身份验证,因为您将有一个共享的身份验证 cookie 可供使用。
验证码:
When you authenticate the user, set the authentication cookie's domain to the second-level domain, i.e. parent.com. Each sub-domain will receive the parent domain's cookies on request, so authentication over each is possible since you will have a shared authentication cookie to work with.
Authentication code:
您可以在身份验证时将 cookie 设置为父域,但您必须明确设置它,它将默认为您所在的完整域。
一旦将身份验证 cookie 正确设置到父域,那么所有子域都应该能够读取它。
You can set the cookie to be the parent domain at authentication time but you have to explicitly set it, it will default to the full domain that you are on.
Once the auth cookie is correctly set to the parent domain, then all sub-domains should be able to read it.
作为旁注,我发现在使用 jro 的方法(效果很好+1)之后,当从 www/ 以外的子域调用时,FormsAuthenication.SignOut() 方法不起作用。 (我猜测是因为 .Domain 属性不匹配) - 为了解决这个问题,我使用了:
As a side note, I found that after using jro's method which worked well +1, the FormsAuthenication.SignOut() method didn't work when called from a subdomain other than www/. (I'm guessing because the .Domain property doesn't match) - To get around this I used:
除了为父域设置cookie之外,还需要确保所有站点(应用程序)具有相同的validationKey和decryptionKey(),以便它们都能识别彼此的身份验证票证和cookie。 这里的文章非常好 http://www.codeproject.com/KB/aspnet/SingleSignon.aspx
In addition to setting a cookie to parent domain also need to make sure that all sites (apps) have same validationKey and decryptionKey () so they all recognise each other's authentication ticket and cookie. Pretty good article here http://www.codeproject.com/KB/aspnet/SingleSignon.aspx
Jro的回答很好。 但请确保更新 webconfig 表单身份验证
设置“domain”
,否则表单身份验证注销将无法正常工作。 这里是我遇到的注销问题穿过。 这里的技巧是有一个“.”。 作为 cookie 域的前缀,设置为“.parent.com”(使用 cookie 检查器)。
Jro's answer works fine. But make sure to update the webconfig forms authentication
setting "domain"
, otherwise forms authentication signout will not work properly. Here is the signout issue I came across. Trick here is to have a '.' as the prefix as the domain is set for the cookie as ".parent.com" (use a cookie inspector).
是的,当然。 您可能需要在某些阶段自行推出,但这应该是可行的。
一个想法:当您将它们重定向到边界时,给它们一个一次性传递令牌,然后告诉接收子域期待它们(此用户,来自此 IP,带有此令牌)。
Yes, sure. You may need to roll your own at some stages, but it should be doable.
One idea: as you redirect them across the boundary, give them a one-time pass token and then tell the receiving sub-domain to expect them (this user, from this IP, with this token).
需要做的 2 件事:
请遵循以下文章更深入。
2 things to be done:
Follow the following article for more depth.