Skip to content

Commit 9ad8871

Browse files
authored
Bump MSAL to version 4.79.2 and handle changes to deprecated WithExtraQueryParameters APIs (#3583)
* Handle deprecation of WithExtraQueryParameters APIs in MSAL.NET * Update MicrosoftIdentityClientVersion * Update SystemFormatsAsn1Version * Add missing Unshipped.txt declaration * Handle deprecation of WithExtraQueryParameters APIs in MSAL.NET * Update MicrosoftIdentityClientVersion * Update SystemFormatsAsn1Version * Add missing Unshipped.txt declaration * Update MSAL version * Revert "Update MSAL version" This reverts commit 7cce634. * Update MSAL version * Adjust dependencies
1 parent d993ba7 commit 9ad8871

File tree

9 files changed

+40
-20
lines changed

9 files changed

+40
-20
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383

8484
<PropertyGroup Label="Common dependency versions">
8585
<MicrosoftIdentityModelVersion Condition="'$(MicrosoftIdentityModelVersion)' == ''">8.14.0</MicrosoftIdentityModelVersion>
86-
<MicrosoftIdentityClientVersion Condition="'$(MicrosoftIdentityClientVersion)' == ''">4.77.1</MicrosoftIdentityClientVersion>
86+
<MicrosoftIdentityClientVersion Condition="'$(MicrosoftIdentityClientVersion)' == ''">4.79.2</MicrosoftIdentityClientVersion>
8787
<MicrosoftIdentityAbstractionsVersion Condition="'$(MicrosoftIdentityAbstractionsVersion)' == ''">9.5.0</MicrosoftIdentityAbstractionsVersion>
8888
<FxCopAnalyzersVersion>3.3.0</FxCopAnalyzersVersion>
8989
<SystemTextEncodingsWebVersion>4.7.2</SystemTextEncodingsWebVersion>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#nullable enable
22
const Microsoft.Identity.Web.Constants.UserIdKey = "IDWEB_USER_ID" -> string!
33
readonly Microsoft.Identity.Web.TokenAcquisition._certificatesObservers -> System.Collections.Generic.IReadOnlyList<Microsoft.Identity.Web.Experimental.ICertificatesObserver!>!
4+
static Microsoft.Identity.Web.TokenAcquisition.MergeExtraQueryParameters(Microsoft.Identity.Web.MergedOptions! mergedOptions, Microsoft.Identity.Web.TokenAcquisitionOptions? tokenAcquisitionOptions) -> System.Collections.Generic.Dictionary<string!, (string! value, bool includeInCacheKey)>?
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
#nullable enable
2+
static Microsoft.Identity.Web.TokenAcquisition.MergeExtraQueryParameters(Microsoft.Identity.Web.MergedOptions! mergedOptions, Microsoft.Identity.Web.TokenAcquisitionOptions? tokenAcquisitionOptions) -> System.Collections.Generic.Dictionary<string!, (string! value, bool includeInCacheKey)>?
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
#nullable enable
2+
static Microsoft.Identity.Web.TokenAcquisition.MergeExtraQueryParameters(Microsoft.Identity.Web.MergedOptions! mergedOptions, Microsoft.Identity.Web.TokenAcquisitionOptions? tokenAcquisitionOptions) -> System.Collections.Generic.Dictionary<string!, (string! value, bool includeInCacheKey)>?
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
#nullable enable
2+
static Microsoft.Identity.Web.TokenAcquisition.MergeExtraQueryParameters(Microsoft.Identity.Web.MergedOptions! mergedOptions, Microsoft.Identity.Web.TokenAcquisitionOptions? tokenAcquisitionOptions) -> System.Collections.Generic.Dictionary<string!, (string! value, bool includeInCacheKey)>?
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
#nullable enable
2+
static Microsoft.Identity.Web.TokenAcquisition.MergeExtraQueryParameters(Microsoft.Identity.Web.MergedOptions! mergedOptions, Microsoft.Identity.Web.TokenAcquisitionOptions? tokenAcquisitionOptions) -> System.Collections.Generic.Dictionary<string!, (string! value, bool includeInCacheKey)>?
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
#nullable enable
2+
static Microsoft.Identity.Web.TokenAcquisition.MergeExtraQueryParameters(Microsoft.Identity.Web.MergedOptions! mergedOptions, Microsoft.Identity.Web.TokenAcquisitionOptions? tokenAcquisitionOptions) -> System.Collections.Generic.Dictionary<string!, (string! value, bool includeInCacheKey)>?

src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public async Task<AcquireTokenResult> AddAccountToCacheFromAuthorizationCodeAsyn
154154

155155
if (mergedOptions.ExtraQueryParameters != null)
156156
{
157-
builder.WithExtraQueryParameters((Dictionary<string, string>)mergedOptions.ExtraQueryParameters);
157+
builder.WithExtraQueryParameters(MergeExtraQueryParameters(mergedOptions, null));
158158
}
159159

160160
if (!string.IsNullOrEmpty(authCodeRedemptionParameters.Tenant))
@@ -1145,8 +1145,8 @@ private void NotifyCertificateSelection(
11451145
// Special case when the OBO inbound token is composite (for instance PFT)
11461146
if (dict.ContainsKey(assertionConstant) && dict.ContainsKey(subAssertionConstant))
11471147
{
1148-
string assertion = dict[assertionConstant];
1149-
string subAssertion = dict[subAssertionConstant];
1148+
string assertion = dict[assertionConstant].value;
1149+
string subAssertion = dict[subAssertionConstant].value;
11501150

11511151
// Check assertion and sub_assertion passed from merging extra query parameters to ensure they do not contain unsupported character(s).
11521152
CheckAssertionsForInjectionAttempt(assertion, subAssertion);
@@ -1164,7 +1164,6 @@ private void NotifyCertificateSelection(
11641164
dict.Remove(assertionConstant);
11651165
dict.Remove(subAssertionConstant);
11661166
}
1167-
11681167
builder.WithExtraQueryParameters(dict);
11691168
}
11701169
if (tokenAcquisitionOptions.ExtraHeadersParameters != null)
@@ -1362,25 +1361,40 @@ private Task<AuthenticationResult> GetAuthenticationResultForWebAppWithAccountFr
13621361
return builder.ExecuteAsync(tokenAcquisitionOptions != null ? tokenAcquisitionOptions.CancellationToken : CancellationToken.None);
13631362
}
13641363

1365-
internal static Dictionary<string, string>? MergeExtraQueryParameters(
1364+
internal static Dictionary<string, (string value, bool includeInCacheKey)>? MergeExtraQueryParameters(
13661365
MergedOptions mergedOptions,
1367-
TokenAcquisitionOptions tokenAcquisitionOptions)
1366+
TokenAcquisitionOptions? tokenAcquisitionOptions)
13681367
{
1369-
if (tokenAcquisitionOptions.ExtraQueryParameters != null)
1368+
// Return null if both sources are empty
1369+
if (tokenAcquisitionOptions?.ExtraQueryParameters == null && mergedOptions.ExtraQueryParameters == null)
13701370
{
1371-
var mergedDict = new Dictionary<string, string>(tokenAcquisitionOptions.ExtraQueryParameters);
1372-
if (mergedOptions.ExtraQueryParameters != null)
1371+
return null;
1372+
}
1373+
1374+
var mergedDict = new Dictionary<string, (string value, bool includeInCacheKey)>(StringComparer.OrdinalIgnoreCase);
1375+
1376+
// Add from tokenAcquisitionOptions first (these take precedence)
1377+
if (tokenAcquisitionOptions?.ExtraQueryParameters != null)
1378+
{
1379+
foreach (var pair in tokenAcquisitionOptions.ExtraQueryParameters)
1380+
{
1381+
mergedDict[pair.Key] = (pair.Value, true);
1382+
}
1383+
}
1384+
1385+
// Add from mergedOptions without overriding existing keys
1386+
if (mergedOptions.ExtraQueryParameters != null)
1387+
{
1388+
foreach (var pair in mergedOptions.ExtraQueryParameters)
13731389
{
1374-
foreach (var pair in mergedOptions!.ExtraQueryParameters)
1390+
if (!mergedDict.ContainsKey(pair.Key))
13751391
{
1376-
if (!mergedDict!.ContainsKey(pair.Key))
1377-
mergedDict.Add(pair.Key, pair.Value);
1392+
mergedDict.Add(pair.Key, (pair.Value, true));
13781393
}
13791394
}
1380-
return mergedDict;
13811395
}
13821396

1383-
return (Dictionary<string, string>?)mergedOptions.ExtraQueryParameters;
1397+
return mergedDict;
13841398
}
13851399

13861400
protected static bool AcceptedTokenVersionMismatch(MsalUiRequiredException msalServiceException)

tests/Microsoft.Identity.Web.Test/TokenAcquisitionAuthorityTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,9 @@ public void MergeExtraQueryParametersTest()
385385

386386
// Assert
387387
Assert.Equal(3, mergedDict!.Count);
388-
Assert.Equal("newvalue1", mergedDict["key1"]);
389-
Assert.Equal("value2", mergedDict["key2"]);
390-
Assert.Equal("value3", mergedDict["key3"]);
388+
Assert.Equal("newvalue1", mergedDict["key1"].value);
389+
Assert.Equal("value2", mergedDict["key2"].value);
390+
Assert.Equal("value3", mergedDict["key3"].value);
391391
}
392392

393393
[Fact]
@@ -411,8 +411,8 @@ public void MergeExtraQueryParameters_TokenAcquisitionOptionsNull_Test()
411411
var mergedDict = TokenAcquisition.MergeExtraQueryParameters(mergedOptions, tokenAcquisitionOptions);
412412

413413
// Assert
414-
Assert.Equal("value1", mergedDict!["key1"]);
415-
Assert.Equal("value2", mergedDict["key2"]);
414+
Assert.Equal("value1", mergedDict!["key1"].value);
415+
Assert.Equal("value2", mergedDict["key2"].value);
416416
}
417417

418418
[Fact]

0 commit comments

Comments
 (0)