简体   繁体   English

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

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

I am implementing SAML Single Sign-On and using idp initiated method for login request. 我正在实现SAML单一登录,并使用idp启动的方法进行登录请求。 After login it redirect users on the login url defined on the request with the base64 encoded SAML Response. 登录后,它将用户重定向到在请求中定义的登录URL,并使用base64编码的SAML响应。

Now, I have extract to this response, validate it and get the attribute value sent by the Idp like email address, name etc. 现在,我已经提取了此响应,对其进行了验证,并获得了Idp发送的属性值,例如电子邮件地址,名称等。

I have decoded from base64 and got the following XML. 我已经从base64解码并获得了以下XML。 This XML have encrypted Signature, CipherData, Certificate etc.. but don't know how to validate and decode/extract the attribute values so that we can use it further. 该XML具有加密的Signature,CipherData,Certificate等。但是不知道如何验证和解码/提取属性值,以便我们进一步使用它。

I search for it and fond the online tool which is decoding it, by providing the private key. 我通过提供私钥来搜索它并喜欢对其进行解码的在线工具 I tried it and got the attribute values. 我尝试了一下,并获得了属性值。

The same thing I have to do in our application using PHP and have to use this attributes value. 我必须在使用PHP的应用程序中做同样的事情,并且必须使用此属性值。 If any one have did the same thing and can put some light on it then it will be really appreciated. 如果有人做过同样的事情并且可以对此有所启发,那么我们将不胜感激。

Pleas Check the SAML Response below. 请检查下面的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>

The online tool that you used is based on the OneLogin's PHP SAML Toolkit [1]. 您使用的在线工具基于OneLogin的PHP SAML工具包[1]。 I implemented both. 我都实现了。

Read the documentation. 阅读文档。 The processResponse and the getAttributes do what you want. processResponse和getAttributes可以满足您的需求。

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

Depending on what you want to do, it may be easier to let existing code handle all SAML for you. 根据您要执行的操作,让现有代码为您处理所有SAML可能会更容易。 For PHP, you have SimpleSAMLphp which can be configured as a service provider. 对于PHP,您具有SimpleSAMLphp,可以将其配置为服务提供者。

SimpleSamlPHP will generate the metadata for you and consume SAML assertions and validate them. SimpleSamlPHP将为您生成元数据,并使用SAML断言并对其进行验证。 Attributes can be retrieved using a function. 可以使用函数来检索属性。 See SimpleSAMLphp Service Provider QuickStart for more information. 有关更多信息,请参见SimpleSAMLphp服务提供商快速入门

You can use LightSAML to receive the encoded SAML Response directly from http request, de-serialize it into a data model, and decrypt it. 您可以使用LightSAML直接从http请求接收编码的SAML响应,将其反序列化为数据模型,然后将其解密。 Here's an example on how to receive a SAML message from HTTP request http://www.lightsaml.com/LightSAML-Core/Cookbook/How-to-receive-SAML-message/ and here's an example on how to decrypt an Assertion http://www.lightsaml.com/LightSAML-Core/Cookbook/How-to-decrypt-Assertion/ 这是一个有关如何从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