Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -290,6 +290,8 @@ private void UpdateCallerSdkDetails(ApiEvent apiEvent)
string callerSdkId;
string callerSdkVer;

RemoveCallerSdkCacheKeyComponents();

// Check if ExtraQueryParameters contains caller-sdk-id and caller-sdk-ver
if (AuthenticationRequestParameters.ExtraQueryParameters.TryGetValue(Constants.CallerSdkIdKey, out callerSdkId))
{
Expand All @@ -313,6 +315,29 @@ private void UpdateCallerSdkDetails(ApiEvent apiEvent)
apiEvent.CallerSdkVersion = callerSdkVer == null ? null : callerSdkVer.Substring(0, Math.Min(callerSdkVer.Length, Constants.CallerSdkVersionMaxLength));
}

private void RemoveCallerSdkCacheKeyComponents()
{
RemoveCacheKeyComponent(Constants.CallerSdkIdKey);
RemoveCacheKeyComponent(Constants.CallerSdkVersionKey);
}

private void RemoveCacheKeyComponent(string key)
{
var cacheKeyComponents = AuthenticationRequestParameters.CacheKeyComponents;

if (cacheKeyComponents == null)
{
return;
}

foreach (string cacheKeyComponent in cacheKeyComponents.Keys
.Where(cacheKeyComponent => string.Equals(cacheKeyComponent, key, StringComparison.OrdinalIgnoreCase))
.ToArray())
{
cacheKeyComponents.Remove(cacheKeyComponent);
}
}

private AssertionType GetAssertionType()
{
if (ServiceBundle.Config.IsManagedIdentity ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,48 @@ await cca.AcquireTokenForClient(TestConstants.s_scope)
}
}

[TestMethod]
public async Task CallerSdkDetails_AreNeverIncludedInCacheKeyComponentsAsync()
{
using (_harness = CreateTestHarness())
{
// Arrange
_harness.HttpManager.AddInstanceDiscoveryMockHandler();
_harness.HttpManager.AddMockHandlerSuccessfulClientCredentialTokenResponseMessage();

var cca = CreateConfidentialClientApp();
var extraQueryParameters = new Dictionary<string, (string, bool)>
{
{ Constants.CallerSdkIdKey, ("testApiId", true) },
{ Constants.CallerSdkVersionKey, ("testSdkVersion", true) },
{ "custom-cache-key-component", ("custom-value", true) }
};

// Act
await cca.AcquireTokenForClient(TestConstants.s_scope)
.WithExtraQueryParameters(extraQueryParameters)
.ExecuteAsync()
.ConfigureAwait(false);

await cca.AcquireTokenForClient(TestConstants.s_scope)
.WithExtraQueryParameters(new Dictionary<string, (string, bool)>
{
{ Constants.CallerSdkIdKey, ("otherApiId", true) },
{ Constants.CallerSdkVersionKey, ("otherSdkVersion", true) },
{ "custom-cache-key-component", ("custom-value", true) }
})
.ExecuteAsync()
.ConfigureAwait(false);

// Assert
var cachedAccessToken = cca.AppTokenCacheInternal.Accessor.GetAllAccessTokens().Single();

CollectionAssert.AreEquivalent(
new[] { "custom-cache-key-component" },
cachedAccessToken.AdditionalCacheKeyComponents.Keys.ToArray());
}
}

[TestMethod]
public async Task CallerSdkDetailsWithClientNameTestAsync()
{
Expand Down
Loading