'Get an instance of OneLogin_Saml2_Auth
idp: The Identity Provider - a social_core.backends.saml.SAMLIdentityProvider instance'

def _create_saml_auth(self, idp):

    auth_inst = super(SAMLAuthBackend, self)._create_saml_auth(idp)
    from .models import SAMLProviderConfig
    if SAMLProviderConfig.current(idp.name).debug_mode:
        def wrap_with_logging(method_name, action_description, xml_getter):
            '    Wrap    the    request    and    response    handlers    to    add    debug    mode    logging    '
            method = getattr(auth_inst, method_name)
            def wrapped_method(*args, **kwargs):
                '    Wrapped    login    or    process_response    method    '
                result = method(*args, **kwargs)
                log.info('SAML    login    %s    for    IdP    %s.    XML    is:\n%s', action_description, idp.name, xml_getter())
                return result
            setattr(auth_inst, method_name, wrapped_method)
        wrap_with_logging('login', 'request', auth_inst.get_last_request_xml)
        wrap_with_logging('process_response', 'response', auth_inst.get_last_response_xml)
    return auth_inst
