gpt4 book ai didi

authentication - 使用 ACS 身份验证在 azure 开发中跨域 cookie

转载 作者:行者123 更新时间:2023-12-04 14:44:41 25 4
gpt4 key购买 nike

您好,我正在 Azure 上开发两个 Web 服务,分别为“domain1.azurewebsite.net”和“domain2.azurewebsite.net”。我已在同一 Active Directory 下的两个服务中实现了 ACS 身份验证。现在我需要通过domain1.azurewebsite.net登录,并与domain2.azurewebsite.net共享cookie(包含auth token),这样我就可以在domain1中访问domain2的数据服务。

我已遵循在线建议,该建议设置了 cookie 域 =“.azurewebsite.net”。我希望这样的cookie能够被所有子域共享,即“*.azurewebsite.net”,这样就可以实现跨域的目的。在web.config中进行设置如下

<system.identityModel.services>
<federationConfiguration>
<cookieHandler requireSsl="false"
domain=".azurewebsites.net"
hideFromScript="false"
persistentSessionLifetime="0:30:0" />
<wsFederation passiveRedirectEnabled="true"
issuer="https://focusns.accesscontrol.windows.net/v2/wsfederation"
realm="urn:Focusns"
requireHttps="false"
persistentCookiesOnPassiveRedirects="true" />
</federationConfiguration>
</system.identityModel.services>

为了启用跨域请求,我使用了 CORS,并且正确设置了“domain2.azurewebsite.net”的响应 header ,如下所示:

Access-Control-Allow-Credentials:true
Access-Control-Allow-Origin:http://domain1.azurewebsites.net

但是,我的问题是,当登录domain1.azurewebsite.net时,未附加带有“.azurewebsite.net”域的cookie。当我使用 Chrome、Opera、FF 检查 cookie 时,我什至看不到它们。但我确实在 IE11 中看到了 cookie,一切正常。我在链接browser security handbook part 2中发现了不同浏览器之间的差异,我怀疑原因是 IE 不支持主机范围 cookie。

无论如何,有人知道我该如何解决这个问题吗?我需要它在 Chrome、FF 等中工作。提前致谢

最佳答案

根据这个问题 Chrome34 ignores cookies with domain ".cloudapp.net" ,

  • Chrome
  • 火狐浏览器
  • (也许是其他浏览器)

拒绝为公共(public)共享域后缀设置 cookie(此处列出: https://publicsuffix.org/list/effective_tld_names.dat )。和“azurewebsites.net”就是其中之一。

IE 没有这个限制,可能是因为 MS 都拥有。

解决方案可能是将站点映射到您拥有的自定义域/子域名称。您无法在 Azure 中设置链接子域,例如“a.b.azurewebsites.net”。如果可以的话,您可以为“b.azurewebsites.net”设置 cookie,Chrome 允许这样做。

关于authentication - 使用 ACS 身份验证在 azure 开发中跨域 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24873526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com