This project implements a Flask-based SAML2 Service Provider (SP) with Single Logout (SLO) capability. It is designed to test and demonstrate the integration of SAML2 authentication and Single Logout functionality using the Python library pysaml2.
- SAML2 authentication.
- Single Logout (SLO) service.
- Debug mode for detailed logging.
- Integration with Identity Providers (IdP) supporting SAML2.
- Python 3.x
- Flask
- pysaml2
- A valid SAML2 Identity Provider (IdP) for testing.
-
Clone the repository:
git clone https://github.com/flengyel/pysaml2-service-provider.git
-
Install the required dependencies:
pip install -r requirements.txt
Note: You might need to create and activate a virtual environment before running the above command.
- Update
conf/sp_conf.py
with the appropriate SAML2 configuration for your environment. - Replace
BASE_URL
inconf/sp_conf.py
with your service provider's base URL. - Install an x509 signing certificate and in
conf/sp_cert.pem
andconf/sp_key.pem
, respectively. - Change
server.pem
andserver.key
at the end ofsp.py
to refer to the server certificate and key for this service provider. - The service provider metadata will be accessible from
BASE_URL/saml/metadata
while the service provider runs. - Install your Identity Provider (IdP) metadata in
conf/idp-metadata.xml
- Configure your Identity Provider (IdP) to trust this Service Provider using the service provider metadata at
BASE_URL/saml/metadata
. - Consider augmenting the service provider metadata with
ResponseLocation
set equal to theSingleLogout
Location
value (the same endpoint).
-
Run the Flask application:
source bin/activate python sp.py
-
Access the application at
https://BASE_URL:8443
(or your configured URL and port).
Use the --debug
flag when starting the application to enable detailed logging:
python sp.py --debug
- Navigate to the main page (
/
route). - Click 'Login via SAML' to authenticate using the configured IdP.
- After authentication, user details will be displayed with a logout option.
- Click 'Logout' to initiate the Single Logout process.
Contributions to this project are welcome. Please ensure to follow the guidelines provided in CONTRIBUTING.md.
This project is licensed under the MIT license. See the LICENSE file for details.
- Florian Lengyel, CUNY
- ChatGPT4
- Contributors to the pysaml2 library