Skip to content

Commit f6da22b

Browse files
authored
Merge pull request #32 from mmacy/b2c-var-reorder
Reorder config vars + comment edit
2 parents f8249a3 + ffbf308 commit f6da22b

File tree

4 files changed

+66
-76
lines changed

4 files changed

+66
-76
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,10 @@ In the steps below, "ClientID" is the same as "Application ID" or "AppId".
135135
$ pip install -r requirements.txt
136136
```
137137

138-
Run app.py from shell or command line. Note that the port needs to match what you've set up in your redirect_uri:
138+
Run app.py from shell or command line. Note that the host and port values need to match what you've set up in your redirect_uri:
139+
139140
```Shell
140-
$ flask run --port 5000
141+
$ flask run --host localhost --port 5000
141142
```
142143

143144
## Community Help and Support

README_B2C.md

Lines changed: 38 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,51 @@ languages:
55
- html
66
products:
77
- 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."
99
urlFragment: ms-identity-python-webapp
1010
---
1111
# Integrating B2C feature of Microsoft identity platform with a Python web application
1212

1313
## About this sample
1414

1515
> 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.
2120
2221
This sample covers the following:
2322

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
2927

3028
### Overview
3129

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 signs in users with the Microsoft identity platform and then calls a web API.
3331

3432
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.
3634

3735
![Overview](./ReadmeFiles/topology.png)
3836

39-
4037
## Prerequisites
4138

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)
4542
1. Have [Python 2.7+ or Python 3+](https://www.python.org/downloads/) installed
4643

47-
4844
## Update the application
4945

5046
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.
5748

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.
5853

5954
## Configure the sample
6055

@@ -66,10 +61,9 @@ From your shell or command line:
6661
git clone https://github.com/Azure-Samples/ms-identity-python-webapp.git
6762
```
6863

69-
or download and extract the repository .zip file.
70-
71-
> 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.
7265

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.
7367
7468
### Step 2: Install sample dependency
7569

