Skip to content

Commit 5ac7288

Browse files
committed
Combine B2C config into the main config
Update README.md Co-authored-by: Pamela Fox <[email protected]> Rename AAD to Microsoft Entra ID Reword it as if the docs article already changed
1 parent 2ad686e commit 5ac7288

File tree

5 files changed

+55
-49
lines changed

5 files changed

+55
-49
lines changed

.env.sample

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
# Note: If you are using Azure App Service, go to your app's Configuration,
22
# and then set the following values into your app's "Application settings".
33

4+
# The following variables are required for the app to run.
45
CLIENT_ID=<client id>
56
CLIENT_SECRET=<client secret>
67

7-
# The AUTHORITY variable expects a full authority URL.
8+
# This sample can be configured as a Microsoft Entra ID app,
9+
# a Microsoft Entra External ID app, or a B2C app.
10+
11+
# 1. If you are using a Microsoft Entra ID tenent,
12+
# configure the AUTHORITY variable as
13+
# "https://login.microsoftonline.com/TENANT_GUID"
14+
# or "https://login.microsoftonline.com/subdomain.onmicrosoft.com".
815
#
9-
# If you are using an AAD tenent, configure it as
10-
# "https://login.microsoftonline.com/TENANT_GUID"
11-
# or "https://login.microsoftonline.com/subdomain.onmicrosoft.com".
16+
# Alternatively, leave it undefined if you are building a multi-tenant AAD app
17+
# in world-wide cloud
18+
#AUTHORITY=<authority url>
1219
#
13-
# If you are using a CIAM tenant, configure it as "https://subdomain.ciamlogin.com"
1420
#
15-
# Alternatively, leave it undefined if you are building a multi-tenant app in world-wide cloud
21+
# 2. If you are using a Microsoft Entra External ID for customers (CIAM) tenant,
22+
# configure AUTHORITY as "https://subdomain.ciamlogin.com"
1623
#AUTHORITY=<authority url>
24+
#
25+
#
26+
# 3. If you are using a B2C tenant, configure the following variables:
27+
# Note the B2C_TENANT_NAME shall be the display name such as "contoso"
28+
#
29+
#B2C_TENANT_NAME=<tenant name>
30+
SIGNUPSIGNIN_USER_FLOW=B2C_1_signupsignin1
31+
EDITPROFILE_USER_FLOW=B2C_1_profile_editing
32+
RESETPASSWORD_USER_FLOW=B2C_1_reset_password

.env.sample.b2c

Lines changed: 0 additions & 9 deletions
This file was deleted.

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,22 @@ urlFragment: ms-identity-python-webapp
1111

1212
This is a Python web application that uses the Flask framework and the Microsoft identity platform to sign in users and make authenticated calls to the Microsoft Graph API.
1313

14+
# Configuration
15+
16+
## If you are configuring your Microsoft Entra ID app or Microsoft Entra External ID app
17+
1418
To get started with this sample, you have two options:
1519

1620
* Use the Azure portal to create the Azure AD applications and related objects. Follow the steps in
1721
[Quickstart: Add sign-in with Microsoft to a Python web app](https://docs.microsoft.com/azure/active-directory/develop/web-app-quickstart?pivots=devlang-python).
1822
* Use PowerShell scripts that automatically create the Azure AD applications and related objects (passwords, permissions, dependencies) for you, and then modify the configuration files. Follow the steps in the [App Creation Scripts README](./AppCreationScripts/AppCreationScripts.md).
1923

24+
## If you are configuring your B2C app
25+
26+
This sample can also work as a B2C app. If you are using a B2C tenant, follow
27+
[Configure authentication in a sample Python web app by using Azure AD B2C](https://learn.microsoft.com/azure/active-directory-b2c/configure-authentication-sample-python-web-app).
28+
29+
2030
# Deployment
2131

2232
Once you finish testing this web app locally, you can deploy it to your production.

README_B2C.md

Lines changed: 0 additions & 30 deletions
This file was deleted.

app_config.py

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

3+
4+
if (os.getenv('B2C_TENANT_NAME')
5+
and os.getenv('SIGNUPSIGNIN_USER_FLOW') and os.getenv('EDITPROFILE_USER_FLOW')):
6+
# This branch is for B2C. You can delete this branch if you are not using B2C.
7+
b2c_tenant = os.getenv('B2C_TENANT_NAME')
8+
authority_template = "https://{tenant}.b2clogin.com/{tenant}.onmicrosoft.com/{user_flow}"
9+
AUTHORITY = authority_template.format(
10+
tenant=b2c_tenant,
11+
user_flow=os.getenv('SIGNUPSIGNIN_USER_FLOW'))
12+
B2C_PROFILE_AUTHORITY = authority_template.format(
13+
tenant=b2c_tenant,
14+
user_flow=os.getenv('EDITPROFILE_USER_FLOW'))
15+
B2C_RESET_PASSWORD_AUTHORITY = authority_template.format(
16+
# If you are using the new "Recommended user flow"
17+
# (https://docs.microsoft.com/en-us/azure/active-directory-b2c/user-flow-versions),
18+
# you can remove the B2C_RESET_PASSWORD_AUTHORITY settings from this file.
19+
tenant=b2c_tenant,
20+
user_flow=os.getenv('RESETPASSWORD_USER_FLOW'))
21+
else: # This branch is for AAD or CIAM
22+
# You can configure your authority via environment variable
23+
# Defaults to a multi-tenant app in world-wide cloud
24+
AUTHORITY = os.getenv("AUTHORITY") or "https://login.microsoftonline.com/common"
25+
326
# Application (client) ID of app registration
427
CLIENT_ID = os.getenv("CLIENT_ID")
528
# Application's generated client secret: never check this into source control!
629
CLIENT_SECRET = os.getenv("CLIENT_SECRET")
730

8-
# You can configure your authority via environment variable
9-
# Defaults to a multi-tenant app in world-wide cloud
10-
AUTHORITY = os.getenv("AUTHORITY", "https://login.microsoftonline.com/common")
11-
1231
REDIRECT_PATH = "/getAToken" # Used for forming an absolute URL to your redirect URI.
1332
# The absolute URL must match the redirect URI you set
1433
# in the app's registration in the Azure portal.

0 commit comments

Comments
 (0)