Registry / security / flask-saml2

flask-saml2

JSON →
library0.3.0pypypiunverified

Flask-SAML2 is a library for adding SAML 2.0 authentication to Flask applications, supporting both Identity Provider (IdP) and Service Provider (SP) roles. The current version is 0.3.0, released sporadically with infrequent updates.

pip install flask-saml2
INSTALL
IMPORT
SIG · FLASK-SAML2
F
flask-saml2
securitypythonv0.3.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SAMLServiceProvider
from flask_saml2 import SAMLServiceProvider
from flask_saml2.sp import SAMLServiceProvider

Minimal Flask app with SAML SP, referencing IdP metadata URL.

from flask import Flask from flask_saml2.sp import SAMLServiceProvider import os app = Flask(__name__) app.secret_key = 'replace-with-a-secret' sp_config = { 'acs_url': 'http://localhost:5000/acs', 'entity_id': 'http://localhost:5000/metadata', 'metadata_url': 'http://localhost:5000/metadata', 'idp_metadata_url': 'https://example.com/idp/metadata', } sp = SAMLServiceProvider(sp_config) app.register_blueprint(sp.blueprint) if __name__ == '__main__': app.run(debug=True)
Debug
Known issues
gotchaThe library does not support Flask's built-in session unless you configure a server-side session backend (e.g., Flask-Session). SAML authentication state is stored in the session, which can overflow client-side cookie sessions.
fix
Use a server-side session extension like Flask-Session with Redis or filesystem.
affects: all
gotchaMetadata fetching is done at startup; if the IdP metadata URL is temporarily unreachable, the application fails to start. The library does not retry or cache gracefully.
fix
Pre-fetch and cache metadata locally, or wrap initialization with error handling.
affects: all
breakingIn version 0.3.0, the `SAMLServiceProvider` constructor no longer accepts a Flask app directly; you must register the blueprint manually.
fix
Call `app.register_blueprint(sp.blueprint)` after creating the SP instance.
affects: >=0.3.0
Upgrade
Version history
0.3.0latest on PyPI · released Dec 30, 2019
Audit
Dependencies
FlaskrequiredRequired web framework
lxmlrequiredXML parsing for SAML messages
isodaterequiredISO 8601 date handling
cryptographyrequiredSAML signature and encryption
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
flask-saml2 — pip install flask-saml2 · libregistry