这是我目前的情况。我设置了一个 ADFS 2.0 服务器,并连接了两个 RP Web 应用程序。这些应用程序 App1 和 App2 是具有 Web API 后端的 Web 应用程序。使用 Javascript AJAX 调用。
根据我对 WIF 的初步了解,我认为我可以通过浏览器登录,然后可以访问这两个应用程序。这被证明是不正确的,因为我无法从 App1 调用 App2 的 Web API 函数。我可以做到这一点的唯一方法是输入 App2 的 URL,只有这样我从 App 1 进行的后续调用才能工作(正确的 FedAuth cookie 在标头中传递)
因此,我一直在寻找从 App1 实际调用 App2 的 Web API 的方法,但我空手而归。我最接近解决方案的是(我相信)通过添加消息处理程序,如本例所示
如果我理解正确,我应该能够让 WebAPI 接收我的 SAML2 安全令牌。
我的代码如下:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
var authentication = CreateAuthenticationConfiguration();
config.MessageHandlers.Add(new AuthenticationHandler(authentication));
}
}
private static AuthenticationConfiguration CreateAuthenticationConfiguration()
{
System.Diagnostics.Debugger.Break();
var authentication = new AuthenticationConfiguration
{
ClaimsAuthenticationManager = new MyClaimsAuthenticationManager(),
EnableSessionToken = true,
RequireSsl = false
};
authentication.AddSaml2(
issuerThumbprint: **Hidden**,
issuerName: "https://192.168.0.55/adfs/ls/",
audienceUri: "http://localhost/MyCompany.App2/",
certificateValidator: X509CertificateValidator.None,
options: AuthenticationOptions.ForAuthorizationHeader("AdfsSaml"),
scheme: AuthenticationScheme.SchemeOnly("AdfsSaml"));
return authentication;
}
调用到达 MyClaimsAuthenticationManager.Authenticate(),但 IncomingPrincipal 仍未通过身份验证。我无法知道它是否接收到 SAML2 令牌,因为在 MyClaimsAuthenticationManager.Authenticate() 之前我无法调试任何东西
我的问题:
1) 尽管在 App1 中进行了身份验证,是否可以调用我的 App2 Web API 函数?(他们使用相同的 ADFS)
2)如果可能的话,我使用 ThinkTecture AuthenticationHandler 是否正确?
谢谢你。