Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
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)>?
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
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)>?
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
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)>?
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
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)>?
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
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)>?
42 changes: 28 additions & 14 deletions src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@

if (mergedOptions.ExtraQueryParameters != null)
{
builder.WithExtraQueryParameters((Dictionary<string, string>)mergedOptions.ExtraQueryParameters);
builder.WithExtraQueryParameters(MergeExtraQueryParameters(mergedOptions, null));

Check failure on line 157 in src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs

View workflow job for this annotation

GitHub Actions / Analyse

Argument 1: cannot convert from 'System.Collections.Generic.Dictionary<string, (string value, bool includeInCacheKey)>' to 'string'

Check failure on line 157 in src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs

View workflow job for this annotation

GitHub Actions / Build and run unit tests

Argument 1: cannot convert from 'System.Collections.Generic.Dictionary<string, (string value, bool includeInCacheKey)>' to 'string'

Check failure on line 157 in src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs

View workflow job for this annotation

GitHub Actions / Build and run unit tests

Argument 1: cannot convert from 'System.Collections.Generic.Dictionary<string, (string value, bool includeInCacheKey)>' to 'string'
}

if (!string.IsNullOrEmpty(authCodeRedemptionParameters.Tenant))
Expand Down Expand Up @@ -433,7 +433,7 @@
var dict = MergeExtraQueryParameters(mergedOptions, tokenAcquisitionOptions);
if (dict != null)
{
builder.WithExtraQueryParameters(dict);

Check failure on line 436 in src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs

View workflow job for this annotation

GitHub Actions / Analyse

Argument 1: cannot convert from 'System.Collections.Generic.Dictionary<string, (string value, bool includeInCacheKey)>' to 'string'

Check failure on line 436 in src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs

View workflow job for this annotation

GitHub Actions / Build and run unit tests

Argument 1: cannot convert from 'System.Collections.Generic.Dictionary<string, (string value, bool includeInCacheKey)>' to 'string'

Check failure on line 436 in src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs

View workflow job for this annotation

GitHub Actions / Build and run unit tests

Argument 1: cannot convert from 'System.Collections.Generic.Dictionary<string, (string value, bool includeInCacheKey)>' to 'string'
}

if (tokenAcquisitionOptions.ExtraHeadersParameters != null)
Expand Down Expand Up @@ -618,7 +618,7 @@

