繁体   English   中英

如何解码SAML响应并获取PHP中Idp发送的属性值

[英]How to decode SAML Response and get the attribute values sent by Idp in PHP

我正在实现SAML单一登录,并使用idp启动的方法进行登录请求。 登录后,它将用户重定向到在请求中定义的登录URL,并使用base64编码的SAML响应。

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

我已经从base64解码并获得了以下XML。 该XML具有加密的Signature,CipherData,Certificate等。但是不知道如何验证和解码/提取属性值,以便我们进一步使用它。

我通过提供私钥来搜索它并喜欢对其进行解码的在线工具 我尝试了一下,并获得了属性值。

我必须在使用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>

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

阅读文档。 processResponse和getAttributes可以满足您的需求。

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

根据您要执行的操作,让现有代码为您处理所有SAML可能会更容易。 对于PHP,您具有SimpleSAMLphp,可以将其配置为服务提供者。

SimpleSamlPHP将为您生成元数据,并使用SAML断言并对其进行验证。 可以使用函数来检索属性。 有关更多信息,请参见SimpleSAMLphp服务提供商快速入门

您可以使用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/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM