Louis Login Backend offers a comprehensive workflow that ensures a seamless Single Sign-On (SSO) experience. The system operates through a series of steps starting from the client application check to email verification and eventual redirection after verification.
For a detailed step-by-step breakdown and to understand how the API endpoints function within this process, please refer to the WORKFLOW documentation.
Note: If you're using a
devcontainer
, the steps involving virtual environments are not necessary. However, for developers not usingdevcontainer
, the virtual environment setup remains relevant.
Follow the instructions below to set up a Quart application in your environment:
Before you start, ensure you have pip
installed. Check its version with:
pip --version
It's a good practice to keep your tools updated. Run the following command:
python -m pip install --upgrade pip setuptools virtualenv
To create an isolated environment for your project, set up a virtual environment named venv
(or another name you prefer):
python -m venv venv
Before installing any packages, activate your virtual environment:
On Windows:
venv\Scripts\activate
Ensure you have a requirements.txt
file in your project directory. Install all dependencies with:
pip install -r requirements.txt
Now, you can proceed with running your Quart application or any other tasks. Always ensure that your virtual environment is activated when working on the project to maintain dependencies separately from your global Python environment.
To run the Quart application correctly, it requires some environment variables to be set. Follow the steps below to set them up:
.env
..env
file using your preferred text editor.Now, define each of the following variables:
MEMBRANE_CORS_ALLOWED_ORIGINS=http://localhost:3000
MEMBRANE_FRONTEND=http://localhost:3000
MEMBRANE_SECRET_KEY=your_secret_key
MEMBRANE_CLIENT_PUBLIC_KEYS_DIRECTORY=keys/
MEMBRANE_SERVER_PRIVATE_KEY=keys/server_private_key.pem
MEMBRANE_SERVER_PUBLIC_KEY=keys/server_public_key.pem
MEMBRANE_COMM_CONNECTION_STRING=your_azure_communication_service_connection_string
MEMBRANE_SENDER_EMAIL=DoNotReply@your_domain.com
MEMBRANE_JWT_ACCESS_TOKEN_EXPIRE_SECONDS=300
MEMBRANE_JWT_EXPIRE_SECONDS=300
MEMBRANE_SESSION_LIFETIME_SECONDS=300
MEMBRANE_SESSION_COOKIE_SECURE=true
MEMBRANE_SESSION_TYPE=null
MEMBRANE_TOKEN_BLACKLIST=
MEMBRANE_APP_ID_FIELD=app_id
MEMBRANE_DATA_FIELD=data
MEMBRANE_REDIRECT_URL_FIELD=redirect_url
MEMBRANE_ENCODE_ALGORITHM=RS256
MEMBRANE_ALLOWED_EMAIL_DOMAINS_PATTERN=^[a-zA-Z0-9._+]+@(?:gc\.ca|canada\.ca|inspection\.gc\.ca)$
MEMBRANE_EMAIL_SUBJECT=Please Verify Your Email Address
MEMBRANE_EMAIL_SEND_HTML_TEMPLATE=<html><h1>{}</h1></html>
MEMBRANE_EMAIL_SEND_POLLER_WAIT_TIME=2
MEMBRANE_EMAIL_SEND_TIMEOUT_SECONDS=30
MEMBRANE_EMAIL_SEND_SUCCESS=Valid email address, Email sent with JWT link
MEMBRANE_GENERIC_500_ERROR_FIELD=error
MEMBRANE_GENERIC_500_ERROR=An unexpected error occurred. Please try again later.
MEMBRANE_LOGGING_LEVEL=DEBUG
MEMBRANE_LOGGING_FORMAT=[%(asctime)s] [%(levelname)s] [%(filename)s:%(lineno)d:%(funcName)s] - %(message)s
MEMBRANE_HEALTH_MESSAGE=ok
MEMBRANE_WORKERS=4
MEMBRANE_KEEP_ALIVE=5
Once you have defined all these variables, save and close the .env
file. The Quart application will now use these environment variable values when it runs.
With your virtual environment activated, start the main app.py
:
quart run
Open a separate terminal or command prompt. Make sure the virtual environment is activated and then run the testapp1.py
to simulate a client application:
quart --app testapp1.py run --port=4000
Ensure that the Membrane Frontend React application is running, ideally on localhost
. This application will serve as the frontend interface for users to provide their email addresses to Membrane Backend.
You can now interact with both the main Quart application and the client simulator to validate the entire authentication flow.
Run the initialization script:
./init_project.sh <your-test-app-id>
This script will:
keys
folder for both the server and the specified app id..env.template
to .env
..env.tests.template
to .env.tests
.init.log
.Open the .env
file generated in the project's root directory.
Generate a secret key:
openssl rand -hex 32
Populate the following variables in the .env
file. Example for tests and dev:
# Mandatory
MEMBRANE_CORS_ALLOWED_ORIGINS=http://localhost:3000
MEMBRANE_FRONTEND=http://localhost:3000
MEMBRANE_SECRET_KEY=your_secret_key
MEMBRANE_CLIENT_PUBLIC_KEYS_DIRECTORY=keys/
MEMBRANE_SERVER_PRIVATE_KEY=keys/server_private_key.pem
MEMBRANE_SERVER_PUBLIC_KEY=keys/server_public_key.pem
MEMBRANE_COMM_CONNECTION_STRING=your_azure_communication_service_connection_string
MEMBRANE_SENDER_EMAIL=DoNotReply@your_domain.com
# Optional
# MEMBRANE_JWT_ACCESS_TOKEN_EXPIRE_SECONDS=
# MEMBRANE_JWT_EXPIRE_SECONDS=
# MEMBRANE_SESSION_LIFETIME_SECONDS=
# MEMBRANE_SESSION_COOKIE_SECURE=
# MEMBRANE_SESSION_TYPE=
# MEMBRANE_TOKEN_BLACKLIST=
# MEMBRANE_APP_ID_FIELD=
# MEMBRANE_DATA_FIELD=
# MEMBRANE_REDIRECT_URL_FIELD=
# MEMBRANE_ENCODE_ALGORITHM=
# MEMBRANE_ALLOWED_EMAIL_DOMAINS_PATTERN=
# MEMBRANE_EMAIL_SUBJECT=
# MEMBRANE_EMAIL_SEND_SUCCESS=
# MEMBRANE_EMAIL_SEND_POLLER_WAIT_TIME=
# MEMBRANE_EMAIL_SEND_TIMEOUT_SECONDS=
# MEMBRANE_EMAIL_SEND_HTML_TEMPLATE=
# MEMBRANE_GENERIC_500_ERROR_FIELD=
# MEMBRANE_GENERIC_500_ERROR=
# MEMBRANE_LOGGING_LEVEL=
# MEMBRANE_LOGGING_FORMAT=
# MEMBRANE_HEALTH_MESSAGE=
# MEMBRANE_WORKERS=
# MEMBRANE_KEEP_ALIVE=
Build the Docker image:
docker build -t your_app_name .
Set your desired port number:
export PORT=<your_port_here>
Run the Docker container:
docker run -v $(pwd)/keys:/app/keys -p $PORT:$PORT -e PORT=$PORT --env-file .env your_app_name