Skip to content

Commit 74a74ad

Browse files
committed
edit pass (clarity, voice, grammar)
1 parent 422df5d commit 74a74ad

File tree

1 file changed

+48
-43
lines changed

1 file changed

+48
-43
lines changed

articles/active-directory/develop/msal-net-aad-b2c-considerations.md

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ You can use MSAL.NET to sign in users with social identities by using [Azure Act
2525
- When you instantiate the public client application, you need to specify the policy in authority.
2626
- When you want to apply a policy, you need to call an override of `AcquireTokenInteractive` containing an `authority` parameter.
2727

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

30-
## Authority for a Azure AD B2C tenant and policy
30+
## Authority for an Azure AD B2C tenant and policy
3131

3232
The authority to use is `https://{azureADB2CHostname}/tfp/{tenant}/{policyName}` where:
3333

@@ -62,7 +62,7 @@ application = PublicClientApplicationBuilder.Create(ClientID)
6262

6363
## Acquire a token to apply a policy
6464

65-
Acquiring a token for an Azure AD B2C protected API in a public client application requires you to use the overrides with an authority:
65+
Acquiring a token for an Azure AD B2C-protected API in a public client application requires you to use the overrides with an authority:
6666

6767
```csharp
6868
IEnumerable<IAccount> accounts = await application.GetAccountsAsync();
@@ -72,10 +72,10 @@ AuthenticationResult ar = await application .AcquireTokenInteractive(scopes)
7272
.ExecuteAsync();
7373
```
7474

75-
with:
75+
In the preceding code snippet:
7676

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.
7979
- `GetAccountByPolicy(IEnumerable<IAccount>, string)` is a method that finds an account for a given policy. For example:
8080

8181
```csharp
@@ -91,93 +91,98 @@ with:
9191
}
9292
```
9393

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

9696
## Special case of EditProfile and ResetPassword policies
9797

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

101100
```csharp
102101
private async void EditProfileButton_Click(object sender, RoutedEventArgs e)
103102
{
104-
IEnumerable<IAccount> accounts = await app.GetAccountsAsync();
105-
try
106-
{
107-
var authResult = await app.AcquireToken(scopes:App.ApiScopes)
108-
.WithAccount(GetUserByPolicy(accounts, App.PolicyEditProfile)),
109-
.WithPrompt(Prompt.NoPrompt),
110-
.WithB2CAuthority(App.AuthorityEditProfile)
111-
.ExecuteAsync();
112-
DisplayBasicTokenInfo(authResult);
113-
}
114-
catch
115-
{
116-
. . .
117-
}
103+
IEnumerable<IAccount> accounts = await app.GetAccountsAsync();
104+
try
105+
{
106+
var authResult = await app.AcquireToken(scopes:App.ApiScopes)
107+
.WithAccount(GetUserByPolicy(accounts, App.PolicyEditProfile)),
108+
.WithPrompt(Prompt.NoPrompt),
109+
.WithB2CAuthority(App.AuthorityEditProfile)
110+
.ExecuteAsync();
111+
DisplayBasicTokenInfo(authResult);
112+
}
113+
catch
114+
{
115+
}
118116
}
119117
```
118+
120119
## 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).
122120

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:
124126

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

130131
### 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.
132132

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+
134137
```csharp
135138
AcquireTokenByUsernamePassword(
136139
IEnumerable<string> scopes,
137140
string username,
138141
SecureString password)
139142
```
140143

141-
This method takes as parameters:
144+
This `AcquireTokenByUsernamePassword` method takes the following parameters:
145+
142146
- The *scopes* to request an access token for.
143147
- A *username*.
144148
- A SecureString *password* for the user.
145149

146-
Remember to use the authority that contains the ROPC policy.
147-
148150
### 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.).
150151

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

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
154155

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

157160
## Caching with Azure AD B2C in MSAL.NET
158161

159162
### Known issue with Azure AD B2C
160163

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:
162167

163-
- `tid` which is the Azure AD Tenant ID, and
168+
- `tid` (the Azure AD tenant ID)
164169
- `preferred_username`
165170

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

168173
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.
169174

170175
### Workarounds
171176

172-
#### Mitigation for the missing tenant ID
177+
#### Mitigation for missing tenant ID
173178

174179
The suggested workaround is to use [caching by policy](#acquire-a-token-to-apply-a-policy) described earlier.
175180

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

178183
#### Mitigation for "Missing from the token response"
179184

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

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

@@ -187,4 +192,4 @@ More details about acquiring tokens interactively with MSAL.NET for Azure AD B2C
187192

188193
| Sample | Platform | Description|
189194
|------ | -------- | -----------|
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

Comments
 (0)