Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions CommunityToolkit.Authentication.Msal/MsalProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,7 @@ public override Task<string> GetTokenAsync(bool silentOnly = false)
/// <returns>A new instance of <see cref="PublicClientApplication"/>.</returns>
protected IPublicClientApplication CreatePublicClientApplication(string clientId, string tenantId, string redirectUri, bool listWindowsWorkAndSchoolAccounts)
{
var authority = listWindowsWorkAndSchoolAccounts ? AadAuthorityAudience.AzureAdAndPersonalMicrosoftAccount : AadAuthorityAudience.PersonalMicrosoftAccount;

var clientBuilder = PublicClientApplicationBuilder.Create(clientId)
.WithAuthority(AzureCloudInstance.AzurePublic, authority)
.WithClientName(ProviderManager.ClientName)
.WithClientVersion(Assembly.GetExecutingAssembly().GetName().Version.ToString());

Expand All @@ -198,6 +195,13 @@ protected IPublicClientApplication CreatePublicClientApplication(string clientId
clientBuilder = clientBuilder.WithTenantId(tenantId);
}

// If the TenantId is not provided, use WithAuthority
else
{
var authority = listWindowsWorkAndSchoolAccounts ? AadAuthorityAudience.AzureAdAndPersonalMicrosoftAccount : AadAuthorityAudience.PersonalMicrosoftAccount;
clientBuilder = clientBuilder.WithAuthority(AzureCloudInstance.AzurePublic, authority);
}

#if WINDOWS_UWP || NET5_0_WINDOWS10_0_17763_0
clientBuilder = clientBuilder.WithBroker();
#elif NETCOREAPP3_1
Expand Down