예제 #1
0
            public void AddCredentialCacheToVault(CredentialCache credentialCache)
            {
                data = credentialCache.GetCacheBlob();
                var str = JsonConvert.SerializeObject(data);

                od.OnAuthUpdated?.OnAuthUpdated(od, str);
            }
예제 #2
0
        private void Initialize()
        {
            if (Client != null)
            {
                return;
            }

            // Load credential cache
            CredentialCache credentialCache = new CredentialCache();

            if (!string.IsNullOrEmpty(Settings.Default.Credentials))
            {
                credentialCache.InitializeCacheFromBlob(Convert.FromBase64String(Settings.Default.Credentials));
            }

            // Authenticate with OneDrive
            Func <CredentialCache, AccountSession> authenticate = cc =>
            {
                Client = OneDriveClient.GetMicrosoftAccountClient(applicationId, applicationReturnUrl, applicationScopes, applicationSecret, cc, null, new OneDriveInfoProvider());
                Task <AccountSession> oneDriveSessionTask = Client.AuthenticateAsync();
                oneDriveSessionTask.Wait();
                return(oneDriveSessionTask.Result);
            };

            try
            {
                Session = authenticate(credentialCache);
            }
            catch
            {
                credentialCache = new CredentialCache();
                Session         = authenticate(credentialCache);
            }

            // Save credentials
            if (Session == null)
            {
                Settings.Default.Credentials = null;
                Settings.Default.Save();
            }
            else if (credentialCache.HasStateChanged)
            {
                Settings.Default.Credentials = Convert.ToBase64String(credentialCache.GetCacheBlob());
                Settings.Default.Save();
            }

            // Find specified root folder
            if (!Path.StartsWith("/") || !IsPathValid(Path))
            {
                throw new Exception("The specified path is not valid");
            }

            Task <Item> task;

            if (Path.Length == 1)
            {
                task = Client.Drive.Root.Request().GetAsync();
            }
            else
            {
                task = Client.Drive.Root.ItemWithPath(Path.Trim('/')).Request().GetAsync();
            }

            task.Wait();
            root = task.Result;
        }
예제 #3
0
 public void SaveCacheBlod() => SettingsWorker.Current.SaveCacheBlod(_credentialCache?.GetCacheBlob());