python-saml-flask is an abstraction of python-saml, to make for quick integration into flask apps (or django with a bit of work).
It is not an official extension, but acts just like one.
-
Save saml.py into your app somewhere (in this example its in a folder called lib)
-
Install
flask-login
andflask-saml
-
Add instantiation code:
#import from flask.ext.login import LoginManager from lib.saml import SamlManager #setup flask-login login_manager = LoginManager() login_manager.init_app(app) login_manager.login_view = '/saml/login' #setup saml manager saml_manager = SamlManager() saml_manager.init_app(app) @saml_manager.login_from_acs def acs_login(acs): # define login logic here depending on idp response # should call login_user() and redirect as necessary pass
-
Add settings and certs:
SAML_SETTINGS_PATH
- String - Optional- otherwise renders
saml_logout_successful.html
template
- otherwise renders
SAML_LOGOUT_PATH
- STRING, - Required- path to a folder named saml which has:
- settings.json
- advanced_settings.json
- a folder named 'certs' with all certs/keys
- path to a folder named saml which has:
-
Create Metadata and trade with IDP
from lib.saml import SamlRequest from flask import request @app.route('/saml/metadata') def metadata(): saml = SamlRequest(request) return saml.generate_metadata()
-
Define
acs_login
. The data you get back will depend on your IDP, so throw a debugger in there to see what was passed in. -
It should now work, you'll have to communicate with your IDP to finalize everything.
Contributions are welocme! Please follow these steps:
- Fork this repository
- Make your changes
- Submit PR