This guide shows how to integrate Flask with Monosign using SAML 2.0. Monosign acts as the Identity Provider (IdP), and the Flask sample acts as the Service Provider (SP). The user signs in through Monosign and returns to Flask, where the verified SAML NameID is displayed.
The sign-in flow was verified with the Flask sample at https://localhost:8443. For your deployment, use a browser-accessible HTTPS origin throughout the configuration. The reference screenshots illustrate the Monosign navigation, and application names and tenant values may vary.
Download the Flask sample application
The ZIP includes the ready-to-run Flask SAML sample, the setup guide, and the .env.example configuration template. Extract it and follow step 5 to run the app.
Prerequisites
Python 3.11 or later, uv, a browser-accessible HTTPS address for Flask, and access to the Monosign Management Portal.
Instructions
Creating an Application on Monosign
Creating the SAML Key on Monosign
Configuring the SAML Settings on Monosign
Assigning a User to the Flask Application
Configuring Single Sign-On for Flask
Sign-In Test
1- Creating an Application on Monosign
Open Applications from the left menu and select Add New.
Select Create from scratch.
Enter the application details and select Next.
Property | Value | Description |
|---|---|---|
Name | Flask SAML | The display name shown in Monosign. |
Type | Web | The sample runs in the browser. |
Url |
| The Flask home page. Replace the example hostname with your HTTPS origin. |
Logo | Optional | Upload an application logo if desired. |
On the Access tab, restrict access to assigned users and select Create Application.
2- Creating the SAML Key on Monosign
Open the application, select Keys, and choose Add New Access Key.
Select SAML as the key type and create the key. The key details show the IdP Entity Id, Sign On Service, metadata URL, and certificate download. You will use these in step 5.
3- Configuring the SAML Settings on Monosign
On the SAML key, select Configure, open SAML Settings → Configuration, enter the values below, and select Update.
Property | Flask example | Description |
|---|---|---|
Assertion Consumer Url |
| Flask receives the SAML Response here via HTTP POST. |
Audience |
| The Flask SP Entity ID. Use the exact metadata URL. |
Entity Id (SP configuration) |
| Use the same SP value as Audience when this field is shown. The IdP Entity Id copied from the key details is a separate value. |
ACS Validation Mode | Enforce | Rejects AuthnRequests that specify an unregistered ACS URL. If the same SP uses another ACS URL, register it under Additional Assertion Consumer Urls. |
NameId Format | System Default (unspecified) | Matches the sample SP metadata. |
Name Id | Example source for the identifier displayed by Flask. Choose a populated field for your assigned users. |
For a localhost test, use https://localhost:8443/saml/acs and https://localhost:8443/saml/metadata. The sample expects a signed SAML Response and an unencrypted assertion. It displays NameID, so no additional attribute mapping is required.
4- Assigning a User to the Flask Application
Open Assignments and select Assign a User.
Search for the test user, check the assignment expiration date, then save. If Name ID is set to Email, confirm that the user has an email address.
5- Configuring Single Sign-On for Flask
Download Flask-SAML.zip, extract it, and open the Flask-SAML folder. Install the locked dependencies, create the local configuration file, and generate a session secret.
uv sync --locked --no-dev cp .env.example .env uv run --locked --no-dev python -c 'import secrets; print(secrets.token_hex(32))'
Download the public signing certificate from the SAML key details. Set these values in .env.
Variable | Value | Source |
|---|---|---|
PUBLIC_ORIGIN |
| Your public Flask HTTPS origin. |
FLASK_SECRET_KEY | Generated session secret | Output of the command above. |
IDP_ENTITY_ID | Entity Id | Monosign SAML key details or IdP metadata. |
IDP_SSO_URL | Sign On Service | Use the HTTP-Redirect binding from the IdP metadata. |
IDP_CERT_FILE |
| Path to the downloaded public PEM signing certificate. |
With an HTTPS reverse proxy on the same host, preserve the public Host header and run Gunicorn on loopback.
uv run --locked --no-dev --env-file .env gunicorn --bind 127.0.0.1:8000 'app:create_app()'
For a workstation test, set PUBLIC_ORIGIN=https://localhost:8443 and use the TLS listener command in the bundled README with a certificate trusted by the browser. Open /saml/metadata to verify that the generated SP Entity ID and ACS match step 3. Restart Gunicorn after editing .env.
6- Sign-In Test
Open the Flask home page in a private browser window and select Sign in with Monosign.
Authenticate as the assigned user using a method available in your Monosign tenant. An existing Monosign session may skip this prompt.
After authentication, Monosign sends the SAML Response to Flask. Confirm that You’re signed in appears and the displayed NameID matches the configured source for the test user.
Select Sign out of Flask to end the local session. Open a fresh private window to test again without reusing a Monosign session.
Troubleshooting
Symptom | Cause | Solution |
|---|---|---|
Flask returns 503 during sign-in. | The three IdP settings are empty. | Complete step 5 and restart Gunicorn. |
Monosign rejects the ACS. | The configured URL differs from the AuthnRequest. | Compare the scheme, host, port, and path with the Flask SP metadata in step 3. |
Flask reports SAML validation failure. | The issuer, signing certificate, signature, or Audience differs from the configuration. | Compare steps 3 and 5 against the SAML key and SP metadata. Check that the Response is signed and the server clocks agree. |
The sign-in transaction is invalid or expired. | The browser lost the session cookie or the transaction expired. | Start again from Flask using the same HTTPS origin and a browser-trusted certificate. |
A user cannot sign in. | The user is unassigned or the assignment expired. | Check the Monosign assignment in step 4. |











