Welcome to the Microsoft Identity Platform Python Code Samples repository!
This repository provides a comprehensive set of end-to-end samples demonstrating how to integrate Microsoft Entra ID authentication and authorization into Python applications. The samples are organized by scenario and technology, making it easy to find the right starting point for your needs.
The samples are grouped by application type and scenario:
| Folder | App description | Authentication libraries |
|---|---|---|
| flask-web-app | Multi-purpose Flask web application with Microsoft Entra sign-in, External ID, B2C support | ms-identity-python[flask] MSAL Python |
| django-web-app | Multi-purpose Django web application with Microsoft Entra sign-in, External ID, B2C support | ms-identity-python[django] MSAL Python |
| console-app-device-code | Console application using device code flow for user authentication | MSAL Python |
| cli-access-protected-api | CLI application accessing protected APIs using client credentials | MSAL Python |
| protect-function-app | Azure Function protected with Easy Auth and scope validation | Azure Functions |
| daemon-console-app | Daemon applications using client credentials (secret/certificate) | MSAL Python |
| on-behalf-of-flow | Multi-tier application demonstrating On-Behalf-Of (OBO) flow | MSAL Python |
Each folder contains one or more samples, each with its own README and instructions.
- Browse the folders above to find the app type/scenario that matches your use case.
- Read the sample's README.md for prerequisites, setup instructions, and code walkthroughs.
- Clone and run the sample following the provided steps.
All samples are built with Python 3.8+ and the latest Microsoft Authentication Library (MSAL) for Python.
- Configuration is managed via
.envfiles and environment variables. - Each sample includes multiple
.env.sampletemplates for different identity providers (Entra ID, External ID, B2C). - Secrets and credentials should never be committed to source control. Use environment variables or Azure Key Vault for sensitive data.
We welcome contributions!
Please see CONTRIBUTING.md for guidelines on submitting new samples or improvements.
- For questions, open an issue.
- For Microsoft identity platform documentation, visit learn.microsoft.com/entra/identity-platform.
This project is licensed under the MIT License.
- Documentation on learn.microsoft.com
- Authentication library source code on GitHub
- Python Package Index