This sample demonstrates how to authenticate a Django web app using Azure Active Directory Authentication.
- Register an Azure AD application with web application authentication and a reply URL of
https://127.0.0.1:8000/complete/aad
, and generate a client secret. - Rename
.env.example
to.env
and populate it with the AAD_CLIENT_ID, AAD_TENANT_ID, AAD_CLIENT_SECRET
- Have a Python environment, you can use miniconda, venv, whatever you prefer, as long as you are running Python 3.x
- Install the needed dependencies with
pip install -r requirements.txt
- Run
python manage.py migrate
to migrate the database schema - Run
python manage.py runsslserver 8000
to run the server, or open in VSCode and hit F5
Open the browser, and visit https://127.0.0.1
and sign in.
To run the sample with docker
:
- Rename the
.env.example
file to.env
, change the environment variables, and register the URLs above. - Run
sh exec.sh
to build and run the docker image in Linux or run.\exec.ps1
to build and run the docker image on Windows. - Use either nginx or ngrok or deploy to Azure App Service to expose the site on https, and modify the app registration reply URL accordingly. Azure AD requires your app to run on https unless it is localhost.