An implementation of the Adal token cache that stores the cache items in the DPAPI-protected file.
Inheritance: Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCache
Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 3
0
        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));
        }