Usage
Installation
xmlsec1 is required by pysaml2:
$ apt install xmlsec1
// or
$ yum install xmlsec1
// or
$ brew install xmlsec1
Install using pip:
$ pip install djangosaml
Add ‘djangosaml’ to your INSTALLED_APPS setting.
INSTALLED_APPS = [
...
'djangosaml',
]
Now update your root urls.py:
urlpatterns = [
...
path('djangosaml/', include('djangosaml.urls')),
]
Demo using mocksaml.com
Go to https://mocksaml.com/ and click Download Metadata button to download the metadata and save it as mock-saml-metadata.xml into project root directory.
In settings.py, add the SAML2 related configuration.
SAML2_AUTH = {
# Path of metadata.xml file downloaded from https://mocksaml.com/
'METADATA_LOCAL_FILE_PATH': BASE_DIR / 'mock-saml-metadata.xml',
'ENTITY_ID': 'http://localhost:8000/djangosaml/acs/',
# This is mocksaml.com's Email/UserName/FirstName/LastName to corresponding SAML2 userprofile attributes.
'ATTRIBUTES_MAP': {
'email': 'email',
'username': 'id',
'first_name': 'firstName',
'last_name': 'lastName',
},
}
Run the server
$ python manage.py runserver
That is it, now you can now login using http://localhost:8000/djangosaml/login/