This project implements a Django REST Framework project configured as a SAML2 Service Provider (SP) that integrates SAML2 and Django REST Framework JWT, using https://stubidp.sustainsys.com/
as the Identity Provider (IdP).
- Python 3.6 or higher
- Virtualenv
- pip
-
Clone the repository:
git clone https://github.com/sinachaichi/django-rest-jwt-saml2 cd django-saml2-sp
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required packages:
pip install -r requirements.txt
-
Apply migrations and run server:
python manage.py migrate python manage.py runserver 8000
Django Settings
Update your settings.py with the necessary configurations for SAML2 and JWT integration.
Also go to the https://stubidp.sustainsys.com/Metadata/BrowserFriendly and downlod the metadata xml file
and put it in the saml2 directory. Or instead you can change the metadata
config inside SAML_CONFIG
as:
'metadata': {
'remote': [{'url': 'https://stubidp.sustainsys.com/Metadata/BrowserFriendly'},]
},
You need to generate a private key and public certificate:
openssl req -new -x509 -key private.key -out public.cert -days 365
Place the generated private.key and public.cert in the certificates directory.
http://localhost:8000/api/saml/login/
The login will redirect to the Sustainsys Stub IdP for authentication. After successful authentication, it will redirect back to your SP and process the SAML response.
For more details on configuration and usage, refer to the djangosaml2 documentation: https://djangosaml2.readthedocs.io/index.html