Skip to content

Commit e9aa448

Browse files
trwalketrwalke
andauthored
Removing known key check for cache key extensions (#5123)
Removing known key check for cache key ext Co-authored-by: trwalke <[email protected]>
1 parent dbbda87 commit e9aa448

File tree

3 files changed

+0
-92
lines changed

3 files changed

+0
-92
lines changed

src/client/Microsoft.Identity.Client/Cache/StorageJsonKeys.cs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -43,45 +43,5 @@ internal static class StorageJsonKeys
4343
public const string ExtendedExpiresOn_MsalCompat = "ext_expires_on";
4444

4545
public const string CacheExtensions = "ext";
46-
47-
//Known storeage keys need to be added here
48-
public static readonly HashSet<string> s_knownStorageJsonKeys = new HashSet<string>
49-
{
50-
HomeAccountId,
51-
Environment,
52-
Realm,
53-
LocalAccountId,
54-
Username,
55-
AuthorityType,
56-
AlternativeAccountId,
57-
GivenName,
58-
FamilyName,
59-
MiddleName,
60-
Name,
61-
AvatarUrl,
62-
CredentialType,
63-
ClientId,
64-
Secret,
65-
Target,
66-
CachedAt,
67-
ExpiresOn,
68-
RefreshOn,
69-
ExtendedExpiresOn,
70-
ClientInfo,
71-
FamilyId,
72-
AppMetadata,
73-
KeyId,
74-
TokenType,
75-
WamAccountIds,
76-
AccountSource,
77-
UserAssertionHash,
78-
ExtendedExpiresOn_MsalCompat,
79-
CacheExtensions
80-
};
81-
82-
public static bool IsKnownStorageJsonKey(string key)
83-
{
84-
return s_knownStorageJsonKeys.Contains(key);
85-
}
8646
}
8747
}

src/client/Microsoft.Identity.Client/Extensibility/AcquireTokenForClientBuilderExtensions.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,6 @@ internal static AcquireTokenForClientParameterBuilder WithAdditionalCacheKeyComp
3838
return builder;
3939
}
4040

41-
StringBuilder offendingKeys = new();
42-
43-
//Ensure known JSON keys are not added to cache key components
44-
foreach (var kvp in cacheKeyComponents)
45-
{
46-
if (StorageJsonKeys.IsKnownStorageJsonKey(kvp.Key))
47-
{
48-
offendingKeys.AppendLine(kvp.Key);
49-
}
50-
}
51-
52-
if (offendingKeys.Length != 0)
53-
{
54-
throw new ArgumentException($"Keys added to {nameof(cacheKeyComponents)} are invalid. Offending keys are: {offendingKeys.ToString()}");
55-
}
56-
5741
if (builder.CommonParameters.CacheKeyComponents == null)
5842
{
5943
builder.CommonParameters.CacheKeyComponents = new SortedList<string, string>(cacheKeyComponents);

tests/Microsoft.Identity.Test.Unit/PublicApiTests/CacheKeyExtensionTests.cs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,6 @@ public class CacheKeyExtensionTests : TestBase
4040
{ "key1", "value1" }
4141
};
4242

43-
private Dictionary<string, string> _knownKeyList = new Dictionary<string, string>
44-
{
45-
{ "client_id", "value1" },
46-
{ "name", "value2" },
47-
{ "environment", "value3" }
48-
};
49-
5043
private Dictionary<string, string> _additionalCacheKeysCombined = new Dictionary<string, string>
5144
{
5245
{ "key1", "value1" },
@@ -314,35 +307,6 @@ public async Task CacheExtEnsurePopKeysFunctionAsync()
314307
}
315308
}
316309

317-
[TestMethod]
318-
public async Task CacheExtEnsureInputKeysAreValidTestAsync()
319-
{
320-
string expectedExceptionMessage = "Keys added to cacheKeyComponents are invalid. Offending keys are: client_id\r\nname\r\nenvironment\r\n";
321-
using (var httpManager = new MockHttpManager())
322-
{
323-
var app = ConfidentialClientApplicationBuilder.Create(TestConstants.ClientId)
324-
.WithAuthority(new Uri(ClientApplicationBase.DefaultAuthority), true)
325-
.WithRedirectUri(TestConstants.RedirectUri)
326-
.WithClientSecret(TestConstants.ClientSecret)
327-
.WithHttpManager(httpManager)
328-
.WithExperimentalFeatures()
329-
.BuildConcrete();
330-
331-
var appCacheAccess = app.AppTokenCache.RecordAccess();
332-
333-
//Ensure that an exception is thrown when known keys are added to the cache key components
334-
var exception = await Assert.ThrowsExceptionAsync<ArgumentException>(async () =>
335-
{
336-
await app.AcquireTokenForClient(TestConstants.s_scope.ToArray())
337-
.WithAdditionalCacheKeyComponents(_knownKeyList)
338-
.ExecuteAsync(CancellationToken.None)
339-
.ConfigureAwait(false);
340-
}).ConfigureAwait(false);
341-
342-
Assert.AreEqual(expectedExceptionMessage, exception.Message);
343-
}
344-
}
345-
346310
[TestMethod]
347311
public async Task CacheExtEnsureInputKeysAddedCorrectlyTestAsync()
348312
{

0 commit comments

Comments
 (0)