【问题标题】:How to send a hard-coded SAML2 response to AuthServices/Acs endpoint for testing如何将硬编码的 SAML2 响应发送到 AuthServices/Acs 端点以进行测试
【发布时间】:2018-12-20 22:58:57
【问题描述】:

我需要将 SSO 与使用 SAML2 的客户集成。不幸的是,我使用的是稍旧版本的库(Kentor)。

我几乎可以让 SSO 流程正常工作。我网页中的登录按钮正确地将我带到客户登录页面。输入用户名/密码后,客户端系统进行身份验证并返回有效响应。

不幸的是,从客户端返回到我们的身份验证端点的重定向失败并显示“403 - 禁止访问:访问被拒绝”。

我想硬编码 saml 响应(我可以在 chrome 调试工具中看到)并直接点击我的 auth localhost 来调试正在发生的事情。我尝试使用 POSTMAN 无济于事。有没有办法做到这一点?

这是我要发布到的硬编码 SAML:http://localhost:11996/AuthServices/Acs

<samlp:Response Destination="http://localhost:11996/AuthServices/Acs"
ID="fbrVm-Lw67Z-Q7uihwClM5N_EXC" IssueInstant="2018-12-20T22:00:30.665Z" Version="2.0"
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">
<saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">xyz:abc:saml20:idp</saml:Issuer>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
    <ds:SignedInfo>
        <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
        <ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
        <ds:Reference URI="#fbrVm-Lw67Z-Q7uihwClM5N_EXC">
            <ds:Transforms>
                <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
                <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
            </ds:Transforms>
            <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
            <ds:DigestValue>RYTG1QX8X/Jyu1BbnFbyeQvb0ZQjhfP7nbA7tdNLbfE=</ds:DigestValue>
        </ds:Reference>
    </ds:SignedInfo>
    <ds:SignatureValue>
        EAIb9VfZ+ywNJGrMYfDGiYvgKo1UTiUB0yeDIZWsSvj4htvGPDTOwssyDdaFBSwB0B9/LjZB0GDD
        Bg3KR/ObpkW07t6Aoy0lSUt8pGJLvuXIcftsXGPeZTEt8ukNm66CZ7O2nGlalXBXvwBWHIUAJQ5j
        4tLkFJvGl/Ku0GF5madBgHrJq0023cjf5rb6+gksAOaSDawpbiXaRtQaluHyCkhgD8PuRoZRudCJ
        OW/1e70FZUb07EE5ZsN8cBXrERAfgECZc27GQ1l2v4ELlEdzNpnPJHugF+bgHowjeED/H0Hza4nl
        IriW+h8kAd2nyn5Kv6KnKG04DqoN+o0PsGGGaw==
    </ds:SignatureValue>
</ds:Signature>
<samlp:Status><samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/></samlp:Status>
<saml:Assertion ID="mS8eJV.gG4EXybyBs4uYWJsK2Es" IssueInstant="2018-12-20T22:00:32.250Z"
    Version="2.0" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
    <saml:Issuer>xyz:abc:saml20:idp</saml:Issuer>
    <saml:Subject>
        <saml:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">10035094</saml:NameID>
        <saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"><saml:SubjectConfirmationData NotOnOrAfter="2018-12-20T22:05:32.250Z"
            Recipient="https://mvauth-staging.mvtransit.com/AuthServices/Acs"/></saml:SubjectConfirmation>
    </saml:Subject>
    <saml:Conditions NotBefore="2018-12-20T21:55:32.250Z" NotOnOrAfter="2018-12-20T22:05:32.250Z">
        <saml:AudienceRestriction>
            <saml:Audience>xyz:abc:saml20:sp</saml:Audience>
        </saml:AudienceRestriction>
    </saml:Conditions>
    <saml:AuthnStatement AuthnInstant="2018-12-20T22:00:30.665Z"
        SessionIndex="mS8eJV.gG4EXybyBs4uYWJsK2Es">
        <saml:AuthnContext>
            <saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified</saml:AuthnContextClassRef>
        </saml:AuthnContext>
    </saml:AuthnStatement>
    <saml:AttributeStatement>
        <saml:Attribute Name="firstname"
            NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified">
            <saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">John</saml:AttributeValue>
        </saml:Attribute>
        <saml:Attribute Name="adLogon" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
            <saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">jsmith</saml:AttributeValue>
        </saml:Attribute>
        <saml:Attribute Name="lastname" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified">
            <saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">Smith</saml:AttributeValue>
        </saml:Attribute>
        <saml:Attribute Name="upi" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
            <saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">20181220</saml:AttributeValue>
        </saml:Attribute>
    </saml:AttributeStatement>
</saml:Assertion>

【问题讨论】:

    标签: saml-2.0 kentor-authservices sustainsys-saml2


    【解决方案1】:

    硬编码的响应很难做到,因为它会

    1. 无效(响应包含时间限制)并且
    2. 触发重放检测。

    所以为了测试,我创建了https://stubidp.sustainsys.com 提供的 stubidp。您可以通过创建自己的租户并编辑 json 设置文件来配置它,以提供包含与您在示例中列出的相同属性的响应。诸如 NameFormat 之类的可选内容不会出现在其中 - 但由于库忽略了它,因此将其用于测试毫无意义。

    【讨论】:

    • 谢谢。我相信我已经取得了一些进展。我启用了登录 Kentor.AuthServices 并意识到我在 web.config 中的一些设置是错误的。我一直收到“收到未经请求的 Saml 响应”错误,因此我将“allowUnsolicitedAuthnResponse”更改为 false 并设置了“returnUrl”。现在,我得到“已成功处理 SAML 响应 Ejx3U2coHBmIhjtYikGZr-HUf_u 并验证 10035094”。
    • 这是我的配置的样子:codestaging.abc.com/MVSAMLServiceProvider" returnUrl="dfjliyd.ngrok.io/api/Account/UnsolicitedExternalLogin"> 跨度>
    • 不幸的是,在我的 returnUrl(api/Account/UnsolicitedExternalLogin 是一个 GET)中,User.Identity.IsAuthenticated = false 并且我没有收到任何索赔。接下来,我尝试使用您的一个建议并这样做: app.Use(async (Context, next) => { await next.Invoke(); });我意识到“Set-Cookie”永远不会在标题中返回。请帮忙?
    • 日志应该包含错误。但我认为错误在于您的实体 ID 不是有效的绝对 Uri。在“staging.abc.com...”前面添加 http(s)
    • 有一个 h.t.t.p.s 在我发表评论时被自动删除。两件事,1. 为 entityid 设置的绝对 url 返回 404,这是一个问题吗?
    猜你喜欢
    • 1970-01-01
    • 2019-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-09
    相关资源
    最近更新 更多