1

这是我目前的情况。我设置了一个 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 的方法,但我空手而归。我最接近解决方案的是(我相信)通过添加消息处理程序,如本例所示

http://leastprivilege.com/2013/04/22/asp-net-web-api-security-the-thinktecture-identitymodel-authenticationhandler/

如果我理解正确,我应该能够让 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 是否正确?

谢谢你。

4

2 回答 2

0

您需要为运行 IIS Web 应用程序的域帐户设置 App 2 的 SPN(这将是应用程序正在使用的应用程序池的标识)。例如:setspn -a http/app2 域\帐户。因此,您必须使用不使用本地/网络身份而是使用特定域帐户的应用程序池。

确保 IIS 应用程序设置为使用应用程序池凭据。当涉及到模拟和委派时,您需要在 AD 中为创建的 SPN 的 App1 帐户设置委派目标。委派还要求您为执行委派的帐户设置本地安全策略“作为操作系统的一部分”,在您的情况下,它将是 App1 的帐户,即如果您执行模拟。

于 2014-04-08T06:22:25.973 回答
0

您的问题有点不清楚应用程序 1 中对应用程序 2 的调用是来自 JS 还是来自您的服务器代码。

如果是后者,那么在您的应用程序 1 中,如果您有引导令牌,则可以对您的 STS 进行 ws-trust 回调以获取应用程序 2 的令牌。您必须阅读 WS-Trust - - 它被称为“委托”。

编辑:我以为您使用 IdentityServer 作为 STS,但我意识到您使用的是 ADFS。两者都支持此功能,顺便说一句。

于 2014-03-18T23:02:20.473 回答