Skip to content

Commit f34705e

Browse files
authored
Log MSAL for ConfidentialClient (Azure#23516)
* Log MSAL for ConfidentialClient
1 parent cae139f commit f34705e

File tree

7 files changed

+35
-9
lines changed

7 files changed

+35
-9
lines changed

sdk/identity/Azure.Identity/src/AuthorizationCodeCredential.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,15 @@ internal AuthorizationCodeCredential(string tenantId, string clientId, string cl
9393
_ => null
9494
};
9595

96-
_client = client ?? new MsalConfidentialClient(_pipeline, tenantId, clientId, clientSecret, options as ITokenCacheOptions, null);
96+
_client = client ??
97+
new MsalConfidentialClient(
98+
_pipeline,
99+
tenantId,
100+
clientId,
101+
clientSecret,
102+
options as ITokenCacheOptions,
103+
null,
104+
options?.IsLoggingPIIEnabled ?? false);
97105
}
98106

99107
/// <summary>

sdk/identity/Azure.Identity/src/ClientCertificateCredential.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,16 @@ internal ClientCertificateCredential(string tenantId, string clientId, IX509Cert
134134

135135
ClientCertificateCredentialOptions certCredOptions = (options as ClientCertificateCredentialOptions);
136136

137-
Client = client ?? new MsalConfidentialClient(_pipeline, tenantId, clientId, certificateProvider, certCredOptions?.SendCertificateChain ?? false, options as ITokenCacheOptions, certCredOptions?.RegionalAuthority);
137+
Client = client ??
138+
new MsalConfidentialClient(
139+
_pipeline,
140+
tenantId,
141+
clientId,
142+
certificateProvider,
143+
certCredOptions?.SendCertificateChain ?? false,
144+
options as ITokenCacheOptions,
145+
certCredOptions?.RegionalAuthority,
146+
options?.IsLoggingPIIEnabled ?? false);
138147
}
139148

140149
/// <summary>

sdk/identity/Azure.Identity/src/ClientSecretCredential.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,15 @@ internal ClientSecretCredential(string tenantId, string clientId, string clientS
9090
ClientSecret = clientSecret;
9191
_allowMultiTenantAuthentication = options?.AllowMultiTenantAuthentication ?? false;
9292
_pipeline = pipeline ?? CredentialPipeline.GetInstance(options);
93-
Client = client ?? new MsalConfidentialClient(_pipeline, tenantId, clientId, clientSecret, options as ITokenCacheOptions, (options as ClientSecretCredentialOptions)?.RegionalAuthority);
93+
Client = client ??
94+
new MsalConfidentialClient(
95+
_pipeline,
96+
tenantId,
97+
clientId,
98+
clientSecret,
99+
options as ITokenCacheOptions,
100+
(options as ClientSecretCredentialOptions)?.RegionalAuthority,
101+
options?.IsLoggingPIIEnabled ?? false);
94102
}
95103

96104
/// <summary>

sdk/identity/Azure.Identity/src/MsalClientBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ internal abstract class MsalClientBase<TClient>
1111
where TClient : IClientApplicationBase
1212
{
1313
private readonly AsyncLockWithValue<TClient> _clientAsyncLock;
14+
internal protected bool LogPII { get; protected set; }
1415

1516
/// <summary>
1617
/// For mocking purposes only.

sdk/identity/Azure.Identity/src/MsalConfidentialClient.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,21 @@ protected MsalConfidentialClient()
2222
{
2323
}
2424

25-
public MsalConfidentialClient(CredentialPipeline pipeline, string tenantId, string clientId, string clientSecret, ITokenCacheOptions cacheOptions, RegionalAuthority? regionalAuthority)
25+
public MsalConfidentialClient(CredentialPipeline pipeline, string tenantId, string clientId, string clientSecret, ITokenCacheOptions cacheOptions, RegionalAuthority? regionalAuthority, bool logPii)
2626
: base(pipeline, tenantId, clientId, cacheOptions)
2727
{
2828
_clientSecret = clientSecret;
2929
RegionalAuthority = regionalAuthority;
30+
LogPII = logPii;
3031
}
3132

32-
public MsalConfidentialClient(CredentialPipeline pipeline, string tenantId, string clientId, ClientCertificateCredential.IX509Certificate2Provider certificateProvider, bool includeX5CClaimHeader, ITokenCacheOptions cacheOptions, RegionalAuthority? regionalAuthority)
33+
public MsalConfidentialClient(CredentialPipeline pipeline, string tenantId, string clientId, ClientCertificateCredential.IX509Certificate2Provider certificateProvider, bool includeX5CClaimHeader, ITokenCacheOptions cacheOptions, RegionalAuthority? regionalAuthority, bool logPii)
3334
: base(pipeline, tenantId, clientId, cacheOptions)
3435
{
3536
_includeX5CClaimHeader = includeX5CClaimHeader;
3637
_certificateProvider = certificateProvider;
3738
RegionalAuthority = regionalAuthority;
39+
LogPII = logPii;
3840
}
3941

4042
internal RegionalAuthority? RegionalAuthority { get; }
@@ -43,7 +45,8 @@ protected override async ValueTask<IConfidentialClientApplication> CreateClientA
4345
{
4446
ConfidentialClientApplicationBuilder confClientBuilder = ConfidentialClientApplicationBuilder.Create(ClientId)
4547
.WithAuthority(Pipeline.AuthorityHost.AbsoluteUri, TenantId)
46-
.WithHttpClientFactory(new HttpPipelineClientFactory(Pipeline.HttpPipeline));
48+
.WithHttpClientFactory(new HttpPipelineClientFactory(Pipeline.HttpPipeline))
49+
.WithLogging(AzureIdentityEventSource.Singleton.LogMsal, enablePiiLogging: LogPII);
4750

4851
if (_clientSecret != null)
4952
{

sdk/identity/Azure.Identity/src/MsalPublicClient.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ namespace Azure.Identity
1414
internal class MsalPublicClient : MsalClientBase<IPublicClientApplication>
1515
{
1616
internal string RedirectUrl { get; }
17-
internal bool LogPII { get; }
1817

1918
protected MsalPublicClient()
2019
{ }

sdk/identity/Azure.Identity/tests/samples/TokenCacheSnippets.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ namespace Azure.Identity.Samples
1212
{
1313
public class TokenCacheSnippets
1414
{
15-
#region Snippet:Identity_TokenCache_CustomPersistence_Usage_TokenCachePath
1615
private const string TOKEN_CACHE_PATH = "./tokencache.bin";
17-
#endregion
1816

1917
public void Identity_TokenCache_PersistentDefault()
2018
{

0 commit comments

Comments
 (0)