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: msal-python-conceptual/advanced/aad-b2c.md
+18-17Lines changed: 18 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: Use MSAL Python to work with Azure AD B2C
2
+
atitle: Use MSAL Python to work with Azure AD B2C
3
3
description: "You can use MSAL Python to sign-in users with social identities, acquire tokens, and customize the sign-in experience by using Azure AD B2C."
4
4
author: Dickson-Mwendia
5
5
manager: CelesteDG
@@ -10,9 +10,8 @@ ms.topic: how-to
10
10
ms.date: 02/07/2024
11
11
ms.author: dmwendia
12
12
ms.reviewer: shermanouko, rayluo
13
-
#Customer intent:
13
+
#Customer intent:
14
14
---
15
-
16
15
# Use MSAL Python to work with Azure AD B2C
17
16
18
17
You can use MSAL Python to sign-in users with social identities, acquire tokens, and customize the sign-in experience by using [Azure AD B2C](https://aka.ms/aadb2c).
@@ -72,12 +71,12 @@ app.acquire_token_by_xyz(...) # Same as in non-B2C scenarios
72
71
```
73
72
74
73
> There is no need to filter accounts by user flow,
75
-
as long as you are following a pattern of
76
-
"create different MSAL app for different user flow"
77
-
(because the B2C user flow is designed to behave like an isolated authority).
78
-
In practice, you will still typically reuse same MSAL app and its token cache for the SignIn user flow,
79
-
and only create new one-time MSAL app when invoking EditProfile or ResetPassword user flows,
80
-
whose returned token (if any) would not be useful anyway.
74
+
> as long as you are following a pattern of
75
+
> "create different MSAL app for different user flow"
76
+
> (because the B2C user flow is designed to behave like an isolated authority).
77
+
> In practice, you will still typically reuse same MSAL app and its token cache for the SignIn user flow,
78
+
> and only create new one-time MSAL app when invoking EditProfile or ResetPassword user flows,
79
+
> whose returned token (if any) would not be useful anyway.
81
80
82
81
## Example of EditProfile and ResetPassword user flows
83
82
@@ -101,15 +100,17 @@ You would just need to update your HTML template to include new link to, for exa
101
100
```
102
101
103
102
## Resource Owner Password Credentials (ROPC) With B2C
103
+
>[!WARNING]
104
+
> This flow has been deprecated for public client scenarios due to security risks, use a more secure flow. Follow [this guide](https://aka.ms/msal-ropc-migration) for migration guidance.
104
105
105
106
There exists no API difference between a B2C and non-B2C scenario. The following content serves as a mini-tutorial.
106
107
107
108
* In your Azure AD B2C tenant, create a new user flow and select **Sign in using ROPC**.
108
-
This will enable the ROPC user flow for your tenant.
109
-
See [Configure the resource owner password credentials flow](/azure/active-directory-b2c/configure-ropc) for more details.
109
+
This will enable the ROPC user flow for your tenant.
110
+
See [Configure the resource owner password credentials flow](/azure/active-directory-b2c/configure-ropc) for more details.
110
111
* Once you create the MSAL instance with the authority which contains the ROPC user flow,
111
-
the [`acquire_token_by_username_password(...)`](https://msal-python.readthedocs.io/en/latest/#msal.PublicClientApplication.acquire_token_by_username_password)
112
-
would work as usual.
112
+
the [`acquire_token_by_username_password(...)`](https://msal-python.readthedocs.io/en/latest/#msal.PublicClientApplication.acquire_token_by_username_password)
113
+
would work as usual.
113
114
* Limitations: This **only works for local accounts** (where you register with B2C using an email or username). This flow does not work if federating to any of the IdPs supported by B2C (Facebook, Google, etc...).
114
115
115
116
Microsoft [discourages the use of resource owner password credentials grant](https://news.microsoft.com/features/whats-solution-growing-problem-passwords-says-microsoft/). In most scenarios, more secure alternatives are available and recommended. This flow requires a very high degree of trust in the application, and carries risks that are not present in other flows. You should only use this flow when other more secure flows aren't viable. Learn more in the [username and password ](username-password-authentication.md) guidance.
@@ -122,7 +123,7 @@ MSAL Python token cache usage pattern starts with querying all existing accounts
122
123
[`get_accounts(...)`, which supports a `username` parameter as filter](https://msal-python.readthedocs.io/en/latest/#msal.ClientApplication.get_accounts).
123
124
That username data is populated by a `preferred_username` claim inside the ID Token.
124
125
125
-
By default, that claim is missing in many of the Azure AD B2C scenarios.
126
+
By default, that claim is missing in many of the Azure AD B2C scenarios.
126
127
127
128
The customer impact is that when trying to display the accounts, their username field would be empty.
128
129
This may not bother you, if you are using Auth Code flow in your web app, and dealing with only one account per user.
@@ -135,6 +136,6 @@ or simply call your `app.get_accounts()` without a specific username parameter.
135
136
136
137
## Samples
137
138
138
-
Sample | Platform | Description
139
-
------ | -------- | -----------
140
-
[Microsoft Identity Python Web App](https://github.com/Azure-Samples/ms-identity-python-webapp) | All platforms supporting Python | A web app showcasing how to use MSAL Python to authenticate users via Azure Active Directory B2C, and access a Web API with the resulting tokens.
|[Microsoft Identity Python Web App](https://github.com/Azure-Samples/ms-identity-python-webapp)| All platforms supporting Python | A web app showcasing how to use MSAL Python to authenticate users via Azure Active Directory B2C, and access a Web API with the resulting tokens.|
Copy file name to clipboardExpand all lines: msal-python-conceptual/advanced/msal-python-adfs-support.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,6 +39,8 @@ The supported AD FS versions in this federated scenario are:
39
39
- Active Directory Federation Services v4 (AD FS 2016)
40
40
41
41
### Acquire a token via username and password
42
+
>[!WARNING]
43
+
> This method of token acquisition has been deprecated for public client flows due to security risks, use a more secure flow. Follow [this guide](https://aka.ms/msal-ropc-migration) for migration guidance.
42
44
43
45
The following applies whether you connect directly to Active Directory Federation Services (AD FS) or through Active Directory.
Copy file name to clipboardExpand all lines: msal-python-conceptual/advanced/username-password-authentication.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,9 @@ ms.custom: sfi-image-nochange
15
15
16
16
# Username and password authentication
17
17
18
+
>[!WARNING]
19
+
> This flow has been deprecated for public client scenarios due to security risks, use a more secure flow. Follow [this guide](https://aka.ms/msal-ropc-migration) for migration guidance.
20
+
18
21
The content below are applicable to [all MSAL libraries](/entra/msal), not just MSAL Python.
19
22
20
23
## The username and password flow is not recommended
Copy file name to clipboardExpand all lines: msal-python-conceptual/getting-started/acquiring-tokens.md
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -123,9 +123,12 @@ else:
123
123
124
124
### Username and password
125
125
126
+
>[!WARNING]
127
+
> This api has been deprecated for public client flows due to security risks, use a more secure flow. Follow [this guide](https://aka.ms/msal-ropc-migration) for migration guidance.
128
+
126
129
We don't recommend using this approach. It's also possible to get a token with a [username and password](/entra/identity-platform/v2-oauth-ropc). MSAL Python provides the [`acquire_token_by_username_password`](/python/api/msal/msal.application.clientapplication#msal-application-clientapplication-acquire-token-by-username-password) method for this use case. It's not recommended because the application will be asking a user for their password directly, which is an insecure pattern.
127
130
128
-
Microsoft doesn't recommend the username and password flow because the application will be asking a user for their password directly, which is an insecure pattern. In most scenarios, there exist more secure flows that you can use. Learn more in the [username and password authentication flow](../advanced/username-password-authentication.md) guidance.
131
+
There are more secure flows that you can use. Learn more in the [username and password authentication flow](../advanced/username-password-authentication.md) guidance.
0 commit comments