From 39f11ea538c95d21a140470ce1039e6d8b971fa0 Mon Sep 17 00:00:00 2001 From: Anran Zhang Date: Tue, 26 Oct 2021 10:47:20 +0800 Subject: [PATCH] Fix AAD silent login problem --- CommunityToolkit.Authentication.Uwp/WindowsProvider.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CommunityToolkit.Authentication.Uwp/WindowsProvider.cs b/CommunityToolkit.Authentication.Uwp/WindowsProvider.cs index 57bc2ea..b0f1235 100644 --- a/CommunityToolkit.Authentication.Uwp/WindowsProvider.cs +++ b/CommunityToolkit.Authentication.Uwp/WindowsProvider.cs @@ -31,6 +31,7 @@ public class WindowsProvider : BaseProvider private const string MicrosoftProviderId = "https://login.microsoft.com"; private const string SettingsKeyAccountId = "WindowsProvider_AccountId"; private const string SettingsKeyProviderId = "WindowsProvider_ProviderId"; + private const string SettingsKeyProviderAuthority = "WindowsProvider_Authority"; private static readonly SemaphoreSlim SemaphoreSlim = new (1); @@ -355,6 +356,7 @@ private async Task SetAccountAsync(WebAccount account) _webAccount = account; Settings[SettingsKeyAccountId] = account.Id; Settings[SettingsKeyProviderId] = account.WebAccountProvider.Id; + Settings[SettingsKeyProviderAuthority] = account.WebAccountProvider.Authority; State = ProviderState.SignedIn; } @@ -370,9 +372,10 @@ private async Task AuthenticateSilentAsync(string[] scope { // Check the cache for an existing user if (Settings[SettingsKeyAccountId] is string savedAccountId && - Settings[SettingsKeyProviderId] is string savedProviderId) + Settings[SettingsKeyProviderId] is string savedProviderId && + Settings[SettingsKeyProviderAuthority] is string savedProviderAuthority) { - var savedProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync(savedProviderId); + var savedProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync(savedProviderId, savedProviderAuthority); account = await WebAuthenticationCoreManager.FindAccountAsync(savedProvider, savedAccountId); } }