diff --git a/src/client/Microsoft.Identity.Client/AppConfig/AbstractApplicationBuilder.cs b/src/client/Microsoft.Identity.Client/AppConfig/AbstractApplicationBuilder.cs
index e62c1f032e..5563d88e29 100644
--- a/src/client/Microsoft.Identity.Client/AppConfig/AbstractApplicationBuilder.cs
+++ b/src/client/Microsoft.Identity.Client/AppConfig/AbstractApplicationBuilder.cs
@@ -542,38 +542,6 @@ public T WithTelemetry(ITelemetryConfig telemetryConfig)
return (T)this;
}
- ///
- /// Sets telemetry client for the application.
- ///
- /// List of telemetry clients to add telemetry logs.
- /// The builder to chain the .With methods
- public T WithTelemetryClient(params ITelemetryClient[] telemetryClients)
- {
- ValidateUseOfExperimentalFeature("ITelemetryClient");
-
- if (telemetryClients == null)
- {
- throw new ArgumentNullException(nameof(telemetryClients));
- }
-
- if (telemetryClients.Length > 0)
- {
- foreach (var telemetryClient in telemetryClients)
- {
- if (telemetryClient == null)
- {
- throw new ArgumentNullException(nameof(telemetryClient));
- }
-
- telemetryClient.Initialize();
- }
-
- Config.TelemetryClients = telemetryClients;
- }
-
- return (T)this;
- }
-
internal virtual void Validate()
{
if (string.IsNullOrWhiteSpace(Config.ClientId))
diff --git a/src/client/Microsoft.Identity.Client/AppConfig/ConfidentialClientApplicationBuilder.cs b/src/client/Microsoft.Identity.Client/AppConfig/ConfidentialClientApplicationBuilder.cs
index 1255e4a6e1..8cd595fbdf 100644
--- a/src/client/Microsoft.Identity.Client/AppConfig/ConfidentialClientApplicationBuilder.cs
+++ b/src/client/Microsoft.Identity.Client/AppConfig/ConfidentialClientApplicationBuilder.cs
@@ -10,6 +10,7 @@
using Microsoft.Identity.Client.Extensibility;
using Microsoft.Identity.Client.Internal;
using Microsoft.Identity.Client.Internal.ClientCredential;
+using Microsoft.IdentityModel.Abstractions;
namespace Microsoft.Identity.Client
{
@@ -313,6 +314,38 @@ public ConfidentialClientApplicationBuilder WithCacheSynchronization(bool enable
return this;
}
+ ///
+ /// Sets telemetry client for the application.
+ ///
+ /// List of telemetry clients to add telemetry logs.
+ /// The builder to chain the .With methods
+ public ConfidentialClientApplicationBuilder WithTelemetryClient(params ITelemetryClient[] telemetryClients)
+ {
+ ValidateUseOfExperimentalFeature("ITelemetryClient");
+
+ if (telemetryClients == null)
+ {
+ throw new ArgumentNullException(nameof(telemetryClients));
+ }
+
+ if (telemetryClients.Length > 0)
+ {
+ foreach (var telemetryClient in telemetryClients)
+ {
+ if (telemetryClient == null)
+ {
+ throw new ArgumentNullException(nameof(telemetryClient));
+ }
+
+ telemetryClient.Initialize();
+ }
+
+ Config.TelemetryClients = telemetryClients;
+ }
+
+ return this;
+ }
+
internal ConfidentialClientApplicationBuilder WithAppTokenCacheInternalForTest(ITokenCacheInternal tokenCacheInternal)
{
Config.AppTokenCacheInternalForTest = tokenCacheInternal;
diff --git a/tests/Microsoft.Identity.Test.Unit/PublicApiTests/TelemetryClientTests.cs b/tests/Microsoft.Identity.Test.Unit/PublicApiTests/TelemetryClientTests.cs
index 382966178e..163902cb6e 100644
--- a/tests/Microsoft.Identity.Test.Unit/PublicApiTests/TelemetryClientTests.cs
+++ b/tests/Microsoft.Identity.Test.Unit/PublicApiTests/TelemetryClientTests.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Threading;
using System.Threading.Tasks;
using Microsoft.Identity.Client;
using Microsoft.Identity.Client.TelemetryCore;
@@ -20,7 +21,7 @@ namespace Microsoft.Identity.Test.Unit.PublicApiTests
public class TelemetryClientTests : TestBase
{
private MockHttpAndServiceBundle _harness;
- private PublicClientApplication _pca;
+ private ConfidentialClientApplication _cca;
private TelemetryClient _telemetryClient;
[TestInitialize]
@@ -95,23 +96,23 @@ public async Task AcquireTokenSuccessfulTelemetryTestAsync()
_harness.HttpManager.AddInstanceDiscoveryMockHandler();
CreateApplication();
- _pca.ServiceBundle.ConfigureMockWebUI();
- _harness.HttpManager.AddSuccessTokenResponseMockHandlerForPost();
+ _harness.HttpManager.AddMockHandlerSuccessfulClientCredentialTokenResponseMessage();
// Acquire token interactively
- var result = await _pca
- .AcquireTokenInteractive(TestConstants.s_scope)
- .ExecuteAsync()
- .ConfigureAwait(false);
+ var result = await _cca.AcquireTokenForClient(TestConstants.s_scope)
+ .WithAuthority(TestConstants.AuthorityUtidTenant)
+ .ExecuteAsync(CancellationToken.None).ConfigureAwait(false);
Assert.IsNotNull(result);
MsalTelemetryEventDetails eventDetails = _telemetryClient.TestTelemetryEventDetails;
- AssertLoggedTelemetry(result, eventDetails, TokenSource.IdentityProvider, CacheRefreshReason.NotApplicable);
+ AssertLoggedTelemetry(result, eventDetails, TokenSource.IdentityProvider, CacheRefreshReason.NoCachedAccessToken);
// Acquire token silently
- var account = (await _pca.GetAccountsAsync().ConfigureAwait(false)).Single();
- result = await _pca.AcquireTokenSilent(TestConstants.s_scope, account).ExecuteAsync().ConfigureAwait(false);
+ var account = (await _cca.GetAccountsAsync().ConfigureAwait(false)).Single();
+ result = await _cca.AcquireTokenSilent(TestConstants.s_scope, account)
+ .WithAuthority(TestConstants.AuthorityUtidTenant)
+ .ExecuteAsync().ConfigureAwait(false);
Assert.IsNotNull(result);
eventDetails = _telemetryClient.TestTelemetryEventDetails;
@@ -132,14 +133,15 @@ private void AssertLoggedTelemetry(AuthenticationResult authenticationResult, Ms
private void CreateApplication()
{
- _pca = PublicClientApplicationBuilder.Create(TestConstants.ClientId)
- .WithHttpManager(_harness.HttpManager)
- .WithDefaultRedirectUri()
- .WithExperimentalFeatures()
- .WithTelemetryClient(_telemetryClient)
- .BuildConcrete();
-
- TokenCacheHelper.PopulateCache(_pca.UserTokenCacheInternal.Accessor);
+ _cca = ConfidentialClientApplicationBuilder
+ .Create(TestConstants.ClientId)
+ .WithClientSecret(TestConstants.ClientSecret)
+ .WithHttpManager(_harness.HttpManager)
+ .WithExperimentalFeatures()
+ .WithTelemetryClient(_telemetryClient)
+ .BuildConcrete();
+
+ TokenCacheHelper.PopulateCache(_cca.UserTokenCacheInternal.Accessor);
}
}