diff --git a/src/client/Microsoft.Identity.Client/OAuth2/OAuth2Client.cs b/src/client/Microsoft.Identity.Client/OAuth2/OAuth2Client.cs index 7940d4d88d..2c87c82f21 100644 --- a/src/client/Microsoft.Identity.Client/OAuth2/OAuth2Client.cs +++ b/src/client/Microsoft.Identity.Client/OAuth2/OAuth2Client.cs @@ -221,17 +221,7 @@ internal void AddBodyParameter(KeyValuePair kvp) private void AddCommonHeaders(RequestContext requestContext) { _headers.Add(OAuth2Header.CorrelationId, requestContext.CorrelationId.ToString()); - _headers.Add(OAuth2Header.RequestCorrelationIdInResponse, "true"); - - if (!string.IsNullOrWhiteSpace(requestContext.Logger.ClientName)) - { - _headers.Add(OAuth2Header.AppName, requestContext.Logger.ClientName); - } - - if (!string.IsNullOrWhiteSpace(requestContext.Logger.ClientVersion)) - { - _headers.Add(OAuth2Header.AppVer, requestContext.Logger.ClientVersion); - } + _headers.Add(OAuth2Header.RequestCorrelationIdInResponse, "true"); } public static T CreateResponse(HttpResponse response, RequestContext requestContext) diff --git a/tests/Microsoft.Identity.Test.Unit/TelemetryTests/HttpTelemetryTests.cs b/tests/Microsoft.Identity.Test.Unit/TelemetryTests/HttpTelemetryTests.cs index e775ff7ae7..5e1dd55c2c 100644 --- a/tests/Microsoft.Identity.Test.Unit/TelemetryTests/HttpTelemetryTests.cs +++ b/tests/Microsoft.Identity.Test.Unit/TelemetryTests/HttpTelemetryTests.cs @@ -29,6 +29,7 @@ using static Microsoft.Identity.Client.TelemetryCore.Internal.Events.ApiEvent; using System.Collections.Generic; using Microsoft.Identity.Client.Internal; +using Microsoft.Identity.Client.OAuth2; namespace Microsoft.Identity.Test.Unit.TelemetryTests { @@ -373,16 +374,16 @@ public async Task CallerSdkDetailsTestAsync() var cca = CreateConfidentialClientApp(); await cca.AcquireTokenForClient(TestConstants.s_scope) - .WithExtraQueryParameters(new Dictionary { + .WithExtraQueryParameters(new Dictionary { { "caller-sdk-id", "testApiId" }, { "caller-sdk-ver", "testSdkVersion"} }) .ExecuteAsync().ConfigureAwait(false); AssertCurrentTelemetry( - requestHandler.ActualRequestMessage, - ApiIds.AcquireTokenForClient, + requestHandler.ActualRequestMessage, + ApiIds.AcquireTokenForClient, CacheRefreshReason.NoCachedAccessToken, - callerSdkId: "testApiId", + callerSdkId: "testApiId", callerSdkVersion: "testSdkVersion"); } } @@ -429,6 +430,7 @@ public async Task CallerSdkDetailsWithClientNameTestAsync() .WithClientVersion("testSdkVersion") .WithAuthority(TestConstants.AuthorityCommonTenant) .WithHttpManager(_harness.HttpManager) + .WithLogging((a, b, c) => { }) .BuildConcrete(); await cca.AcquireTokenForClient(TestConstants.s_scope) @@ -443,6 +445,34 @@ await cca.AcquireTokenForClient(TestConstants.s_scope) } } + [TestMethod] + public async Task ClientNameVersionNotInHeaders() + { + using (_harness = CreateTestHarness()) + { + _harness.HttpManager.AddInstanceDiscoveryMockHandler(); + var requestHandler = _harness.HttpManager.AddMockHandlerSuccessfulClientCredentialTokenResponseMessage(); + + var cca = ConfidentialClientApplicationBuilder.Create(TestConstants.ClientId) + .WithClientSecret(TestConstants.ClientSecret) + .WithClientName("testApiId") + .WithClientVersion("testSdkVersion") + .WithAuthority(TestConstants.AuthorityCommonTenant) + .WithHttpManager(_harness.HttpManager) + .WithLogging((a, b, c) => { }) + .BuildConcrete(); + + await cca.AcquireTokenForClient(TestConstants.s_scope) + .ExecuteAsync().ConfigureAwait(false); + + requestHandler.ActualRequestHeaders.TryGetValues(OAuth2Header.AppName, out var appName); + requestHandler.ActualRequestHeaders.TryGetValues(OAuth2Header.AppVer, out var appVer); + + Assert.IsNull(appName); + Assert.IsNull(appVer); + } + } + [TestMethod] public async Task CallerSdkDetailsWithNullClientNameTestAsync() { @@ -698,8 +728,8 @@ private void AssertCurrentTelemetry( ApiIds apiId, CacheRefreshReason cacheInfo, bool isCacheSerialized = false, - bool isLegacyCacheEnabled = true, - string callerSdkId = "", + bool isLegacyCacheEnabled = true, + string callerSdkId = "", string callerSdkVersion = "") { string[] telemetryCategories = requestMessage.Headers.GetValues( @@ -727,6 +757,6 @@ private void AssertCurrentTelemetry( Assert.AreEqual(callerSdkId, telemetryCategories[2].Split(',')[3]); Assert.AreEqual(callerSdkVersion, telemetryCategories[2].Split(',')[4]); - } + } } }