Quickstart: Add sign-in with Microsoft to a Python web app
Welcome! This probably isn't the page you were expecting. While we work on a fix, this link should take you to the right article:
We apologize for the inconvenience and appreciate your patience while we work to get this resolved.
In this quickstart, you download and run a code sample that demonstrates how a Python web application can sign in users and get an access token to call the Microsoft Graph API. Users with a personal Microsoft Account or an account in any Azure Active Directory (Azure AD) organization can sign into the application.
See How the sample works for an illustration.
- An Azure account with an active subscription. Create an account for free.
- Python 2.7+ or Python 3+
- Flask, Flask-Session, requests
- MSAL Python
Step 1: Configure your application in Azure portal
For the code sample in this quickstart to work:
- Add a reply URL as
- Create a Client Secret.
- Add Microsoft Graph API's User.ReadBasic.All delegated permission.
Your application is configured with this attribute
Step 2: Download your project
Download the project and extract the zip file to a local folder closer to the root folder - for example, C:\Azure-Samples
Step 3: Run the code sample
You will need to install MSAL Python library, Flask framework, Flask-Sessions for server-side session management and requests using pip as follows:
pip install -r requirements.txt
app.pyfrom shell or command line:
This quickstart application uses a client secret to identify itself as confidential client. Because the client secret is added as a plain-text to your project files, for security reasons, it is recommended that you use a certificate instead of a client secret before considering the application as production application. For more information on how to use a certificate, see these instructions.
How the sample works
MSAL is the library used to sign in users and request tokens used to access an API protected by the Microsoft identity Platform. You can add MSAL Python to your application using Pip.
pip install msal
You can add the reference to MSAL Python by adding the following code to the top of the file where you will be using MSAL:
Help and support
If you need help, want to report an issue, or want to learn about your support options, see Help and support for developers.
Learn more about web apps that sign in users in our multi-part scenario series.