in src/Authentication/MsalSilentTokenProvider.cs [35:81]
public async Task<AuthenticationResult?> GetTokenAsync(TokenRequest tokenRequest, CancellationToken cancellationToken = default)
{
var accounts = await app.GetAccountsAsync();
foreach (var account in accounts)
{
this.logger.LogTrace(Resources.MsalAccountInCache, $"{account.HomeAccountId?.TenantId}\\{account.Username}");
}
var authority = new Uri(app.Authority);
if (!Guid.TryParse(authority.AbsolutePath.Trim('/'), out Guid authorityTenantId))
{
this.logger.LogTrace(Resources.MsalNoAuthorityTenant, authority);
}
var applicableAccounts = MsalExtensions.GetApplicableAccounts(accounts, authorityTenantId, tokenRequest.LoginHint);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && app.AppConfig.IsBrokerEnabled)
{
applicableAccounts.Add((PublicClientApplication.OperatingSystemAccount, PublicClientApplication.OperatingSystemAccount.HomeAccountId.Identifier));
}
foreach ((IAccount account, string canonicalName) in applicableAccounts)
{
try
{
this.logger.LogTrace(Resources.MsalAccountAttempt, canonicalName);
var result = await app.AcquireTokenSilent(MsalConstants.AzureDevOpsScopes, account)
.WithAccountTenantId(account)
.ExecuteAsync(cancellationToken);
return result;
}
catch (MsalUiRequiredException ex)
{
this.logger.LogTrace(ex.Message);
}
catch (MsalServiceException ex)
{
this.logger.LogWarning(ex.Message);
}
}
return null;
}