SAML-Toolkits / python3-saml

MIT License
704 stars 309 forks source link

How to initialize OneLogin_Saml2_Auth with settings_data in dict type? #327

Closed jtamyrc closed 2 years ago

jtamyrc commented 2 years ago

I would like to inititalize auth by passing a settings_data dict but I cannot find any documentation of it, could you please advice? What is the format of the settings_data I should prepare to pass?

# the current settings_data I try to use
settings_data = {
    'settings': {
        'strict': True,
        'debug': True,
        'sp': {
            'entityId': 'https://example.com/metadata',
            'assertionConsumerService': {
                'url': 'https://example.ngrok.io/?acs',
                'binding': 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST'
            },
            'singleLogoutService': {
                'url': 'https://example.com/?sls',
                'binding': 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect'
            },
            'NameIDFormat': 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified',
            'x509cert': 'xxx',
            'privateKey': ''
        },
        'idp': {
            'entityId': 'https://samltest.id/saml/idp',
            'singleSignOnService': {
                'url': 'https://samltest.id/idp/profile/SAML2/Redirect/SSO',
                'binding': 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect'
            },
            'singleLogoutService': {
                'url': 'https://samltest.id/idp/profile/SAML2/Redirect/SLO',
                'binding': 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect'
            },
            'x509cert': 'xxx'
        }
    },
    'advanced_settings': {
        'security': {
            'nameIdEncrypted': False,
            'authnRequestsSigned': False,
            'logoutRequestSigned': False,
            'logoutResponseSigned': False,
            'signMetadata': False,
            'wantAttributeStatement': False,
            'wantMessagesSigned': False,
            'wantAssertionsSigned': False,
            'wantNameId': True,
            'wantNameIdEncrypted': False,
            'wantAssertionsEncrypted': False,
            'signatureAlgorithm': 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256',
            'digestAlgorithm': 'http://www.w3.org/2001/04/xmlenc#sha256'
        },
        'contactPerson': {
            'technical': {
                'givenName': 'xxx',
                'emailAddress': 'xxx'
            },
            'support': {
                'givenName': 'xxx',
                'emailAddress': 'xxx'
            }
        },
        'organization': {
            'nl-NL': {
                'name': 'xxx',
                'displayname': 'xxx',
                'url': 'xxx'
            }
        }
    }
}

# Initializes toolkit with the dict provided.
auth = OneLogin_Saml2_Auth(req, settings_data)
jtamyrc commented 2 years ago

I check the source code from the error. It turns out the settings_data should be defined like below.

settings_data = {
    'strict': True,
    'debug': True,
    'sp': {
        'entityId': 'https://example.ngrok.io/metadata',
        'assertionConsumerService': {
            'url': 'https://example.ngrok.io/?acs',
            'binding': 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST'
        },
        'singleLogoutService': {
            'url': 'https://example.ngrok.io/?sls',
            'binding': 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect'
        },
        'NameIDFormat': 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified',
        'x509cert': 'xxx',
        'privateKey': ''
    },
    'idp': {
        'entityId': 'https://samltest.id/saml/idp',
        'singleSignOnService': {
            'url': 'https://samltest.id/idp/profile/SAML2/Redirect/SSO',
            'binding': 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect'
        },
        'singleLogoutService': {
            'url': 'https://samltest.id/idp/profile/SAML2/Redirect/SLO',
            'binding': 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect'
        },
        'x509cert': 'xxx'
    },
    'security': {
        'nameIdEncrypted': False,
        'authnRequestsSigned': False,
        'logoutRequestSigned': False,
        'logoutResponseSigned': False,
        'signMetadata': False,
        'wantAttributeStatement': False,
        'wantMessagesSigned': False,
        'wantAssertionsSigned': False,
        'wantNameId': True,
        'wantNameIdEncrypted': False,
        'wantAssertionsEncrypted': False,
        'signatureAlgorithm': 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256',
        'digestAlgorithm': 'http://www.w3.org/2001/04/xmlenc#sha256'
    },
    'contactPerson': {
        'technical': {
            'givenName': 'xxx',
            'emailAddress': 'xxx'
        },
        'support': {
            'givenName': 'xxx',
            'emailAddress': 'xxx'
        }
    },
    'organization': {
        'nl-NL': {
            'name': 'xxx',
            'displayname': 'xxx',
            'url': 'xxx'
        }
    }
}