【问题标题】:How to decode SAML Response and get the attribute values sent by Idp in PHP如何在 PHP 中解码 SAML Response 并获取 Idp 发送的属性值
【发布时间】:2015-10-24 00:39:25
【问题描述】:

我正在实施 SAML 单点登录并使用 idp 发起的登录请求方法。登录后,它使用 base64 编码的 SAML 响应将用户重定向到请求中定义的登录 url。

现在,我已提取此响应,对其进行验证并获取 Idp 发送的属性值,例如电子邮件地址、姓名等。

我已从 base64 解码并得到以下 XML。此 XML 已加密 Signature、CipherData、Certificate 等。但不知道如何验证和解码/提取属性值,以便我们进一步使用它。

我通过提供私钥来搜索它并喜欢正在解码它的online tool。我试了一下,得到了属性值。

我必须在使用 PHP 的应用程序中做同样的事情,并且必须使用这个属性值。如果有人做过同样的事情并且可以对此有所了解,那将不胜感激。

请检查下面的 SAML 响应。

<samlp:Response Version="2.0" ID="vafmraxdfkermx" IssueInstant="2015-07-31T07:26:00.180Z" Destination="http://domain.com/saml/SSO" xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">
<saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">MI-TEST-SAML2-EntityID</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/2000/09/xmldsig#rsa-sha1"/>
        <ds:Reference URI="#DLSr8z03t7WZ-F7ZFwbxUw91vQF">
            <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/2000/09/xmldsig#sha1"/>
            <ds:DigestValue>gnvnDwu/eDBpLnPtiaHeOI7UCD4=</ds:DigestValue>
        </ds:Reference>
    </ds:SignedInfo>
    <ds:SignatureValue>
        Signature Value
    </ds:SignatureValue>
    <ds:KeyInfo>
        <ds:X509Data>
            <ds:X509Certificate>
                Certifivate Contents
            </ds:X509Certificate>
        </ds:X509Data>
    </ds:KeyInfo>
</ds:Signature>
<samlp:Status>
    <samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>
</samlp:Status>
<saml:EncryptedAssertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
    <xenc:EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
        <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"/>
        <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
            <xenc:EncryptedKey>
                <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"/>
                <xenc:CipherData>
                    <xenc:CipherValue>CIPHER VALUE</xenc:CipherValue>
                </xenc:CipherData>
            </xenc:EncryptedKey>
        </ds:KeyInfo>
        <xenc:CipherData>
            <xenc:CipherValue>CIPHER CONTETNS</xenc:CipherValue>
        </xenc:CipherData>
    </xenc:EncryptedData>
</saml:EncryptedAssertion>

【问题讨论】:

    标签: php single-sign-on saml opensaml


    【解决方案1】:

    您使用的在线工具基于 OneLogin 的 PHP SAML 工具包 [1]。我都实现了。

    阅读文档。 processResponse 和 getAttributes 做你想做的事。

    [1]https://github.com/onelogin/php-saml

    【讨论】:

    • 感谢您的回复,发布问题后我也发现了同样的东西,它工作得很好,我已经完成了使用相同的功能。 github.com/onelogin/php-saml
    【解决方案2】:

    根据您想要做什么,让现有代码为您处理所有 SAML 可能会更容易。对于 PHP,您可以将 SimpleSAMLphp 配置为服务提供者。

    SimpleSamlPHP 将为您生成元数据并使用 SAML 断言并验证它们。可以使用函数检索属性。请参阅SimpleSAMLphp Service Provider QuickStart 了解更多信息。

    【讨论】:

      【解决方案3】:

      您可以使用LightSAML 直接从http 请求接收编码的SAML 响应,将其反序列化为数据模型,并对其进行解密。这是一个关于如何从 HTTP 请求 http://www.lightsaml.com/LightSAML-Core/Cookbook/How-to-receive-SAML-message/ 接收 SAML 消息的示例,这是一个关于如何解密断言 http://www.lightsaml.com/LightSAML-Core/Cookbook/How-to-decrypt-Assertion/ 的示例

      【讨论】:

        猜你喜欢
        • 2016-02-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-09
        • 2021-02-08
        相关资源
        最近更新 更多