static IAzureSession CreateInstance(IDataStore dataStore = null)
        {
            var session = new AdalSession
            {
                ClientFactory         = new ClientFactory(),
                AuthenticationFactory = new AuthenticationFactory(),
                DataStore             = dataStore ?? new DiskDataStore(),
                OldProfileFile        = "WindowsAzureProfile.xml",
                OldProfileFileBackup  = "WindowsAzureProfile.xml.bak",
                ProfileDirectory      = Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                    Resources.AzureDirectoryName),
                ProfileFile    = "AzureProfile.json",
                TokenCacheFile = "TokenCache.dat"
            };

            try
            {
                FileUtilities.DataStore = session.DataStore;
                FileUtilities.EnsureDirectoryExists(session.ProfileDirectory);
                var cacheFile = Path.Combine(session.ProfileDirectory, session.TokenCacheFile);
                session.TokenCache = new ProtectedFileTokenCache(cacheFile, session.DataStore);
            }
            catch
            {
                session.TokenCache = new AuthenticationStoreTokenCache(new AzureTokenCache());
            }

            return(session);
        }
示例#2
0
        static IAzureSession CreateInstance(IDataStore dataStore = null)
        {
            string profilePath = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                Resources.AzureDirectoryName);

            dataStore = dataStore ?? new DiskDataStore();

            var session = new AdalSession
            {
                ClientFactory         = new ClientFactory(),
                AuthenticationFactory = new AuthenticationFactory(),
                DataStore             = dataStore,
                OldProfileFile        = "WindowsAzureProfile.xml",
                OldProfileFileBackup  = "WindowsAzureProfile.xml.bak",
                ProfileDirectory      = profilePath,
                ProfileFile           = "AzureProfile.json",
            };

            var autoSave = InitializeSessionSettings(dataStore, profilePath, ContextAutosaveSettings.AutoSaveSettingsFile);

            session.ARMContextSaveMode  = autoSave.Mode;
            session.ARMProfileDirectory = autoSave.ContextDirectory;
            session.ARMProfileFile      = autoSave.ContextFile;
            session.TokenCacheDirectory = autoSave.CacheDirectory;
            session.TokenCacheFile      = autoSave.CacheFile;
            session.TokenCache          = InitializeTokenCache(dataStore, session.TokenCacheDirectory, session.TokenCacheFile, autoSave.Mode);
            InitializeDataCollection(session);
            return(session);
        }
示例#3
0
        static IAzureSession CreateInstance(IDataStore dataStore = null)
        {
            string profilePath = Path.Combine(
#if NETSTANDARD
                Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
                Resources.AzureDirectoryName);
            string oldProfilePath = Path.Combine(
#endif
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                Resources.OldAzureDirectoryName);

            dataStore = dataStore ?? new DiskDataStore();


            string oldCachePath = Path.Combine(profilePath, "TokenCache.dat");
            string cachePath    = Path.Combine(SharedUtilities.GetUserRootDirectory(), ".IdentityService");
            var    session      = new AdalSession
            {
                ClientFactory         = new ClientFactory(),
                AuthenticationFactory = new AuthenticationFactory(),
                DataStore             = dataStore,
                OldProfileFile        = "WindowsAzureProfile.xml",
                OldProfileFileBackup  = "WindowsAzureProfile.xml.bak",
                ProfileDirectory      = profilePath,
                ProfileFile           = "AzureProfile.json",
            };

            var migrated =
#if !NETSTANDARD
                false;
#else
                MigrateSettings(dataStore, oldProfilePath, profilePath);
#endif
            var autoSave = InitializeSessionSettings(dataStore, cachePath, profilePath, ContextAutosaveSettings.AutoSaveSettingsFile, migrated);
            session.ARMContextSaveMode  = autoSave.Mode;
            session.ARMProfileDirectory = autoSave.ContextDirectory;
            session.ARMProfileFile      = autoSave.ContextFile;
            session.TokenCacheDirectory = autoSave.CacheDirectory;
            session.TokenCacheFile      = autoSave.CacheFile;

            InitializeConfigs(session);
            InitializeDataCollection(session);
            session.RegisterComponent(HttpClientOperationsFactory.Name, () => HttpClientOperationsFactory.Create());
            session.TokenCache = session.TokenCache ?? new AzureTokenCache();
            return(session);
        }
示例#4
0
        static IAzureSession CreateInstance()
        {
            var session = new AdalSession
            {
                ClientFactory         = new ClientFactory(),
                AuthenticationFactory = new AuthenticationFactory(),
                DataStore             = new DiskDataStore(),
                OldProfileFile        = "WindowsAzureProfile.xml",
                OldProfileFileBackup  = "WindowsAzureProfile.xml.bak",
                ProfileDirectory      = Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                    Resources.AzureDirectoryName),
                ProfileFile    = "AzureProfile.json",
                TokenCacheFile = "TokenCache.dat"
            };

            try
            {
                FileUtilities.DataStore = session.DataStore;
                FileUtilities.EnsureDirectoryExists(session.ProfileDirectory);
                var cacheFile = Path.Combine(session.ProfileDirectory, session.TokenCacheFile);
                var contents  = new byte[0];
                if (session.DataStore.FileExists(cacheFile))
                {
                    contents = session.DataStore.ReadFileAsBytes(cacheFile);
                }

                if (contents != null && contents.Length > 0)
                {
                    contents = ProtectedData.Unprotect(contents, null, DataProtectionScope.CurrentUser);
                }

                session.TokenCache = new ProtectedFileTokenCache(contents);
            }
            catch
            {
                session.TokenCache = new AuthenticationStoreTokenCache(new AzureTokenCache());
            }

            return(session);
        }