Skip to content

Commit

Permalink
Stop sending x-app-name and x-app-ver as they are ignored (#5037)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgavrilMS authored Jan 1, 2025
1 parent c06c1e2 commit 01e79b1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
12 changes: 1 addition & 11 deletions src/client/Microsoft.Identity.Client/OAuth2/OAuth2Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,7 @@ internal void AddBodyParameter(KeyValuePair<string, string> 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<T>(HttpResponse response, RequestContext requestContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -373,16 +374,16 @@ public async Task CallerSdkDetailsTestAsync()
var cca = CreateConfidentialClientApp();

await cca.AcquireTokenForClient(TestConstants.s_scope)
.WithExtraQueryParameters(new Dictionary<string, string> {
.WithExtraQueryParameters(new Dictionary<string, string> {
{ "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");
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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()
{
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -727,6 +757,6 @@ private void AssertCurrentTelemetry(
Assert.AreEqual(callerSdkId, telemetryCategories[2].Split(',')[3]);

Assert.AreEqual(callerSdkVersion, telemetryCategories[2].Split(',')[4]);
}
}
}
}

0 comments on commit 01e79b1

Please sign in to comment.