Skip to content

Commit d985141

Browse files
Merge pull request #191 from Richasy/anran/removeNullProvider
Avoid adding empty providers
2 parents 15513b1 + 43dc26b commit d985141

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

CommunityToolkit.Authentication.Uwp/WindowsProvider.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,24 +562,37 @@ private async Task<List<WebAccountProvider>> GetWebAccountProvidersAsync()
562562
if (_webAccountProviderConfig.WebAccountProviderType == WebAccountProviderType.Any ||
563563
_webAccountProviderConfig.WebAccountProviderType == WebAccountProviderType.Msa)
564564
{
565-
providers.Add(await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftProviderId, MicrosoftAccountAuthority));
565+
await FindAndAddProviderAsync(MicrosoftProviderId, MicrosoftAccountAuthority);
566566
}
567567

568568
// AAD
569569
if (_webAccountProviderConfig.WebAccountProviderType == WebAccountProviderType.Any ||
570570
_webAccountProviderConfig.WebAccountProviderType == WebAccountProviderType.Aad)
571571
{
572-
providers.Add(await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftProviderId, AadAuthority));
572+
await FindAndAddProviderAsync(MicrosoftProviderId, AadAuthority);
573573
}
574574

575575
// Local
576576
if (_webAccountProviderConfig.WebAccountProviderType == WebAccountProviderType.Any ||
577577
_webAccountProviderConfig.WebAccountProviderType == WebAccountProviderType.Local)
578578
{
579-
providers.Add(await WebAuthenticationCoreManager.FindAccountProviderAsync(LocalProviderId));
579+
await FindAndAddProviderAsync(LocalProviderId);
580580
}
581581

582582
return providers;
583+
584+
async Task FindAndAddProviderAsync(
585+
string webAccountProviderId,
586+
string authority = default)
587+
{
588+
var provider = string.IsNullOrEmpty(authority)
589+
? await WebAuthenticationCoreManager.FindAccountProviderAsync(webAccountProviderId)
590+
: await WebAuthenticationCoreManager.FindAccountProviderAsync(webAccountProviderId, authority);
591+
if (provider != null)
592+
{
593+
providers.Add(provider);
594+
}
595+
}
583596
}
584597
}
585598
}

0 commit comments

Comments
 (0)