if (dict != null)
{
builder.WithExtraQueryParameters(dict);

Check failure on line 621 in src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs

View workflow job for this annotation

GitHub Actions / Analyse

Argument 1: cannot convert from 'System.Collections.Generic.Dictionary<string, (string value, bool includeInCacheKey)>' to 'string'

Check failure on line 621 in src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs

View workflow job for this annotation

GitHub Actions / Build and run unit tests

Argument 1: cannot convert from 'System.Collections.Generic.Dictionary<string, (string value, bool includeInCacheKey)>' to 'string'

Check failure on line 621 in src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs

View workflow job for this annotation

GitHub Actions / Build and run unit tests

Argument 1: cannot convert from 'System.Collections.Generic.Dictionary<string, (string value, bool includeInCacheKey)>' to 'string'
}
if (tokenAcquisitionOptions.ExtraHeadersParameters != null)
{
Expand Down Expand Up @@ -1145,8 +1145,8 @@
// Special case when the OBO inbound token is composite (for instance PFT)
if (dict.ContainsKey(assertionConstant) && dict.ContainsKey(subAssertionConstant))
{
string assertion = dict[assertionConstant];
string subAssertion = dict[subAssertionConstant];
string assertion = dict[assertionConstant].value;
string subAssertion = dict[subAssertionConstant].value;

// Check assertion and sub_assertion passed from merging extra query parameters to ensure they do not contain unsupported character(s).
CheckAssertionsForInjectionAttempt(assertion, subAssertion);
Expand All @@ -1164,8 +1164,7 @@
dict.Remove(assertionConstant);
dict.Remove(subAssertionConstant);
}

builder.WithExtraQueryParameters(dict);

Check failure on line 1167 in src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs

View workflow job for this annotation

GitHub Actions / Analyse

Argument 1: cannot convert from 'System.Collections.Generic.Dictionary<string, (string value, bool includeInCacheKey)>' to 'string'

Check failure on line 1167 in src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs

View workflow job for this annotation

GitHub Actions / Build and run unit tests

Argument 1: cannot convert from 'System.Collections.Generic.Dictionary<string, (string value, bool includeInCacheKey)>' to 'string'

Check failure on line 1167 in src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs

View workflow job for this annotation

GitHub Actions / Build and run unit tests

Argument 1: cannot convert from 'System.Collections.Generic.Dictionary<string, (string value, bool includeInCacheKey)>' to 'string'
}
if (tokenAcquisitionOptions.ExtraHeadersParameters != null)
{
Expand Down Expand Up @@ -1322,7 +1321,7 @@

if (dict != null)
{
builder.WithExtraQueryParameters(dict);

Check failure on line 1324 in src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs

View workflow job for this annotation

GitHub Actions / Analyse

Argument 1: cannot convert from 'System.Collections.Generic.Dictionary<string, (string value, bool includeInCacheKey)>' to 'string'

Check failure on line 1324 in src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs

View workflow job for this annotation

GitHub Actions / Build and run unit tests

Argument 1: cannot convert from 'System.Collections.Generic.Dictionary<string, (string value, bool includeInCacheKey)>' to 'string'

Check failure on line 1324 in src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs

View workflow job for this annotation

GitHub Actions / Build and run unit tests

Argument 1: cannot convert from 'System.Collections.Generic.Dictionary<string, (string value, bool includeInCacheKey)>' to 'string'
}
if (tokenAcquisitionOptions.ExtraHeadersParameters != null)
{
Expand Down Expand Up @@ -1362,25 +1361,40 @@
return builder.ExecuteAsync(tokenAcquisitionOptions != null ? tokenAcquisitionOptions.CancellationToken : CancellationToken.None);
}

internal static Dictionary<string, string>? MergeExtraQueryParameters(
internal static Dictionary<string, (string value, bool includeInCacheKey)>? MergeExtraQueryParameters(
MergedOptions mergedOptions,
TokenAcquisitionOptions tokenAcquisitionOptions)
TokenAcquisitionOptions? tokenAcquisitionOptions)
{
if (tokenAcquisitionOptions.ExtraQueryParameters != null)
// Return null if both sources are empty
if (tokenAcquisitionOptions?.ExtraQueryParameters == null && mergedOptions.ExtraQueryParameters == null)
{
var mergedDict = new Dictionary<string, string>(tokenAcquisitionOptions.ExtraQueryParameters);
if (mergedOptions.ExtraQueryParameters != null)
return null;
}

var mergedDict = new Dictionary<string, (string value, bool includeInCacheKey)>(StringComparer.OrdinalIgnoreCase);

// Add from tokenAcquisitionOptions first (these take precedence)
if (tokenAcquisitionOptions?.ExtraQueryParameters != null)
{
foreach (var pair in tokenAcquisitionOptions.ExtraQueryParameters)
{
mergedDict[pair.Key] = (pair.Value, true);
}
}

// Add from mergedOptions without overriding existing keys
if (mergedOptions.ExtraQueryParameters != null)
{
foreach (var pair in mergedOptions.ExtraQueryParameters)
{
foreach (var pair in mergedOptions!.ExtraQueryParameters)
if (!mergedDict.ContainsKey(pair.Key))
{
if (!mergedDict!.ContainsKey(pair.Key))
mergedDict.Add(pair.Key, pair.Value);
mergedDict.Add(pair.Key, (pair.Value, true));
}
}
return mergedDict;
}

return (Dictionary<string, string>?)mergedOptions.ExtraQueryParameters;
return mergedDict;
}

protected static bool AcceptedTokenVersionMismatch(MsalUiRequiredException msalServiceException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ public void MergeExtraQueryParametersTest()

// Assert
Assert.Equal(3, mergedDict!.Count);
Assert.Equal("newvalue1", mergedDict["key1"]);
Assert.Equal("value2", mergedDict["key2"]);
Assert.Equal("value3", mergedDict["key3"]);
Assert.Equal("newvalue1", mergedDict["key1"].value);
Assert.Equal("value2", mergedDict["key2"].value);
Assert.Equal("value3", mergedDict["key3"].value);
}

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

// Assert
Assert.Equal("value1", mergedDict!["key1"]);
Assert.Equal("value2", mergedDict["key2"]);
Assert.Equal("value1", mergedDict!["key1"].value);
Assert.Equal("value2", mergedDict["key2"].value);
}

[Fact]
Expand Down
Loading