Skip to main content

SAML 2.0 IdP and SP for Flask and Python 3

Project description

This Flask plugin provides functionality for creating both SAML Service Providers and Identity Providers. Applications can implement one or both of these providers.

flask-saml2 works with Flask 1.0+ and Python 3.6+.

This is a heavily modified fork of NoodleMarkets/dj-saml-idp which in turn is a fork of deforestg/dj-saml-idp which in turn is a fork of novapost/django-saml2-idp.


For a full description of how SAML works, please seek guides elsewhere on the internet. For a quick introduction, and a run through of some of the terminology used in this package, read on.

The SAML protocal is a conversation between two parties: Identity Providers (IdP) and Service Providers (SP). When an unauthenticated client (usually a browser) accesses a Service Provider, the Service Provider will make an authentication request (AuthnRequest), sign it using its private key, and then forward this request via the client to the Identity Provider. Once the client logs in at the central Identity Provider, the Identity Provider makes a response, signs it, and forwards this response via the client to the requesting Service Provider. The client is then authenticated on the Service Provider via the central Identity Provider, without the Service Provider having to know anything about the authentication method, or any passwords involved.

Example implementations

A minimal but functional example implementation of both a Service Provider and an Identity Provider can be found in the examples/ directory of this repository. To get the examples running, first clone the repository and install the dependencies:

$ git clone
$ cd flask-saml2
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install -e .
$ pip install -r tests/requirements.txt

Next, run the IdP and the SP in separate terminal windows:

$ cd flask-saml2
$ source venv/bin/activate
$ ./examples/
$ cd flask-saml2
$ source venv/bin/activate
$ ./examples/

Finally, navigate to http://localhost:9000/ to access the Service Provider landing page.


The test runner is pytest and we are using tox to run tests against different versions of Flask and Python. The test can be run locally using tox directly (preferably in a virtual environment):

$ pip install tox
$ tox


Distributed under the MIT License.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask-saml2-0.3.0.tar.gz (30.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page