private async Task AuthenticateAsync()
 {
     if (session == null)
     {
         session = await client.AuthenticateAsync();
     }
 }
        private async void Continue_Tapped(object sender, TappedRoutedEventArgs e)
        {
            try
            {
                MainPage.ShowLoader(ResourceLoader.GetForCurrentView().GetString("SynchronizingAccountsWithCloud"));

                IOneDriveClient oneDriveClient = OneDriveClientExtensions.GetUniversalClient(new[] { "onedrive.appfolder" });
                AccountSession  session        = await oneDriveClient.AuthenticateAsync();

                IEncrypter encrypter = new AESEncrypter();

                if (session.AccountType == AccountType.MicrosoftAccount)
                {
                    synchronizer.SetEncrypter(encrypter, userKey);
                    await AccountStorage.Instance.Synchronize();

                    MainPage.HideLoader();

                    Frame.Navigate(typeof(SetupSynchronizationFinishedPage), mainPage);
                }
            }
            catch (OneDriveException ex)
            {
                MessageDialog dialog = GetOneDriveErrorMessageDialog(ex);
                await dialog.ShowAsync();
            }
        }
示例#3
0
        private async void ButtonTurnOnSynchronization_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
        {
            try
            {
                ButtonTurnOnSynchronization.IsLoading = true;

                AccountSession session = await oneDriveClient.AuthenticateAsync();

                if (session.AccountType == AccountType.MicrosoftAccount)
                {
                    ISynchronizer synchronizer = new OneDriveSynchronizer(oneDriveClient);
                    await synchronizer.Setup();

                    mainPage.Navigate(typeof(SetupSynchronizationPage), new object[] { synchronizer, mainPage });
                }
            }
            catch (OneDriveException ex)
            {
                ButtonTurnOnSynchronization.IsLoading = false;

                if (!ex.IsMatch(OneDriveErrorCode.Unauthenticated.ToString()) && !ex.IsMatch(OneDriveErrorCode.AccessDenied.ToString()) && !ex.IsMatch(OneDriveErrorCode.AuthenticationCancelled.ToString()) && !ex.IsMatch(OneDriveErrorCode.AuthenticationFailure.ToString()))
                {
                    MainPage.AddBanner(new Banner(BannerType.Danger, ResourceLoader.GetForCurrentView().GetString("UnknownErrorWhileAuthenticating"), true));
                }
            }
        }
示例#4
0
        private async void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                oneDriveClient = OneDriveClientExtensions.GetUniversalClient(scopes);
                var accountSession = await oneDriveClient.AuthenticateAsync();

                if (accountSession!=null)
                {
                    var rootItem = await oneDriveClient
                                        .Drive
                                        .Root
                                        .Request()
                                        .GetAsync();

                   var items=await oneDriveClient
                                          .Drive
                                          .Items[rootItem.Id]
                                          .Children
                                          .Request()
                                          .GetAsync();
                    gridView.ItemsSource = items.CurrentPage;
                }
            }
            catch (OneDriveException oe)
            {
                txtMsg.Text="登陆失败";
            }
        }
 private async void OnOneDriveWebViewLogin(object sender, RoutedEventArgs e)
 {
     _client = OneDriveClientExtensions.GetClientUsingWebAuthenticationBroker(ClientId, Scopes);
     await _client.AuthenticateAsync();
     refreshToken = _client.AuthenticationProvider.CurrentAccountSession.RefreshToken;
     ApplicationData.Current.LocalSettings.Values["RefreshToken"] = refreshToken;
 }
