Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialization of OneLogin_Saml2_Settings #401

Open
mecampbellsoup opened this issue Feb 26, 2024 · 1 comment
Open

Serialization of OneLogin_Saml2_Settings #401

mecampbellsoup opened this issue Feb 26, 2024 · 1 comment

Comments

@mecampbellsoup
Copy link

mecampbellsoup commented Feb 26, 2024

We use django-allauth and are implementing support for customers/users bringing their own SAML IdP configurations.

We use OneLogin_Saml2_Settings in order to validate the SAML configurations they give to us.

However, I'm not seeing a clear and obvious way to have the OneLogin_Saml2_Settings object returned by OneLogin_Saml2_Settings(settings_input_from_customer) to give me back a serialized JSON or dict object that I can write to our DB to persist the configuration.

I'd imagine an API like OneLogin_Saml2_Settings._settings or something public-facing like OneLogin_Saml2_Settings.get_settings() that I can call on a valid instance to get back a mapping of the settings.

Am I missing something obvious?

As a result of not seeing an API for this, my code is doing something clunky like:

_settings = {
        "idp": {
			...
        },
        "sp": {
			...
        },
        "strict": True,
    }
# Initialization of the following object performs settings validation
OneLogin_Saml2_Settings(_settings)
return _settings
@pitbulk
Copy link
Contributor

pitbulk commented Jun 26, 2024

The toolkit contains idp_metadata_parser.py which basically allow you to get and parse any IdP SAML Metadata and transform it to a dict.

If you already have the Toolkit settings in a dict and you only want to validate, initializing the Settings object with your dict will do the trick as it internally call check_settings to validate the settings and if anything is wrong, will raise a OneLogin_Saml2_Error

So your code should look like the following:

try:
    OneLogin_Saml2_Settings(_settings)
except OneLogin_Saml2_Error as e:
    print e.code
    print e.message
    return None

return _settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants