Skip to content

Latest commit

 

History

History
105 lines (100 loc) · 4.64 KB

quickstart-v2-python-webapp.md

File metadata and controls

105 lines (100 loc) · 4.64 KB
title description ROBOTS author manager ms.author ms.custom ms.date ms.service ms.topic
Quickstart: Add sign-in with Microsoft to a Python web app
In this quickstart, learn how a Python web app can sign in users, get an access token from the Microsoft identity platform, and call the Microsoft Graph API.
NOINDEX
henrymbuguakiarie
CelesteDG
henrymbugua
devx-track-python, scenarios:getting-started, "languages:Python", mode-api
01/24/2023
identity-platform
quickstart

Quickstart: Add sign-in with Microsoft to a Python web app

[!div renderon="docs"] 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:

Quickstart: Add sign-in with Microsoft to a Python web app

We apologize for the inconvenience and appreciate your patience while we work to get this resolved.

[!div renderon="portal" class="sxs-lookup"] 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 Microsoft Entra organization can sign into the application.

See How the sample works for an illustration.

Prerequisites

Step 1: Configure your application in Azure portal

For the code sample in this quickstart to work:

  1. Add a reply URL as http://localhost:5000/getAToken.
  2. Create a Client Secret.
  3. Add Microsoft Graph API's User.ReadBasic.All delegated permission.

[!div class="nextstepaction"] Make these changes for me

[!div class="alert alert-info"] Already configured 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

[!div class="nextstepaction"] Download the code sample

[!NOTE] Enter_the_Supported_Account_Info_Here

Step 3: Run the code sample

  1. 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
  2. Run app.py from shell or command line:

    python app.py

    [!IMPORTANT] 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.

More information

How the sample works

Shows how the sample app generated by this quickstart works

Getting MSAL

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

MSAL initialization

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:

import msal

[!INCLUDE Help and support]

Next steps

Learn more about web apps that sign in users in our multi-part scenario series.

[!div class="nextstepaction"] Scenario: Web app that signs in users