当您重定向登录时,securepage.aspx 的返回 URL 通常存储在上下文参数中。在 ACS 托管登录页面和自定义可下载页面中,都有 JavaScript 查询 ACS 的身份提供商列表,然后为每个 IP 生成登录链接。 ACS 托管版本的特殊之处在于,它还将收集提供给它的 wctx 并自定义每个 IP 登录 url 以保留此上下文。这样 ACS 就知道在身份验证完成后将用户重定向回哪里。
然而,自定义可下载登录页面不会保留此上下文,这就是您出现此行为的原因,ACS 只是将您重定向到您在 ACS 配置中指定的返回 URL,在本例中为 default.aspx。
但您可以更改自定义登录页面以插入此缺失的参数。这里的复杂之处在于,根据协议的不同,此上下文的通信方式也不同。对于 LiveID (WS-联邦) 传入的 wctx 可以在 liveID 登录链接中的传出 wctx 中重新传输,但以盒装形式“cx”。下面是我添加到 CreateIdentityProviderButton() 函数中的一些 javascript,以实现此目的。
...
//Creates a stylized link to an identity provider's login page
function CreateIdentityProviderButton(identityProvider) {
// Some code I stole from fellow stackoverflow member for extracting query parameters =)
var urlParams = {};
(function () {
var e,
a = /\+/g, // Regex for replacing addition symbol with a space
r = /([^&=]+)=?([^&]*)/g,
d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
q = window.location.search.substring(1);
while (e = r.exec(q))
urlParams[d(e[1])] = d(e[2]);
})();
var cx = "&cx=" + encodeURIComponent(urlParams.wctx);
var idpList = document.getElementById("IdentityProvidersList");
var button = document.createElement("button");
button.setAttribute("name", identityProvider.Name);
button.setAttribute("id", identityProvider.LoginUrl + encodeURIComponent(cx));
...
对于雅虎或谷歌(OpenID)此上下文返回于openid.return_to,作为“上下文”查询参数。因此,在您的登录页面中,您可以类似地编辑登录链接中的 openid.return_to ,如下所示:
... openid.return_to=https://youracstenant.accesscontrol.windows.net:443/v2/openid?context=<value of the wctx extracted from javascript above> ...
您可以根据您在 ACS IdentityProvider.js json 响应中看到的身份提供商名称,编写代码以特殊情况处理您的登录链接。