From 586088b3292c55244141506c3cb61601dc419ffd Mon Sep 17 00:00:00 2001 From: Gautam Sheth Date: Fri, 30 Aug 2024 23:58:49 +0300 Subject: [PATCH] Undo file system caching, need to test some more --- .../PnP.Framework/AuthenticationManager.cs | 33 ++++++------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/src/lib/PnP.Framework/AuthenticationManager.cs b/src/lib/PnP.Framework/AuthenticationManager.cs index ceb4acdb..6c60b32c 100644 --- a/src/lib/PnP.Framework/AuthenticationManager.cs +++ b/src/lib/PnP.Framework/AuthenticationManager.cs @@ -419,9 +419,7 @@ public AuthenticationManager(string clientId, string username, SecureString pass this.username = username; this.password = password; publicClientApplication = builder.Build(); - - var cacheHelper = MsalCacheHelperUtility.CreateCacheHelper(); - cacheHelper?.RegisterCache(publicClientApplication.UserTokenCache); + // register tokencache if callback provided tokenCacheCallback?.Invoke(publicClientApplication.UserTokenCache); authenticationType = ClientContextType.AzureADCredentials; @@ -456,8 +454,12 @@ public AuthenticationManager(string clientId, string redirectUrl = null, string { this.azureEnvironment = azureEnvironment; - PublicClientApplicationBuilder builder = PublicClientApplicationBuilder.Create(clientId).WithHttpClientFactory(HttpClientFactory); ; + PublicClientApplicationBuilder builder = PublicClientApplicationBuilder.Create(clientId).WithHttpClientFactory(HttpClientFactory); builder = GetBuilderWithAuthority(builder, azureEnvironment); + if (!string.IsNullOrEmpty(tenantId)) + { + builder = builder.WithTenantId(tenantId); + } if (useWAM && SharedUtilities.IsWindowsPlatform()) { BrokerOptions brokerOptions = new(BrokerOptions.OperatingSystems.Windows) @@ -465,31 +467,19 @@ public AuthenticationManager(string clientId, string redirectUrl = null, string Title = "Login with M365 PnP", ListOperatingSystemAccounts = true, }; - builder = builder.WithBroker(brokerOptions).WithDefaultRedirectUri().WithParentActivityOrWindow(WindowHandleUtilities.GetConsoleOrTerminalWindow); - - if (!string.IsNullOrEmpty(tenantId)) - { - builder = builder.WithTenantId(tenantId); - } + builder = builder.WithBroker(brokerOptions).WithDefaultRedirectUri().WithParentActivityOrWindow(WindowHandleUtilities.GetConsoleOrTerminalWindow); } else { if (!string.IsNullOrEmpty(redirectUrl)) { builder = builder.WithRedirectUri(redirectUrl); - } - if (!string.IsNullOrEmpty(tenantId)) - { - builder = builder.WithTenantId(tenantId); - } + } this.customWebUi = customWebUi; } builder.WithLegacyCacheCompatibility(false); publicClientApplication = builder.Build(); - - var cacheHelper = MsalCacheHelperUtility.CreateCacheHelper(); - cacheHelper?.RegisterCache(publicClientApplication.UserTokenCache); - + // register tokencache if callback provided tokenCacheCallback?.Invoke(publicClientApplication.UserTokenCache); @@ -535,10 +525,7 @@ public AuthenticationManager(string clientId, string tenantId, Func