You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
17
+
In this quickstart, you download and run a code sample that demonstrates how a Python web application can sign in users and 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.
18
18
19
-
See [How the sample works](#how-the-sample-works) for an illustration.
20
-
21
-
## Prerequisites
22
-
23
-
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
24
-
-[Python 2.7+](https://www.python.org/downloads/release/python-2713) or [Python 3+](https://www.python.org/downloads/release/python-364/)
The following diagram displays how the sample app works:
27
20
21
+

28
22
29
-
## Register and download your quickstart app
23
+
1. The application uses the [`identity` package](https://pypi.org/project/identity/) to obtain an access token from the Microsoft Identity platform.
24
+
2. The access token is used as a bearer token to authenticate the user when calling the Microsoft Graph API.
30
25
31
-
You have two options to start your quickstart application: express (Option 1), and manual (Option 2)
32
26
33
-
### Option 1: Register and auto configure your app and then download your code sample
34
-
35
-
1. Go to the <ahref="https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/applicationsListBlade/quickStartType/PythonQuickstartPage/sourceType/docs"target="_blank">Azure portal - App registrations</a> quickstart experience.
36
-
1. Enter a name for your application and select **Register**.
37
-
1. Follow the instructions to download and automatically configure your new application.
27
+
## Prerequisites
38
28
39
-
### Option 2: Register and manually configure your application and code sample
29
+
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
30
+
- An Azure Active Directory (Azure AD) tenant. For more information on how to get an Azure AD tenant, see [how to get an Azure AD tenant.](/azure/active-directory/develop/quickstart-create-new-tenant)
31
+
-[Python 3.7+](https://www.python.org/downloads/)
40
32
41
-
####Step 1: Register your application
33
+
## Step 1: Register your application
42
34
43
-
To register your application and add the app's registration information to your solution manually, follow these steps:
35
+
Follow these steps to register your application in the Azure portal:
44
36
45
37
1. Sign in to the <ahref="https://portal.azure.com/"target="_blank">Azure portal</a>.
46
38
1. If you have access to multiple tenants, use the **Directory + subscription** filter :::image type="icon" source="../../media/common/portal-directory-subscription-filter.png" border="false"::: in the top menu to select the tenant in which you want to register an application.
-`Enter_the_Application_Id_here` - is the Application ID for the application you registered.
84
-
-`Enter_the_Client_Secret_Here` - is the **Client Secret** you created in **Certificates & Secrets** for the application you registered.
85
-
-`Enter_the_Tenant_Name_Here` - is the **Directory (tenant) ID** value of the application you registered.
75
+
1. Create a *.env* file in the root folder of the project using *.env.sample* as a guide.
86
76
87
-
#### Step 4: Run the code sample
77
+
```python
78
+
TENANT_ID=<tenant id>
79
+
CLIENT_ID=<client id>
80
+
CLIENT_SECRET=<client secret>
81
+
```
88
82
89
-
1. You will need to install MSAL Python library, Flask framework, Flask-Sessions for server-side session management and requests using pip as follows:
83
+
* Set the value of `TENANT_ID` to the **Directory (tenant) ID** of the registered application, also available on the overview page.
84
+
* Set the value of `CLIENT_ID` to the **Application (client) ID**for the registered application, available on the overview page.
85
+
* Set the value of `CLIENT_SECRET` to the client secret you created in**Certificates & Secrets**for the registered application.
86
+
87
+
The environment variables are referenced in*app_config.py*, and are kept in a separate *.env*file to keep them out of source control. The provided *.gitignore*file prevents the *.env*filefrom being checked in.
2. Run the app fromthe command line, specifying the host and port to match the redirect URI:
96
102
97
103
```shell
98
-
python app.py
104
+
python3 -m flask run --host=localhost --port=5000
99
105
```
100
106
101
107
> [!IMPORTANT]
102
108
> 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](../../active-directory-certificate-credentials.md).
103
109
104
-
## More information
105
-
106
-
### How the sample works
107
-

108
-
109
-
### Getting MSAL
110
-
MSAL is the library used to sign in users and request tokens used to access an API protected by the Microsoft identity Platform.
111
-
You can add MSAL Python to your application using Pip.
112
-
113
-
```Shell
114
-
pip install msal
115
-
```
116
-
117
-
### MSAL initialization
118
-
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:
119
-
120
-
```Python
121
-
import msal
122
-
```
123
110
124
111
[!INCLUDE [Help and support](../../../../../includes/active-directory-develop-help-support-include.md)]
125
112
@@ -129,3 +116,6 @@ Learn more about web apps that sign in users in our multi-part scenario series.
129
116
130
117
> [!div class="nextstepaction"]
131
118
> [Scenario: Web app that signs in users](../../scenario-web-app-sign-user-overview.md)
119
+
120
+
> [!div class="nextstepaction"]
121
+
> [Scenario: Web app that calls web APIs](../../scenario-web-app-call-api-overview.md)
0 commit comments