Ejemplo n.º 1
0
    def __build_sign_query(saml_data,
                           relay_state,
                           algorithm,
                           saml_type,
                           lowercase_urlencoding=False):
        """
        Build sign query

        :param saml_data: The Request data
        :type saml_data: str

        :param relay_state: The Relay State
        :type relay_state: str

        :param algorithm: The Signature Algorithm
        :type algorithm: str

        :param saml_type: The target URL the user should be redirected to
        :type saml_type: string  SAMLRequest | SAMLResponse

        :param lowercase_urlencoding: lowercase or no
        :type lowercase_urlencoding: boolean
        """
        sign_data = [
            '%s=%s' %
            (saml_type,
             OneLogin_Saml2_Utils.escape_url(saml_data, lowercase_urlencoding))
        ]
        if relay_state is not None:
            sign_data.append('RelayState=%s' % OneLogin_Saml2_Utils.escape_url(
                relay_state, lowercase_urlencoding))
        sign_data.append(
            'SigAlg=%s' %
            OneLogin_Saml2_Utils.escape_url(algorithm, lowercase_urlencoding))
        return '&'.join(sign_data)
Ejemplo n.º 2
0
def prepare_saml_response_from_xml(xml, relay_state='testshib'):
    """
    Pre Process XML so that it can be used as a SAML Response coming from SAML IdP.

    This method will perform the following operations on the XML in given order

    1. base64 encode XML.
    2. URL encode the base64 encoded data.

    Arguments:
        xml (string): XML data
        relay_state (string): Relay State of the SAML Response

    Returns:
         (str): Base64 and URL encoded XML.
    """
    b64encoded_xml = b64encode(xml.encode())
    return 'RelayState={relay_state}&SAMLResponse={saml_response}'.format(
        relay_state=OneLogin_Saml2_Utils.escape_url(relay_state),
        saml_response=OneLogin_Saml2_Utils.escape_url(b64encoded_xml))
Ejemplo n.º 3
0
    def __build_sign_query(saml_data, relay_state, algorithm, saml_type):
        """
        Build sign query

        :param saml_data: The Request data
        :type saml_data: str

        :param relay_state: The Relay State
        :type relay_state: str

        :param algorithm: The Signature Algorithm
        :type algorithm: str

        :param saml_type: The target URL the user should be redirected to
        :type saml_type: string  SAMLRequest | SAMLResponse
        """

        sign_data = ['%s=%s' % (saml_type, OneLogin_Saml2_Utils.escape_url(saml_data))]
        if relay_state is not None:
            sign_data.append('RelayState=%s' % OneLogin_Saml2_Utils.escape_url(relay_state))
        sign_data.append('SigAlg=%s' % OneLogin_Saml2_Utils.escape_url(algorithm))
        return '&'.join(sign_data)