【问题标题】:WS-Trust MEX endpoint in IdentityServer 2 returns HTTP 400 for GET requestsIdentityServer 2 中的 WS-Trust MEX 端点为 GET 请求返回 HTTP 400
【发布时间】:2016-05-26 16:14:51
【问题描述】:

我们定制了 IdentityServer 2 以在 Azure AD 中提供身份联合功能(用于 Office 365 等)。这具有用于被动请求者流的 WS-Federation 端点和用于主动客户端的 WS-Trust。 WS-Trust 的 MEX 端点应返回 WS-Trust SOAP 的 WSDL,以响应 POST(如 Lync 使用)和 GET(如 Windows 10 登录使用)。不幸的是,它返回 HTTP 400:ws-trust system.servicemodel.protocolexception “从网络接收的 XML 存在问题”。

从源码中可以看出: https://github.com/IdentityServer/IdentityServer2/blob/master/src/Libraries/Thinktecture.IdentityServer.Protocols/WSTrust/TokenServiceHostFactory.cs

var host = new WSTrustServiceHost(config, baseAddresses);

// add behavior for load balancing support
host.Description.Behaviors.Add(new UseRequestHeadersForMetadataAddressBehavior());

// modify address filter mode for load balancing
var serviceBehavior = host.Description.Behaviors.Find<ServiceBehaviorAttribute>();
serviceBehavior.AddressFilterMode = AddressFilterMode.Any;
serviceBehavior.IncludeExceptionDetailInFaults = true;

System.ServiceModel.Security.WSTrustServiceHost 的一个实例正在启动以处理对 WS-Trust 的调用,并处理其元数据。检查 WSTrustServiceHost ctor 中默认添加的 ServiceMetadataBehavior,我们可以看到它确实启用了通过 HTTP 和 HTTPS 进行 GET 的元数据。 http://referencesource.microsoft.com/#System.ServiceModel/System/ServiceModel/Security/WSTrustServiceHost.cs,8c80389f2532b060,references

所以我有点困惑为什么https://myhost.com/issue/wstrust/mex 在使用 POST 时返回元数据,但在发送 GET 时返回 400。在 System.ServiceModel 的 EnqueueMessageAsyncResult.CompleteParseAndEnqueue() 中引发了异常 http://referencesource.microsoft.com/#System.ServiceModel/System/ServiceModel/Channels/HttpPipeline.cs,b347567a68ab778c,references

非常感谢任何帮助!

【问题讨论】:

    标签: wcf-binding identityserver2


    【解决方案1】:

    对于其他卡在同一个地方的人,我已明确设置 TokenServiceHostFactory 以响应 HTTP GET。

    // added for AAD Windows 10 sign in - device requests metadata with GET
    ServiceMetadataBehavior metad = host.Description.Behaviors.Find<ServiceMetadataBehavior>();
    if (metad == null)
        metad = new ServiceMetadataBehavior();
    for (int i = 0; i < baseAddresses.Length; i++)
    {
        // there will be two bindings: one for http and one secure
        switch (baseAddresses[i].Scheme)
        {
            case "http":
                metad.HttpGetEnabled = true;
                metad.HttpGetUrl = new Uri(baseAddresses[i], "/issue/wstrust/mex");
                break;
            case "https":
                metad.HttpsGetEnabled = true;
                metad.HttpsGetUrl = new Uri(baseAddresses[i], "/issue/wstrust/mex");
                break;
        }
    }
    

    【讨论】:

    • 嗨 Rob,我看到您正在努力让 win10 aad 登录与 IdentityServer 结合使用。你最终得到这个工作了吗?经过大量努力尝试让 aad 登录以使用我们自己的自定义 IdP,我们最终放弃并使用 ADFS 进行设置。不是我们的最佳解决方案。只要知道它可以在不支持 MS 的平台上工作就会令人鼓舞,我考虑让 IdentityServer 看起来可以替代我们的自定义解决方案。
    • 我在 Twitter 上回答了你的问题,但对于未来的访问者来说,这里是答案......除了上述之外,所有当前 Windows 10 版本的 WSDL 解析器中还有一个错误,基本上, Win10 要求将 Trust13Issue 操作列为该 元素中的最后一个节点 - 任何其他位置,它将不起作用。解决方法是托管您手动重新排序操作元素的 WSDL 的静态副本。脆弱,但它有效。另请注意,Win10 将优先使用 WS-Trust 1.3 端点而不是 Feb2005,因此只需修改这些绑定。
    • 感谢您的提示,我现在有了一个使用 IdentityServer2 的 POC :-)。我在使用 IDS 的 mex 端点时遇到了问题,因此我托管了来自 ADFS 的 mex 输出的静态副本,经过编辑后仅指向 IDS WS-Trust 1.3 端点。 mex 中的 WS-Trust 2005 端点我指出了一些不存在的东西。我注意到的一件更有趣的事情是,AAD 联合现在似乎支持 OpenId Connect。如果您致电Get-MSOLDomainFederationSettings,则会列出一个发现端点。在 win 10 登录期间,我还看到对我的 IDS 服务器上不存在的 openid 发现端点的调用。令人惊讶!
    • @MarkHasper 我们还将 IdentityServer2 与 AzureAD 集成。成功设置 WS-Federation 和域加入/Web 登录成功。但是,当尝试登录到 Windows 10 设备时,我可以看到来自 Windows10 设备的调用命中 WS-Federation 元数据点 (myhost/FederationMetadata/2007-06/FederationMetadata.xml) 并且我遇到断点命中。但是,在此之后无法跟踪任何呼叫并且身份验证失败。我为 WSTrustService 主机添加了 HttpGet 端点。似乎我错过了一些东西。你能帮忙吗?
    【解决方案2】:

    遇到此问题的人,有一种解决方法,即获取 ADFS 元数据文件,然后使用您自己的 WS-Trust13 实现更改 usernamemixed 和 certificatemixed 的 WS-TRUST1.3 端点。 Microsoft 似乎只支持它自己的 ADFS 元数据文件。我也联系了 Microsoft 支持,但他们尚未提供答案。尽管他们承认元数据解析可能被硬编码到 ADFS,并且与标准 WS-TRUST13 元数据实现不一致。

            <wsdl:port name="CertificateWSTrustBinding_IWSTrust13Async" binding="tns:CertificateWSTrustBinding_IWSTrust13Async">
            <soap12:address location="https://sts.gemalto.com/adfs/services/trust/13/certificatemixed"/>
            <wsa10:EndpointReference>
                <wsa10:Address>https://sts.gemalto.com/adfs/services/trust/13/certificatemixed</wsa10:Address>
            </wsa10:EndpointReference>
        </wsdl:port>
        <wsdl:port name="UserNameWSTrustBinding_IWSTrust13Async" binding="tns:UserNameWSTrustBinding_IWSTrust13Async">
            <soap12:address location="https://sts.gemalto.com/adfs/services/trust/13/usernamemixed"/>
            <wsa10:EndpointReference>
                <wsa10:Address>https://sts.gemalto.com/adfs/services/trust/13/usernamemixed</wsa10:Address>
            </wsa10:EndpointReference>
        </wsdl:port>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-26
      • 2015-09-27
      • 2020-11-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多