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: articles/active-directory/develop/msal-net-aad-b2c-considerations.md
+48-43Lines changed: 48 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,9 +25,9 @@ You can use MSAL.NET to sign in users with social identities by using [Azure Act
25
25
- When you instantiate the public client application, you need to specify the policy in authority.
26
26
- When you want to apply a policy, you need to call an override of `AcquireTokenInteractive` containing an `authority` parameter.
27
27
28
-
This page is for MSAL 3.x. If you are interested in MSAL 2.x, please see [Azure AD B2C specifics in MSAL 2.x](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/AAD-B2C-Specifics-MSAL-2.x).
28
+
This article is for MSAL 3.x. If you are interested in MSAL 2.x, see [Azure AD B2C specifics in MSAL 2.x](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/AAD-B2C-Specifics-MSAL-2.x).
29
29
30
-
## Authority for a Azure AD B2C tenant and policy
30
+
## Authority for an Azure AD B2C tenant and policy
31
31
32
32
The authority to use is `https://{azureADB2CHostname}/tfp/{tenant}/{policyName}` where:
@@ -72,10 +72,10 @@ AuthenticationResult ar = await application .AcquireTokenInteractive(scopes)
72
72
.ExecuteAsync();
73
73
```
74
74
75
-
with:
75
+
In the preceding code snippet:
76
76
77
-
-`policy`being one of the previous strings (for instance`PolicySignUpSignIn`).
78
-
-`ParentActivityOrWindow` is required for Android (the Activity), and optional for other platforms which support the parent UI, such as windows in Windows and UIViewController in iOS. See more information [here on the UI dialog](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/Acquiring-tokens-interactively#withparentactivityorwindow).
77
+
-`policy`is a string containing the name of your Azure AD B2C user flow or custom policy (for example,`PolicySignUpSignIn`).
78
+
-`ParentActivityOrWindow` is required for Android (the Activity) and is optional for other platforms that support a parent UI like windows on Microsoft Windows and UIViewController in iOS. For more information on the UI dialog, see [WithParentActivityOrWindow](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/Acquiring-tokens-interactively#withparentactivityorwindow) on the MSAL Wiki.
79
79
-`GetAccountByPolicy(IEnumerable<IAccount>, string)` is a method that finds an account for a given policy. For example:
80
80
81
81
```csharp
@@ -91,93 +91,98 @@ with:
91
91
}
92
92
```
93
93
94
-
Applying a policy or user flow (for example, letting the end user edit their profile or reset their password) is currently done by calling `AcquireTokenInteractive`. In the case of these two policies, you don't use the returned token / authentication result.
94
+
Applying a user flow or custom policy (for example, letting the user edit their profile or reset their password) is currently done by calling `AcquireTokenInteractive`. For these two policies, you don't use the returned token/authentication result.
95
95
96
96
## Special case of EditProfile and ResetPassword policies
97
97
98
-
When you want to provide an experience where your end users sign in with a social identity and then edit their profile, you want to apply the Azure AD B2C Edit Profile policy. The way to do this is by calling `AcquireTokenInteractive` with
99
-
the specific authority for that policy, and a Prompt set to `Prompt.NoPrompt` to prevent the account selection dialog from being displayed (as the user is already signed-in and has an active cookie session).
98
+
When you want to provide an experience where your users sign in with a social identity and then edit their profile, apply the Azure AD B2C edit profile policy. Do so by calling `AcquireTokenInteractive` with the authority for that policy. Set Prompt to `Prompt.NoPrompt` to prevent the account selection dialog from being displayed as the user is already signed-in and has an active cookie session.
## Resource owner password credentials (ROPC) with Azure AD B2C
121
-
For more details on the ROPC flow, please see this [documentation](v2-oauth-ropc.md).
122
120
123
-
This flow is **not recommended** because your application asking a user for their password is not secure. For more information about this problem, see [this article](https://news.microsoft.com/features/whats-solution-growing-problem-passwords-says-microsoft/).
121
+
For more information on the ROPC flow, see [Sign in with resource owner password credentials grant](v2-oauth-ropc.md).
122
+
123
+
The ROPC flow is **not recommended** because asking a user for their password in your application is not secure. For more information about this problem, see [What’s the solution to the growing problem of passwords?](https://news.microsoft.com/features/whats-solution-growing-problem-passwords-says-microsoft/).
124
+
125
+
By using username/password in an ROPC flow, you sacrifice several things:
124
126
125
-
By using username/password, you are giving up a number of things:
126
-
- Core tenets of modern identity: password gets fished, replayed. Because we have this concept of a share secret that can be intercepted. This is incompatible with passwordless.
127
+
- Core tenets of modern identity: The password can be fished or replayed because the shared secret can be intercepted. By definitely, ROPC is incompatible with passwordless flows.
127
128
- Users who need to do MFA won't be able to sign in (as there is no interaction).
128
-
- Users won't be able to do single sign-on.
129
+
- Users won't be able to use single sign-on (SSO).
129
130
130
131
### Configure the ROPC flow in Azure AD B2C
131
-
In your Azure AD B2C tenant, create a new user flow and select **Sign in using ROPC**. This will enable the ROPC policy for your tenant. See [Configure the resource owner password credentials flow](/azure/active-directory-b2c/configure-ropc) for more details.
132
132
133
-
`IPublicClientApplication` contains a method:
133
+
In your Azure AD B2C tenant, create a new user flow and select **Sign in using ROPC** to enable ROPC for the user flow. For more information, see [Configure the resource owner password credentials flow](/azure/active-directory-b2c/configure-ropc).
134
+
135
+
`IPublicClientApplication` contains the `AcquireTokenByUsernamePassword` method:
136
+
134
137
```csharp
135
138
AcquireTokenByUsernamePassword(
136
139
IEnumerable<string>scopes,
137
140
stringusername,
138
141
SecureStringpassword)
139
142
```
140
143
141
-
This method takes as parameters:
144
+
This `AcquireTokenByUsernamePassword` method takes the following parameters:
145
+
142
146
- The *scopes* to request an access token for.
143
147
- A *username*.
144
148
- A SecureString *password* for the user.
145
149
146
-
Remember to use the authority that contains the ROPC policy.
147
-
148
150
### Limitations of the ROPC flow
149
-
- The ROPC flow **only works for local accounts** (where you register with Azure AD B2C using an email or username). This flow does not work if federating to any of the identity providers supported by Azure AD B2C (Facebook, Google, etc.).
150
151
151
-
## Google Auth and Embedded Webview
152
+
The ROPC flow **only works for local accounts**, where your users have registered with Azure AD B2C using an email address or username. This flow doesn't work when federating to an external identity provider supported by Azure AD B2C (Facebook, Google, etc.).
152
153
153
-
If you are a Azure AD B2C developer using Google as an identity provider we recommand you use the system browser, as Google does not allow [authentication from embedded webviews](https://developers.googleblog.com/2016/08/modernizing-oauth-interactions-in-native-apps.html). Currently, `login.microsoftonline.com` is a trusted authority with Google. Using this authority will work with embedded webview. However using `b2clogin.com` is not a trusted authority with Google, so users will not be able to authenticate.
154
+
## Google auth and embedded webview
154
155
155
-
We will provide an update to this [issue](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/688) if things change.
156
+
If you're using Google as an identity provider, we recommend you use the system browser as Google doesn't allow [authentication from embedded webviews](https://developers.googleblog.com/2016/08/modernizing-oauth-interactions-in-native-apps.html). Currently, `login.microsoftonline.com` is a trusted authority with Google and will work with embedded webview. However, `b2clogin.com` is not a trusted authority with Google, so users will not be able to authenticate.
157
+
158
+
We'll provide an update to this [issue](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/688) if things change.
156
159
157
160
## Caching with Azure AD B2C in MSAL.NET
158
161
159
162
### Known issue with Azure AD B2C
160
163
161
-
MSAL.NET supports a [token cache](/dotnet/api/microsoft.identity.client.tokencache?view=azure-dotnet). The token caching key is based on the claims returned by the Identity Provider. Currently MSAL.NET needs two claims to build a token cache key:
164
+
MSAL.NET supports a [token cache](/dotnet/api/microsoft.identity.client.tokencache?view=azure-dotnet). The token caching key is based on the claims returned by the identity provider (IdP).
165
+
166
+
Currently, MSAL.NET needs two claims to build a token cache key:
162
167
163
-
-`tid`which is the Azure AD Tenant ID, and
168
+
-`tid`(the Azure AD tenant ID)
164
169
-`preferred_username`
165
170
166
-
Both of these claims may be missing in Azure AD B2C scenarios because not all social identity providers (IdPs) return them in the tokens they return to Azure AD B2C.
171
+
Both of these claims may be missing in Azure AD B2C scenarios because not all social identity providers (Facebook, Google, and others) return them in the tokens they return to Azure AD B2C.
167
172
168
173
A symptom of such a scenario is that MSAL.NET returns `Missing from the token response` when you access the `preferred_username` claim value in tokens issued by Azure AD B2C. MSAL uses the `Missing from the token response` value for `preferred_username` to maintain cache cross-compatibility between libraries.
169
174
170
175
### Workarounds
171
176
172
-
#### Mitigation for the missing tenant ID
177
+
#### Mitigation for missing tenant ID
173
178
174
179
The suggested workaround is to use [caching by policy](#acquire-a-token-to-apply-a-policy) described earlier.
175
180
176
181
Alternatively, you can use the `tid` claim if you're using [custom policies](../../active-directory-b2c/custom-policy-get-started.md) in Azure AD B2C. Custom policies can return additional claims to your application by using [claims transformation](/azure/active-directory-b2c/claims-transformation-technical-profile).
177
182
178
183
#### Mitigation for "Missing from the token response"
179
184
180
-
One option is to use the `name` claim as the preferred username. To include the `name` claim in ID tokens issued by Azure AD B2C, select **Display Name** when you configure your user flow.
185
+
One option is to use the `name` claim instead of `preferred_username`. To include the `name` claim in the ID tokens issued by Azure AD B2C, select **Display Name** when you configure your user flow.
181
186
182
187
For more information about specifying the claims returned by your user flows, see [Tutorial: Create user flows in Azure AD B2C](../../active-directory-b2c/tutorial-create-user-flows.md).
183
188
@@ -187,4 +192,4 @@ More details about acquiring tokens interactively with MSAL.NET for Azure AD B2C
187
192
188
193
| Sample | Platform | Description|
189
194
|------ | -------- | -----------|
190
-
|[active-directory-b2c-xamarin-native](https://github.com/Azure-Samples/active-directory-b2c-xamarin-native)| Xamarin iOS, Xamarin Android, UWP | A Xamarin Forms app tha tuses MSAL.NET to authenticate users via Azure AD B2C and then access a web API with the tokens returned.|
195
+
|[active-directory-b2c-xamarin-native](https://github.com/Azure-Samples/active-directory-b2c-xamarin-native)| Xamarin iOS, Xamarin Android, UWP | A Xamarin Forms app that uses MSAL.NET to authenticate users via Azure AD B2C and then access a web API with the tokens returned.|
0 commit comments