Sustainsys.SAML2 使用 http-redirect 而不是 http-post

Sustainsys.SAML2 uses http-redirect instead of http-post

我应该说我刚刚开始探索 SAML 身份验证并遇到了身份验证问题,不幸的是我无法在我的开发机器上重现这让我更加困惑。

我使用 OWIN 进行了以下配置:

var options = new Saml2AuthenticationOptions(false)
{
    Notifications = new Saml2Notifications
    {
        AuthenticationRequestCreated = (request, provider, dictionary) =>
        {
            request.Binding = Saml2BindingType.HttpPost;
        }
    },
    AuthenticationType = services.AuthenticationType,
    Caption = services.Caption,
    SPOptions = new SPOptions
    {
        EntityId = new EntityId(Path.Combine(services.RelyingPartyUri, "Saml2"))
    }
};

options.IdentityProviders.Add(new IdentityProvider(new EntityId(services.IdentityProviderConfiguration.IdentityProviderMetadataUri), options.SPOptions)
{
    AllowUnsolicitedAuthnResponse = true,
    Binding = Saml2BindingType.HttpPost,
    LoadMetadata = true,
    SingleSignOnServiceUrl = new Uri(services.IdentityProviderConfiguration.SingleSignOnUri)
});

app.UseSaml2Authentication(options);

services变量包含元数据uri、sso uri等配置

此配置在我的机器上运行完美。我已经检查了登录 SAML 请求,这是我所拥有的:

<saml2p:AuthnRequest 
    xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" 
    xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" 
    ID="id10c4b76119b64952857d38c7581ca0b4" 
    Version="2.0" 
    IssueInstant="2018-12-04T14:29:00Z" 
    Destination="https://identity.provider/trust/saml2/http-post/sso/application" 
    ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" 
    AssertionConsumerServiceURL="https://application/Saml2/Acs">
    <saml2:Issuer>https://application/Saml2</saml2:Issuer>
</saml2p:AuthnRequest>

然后身份验证工作正常。

当我出于测试目的将此代码部署到外部服务器时,有时它会按预期工作,但我经常无法对用户进行身份验证,因为身份验证机制使用的是 http-redirect 而不是 http-post。

在这种情况下,我看到以下登录 SAML 请求:

<saml2p:AuthnRequest 
    xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" 
    xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" 
    ID="id10c4b76119b64952857d38c7581ca0b4" 
    Version="2.0" 
    IssueInstant="2018-12-04T14:29:00Z" 
    Destination="https://identity.provider/trust/saml2/http-redirect/sso/application" 
    ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" 
    AssertionConsumerServiceURL="https://application/Saml2/Acs">
    <saml2:Issuer>https://application/Saml2</saml2:Issuer>
</saml2p:AuthnRequest>

用于身份验证的 SSO uri 的差异。

到目前为止我所做的是检查配置文件以消除配置问题。所有配置均有效,并且 services.IdentityProviderConfiguration.SingleSignOnUri 包含带有 http-post 的有效 SSO uri。我尝试过不同的设置,正如您在代码片段中看到的那样,我将 Binding 设置为 HttpPost,如果 SingleSignOnServiceUrl 是从 IDP 元数据自动获取的,我认为这应该已经解决了我的问题。我还查看了 sustainsys.SAML2 源代码,但找不到任何可以给我线索的东西。

非常感谢任何帮助!

如果您设置 LoadMetadata=true,元数据中的设置将覆盖您的手动配置。显然,Idp 的元数据包含一个具有 POST 绑定的端点 https://identity.provider/trust/saml2/http-redirect/sso/application

要解决此问题,请 Idp 获取正确的元数据。或者设置 LoadMetadata=false 并依赖代码内配置。在这种情况下,您必须将 Idp 签名证书添加到您的代码中。