djangosaml2 is a Python library that integrates `pysaml2` into Django applications, enabling SAML 2.0 based Single Sign-On (SSO). The current stable version is 1.12.0. It receives regular updates to support new Django and Python versions, often aligning with Django's release cycle.
pip install djangosaml2Verified import paths — ran on the pinned version, not inferred.
This quickstart outlines the essential `settings.py` and `urls.py` configurations for `djangosaml2`. It involves adding the app and authentication backend, defining `LOGIN_URL`, and setting up the `SAML_CONFIG` dictionary which holds all PySAML2 related configurations, including SP entity ID, endpoints, attribute mappings, and IdP metadata. Ensure `xmlsec1` is installed at the OS level and paths to certificates are correct.
Upgrade Python to 3.9+ and Django to 4.2+ (or compatible versions as per `djangosaml2`'s `requires_python` and release notes).
Install `xmlsec1` on your operating system (e.g., `apt-get install xmlsec1` on Debian/Ubuntu, `brew install xmlsec1` on macOS) and ensure the `xmlsec_binary` path in `SAML_CONFIG` is correct.
Upgrade Django to 3.1 or higher. If not possible, configure `allow_unsolicited` to `True` in your `pySAML2` configuration within `SAML_CONFIG` (though this might have security implications and should be evaluated carefully).
Instead of modifying `SAML_CONFIG` directly, use the `SAML_CONFIG_LOADER` setting to point to a callable that returns the `saml2.config.SPConfig` object dynamically, scoped to the current request.
Always use a unique attribute (e.g., 'email') for `SAML_DJANGO_USER_MAIN_ATTRIBUTE`. If using an attribute that might not be unique, consider implementing custom user lookup logic.