diff --git a/src/Commands/Base/PnPConnection.cs b/src/Commands/Base/PnPConnection.cs index 5bd5b7209..c7c2c434f 100644 --- a/src/Commands/Base/PnPConnection.cs +++ b/src/Commands/Base/PnPConnection.cs @@ -264,7 +264,7 @@ internal static PnPConnection CreateWithDeviceLogin(string clientId, string url, { EnableCaching(url, clientId); } - if (CacheEnabled(url, clientId)) + if (persistLogin && CacheEnabled(url, clientId)) { WriteCacheEnabledMessage(host); } @@ -287,7 +287,10 @@ internal static PnPConnection CreateWithDeviceLogin(string clientId, string url, return Task.FromResult(0); }, azureEnvironment, tokenCacheCallback: async (tokenCache) => { - await MSALCacheHelper(tokenCache, url, clientId); + if (persistLogin) + { + await MSALCacheHelper(tokenCache, url, clientId); + } }); } using (authManager) @@ -458,7 +461,7 @@ internal static PnPConnection CreateWithCredentials(Cmdlet cmdlet, Uri url, PSCr { EnableCaching(url.ToString(), clientId); } - if (CacheEnabled(url.ToString(), clientId)) + if (persistLogin && CacheEnabled(url.ToString(), clientId)) { WriteCacheEnabledMessage(host); } @@ -492,7 +495,10 @@ internal static PnPConnection CreateWithCredentials(Cmdlet cmdlet, Uri url, PSCr { authManager = PnP.Framework.AuthenticationManager.CreateWithCredentials(clientId, credentials.UserName, credentials.Password, redirectUrl, azureEnvironment, tokenCacheCallback: async (tokenCache) => { - await MSALCacheHelper(tokenCache, url.ToString(), clientId); + if (persistLogin) + { + await MSALCacheHelper(tokenCache, url.ToString(), clientId); + } }); } using (authManager) @@ -603,7 +609,7 @@ internal static PnPConnection CreateWithInteractiveLogin(Uri uri, string clientI { EnableCaching(uri.ToString(), clientId); } - if (CacheEnabled(uri.ToString(), clientId)) + if (persistLogin && CacheEnabled(uri.ToString(), clientId)) { WriteCacheEnabledMessage(host); } @@ -628,7 +634,10 @@ internal static PnPConnection CreateWithInteractiveLogin(Uri uri, string clientI htmlMessageFailure, azureEnvironment: azureEnvironment, tokenCacheCallback: async (tokenCache) => { - await MSALCacheHelper(tokenCache, uri.ToString(), clientId); + if (persistLogin) + { + await MSALCacheHelper(tokenCache, uri.ToString(), clientId); + } }, useWAM: enableLoginWithWAM); } using (authManager)