Skip to content

Commit

Permalink
msauth: add extra tracing of MSA-PT and ATS
Browse files Browse the repository at this point in the history
  • Loading branch information
mjcheetham committed Jul 31, 2023
1 parent 68bcc34 commit 029c1f3
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/shared/Core/Authentication/MicrosoftAuthentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public async Task<IMicrosoftAuthenticationResult> GetTokenAsync(
? "OS broker is available and enabled."
: "OS broker is not available or enabled.");

if (msaPt)
{
Context.Trace.WriteLine("MSA passthrough is enabled.");
}

try
{
// Create the public client application for authentication
Expand Down Expand Up @@ -289,17 +294,20 @@ private async Task<AuthenticationResult> GetAccessTokenSilentlyAsync(
{
if (userName is null)
{
Context.Trace.WriteLine("Attempting to acquire token silently for current operating system account...");
Context.Trace.WriteLine(
"Attempting to acquire token silently for current operating system account...");

return await app.AcquireTokenSilent(scopes, PublicClientApplication.OperatingSystemAccount).ExecuteAsync();
return await app.AcquireTokenSilent(scopes, PublicClientApplication.OperatingSystemAccount)
.ExecuteAsync();
}
else
{
Context.Trace.WriteLine($"Attempting to acquire token silently for user '{userName}'...");

// Enumerate all accounts and find the one matching the user name
IEnumerable<IAccount> accounts = await app.GetAccountsAsync();
IAccount account = accounts.FirstOrDefault(x => StringComparer.OrdinalIgnoreCase.Equals(x.Username, userName));
IAccount account = accounts.FirstOrDefault(x =>
StringComparer.OrdinalIgnoreCase.Equals(x.Username, userName));
if (account is null)
{
Context.Trace.WriteLine($"No cached account found for user '{userName}'...");
Expand All @@ -325,6 +333,11 @@ private async Task<AuthenticationResult> GetAccessTokenSilentlyAsync(
Context.Trace.WriteLine("Failed to acquire token silently; user interaction is required.");
return null;
}
catch (Exception ex)
{
Context.Trace.WriteLine("Failed to acquire token silently.");
Context.Trace.WriteException(ex);
}
}

private async Task<IPublicClientApplication> CreatePublicClientApplicationAsync(
Expand Down

0 comments on commit 029c1f3

Please sign in to comment.