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
Copy file name to clipboardExpand all lines: README_B2C.md
+38-49Lines changed: 38 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,56 +5,51 @@ languages:
5
5
- html
6
6
products:
7
7
- azure-active-directory
8
-
description: "This sample demonstrates a Python web application calling a web api that is secured using Azure Active Directory."
8
+
description: "This sample demonstrates a Python web application calling a web API that is secured using Azure Active Directory."
9
9
urlFragment: ms-identity-python-webapp
10
10
---
11
11
# Integrating B2C feature of Microsoft identity platform with a Python web application
12
12
13
13
## About this sample
14
14
15
15
> This sample was initially developed as a web app to demonstrate how to
16
-
> [Integrate Microsoft Identity Platform with a Python web application](https://github.com/Azure-Samples/ms-identity-python-webapp/blob/master/README.md).
17
-
> The same code base can also be used to demonstrate how to
18
-
> Integrate B2C of Microsoft identity platform with a Python web application.
19
-
> All you need is some different steps to register your app in your own B2C tenant,
20
-
> and then feed those different settings into the configuration file of this sample.
16
+
> [integrate Microsoft identity platform with a Python web application](https://github.com/Azure-Samples/ms-identity-python-webapp/blob/master/README.md).
17
+
> The same code base can also be used to demonstrate how to integrate Azure Active Directory B2C
18
+
> in a Python web application. You need to follow a few different steps and register your app in your
19
+
> own B2C tenant, and then feed those different settings into the configuration file of this sample.
21
20
22
21
This sample covers the following:
23
22
24
-
* Update the application in Azure AD B2C
25
-
* Configure the sample to use the application
26
-
* Enable authentication in a web application using Azure Active Directory B2C
27
-
* Access a web API using Azure Active Directory B2C
28
-
23
+
* Update the application in Azure Active Directory B2C (Azure AD B2C)
24
+
* Configure the sample to use the application registration
25
+
* Enable authentication in a web application using Azure AD B2C
26
+
* Access a web API protected by Azure AD B2C
29
27
30
28
### Overview
31
29
32
-
This sample demonstrates a Python web application that signs-in users with the Microsoft identity platform and calls another web api.
30
+
This sample demonstrates a Python web application that signsin users with the Microsoft identity platform and then calls a web API.
33
31
34
32
1. The python web application uses the Microsoft Authentication Library (MSAL) to obtain an access token from the Microsoft identity platform (formerly Azure AD v2.0):
35
-
2. The access token is used as a bearer token to authenticate the user when calling the web api.
33
+
2. The access token is used as a bearer token to authenticate the user when calling the web API.
36
34
37
35

38
36
39
-
40
37
## Prerequisites
41
38
42
-
1.[Create an Azure Active Directory B2C tenant](https://docs.microsoft.com/en-us/azure/active-directory-b2c/tutorial-create-tenant)
43
-
1.[Register an application in Azure Active Directory B2C](https://docs.microsoft.com/en-us/azure/active-directory-b2c/tutorial-register-applications).
44
-
1.[Create user flows in Azure Active Directory B2C](https://docs.microsoft.com/en-us/azure/active-directory-b2c/tutorial-create-user-flows)
39
+
1.[Create an Azure AD B2C tenant](https://docs.microsoft.com/azure/active-directory-b2c/tutorial-create-tenant)
40
+
1.[Register an application in Azure AD B2C](https://docs.microsoft.com/azure/active-directory-b2c/tutorial-register-applications)
41
+
1.[Create user flows in Azure AD B2C](https://docs.microsoft.com/azure/active-directory-b2c/tutorial-create-user-flows)
45
42
1. Have [Python 2.7+ or Python 3+](https://www.python.org/downloads/) installed
46
43
47
-
48
44
## Update the application
49
45
50
46
In the tutorial that you completed as part of the prerequisites, you [added a web application in Azure AD B2C](https://docs.microsoft.com/azure/active-directory-b2c/tutorial-register-applications).
51
-
To enable communication with the sample in this tutorial, you need to add a redirect URI to that application in Azure AD B2C.
52
-
53
-
* Modify an existing or add a new **Reply URL**, for example `http://localhost:5000/getAToken` or `https://your_domain.com:5000/getAToken`.
54
-
You could use any port or any path. Later we will set this sample to match what you register here.
55
-
* On the properties page, record the application ID that you'll use when you configure the web application.
56
-
* Also generate a key (client secret) for your web application. Record the key that you'll use when you configure this sample.
47
+
To enable communication with the sample in this tutorial, you need to add a redirect URI to the registration in Azure AD B2C.
57
48
49
+
* Modify an existing or add a new **Redirect URI**, for example `http://localhost:5000/getAToken` or `https://your_domain.com:5000/getAToken`.
50
+
* You can use any port or path. Later, we'll configure this sample to match what you register here.
51
+
* On the properties page, record the **Application (client) ID** that you'll use when you configure the web application.
52
+
* Generate a **client secret** for your web application. Record the secret's value for later use when you configure this sample.
58
53
59
54
## Configure the sample
60
55
@@ -66,10 +61,9 @@ From your shell or command line:
> Given that the name of the sample is quite long, you might want to clone it in a folder close to the root of your hard drive, to avoid file name length limitations when running on Windows.
64
+
...or download and extract the repository's .ZIP archive.
72
65
66
+
> TIP: To avoid hitting path length restrictions when running on Windows, you might want to clone the sample in a folder close to the root of your hard drive.
73
67
74
68
### Step 2: Install sample dependency
75
69
@@ -79,11 +73,9 @@ Install the dependencies using pip:
79
73
$ pip install -r requirements.txt
80
74
```
81
75
82
-
### Step 3: Configure the sample to use your Azure AD tenant
83
-
84
-
In the steps below, "ClientID" is the same as "Application ID" or "AppId".
76
+
### Step 3: Configure the sample to use your Azure AD B2C tenant
85
77
86
-
#### Configure the pythonwebapp project
78
+
Configure the pythonwebapp project by making the following changes.
87
79
88
80
> Note: if you used the setup scripts, the changes below may have been applied for you
89
81
@@ -92,27 +84,26 @@ In the steps below, "ClientID" is the same as "Application ID" or "AppId".
92
84
93
85
* Update the value of `b2c_tenant` with the name of the Azure AD B2C tenant that you created.
94
86
For example, replace `fabrikamb2c` with `contoso`.
95
-
* Replace the value of `CLIENT_ID` with the application ID that you recorded.
96
-
* Replace the value of `CLIENT_SECRET` with the key that you recorded.
97
-
* Replace the value of `signupsignin_user_flow` with `b2c_1_signupsignin1`.
98
-
* Replace the value of `editprofile_user_flow` with `b2c_1_profileediting1`.
99
-
* Replace the value of `resetpassword_user_flow` with `b2c_1_passwordreset1`.
100
-
* Replace the value of `REDIRECT_PATH` with the path part you set up in **Reply URL**.
87
+
* Replace the value of `CLIENT_ID` with the Application (client) ID that you recorded.
88
+
* Replace the value of `CLIENT_SECRET` with the client secret that you recorded.
89
+
* Replace the value of `signupsignin_user_flow` with `B2C_1_signupsignin1`.
90
+
* Replace the value of `editprofile_user_flow` with `B2C_1_profileediting1`.
91
+
* Replace the value of `resetpassword_user_flow` with `B2C_1_passwordreset1`.
92
+
* Replace the value of `REDIRECT_PATH` with the path part you set up in **Redirect URIs**.
101
93
For example, `/getAToken`. It will be used by this sample app to form
102
-
an absolute URL which matches your full **Reply URL**.
94
+
an absolute URL which matches your full **Redirect URI**.
103
95
* You do not have to configure the `ENDPOINT` and `SCOPE` right now
104
96
105
-
106
97
## Enable authentication
107
98
108
-
Run app.py from shell or command line. Note that the port needs to match what you've set up in your **Reply URL**:
99
+
Run app.py from shell or command line. Note that the port needs to match what you've set up in your **Redirect URI**:
100
+
109
101
```Shell
110
-
$ flask run --port 5000
102
+
$ flask run --host localhost --port 5000
111
103
```
112
104
113
105
You should now be able to visit `http://localhost:5000` and use the sign-in feature.
114
-
This is how you enable authentication in a web application using Azure Active Directory B2C.
115
-
106
+
This is how you enable authentication in a web application using Azure AD B2C.
116
107
117
108
## Access a web API
118
109
@@ -129,8 +120,7 @@ Now you can configure this sample to access that web API.
129
120
For example, write them as `["demo.read", "demo.write"]`.
130
121
131
122
Now, re-run your web app sample, and you will find a new link showed up,
132
-
and you can access the web API using Azure Active Directory B2C.
133
-
123
+
and you can access the web API using Azure AD B2C.
134
124
135
125
## Community Help and Support
136
126
@@ -150,9 +140,8 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
150
140
151
141
## More information
152
142
153
-
For more information, see MSAL.Python's [conceptual documentation]("https://github.com/AzureAD/microsoft-authentication-library-for-python/wiki"):
154
-
143
+
For more information about MSAL for Python,see its [conceptual documentation wiki](https://github.com/AzureAD/microsoft-authentication-library-for-python/wiki):
155
144
156
-
For more information about web apps scenarios on the Microsoft identity platform see [Scenario: Web app that calls web APIs](https://docs.microsoft.com/en-us/azure/active-directory/develop/scenario-web-app-call-api-overview)
145
+
For more information about web app scenarios on the Microsoft identity platform, see [Scenario: Web app that calls web APIs](https://docs.microsoft.com/azure/active-directory/develop/scenario-web-app-call-api-overview)
157
146
158
-
For more information about how OAuth 2.0 protocols work in this scenario and other scenarios, see [Authentication Scenarios for Azure AD](http://go.microsoft.com/fwlink/?LinkId=394414).
147
+
For more information about how OAuth 2.0 protocols work in this and other scenarios, see [Authentication Scenarios for Azure AD](http://go.microsoft.com/fwlink/?LinkId=394414).
0 commit comments