Skip to content

Commit 725ab49

Browse files
committed
msauth: add extra tracing of MSA-PT and ATS
1 parent 68bcc34 commit 725ab49

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/shared/Core/Authentication/MicrosoftAuthentication.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public async Task<IMicrosoftAuthenticationResult> GetTokenAsync(
6868
? "OS broker is available and enabled."
6969
: "OS broker is not available or enabled.");
7070

71+
if (msaPt)
72+
{
73+
Context.Trace.WriteLine("MSA passthrough is enabled.");
74+
}
75+
7176
try
7277
{
7378
// Create the public client application for authentication
@@ -289,17 +294,20 @@ private async Task<AuthenticationResult> GetAccessTokenSilentlyAsync(
289294
{
290295
if (userName is null)
291296
{
292-
Context.Trace.WriteLine("Attempting to acquire token silently for current operating system account...");
297+
Context.Trace.WriteLine(
298+
"Attempting to acquire token silently for current operating system account...");
293299

294-
return await app.AcquireTokenSilent(scopes, PublicClientApplication.OperatingSystemAccount).ExecuteAsync();
300+
return await app.AcquireTokenSilent(scopes, PublicClientApplication.OperatingSystemAccount)
301+
.ExecuteAsync();
295302
}
296303
else
297304
{
298305
Context.Trace.WriteLine($"Attempting to acquire token silently for user '{userName}'...");
299306

300307
// Enumerate all accounts and find the one matching the user name
301308
IEnumerable<IAccount> accounts = await app.GetAccountsAsync();
302-
IAccount account = accounts.FirstOrDefault(x => StringComparer.OrdinalIgnoreCase.Equals(x.Username, userName));
309+
IAccount account = accounts.FirstOrDefault(x =>
310+
StringComparer.OrdinalIgnoreCase.Equals(x.Username, userName));
303311
if (account is null)
304312
{
305313
Context.Trace.WriteLine($"No cached account found for user '{userName}'...");
@@ -325,6 +333,12 @@ private async Task<AuthenticationResult> GetAccessTokenSilentlyAsync(
325333
Context.Trace.WriteLine("Failed to acquire token silently; user interaction is required.");
326334
return null;
327335
}
336+
catch (Exception ex)
337+
{
338+
Context.Trace.WriteLine("Failed to acquire token silently.");
339+
Context.Trace.WriteException(ex);
340+
return null;
341+
}
328342
}
329343

330344
private async Task<IPublicClientApplication> CreatePublicClientApplicationAsync(

0 commit comments

Comments
 (0)