Skip to content

Commit 80b05ce

Browse files
author
Tiago Brenck
committed
Renaming policy to user flow
1 parent 2de14ce commit 80b05ce

File tree

4 files changed

+29
-31
lines changed

4 files changed

+29
-31
lines changed

Microsoft.Identity.Web/AzureADB2COpenIDConnectEventHandlers.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Microsoft.Identity.Web
1212
{
1313
internal class AzureADB2COpenIDConnectEventHandlers
1414
{
15-
private IDictionary<string, string> _policyToIssuerAddress =
15+
private IDictionary<string, string> _userFlowToIssuerAddress =
1616
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
1717

1818
public AzureADB2COpenIDConnectEventHandlers(string schemeName, MicrosoftIdentityOptions options)
@@ -28,13 +28,13 @@ public AzureADB2COpenIDConnectEventHandlers(string schemeName, MicrosoftIdentity
2828
public Task OnRedirectToIdentityProvider(RedirectContext context)
2929
{
3030
var defaultUserFlow = Options.DefaultUserFlow;
31-
if (context.Properties.Items.TryGetValue(OidcConstants.PolicyKey, out var policy) &&
32-
!string.IsNullOrEmpty(policy) &&
33-
!string.Equals(policy, defaultUserFlow, StringComparison.OrdinalIgnoreCase))
31+
if (context.Properties.Items.TryGetValue(OidcConstants.PolicyKey, out var userFlow) &&
32+
!string.IsNullOrEmpty(userFlow) &&
33+
!string.Equals(userFlow, defaultUserFlow, StringComparison.OrdinalIgnoreCase))
3434
{
3535
context.ProtocolMessage.Scope = OpenIdConnectScope.OpenIdProfile;
3636
context.ProtocolMessage.ResponseType = OpenIdConnectResponseType.IdToken;
37-
context.ProtocolMessage.IssuerAddress = BuildIssuerAddress(context, defaultUserFlow, policy);
37+
context.ProtocolMessage.IssuerAddress = BuildIssuerAddress(context, defaultUserFlow, userFlow);
3838
context.Properties.Items.Remove(OidcConstants.PolicyKey);
3939
}
4040

@@ -43,20 +43,20 @@ public Task OnRedirectToIdentityProvider(RedirectContext context)
4343

4444
private string BuildIssuerAddress(RedirectContext context, string defaultUserFlow, string userFlow)
4545
{
46-
if (!_policyToIssuerAddress.TryGetValue(userFlow, out var issuerAddress))
46+
if (!_userFlowToIssuerAddress.TryGetValue(userFlow, out var issuerAddress))
4747
{
48-
_policyToIssuerAddress[userFlow] = context.ProtocolMessage.IssuerAddress.ToLowerInvariant()
48+
_userFlowToIssuerAddress[userFlow] = context.ProtocolMessage.IssuerAddress.ToLowerInvariant()
4949
.Replace($"/{defaultUserFlow.ToLowerInvariant()}/", $"/{userFlow.ToLowerInvariant()}/");
5050
}
5151

52-
return _policyToIssuerAddress[userFlow];
52+
return _userFlowToIssuerAddress[userFlow];
5353
}
5454

5555
public Task OnRemoteFailure(RemoteFailureContext context)
5656
{
5757
context.HandleResponse();
5858
// Handle the error code that Azure Active Directory B2C throws when trying to reset a password from the login page
59-
// because password reset is not supported by a "sign-up or sign-in policy".
59+
// because password reset is not supported by a "sign-up or sign-in user flow".
6060
// Below is a sample error message:
6161
// 'access_denied', error_description: 'AADB2C90118: The user has forgotten their password.
6262
// Correlation ID: f99deff4-f43b-43cc-b4e7-36141dbaf0a0

Microsoft.Identity.Web/ClaimsPrincipalExtensions.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ namespace Microsoft.Identity.Web
1111
/// </summary>
1212
public static class ClaimsPrincipalExtensions
1313
{
14-
// TODO: how to make this work with B2C, given that there is no tenant ID with B2C?
15-
1614
/// <summary>
1715
/// Gets the Account identifier for an MSAL.NET account from a <see cref="ClaimsPrincipal"/>
1816
/// </summary>
@@ -23,12 +21,12 @@ public static string GetMsalAccountId(this ClaimsPrincipal claimsPrincipal)
2321
string userObjectId = claimsPrincipal.GetObjectId();
2422
string nameIdentifierId = claimsPrincipal.GetNameIdentifierId();
2523
string tenantId = claimsPrincipal.GetTenantId();
26-
string policyId = claimsPrincipal.GetPolicyId();
24+
string userFlowId = claimsPrincipal.GetUserFlowId();
2725

28-
if (!string.IsNullOrWhiteSpace(nameIdentifierId) && !string.IsNullOrWhiteSpace(tenantId) && !string.IsNullOrWhiteSpace(policyId))
26+
if (!string.IsNullOrWhiteSpace(nameIdentifierId) && !string.IsNullOrWhiteSpace(tenantId) && !string.IsNullOrWhiteSpace(userFlowId))
2927
{
3028
// B2C pattern: {oid}-{tfp}.{tid}
31-
return $"{nameIdentifierId}-{policyId}.{tenantId}";
29+
return $"{nameIdentifierId}-{userFlowId}.{tenantId}";
3230
}
3331
else if (!string.IsNullOrWhiteSpace(userObjectId) && !string.IsNullOrWhiteSpace(tenantId))
3432
{
@@ -129,14 +127,14 @@ public static string GetDisplayName(this ClaimsPrincipal claimsPrincipal)
129127
}
130128

131129
/// <summary>
132-
/// Gets the Policy Id associated with the <see cref="ClaimsPrincipal"/>
130+
/// Gets the user flow id associated with the <see cref="ClaimsPrincipal"/>
133131
/// </summary>
134-
/// <param name="claimsPrincipal">the <see cref="ClaimsPrincipal"/> from which to retrieve the policy id</param>
135-
/// <returns>Policy Id of the identity, or <c>null</c> if it cannot be found</returns>
136-
public static string GetPolicyId(this ClaimsPrincipal claimsPrincipal)
132+
/// <param name="claimsPrincipal">the <see cref="ClaimsPrincipal"/> from which to retrieve the user flow id</param>
133+
/// <returns>User Flow Id of the identity, or <c>null</c> if it cannot be found</returns>
134+
public static string GetUserFlowId(this ClaimsPrincipal claimsPrincipal)
137135
{
138-
string policyId = claimsPrincipal.FindFirstValue(ClaimConstants.Tfp);
139-
return policyId;
136+
string userFlowId = claimsPrincipal.FindFirstValue(ClaimConstants.Tfp);
137+
return userFlowId;
140138
}
141139

142140
/// <summary>

Microsoft.Identity.Web/TokenAcquisition.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public async Task RemoveAccountAsync(RedirectContext context)
247247
IConfidentialClientApplication app = GetOrBuildConfidentialClientApplication();
248248
IAccount account = null;
249249

250-
// For B2C, we should remove all accounts of the user regardless the policy
250+
// For B2C, we should remove all accounts of the user regardless the user flow
251251
if(_microsoftIdentityOptions.IsB2C)
252252
{
253253
var b2cAccounts = await app.GetAccountsAsync().ConfigureAwait(false);
@@ -376,11 +376,11 @@ private async Task<string> GetAccessTokenOnBehalfOfUserFromCacheAsync(
376376
}
377377
}
378378

379-
// If is B2C and could not get an account (most likely because there is no tid claims), try to get it by policy
379+
// If is B2C and could not get an account (most likely because there is no tid claims), try to get it by user flow
380380
if (_microsoftIdentityOptions.IsB2C && account == null)
381381
{
382-
string currentPolicy = claimsPrincipal.GetPolicyId();
383-
account = GetAccountByPolicy(await application.GetAccountsAsync().ConfigureAwait(false), currentPolicy);
382+
string currentUserFlow = claimsPrincipal.GetUserFlowId();
383+
account = GetAccountByUserFlow(await application.GetAccountsAsync().ConfigureAwait(false), currentUserFlow);
384384
}
385385

386386
return await GetAccessTokenOnBehalfOfUserFromCacheAsync(application, account, scopes, tenant).ConfigureAwait(false);
@@ -496,17 +496,17 @@ private static bool AcceptedTokenVersionMismatch(MsalUiRequiredException msalSev
496496
}
497497

498498
/// <summary>
499-
/// Gets an IAccount for the current B2C policy in the user claims
499+
/// Gets an IAccount for the current B2C user flow in the user claims
500500
/// </summary>
501501
/// <param name="accounts"></param>
502-
/// <param name="policy"></param>
502+
/// <param name="userFlow"></param>
503503
/// <returns></returns>
504-
private IAccount GetAccountByPolicy(IEnumerable<IAccount> accounts, string policy)
504+
private IAccount GetAccountByUserFlow(IEnumerable<IAccount> accounts, string userFlow)
505505
{
506506
foreach (var account in accounts)
507507
{
508508
string accountIdentifier = account.HomeAccountId.ObjectId.Split('.')[0];
509-
if (accountIdentifier.EndsWith(policy.ToLower()))
509+
if (accountIdentifier.EndsWith(userFlow.ToLower()))
510510
return account;
511511
}
512512

Microsoft.Identity.Web/WebAppServiceCollectionExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ public static AuthenticationBuilder AddSignIn(
248248

249249
if (microsoftIdentityOptions.IsB2C)
250250
{
251-
// When a new Challenge is returned using any B2C policy different than sisu, we must change
252-
// the ProtocolMessage.IssuerAddress to the desired policy otherwise the redirect would use the sisu policy
251+
// When a new Challenge is returned using any B2C user flow different than susi, we must change
252+
// the ProtocolMessage.IssuerAddress to the desired user flow otherwise the redirect would use the susi user flow
253253
await b2COidcHandlers.OnRedirectToIdentityProvider(context);
254254
}
255255

@@ -263,7 +263,7 @@ public static AuthenticationBuilder AddSignIn(
263263
{
264264
// Handles the error when a user cancels an action on the Azure Active Directory B2C UI.
265265
// Handle the error code that Azure Active Directory B2C throws when trying to reset a password from the login page
266-
// because password reset is not supported by a "sign-up or sign-in policy".
266+
// because password reset is not supported by a "sign-up or sign-in user flow".
267267
await b2COidcHandlers.OnRemoteFailure(context);
268268

269269
await remoteFailureHandler(context).ConfigureAwait(false);

0 commit comments

Comments
 (0)