@@ -79,11 +73,9 @@ Install the dependencies using pip:
7973
$ pip install -r requirements.txt
8074
```
8175

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
8577

86-
#### Configure the pythonwebapp project
78+
Configure the pythonwebapp project by making the following changes.
8779

8880
> Note: if you used the setup scripts, the changes below may have been applied for you
8981
@@ -92,27 +84,26 @@ In the steps below, "ClientID" is the same as "Application ID" or "AppId".
9284

9385
* Update the value of `b2c_tenant` with the name of the Azure AD B2C tenant that you created.
9486
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**.
10193
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**.
10395
* You do not have to configure the `ENDPOINT` and `SCOPE` right now
10496

105-
10697
## Enable authentication
10798

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 host and port values need to match what you've set up in your **Redirect URI**:
100+
109101
```Shell
110-
$ flask run --port 5000
102+
$ flask run --host localhost --port 5000
111103
```
112104

113105
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.
116107

117108
## Access a web API
118109

@@ -129,8 +120,7 @@ Now you can configure this sample to access that web API.
129120
For example, write them as `["demo.read", "demo.write"]`.
130121

131122
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.
134124

135125
## Community Help and Support
136126

@@ -150,9 +140,8 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
150140

151141
## More information
152142

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):
155144

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)
157146

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).

app_config.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os
22

3-
CLIENT_SECRET = "Enter_the_Client_Secret_Here" # Our Quickstart uses this placeholder
4-
# In your production app, we recommend you to use other ways to store your secret,
5-
# such as KeyVault, or environment variable as described in Flask's documentation here
3+
CLIENT_ID = "Enter_the_Application_Id_here" # Application (client) ID of app registration
4+
5+
CLIENT_SECRET = "Enter_the_Client_Secret_Here" # Placeholder - for use ONLY during testing.
6+
# In a production app, we recommend you use a more secure method of storing your secret,
7+
# like Azure Key Vault. Or, use an environment variable as described in Flask's documentation:
68
# https://flask.palletsprojects.com/en/1.1.x/config/#configuring-from-environment-variables
79
# CLIENT_SECRET = os.getenv("CLIENT_SECRET")
810
# if not CLIENT_SECRET:
@@ -11,10 +13,9 @@
1113
AUTHORITY = "https://login.microsoftonline.com/common" # For multi-tenant app
1214
# AUTHORITY = "https://login.microsoftonline.com/Enter_the_Tenant_Name_Here"
1315

14-
CLIENT_ID = "Enter_the_Application_Id_here"
15-
16-
REDIRECT_PATH = "/getAToken" # It will be used to form an absolute URL
17-
# And that absolute URL must match your app's redirect_uri set in AAD
16+
REDIRECT_PATH = "/getAToken" # Used for forming an absolute URL to your redirect URI.
17+
# The absolute URL must match the redirect URI you set
18+
# in the app's registration in the Azure portal.
1819

1920
# You can find more Microsoft Graph API endpoints from Graph Explorer
2021
# https://developer.microsoft.com/en-us/graph/graph-explorer
@@ -24,5 +25,4 @@
2425
# https://docs.microsoft.com/en-us/graph/permissions-reference
2526
SCOPE = ["User.ReadBasic.All"]
2627

27-
SESSION_TYPE = "filesystem" # So token cache will be stored in server-side session
28-
28+
SESSION_TYPE = "filesystem" # Specifies the token cache should be stored in server-side session

app_config_b2c.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import os
22

33
b2c_tenant = "fabrikamb2c"
4-
signupsignin_user_flow = "b2c_1_signupsignin1"
5-
editprofile_user_flow = "b2c_1_profileediting1"
6-
resetpassword_user_flow = "b2c_1_passwordreset1"
4+
signupsignin_user_flow = "B2C_1_signupsignin1"
5+
editprofile_user_flow = "B2C_1_profileediting1"
6+
resetpassword_user_flow = "B2C_1_passwordreset1"
77
authority_template = "https://{tenant}.b2clogin.com/{tenant}.onmicrosoft.com/{user_flow}"
88

9-
CLIENT_SECRET = "Enter_the_Client_Secret_Here" # Our Quickstart uses this placeholder
10-
# In your production app, we recommend you to use other ways to store your secret,
11-
# such as KeyVault, or environment variable as described in Flask's documentation here
9+
CLIENT_ID = "Enter_the_Application_Id_here" # Application (client) ID of app registration
10+
11+
CLIENT_SECRET = "Enter_the_Client_Secret_Here" # Placeholder - for use ONLY during testing.
12+
# In a production app, we recommend you use a more secure method of storing your secret,
13+
# like Azure Key Vault. Or, use an environment variable as described in Flask's documentation:
1214
# https://flask.palletsprojects.com/en/1.1.x/config/#configuring-from-environment-variables
1315
# CLIENT_SECRET = os.getenv("CLIENT_SECRET")
1416
# if not CLIENT_SECRET:
@@ -21,16 +23,14 @@
2123
B2C_RESET_PASSWORD_AUTHORITY = authority_template.format(
2224
tenant=b2c_tenant, user_flow=resetpassword_user_flow)
2325

24-
CLIENT_ID = "Enter_the_Application_Id_here"
25-
26-
REDIRECT_PATH = "/getAToken" # It will be used to form an absolute URL
27-
# And that absolute URL must match your app's redirect_uri set in AAD
28-
29-
# This is the resource that you are going to access in your B2C tenant
30-
ENDPOINT = ''
26+
REDIRECT_PATH = "/getAToken" # Used for forming an absolute URL to your redirect URI.
27+
# The absolute URL must match the redirect URI you set
28+
# in the app's registration in the Azure portal.
3129

32-
# These are the scopes that you defined for the web API
33-
SCOPE = [] # For illustration purposes only: ["demo.read", "demo.write"]
30+
# This is the API resource endpoint
31+
ENDPOINT = '' # Application ID URI of app registration in Azure portal
3432

35-
SESSION_TYPE = "filesystem" # So token cache will be stored in server-side session
33+
# These are the scopes you've exposed in the web API app registration in the Azure portal
34+
SCOPE = [] # Example with two exposed scopes: ["demo.read", "demo.write"]
3635

36+
SESSION_TYPE = "filesystem" # Specifies the token cache should be stored in server-side session

0 commit comments

Comments
 (0)