示例#6
0
        public async Task <IOneDriveClient> LoginAsync()
        {
            try {
                if (oneDriveClient == null)
                {
                    oneDriveClient = OneDriveClientExtensions.GetUniversalClient(ServiceConstants.Scopes);
                    await oneDriveClient.AuthenticateAsync();
                }

                if (!oneDriveClient.IsAuthenticated)
                {
                    await oneDriveClient.AuthenticateAsync();
                }

                return(oneDriveClient);
            }
            catch (OneDriveException exception) {
                // Swallow authentication cancelled exceptions
                if (!exception.IsMatch(OneDriveErrorCode.AuthenticationCancelled.ToString()))
                {
                    if (exception.IsMatch(OneDriveErrorCode.AuthenticationFailure.ToString()))
                    {
                        await dialogService.ShowMessage(
                            "Authentication failed",
                            "Authentication failed");
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(oneDriveClient);
        }
示例#7
0
        private async void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                oneDriveClient = OneDriveClientExtensions.GetUniversalClient(scopes);
                var accountSession = await oneDriveClient.AuthenticateAsync();

                if (accountSession != null)
                {
                    var rootItem = await oneDriveClient
                                   .Drive
                                   .Root
                                   .Request()
                                   .GetAsync();

                    var items = await oneDriveClient
                                .Drive
                                .Items[rootItem.Id]
                                .Children
                                .Request()
                                .GetAsync();
                    gridView.ItemsSource = items.CurrentPage;
                }
            }
            catch (OneDriveException oe)
            {
                txtMsg.Text = "登陆失败";
            }
        }
示例#8
0
        public async Task <bool> AuthenticateAsync()
        {
            try
            {
                oneDriveClient = OneDriveClientExtensions.GetUniversalClient(Scopes);
                await oneDriveClient.AuthenticateAsync();
            }
            catch
            {
                System.Diagnostics.Debug.WriteLine("Fail auth. Make sure app is registered in store.");
            }

            try
            {
                // little hack to make shure the service works
                await oneDriveClient.Drive.Request().GetAsync();

                IsAuthenticated = true;
            }
            catch (Exception)
            {
                IsAuthenticated = false;
            }

            return(IsAuthenticated);
        }
示例#9
0
 public async Task Setup()
 {
     // onedrive
     var scopes = new string[] { "wl.basic", "wl.signin", "onedrive.readwrite" };
     client = OneDriveClientExtensions.GetUniversalClient(scopes);
     session = await client.AuthenticateAsync();
 }
        private async void OnOneDriveWebViewLogin(object sender, RoutedEventArgs e)
        {
            _client = OneDriveClientExtensions.GetClientUsingWebAuthenticationBroker(ClientId, Scopes);
            await _client.AuthenticateAsync();

            refreshToken = _client.AuthenticationProvider.CurrentAccountSession.RefreshToken;
            ApplicationData.Current.LocalSettings.Values["RefreshToken"] = refreshToken;
        }
示例#11
0
 public async Task <AccountSession> Initialize()
 {
     // onedrive
     try
     {
         var scopes = new string[] { "wl.basic", "wl.signin", "onedrive.readwrite" };
         client = OneDriveClientExtensions.GetUniversalClient(scopes);
         return(await client.AuthenticateAsync());
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#12
0
 async private void Initialize()
 {
     try
     {
         if (oneDriveClient == null)
         {
             oneDriveClient = OneDriveClientExtensions.GetClientUsingOnlineIdAuthenticator(scopes);
             await oneDriveClient.AuthenticateAsync();
         }
     }
     catch (Exception ex)
     {
     }
 }
        public async Task<IOneDriveClient> LoginAsync()
        {
            if (oneDriveClient == null)
            {
                oneDriveClient = OneDriveClient.GetMicrosoftAccountClient(
                    ServiceConstants.MSA_CLIENT_ID,
                    ServiceConstants.RETURN_URL,
                    ServiceConstants.Scopes,
                    ServiceConstants.MSA_CLIENT_SECRET,
                    null, null,
                    new CustomServiceInfoProvider());
                try
                {
                    await oneDriveClient.AuthenticateAsync();
                }
                catch (Exception ex)
                {
                    Debug.Write(ex);
                }
            }

            try
            {
                if (!oneDriveClient.IsAuthenticated)
                {
                    await oneDriveClient.AuthenticateAsync();
                }

                return oneDriveClient;
            }
            catch (OneDriveException exception)
            {
                // Swallow authentication cancelled exceptions
                if (!exception.IsMatch(OneDriveErrorCode.AuthenticationCancelled.ToString()))
                {
                    if (exception.IsMatch(OneDriveErrorCode.AuthenticationFailure.ToString()))
                    {
                        await dialogService.ShowMessage(
                            "Authentication failed",
                            "Authentication failed");
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return oneDriveClient;
        }
        public async Task <IOneDriveClient> LoginAsync()
        {
            if (oneDriveClient == null)
            {
                oneDriveClient = OneDriveClient.GetMicrosoftAccountClient(
                    OneDriveAuthenticationConstants.MSA_CLIENT_ID,
                    OneDriveAuthenticationConstants.RETURN_URL,
                    OneDriveAuthenticationConstants.Scopes,
                    OneDriveAuthenticationConstants.MSA_CLIENT_SECRET,
                    null, null,
                    new CustomServiceInfoProvider());
                try
                {
                    await oneDriveClient.AuthenticateAsync();
                }
                catch (Exception ex)
                {
                    Debug.Write(ex);
                }
            }

            try
            {
                if (!oneDriveClient.IsAuthenticated)
                {
                    await oneDriveClient.AuthenticateAsync();
                }

                return(oneDriveClient);
            }
            catch (OneDriveException exception)
            {
                // Swallow authentication cancelled exceptions
                if (!exception.IsMatch(OneDriveErrorCode.AuthenticationCancelled.ToString()))
                {
                    if (exception.IsMatch(OneDriveErrorCode.AuthenticationFailure.ToString()))
                    {
                        await dialogService.ShowMessage(
                            "Authentication failed",
                            "Authentication failed");
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(oneDriveClient);
        }
示例#15
0
        public async Task<AccountSession> Initialize()
        {
            // onedrive
            try
            {
                var scopes = new string[] { "wl.basic", "wl.signin", "onedrive.readwrite" };
                client = OneDriveClientExtensions.GetUniversalClient(scopes);
                return await client.AuthenticateAsync();
            }
            catch (Exception)
            {

                throw;
            }

        }
示例#16
0
        private async void AuthenticateClick(object sender, RoutedEventArgs e)
        {
            ShowBusy(true);
            Exception error = null;

            try
            {
                _session = null;

                // Using the OnlineIdAuthenticator
                _client = OneDriveClientExtensions.GetClientUsingOnlineIdAuthenticator(
                    _scopes);

                // Using the WebAuthenticationBroker
                //_client = OneDriveClientExtensions.GetClientUsingWebAuthenticationBroker(
                //    "000000004C172C3F",
                //    _scopes);

                _session = await _client.AuthenticateAsync();

                Debug.WriteLine($"Token: {_session.AccessToken}");

                var dialog = new MessageDialog("You are authenticated!", "Success!");
                await dialog.ShowAsync();

                ShowBusy(false);
            }
            catch (Exception ex)
            {
                error = ex;
            }

            if (error != null)
            {
                var dialog = new MessageDialog("Problem when authenticating!", "Sorry!");
                await dialog.ShowAsync();

                ShowBusy(false);
            }
        }
        /// <summary>
        /// Tests logging into MobileService with Microsoft Account token (via OneDrive SDK).
        /// App needs to be assosciated with a WindowsStoreApp
        /// </summary>
        private async Task TestClientDirectedMicrosoftAccountLogin()
        {
            try
            {
                Task <AccountSession> sessionTask = null;

                // Force AuthenticateAsync() to run on the UI thread.
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    IOneDriveClient oneDriveClient = OneDriveClientExtensions.GetUniversalClient(new string[] { "wl.signin" });
                    sessionTask = oneDriveClient.AuthenticateAsync();
                });

                AccountSession session = await sessionTask;

                if (session != null && session.AccessToken != null)
                {
                    JObject accessToken = new JObject();
                    accessToken["access_token"] = session.AccessToken;

                    MobileServiceUser user = await this.GetClient().LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount, accessToken);

                    Log(string.Format("Log in with Microsoft Account OneDrive SDK succeeded - userId {0}", user.UserId));
                }
                else
                {
                    Assert.Fail("Log in with Microsoft Account OneDrive SDK failed");
                }
            }
            catch (Exception exception)
            {
                Log(string.Format("ExceptionType: {0} Message: {1} StackTrace: {2}",
                                  exception.GetType().ToString(),
                                  exception.Message,
                                  exception.StackTrace));
                Assert.Fail("Log in with Microsoft Account OneDrive SDK failed");
            }
        }
        public async Task <Item> GetItemsFromSelectionAsync(IOneDriveClient oneDriveClient = null)
        {
            const string msa_client_id = "0000000044128B55";
            var          offers        = new string[] { "onedrive.readwrite", "wl.signin" };

            if (oneDriveClient == null)
            {
                oneDriveClient = OneDriveClient.GetMicrosoftAccountClient(
                    msa_client_id,
                    "https://login.live.com/oauth20_desktop.srf",
                    offers,
                    webAuthenticationUi: new FormsWebAuthenticationUi());

                await oneDriveClient.AuthenticateAsync();
            }

            var parts    = this.SelectionId.Split('.');
            var bundleID = parts[2];

            return
                (await
                 oneDriveClient.Drive.Items[bundleID].Request().Expand("thumbnails,children(expand=thumbnails)").GetAsync());
        }
        public async Task<IOneDriveClient> LoginAsync()
        {
            if (oneDriveClient == null)
            {
                oneDriveClient = OneDriveClientExtensions.GetClientUsingWebAuthenticationBroker(MSA_CLIENT_ID, scopes);
                await oneDriveClient.AuthenticateAsync();
            }

            try
            {
                if (!oneDriveClient.IsAuthenticated)
                {
                    await oneDriveClient.AuthenticateAsync();
                }

                return oneDriveClient;
            }
            catch (OneDriveException exception)
            {
                // Swallow authentication cancelled exceptions
                if (!exception.IsMatch(OneDriveErrorCode.AuthenticationCancelled.ToString()))
                {
                    if (exception.IsMatch(OneDriveErrorCode.AuthenticationFailure.ToString()))
                    {
                        await dialogService.ShowMessage(
                            "Authentication failed",
                            "Authentication failed");
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return oneDriveClient;
        }
 private async void OnOneDriveLogin(object sender, RoutedEventArgs e)
 {
     _client = OneDriveClientExtensions.GetClientUsingOnlineIdAuthenticator(Scopes);
     await _client.AuthenticateAsync();
 }
示例#21
0
 private async Task AuthenticateOneDrive()
 {
     string[] scopes = { "wl.signin", "wl.offline_access", "onedrive.readwrite" };
     oneDriveClient = OneDriveClientExtensions.GetClientUsingOnlineIdAuthenticator(scopes);
     await oneDriveClient.AuthenticateAsync();
 }
        public async Task<Item> GetItemsFromSelectionAsync(IOneDriveClient oneDriveClient = null)
        {
            const string msa_client_id = "0000000044128B55";
            var offers = new string[] { "onedrive.readwrite", "wl.signin" };

            if (oneDriveClient == null)
            {
                oneDriveClient = OneDriveClient.GetMicrosoftAccountClient(
                    msa_client_id,
                    "https://login.live.com/oauth20_desktop.srf",
                    offers,
                    webAuthenticationUi: new FormsWebAuthenticationUi());

                await oneDriveClient.AuthenticateAsync();
            }

            var parts = this.SelectionId.Split('.');
            var bundleID = parts[2];
            return
                await
                    oneDriveClient.Drive.Items[bundleID].Request().Expand("thumbnails,children(expand=thumbnails)").GetAsync();
        }
 private async void OnOneDriveLogin(object sender, RoutedEventArgs e)
 {
     _client = OneDriveClientExtensions.GetClientUsingOnlineIdAuthenticator(Scopes);
     await _client.AuthenticateAsync();
 }
示例#24
0
 public async Task AuthenciateAccount()
 {
     await oneDriveClient.AuthenticateAsync();
 }