【问题标题】:Sustainsys.SAML2 uses http-redirect instead of http-postSustainsys.SAML2 使用 http-redirect 而不是 http-post
【发布时间】:2018-12-05 15:23:13
【问题描述】:

我应该说我刚刚开始探索 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。我尝试了不同的设置,正如您在代码 sn-p 中看到的那样,我将 Binding 设置为 HttpPost,如果SingleSignOnServiceUrl 是从 IDP 元数据中自动获取的,我认为这应该可以解决我的问题。我还查看了sustainsys.SAML2 源代码,但找不到任何可以给我线索的东西。

非常感谢任何帮助!

【问题讨论】:

    标签: sustainsys-saml2


    【解决方案1】:

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

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

    【讨论】:

    • 感谢安德斯的回答!我检查了元数据文件。是的,它包含错误的端点。一位管理 Idp 的人证实了这一点。我已经设置了sustainsys.saml2 来从文件中加载元数据(他们为我提供了一个),这解决了我的问题。我仍然不明白一件事,为什么在我的机器上手动配置 SingleSignOnServiceUrl 被考虑在内,而在开发服务器上它回退到服务器的元数据。
    猜你喜欢
    • 2021-12-18
    • 1970-01-01
    • 1970-01-01
    • 2013-06-21
    • 2015-06-02
    • 2017-08-09
    • 1970-01-01
    • 1970-01-01
    • 2019-09-05
    相关资源
    最近更新 更多