static IAzureTokenCache InitializeTokenCache(IDataStore store, string cacheDirectory, string cacheFile, string autoSaveMode) { IAzureTokenCache result = new AuthenticationStoreTokenCache(new AzureTokenCache()); if (autoSaveMode == ContextSaveMode.CurrentUser) { try { FileUtilities.DataStore = store; FileUtilities.EnsureDirectoryExists(cacheDirectory); var cachePath = Path.Combine(cacheDirectory, cacheFile); result = new ProtectedFileTokenCache(cachePath, store); } catch { } } return(result); }
static IAzureTokenCache InitializeTokenCache(IDataStore store, string cacheDirectory, string cacheFile, string autoSaveMode) { IAzureTokenCache result = new AuthenticationStoreTokenCache(new AzureTokenCache()); if (autoSaveMode == ContextSaveMode.CurrentUser) { try { FileUtilities.DataStore = store; FileUtilities.EnsureDirectoryExists(cacheDirectory); var cachePath = Path.Combine(cacheDirectory, cacheFile); result = new ProtectedFileTokenCache(cachePath, store); } catch (Exception ex) { TracingAdapter.Information("[AzureSessionInitializer]: Cannot initialize token cache in 'CurrentUser' mode. Falling back to 'Process' mode."); TracingAdapter.Information($"[AzureSessionInitializer]: Message: {ex.Message}; Stacktrace: {ex.StackTrace}"); } } return(result); }
public void DeleteCorruptedTokenCache() { //setup string testFileName = @"c:\foobar\TokenCache.dat"; AzureSession.DataStore.WriteFile(testFileName, new byte[] { 0, 1 }); //Act ProtectedFileTokenCache tokenCache = new ProtectedFileTokenCache(testFileName); //Assert Assert.False(AzureSession.DataStore.FileExists(testFileName)); }