public void TestLoginAsyncNullScopes()
 {
     var authClient = new LiveAuthClient();
     try
     {
         authClient.LoginAsync(null);
         Assert.Fail("Expected ArgumentNullException to be thrown.");
     }
     catch (ArgumentNullException)
     {
     }
 }
 public async void TestLoginAsyncNullScopes()
 {
     var authClient = new LiveAuthClient("SomeClientId");
     try
     {
         LiveLoginResult result = await authClient.LoginAsync(null);
         Assert.Fail("Expected ArgumentNullException to be thrown.");
     }
     catch (ArgumentNullException)
     {
     }
 }
        private static ZumoTest CreateLiveSDKLoginTest()
        {
            return(new ZumoTest("Login via token with Live SDK", async delegate(ZumoTest test)
            {
                var client = ZumoTestGlobals.Instance.Client;
#if !WINDOWS_PHONE
                var uri = client.ApplicationUri.ToString();
                var liveIdClient = new LiveAuthClient(uri);
#else
                string clientId;
                testPropertyBag.TryGetValue(ClientIdKeyName, out clientId);
                if (clientId == null)
                {
                    test.AddLog("ClientId of Microsoft application not entered correctly.");
                    return false;
                }

                var liveIdClient = new LiveAuthClient(clientId);
#endif
                var liveLoginResult = await liveIdClient.LoginAsync(new string[] { "wl.basic" });
                if (liveLoginResult.Status == LiveConnectSessionStatus.Connected)
                {
                    var liveConnectClient = new LiveConnectClient(liveLoginResult.Session);
                    var me = await liveConnectClient.GetAsync("me");
                    test.AddLog("Logged in as {0}", me.RawResult);
                    if (liveLoginResult.Session.AuthenticationToken == null)
                    {
                        test.AddLog("Error, authentication token in the live login result is null");
                        return false;
                    }
                    else
                    {
                        var token = new JObject(new JProperty("authenticationToken", liveLoginResult.Session.AuthenticationToken));
                        var user = await client.LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount, token);
                        test.AddLog("Logged in as {0}", user.UserId);
                        return true;
                    }
                }
                else
                {
                    test.AddLog("Login failed.");
                    return false;
                }
            }, ZumoTestGlobals.RuntimeFeatureNames.LIVE_LOGIN));
        }
示例#4
0
        public async Task <UserInfo> Authenticate()
        {
            var authClient = new LiveAuthClient();
            var authResult = await authClient.LoginAsync(new List <string>() { "wl.signin", "wl.basic", "wl.skydrive" });

            if (authResult.Status == LiveConnectSessionStatus.Connected)
            {
                var session      = authResult.Session;
                var client       = new LiveConnectClient(session);
                var liveOpResult = await client.GetAsync("me");

                dynamic dynResult = liveOpResult.Result;
                return(new UserInfo {
                    Id = dynResult.id, UserName = dynResult.name, Name = dynResult.name
                });
            }
            return(null);
        }
    public async Task <LiveConnectClient> Login()
    {
        _authClient = new LiveAuthClient("**your client id here**");

        LiveLoginResult result = await _authClient.InitializeAsync(Scopes);

        if (result.Status == LiveConnectSessionStatus.Connected)
        {
            return(new LiveConnectClient(result.Session));
        }
        result = await _authClient.LoginAsync(Scopes);

        if (result.Status == LiveConnectSessionStatus.Connected)
        {
            return(new LiveConnectClient(result.Session));
        }
        return(null);
    }
示例#6
0
        public async Task <LiveConnectClient> Login()
        {
            AuthClient = new LiveAuthClient("000000004015B444");

            LiveLoginResult result = await AuthClient.InitializeAsync(new string[] { "wl.signin", "wl.skydrive" });

            if (result.Status == LiveConnectSessionStatus.Connected)
            {
                return(new LiveConnectClient(result.Session));
            }
            result = await AuthClient.LoginAsync(new string[] { "wl.signin", "wl.skydrive" });

            if (result.Status == LiveConnectSessionStatus.Connected)
            {
                return(new LiveConnectClient(result.Session));
            }
            return(null);
        }
示例#7
0
        public override async Task LoginAsync(IList <string> scopes)
        {
            if (string.IsNullOrEmpty(ClientId))
            {
                EtcUtility.Instance.MsgBox("ClientId Required");
                return;
            }

            if (AuthClient == null)
            {
                AuthClient = authClient = new LiveAuthClient(ClientId);
            }
            else
            {
                authClient = (LiveAuthClient)AuthClient;
            }

            try
            {
                IsBusy = true;
                await TaskEx.Run(() =>
                {
                    StaticFunctions.InvokeIfRequiredAsync(StaticFunctions.BaseContext,
                                                          para =>
                    {
                        //authClient.LoginCompleted +=
                        //    (s, e) =>
                        //    {
                        //        if (e.Status == LiveConnectSessionStatus.Connected)
                        //        {
                        //            LoadUser();
                        //        }
                        //    };
                        //두번째 접속 시도
                        authClient.LoginAsync(scopes);
                    }, null);
                });
            }
            catch (Exception ex)
            {
                EtcUtility.Instance.MsgBox("NotConnectLiveID " + ex.Message);
            }
        }
        private async void SignIn(object sender, RoutedEventArgs e)
        {
            try
            {
                LiveAuthClient  auth        = new LiveAuthClient();
                LiveLoginResult loginResult =
                    await auth.LoginAsync(new string[] { "wl.basic" });

                if (loginResult.Status == LiveConnectSessionStatus.Connected)
                {
                    this.infoTextBlock.Text = "Signed in.";
                }
            }
            catch (LiveAuthException exception)
            {
                this.infoTextBlock.Text = "Error signing in: "
                                          + exception.Message;
            }
        }
示例#9
0
        /// <summary>
        /// Upload a file to OneDrive
        /// </summary>
        /// <param name="Filename"></param>
        /// <param name="Content"></param>
        /// <returns></returns>
        public static async Task <int> UploadFileAsync(String Foldername, String Filename)
        {
            try
            {
                //  create OneDrive auth client
                var authClient = new LiveAuthClient();

                //  ask for both read and write access to the OneDrive
                LiveLoginResult result = await authClient.LoginAsync(new string[] { "wl.signin", "wl.skydrive", "wl.skydrive_update" });

                //  if login successful
                if (result.Status == LiveConnectSessionStatus.Connected)
                {
                    //  create a OneDrive client
                    liveClient = new LiveConnectClient(result.Session);

                    //  create a local file
                    StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(Filename);

                    //  create a folder
                    string folderID = await GetFolderIDAsync(Foldername, true);

                    if (string.IsNullOrEmpty(folderID))
                    {
                        //  return error
                        return(0);
                    }

                    //  upload local file to OneDrive
                    await liveClient.BackgroundUploadAsync(folderID, file.Name, file, OverwriteOption.Overwrite);

                    return(1);
                }
            }
            catch (Exception e)
            {
                return(e.Message.Length);
            }

            //  return error
            return(0);
        }
示例#10
0
        private async void signInButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                LiveLoginResult loginResult = await _liveAuthClient.LoginAsync(_scopes);

                if (loginResult.Status == LiveConnectSessionStatus.Connected)
                {
                    _liveConnectClient = new LiveConnectClient(loginResult.Session);

                    responseTextBlock.Text = "signed in";

                    createPageButton.IsEnabled = true;
                }
            }
            catch (LiveAuthException ex)
            {
                responseTextBlock.Text = ex.ToString();
            }
        }
示例#11
0
        private async void downButton_Click_1(object sender, RoutedEventArgs e) //下载
        {
            try
            {
                msgText.Text = "亲:正在下载";
                string id         = string.Empty;
                var    authClient = new LiveAuthClient();
                var    authResult = await authClient.LoginAsync(new string[] { "wl.skydrive" });

                if (authResult.Session != null)
                {
                    var connectClient = new LiveConnectClient(authResult.Session);



                    LiveOperationResult operationResult = await connectClient.GetAsync("me/skydrive/search?q=WorkBook.xml");

                    List <object> items = operationResult.Result["data"] as List <object>;
                    IDictionary <string, object> file = items.First() as IDictionary <string, object>;
                    id = file["id"].ToString();

                    LiveDownloadOperation operation = await connectClient.CreateBackgroundDownloadAsync(string.Format("{0}/content", id));

                    var result = await operation.StartAsync();

                    Stream stream = result.Stream.AsStreamForRead();

                    StorageFolder localFolder = ApplicationData.Current.LocalFolder;
                    StorageFile   files       = await localFolder.GetFileAsync(App.WordBookFileName);

                    XDocument xBook = XDocument.Load(stream);
                    await FileIO.WriteTextAsync(files, xBook.ToString());

                    msgText.Text = "恭喜:您已成功从OneDrive下载生词!";
                }
            }
            catch (Exception ex)
            {
                msgText.Text = ex.Message;
            }
        }
        private async Task Authenticate()
        {
            try
            {
                var liveIdClient = new LiveAuthClient("000000004810306D");
                var initResult   = await liveIdClient.InitializeAsync(scopes);

                _session = initResult.Session;

                if (null == _session)
                {
                    LiveLoginResult result = await liveIdClient.LoginAsync(scopes);

                    if (result.Status == LiveConnectSessionStatus.Connected)
                    {
                        _session = result.Session;
                        if (AuthenticationSuccessful != null)
                        {
                            AuthenticationSuccessful();
                        }
                    }
                    else
                    {
                        _session = null;
                        if (AuthenticationFailed != null)
                        {
                            AuthenticationFailed();
                        }
                        //MessageBox.Show("Unable to authenticate with Windows Live.", "Login failed :(", MessageBoxButton.OK);
                    }
                }

                if (AuthenticationSuccessful != null)
                {
                    AuthenticationSuccessful();
                }
            }
            catch (Exception)
            {
            }
        }
示例#13
0
        private async System.Threading.Tasks.Task Authenticate()
        {
            LiveAuthClient liveIdClient = new LiveAuthClient("https://idb.azure-mobile.net/");

            while (session == null)
            {
                // Force a logout to make it easier to test with multiple Microsoft Accounts
                if (liveIdClient.CanLogout)
                {
                    liveIdClient.Logout();
                }

                LiveLoginResult result = await liveIdClient.LoginAsync(new[] { "wl.basic" });

                if (result.Status == LiveConnectSessionStatus.Connected)
                {
                    session = result.Session;
                    LiveConnectClient   client   = new LiveConnectClient(result.Session);
                    LiveOperationResult meResult = await client.GetAsync("me");

                    MobileServiceUser loginResult = await App.MobileService.LoginAsync(result.Session.AuthenticationToken);

                    //string title = string.Format("Welcome {0}!", meResult.Result["first_name"]);
                    App.LoginName = string.Format("{0}", meResult.Result["name"]);
                    App.Gender    = string.Format("{0}", meResult.Result["gender"]);
                    App.UserID    = string.Format("{0}", loginResult.UserId);

                    //var message = string.Format("You are now logged in - {0}", loginResult.UserId);
                    //var dialog = new MessageDialog(message, title);
                    //dialog.Commands.Add(new UICommand("OK"));
                    //await dialog.ShowAsync();
                }
                else
                {
                    session = null;
                    var dialog = new MessageDialog("You must log in.", "Login Required");
                    dialog.Commands.Add(new UICommand("OK"));
                    await dialog.ShowAsync();
                }
            }
        }
        private async void btnGreetUser_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                LiveAuthClient  auth             = new LiveAuthClient();
                LiveLoginResult initializeResult = await auth.InitializeAsync();

                try
                {
                    LiveLoginResult loginResult = await auth.LoginAsync(new string[] { "wl.basic" });

                    if (loginResult.Status == LiveConnectSessionStatus.Connected)
                    {
                        LiveConnectClient   connect         = new LiveConnectClient(auth.Session);
                        LiveOperationResult operationResult = await connect.GetAsync("me");

                        dynamic result = operationResult.Result;
                        if (result != null)
                        {
                            this.infoTextBlock.Text = string.Join(" ", "Hello", result.name, "!");
                        }
                        else
                        {
                            this.infoTextBlock.Text = "Error getting name.";
                        }
                    }
                }
                catch (LiveAuthException exception)
                {
                    this.infoTextBlock.Text = "Error signing in: " + exception.Message;
                }
                catch (LiveConnectException exception)
                {
                    this.infoTextBlock.Text = "Error calling API: " + exception.Message;
                }
            }
            catch (LiveAuthException exception)
            {
                this.infoTextBlock.Text = "Error initializing: " + exception.Message;
            }
        }
示例#15
0
        /// <summary>
        /// Login mit einem entsprechenden Dialog.
        /// </summary>
        /// <returns>Ein MobileServiceUser, der awaited werden kann oder null bei Misserfolg.</returns>
        internal async static Task <MobileServiceUser> Authenticate(MobileServiceClient mobileService)
        {
            LiveAuthClient liveAuthClient = new LiveAuthClient(APIKeys.LiveClientId);
            var            source         = new TaskCompletionSource <MobileServiceUser>();

            liveAuthClient.Logout();

            var scopes = new string[] { "wl.basic", "wl.offline_access", "wl.signin" };

            App.Current.RootVisual.Visibility = System.Windows.Visibility.Collapsed;

            try
            {
                session = (await liveAuthClient.LoginAsync(scopes)).Session;
            }
            finally
            {
                App.Current.RootVisual.Visibility = System.Windows.Visibility.Visible;
            }
            return(await mobileService.LoginWithMicrosoftAccountAsync(session.AuthenticationToken));
        }
示例#16
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            getGpsLocation();
            try
            {
                LiveAuthClient  auth             = new LiveAuthClient();
                LiveLoginResult initializeResult = await auth.InitializeAsync();

                try
                {
                    LiveLoginResult loginResult = await auth.LoginAsync(new string[] { "wl.basic", "wl.emails" });

                    if (loginResult.Status == LiveConnectSessionStatus.Connected)
                    {
                        LiveConnectClient   connect         = new LiveConnectClient(auth.Session);
                        LiveOperationResult operationResult = await connect.GetAsync("me");

                        dynamic result = operationResult.Result;
                        if (result != null)
                        {
                            User u = new User();
                            u.FirstName = result.first_name;
                            u.LastName  = result.last_name;
                            u.Email     = result.emails.account;
                            _vm.SaveUser(u);
                            _vm.ActiveUser = u;
                        }
                    }
                }
                catch (LiveAuthException exception)
                {
                }
                catch (LiveConnectException exception)
                {
                }
            }
            catch (LiveAuthException exception)
            {
            }
        }
示例#17
0
        private async void downButton_Click_1(object sender, RoutedEventArgs e)//下载
        {
            try
            {
                msgText.Text = "亲:正在下载";
                string id         = string.Empty;
                var    authClient = new LiveAuthClient();
                var    authResult = await authClient.LoginAsync(new string[] { "wl.skydrive" });

                if (authResult.Session != null)
                {
                    var connectClient = new LiveConnectClient(authResult.Session);
                    LiveOperationResult operationResult = await connectClient.GetAsync("me/skydrive/search?q=notes.json");

                    List <object> items = operationResult.Result["data"] as List <object>;
                    IDictionary <string, object> file = items.First() as IDictionary <string, object>;
                    id = file["id"].ToString();
                    LiveDownloadOperation operation = await connectClient.CreateBackgroundDownloadAsync(string.Format("{0}/content", id));

                    var result = await operation.StartAsync();

                    Stream stream = result.Stream.AsStreamForRead();
                    Notes = (ObservableCollection <Note>)jsonSerializer.ReadObject(stream);
                    StorageFile files = await ApplicationData.Current.LocalFolder.GetFileAsync(fileName);

                    using (var streamJson = await ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync(fileName,
                                                                                                              CreationCollisionOption.ReplaceExisting))
                    {
                        jsonSerializer.WriteObject(streamJson, Notes);
                    }
                    msgText.Text = "恭喜:您已成功从OneDrive下载记事!";

                    Frame.Navigate(typeof(MainPage));
                }
            }
            catch (Exception ex)
            {
                msgText.Text = ex.Message;
            }
        }
示例#18
0
        private async void login()
        {
            try
            {
                string          clientId         = "000000004C10C962";
                LiveAuthClient  auth             = new LiveAuthClient(clientId);
                LiveLoginResult initializeResult = await auth.InitializeAsync();

                try
                {
                    LiveLoginResult loginResult = await auth.LoginAsync(new string[] { "wl.basic", "wl.emails" });

                    if (loginResult.Status == LiveConnectSessionStatus.Connected)
                    {
                        LiveConnectClient   connect         = new LiveConnectClient(auth.Session);
                        LiveOperationResult operationResult = await connect.GetAsync("me");

                        dynamic result = operationResult.Result;
                        if (result != null)
                        {
                            u.FirstName = result.first_name;
                            u.LastName  = result.last_name;
                            u.Email     = result.emails.account;
                            _vm.SaveUser(u);
                            _vm.ActiveUser = u;
                        }
                    }
                }
                catch (LiveAuthException exception)
                {
                }
                catch (LiveConnectException exception)
                {
                }
            }
            catch (LiveAuthException exception)
            {
            }
        }
示例#19
0
        public async Task <ConnectionResult> ShowLogin()
        {
            var             authClient = new LiveAuthClient();
            LiveLoginResult loginResult;

            try
            {
                // IMPORTANT!  The app MUST be associated with the store, or a (otherwise unhelpful) NullReferenceException
                // will be raised when calling the AuthClient methods.
                loginResult = await authClient.LoginAsync(_scopes);
            }
            catch (NullReferenceException)
            {
                // This is basically for the sake of example only, since an actual app obtained through the store will not have
                // the probnlem of not having been associated with the Windows Store.
                AppNotAssociatedWithStoreError(this, EventArgs.Empty);
                return(new ConnectionResult {
                    SessionStatus = LiveConnectSessionStatus.NotConnected, CanLogout = false
                });
            }
            catch (LiveAuthException ex)
            {
                throw new InvalidOperationException("An error occurred during initialization.", ex);
            }

            // Set the current instance session based on the login
            var currentSession = loginResult.Status == LiveConnectSessionStatus.Connected ? loginResult.Session : null;

            UpdateSession(currentSession);

            var result = new ConnectionResult
            {
                SessionStatus = loginResult.Status,
                CanLogout     = authClient.CanLogout,
            };

            return(result);
        }
示例#20
0
        private void OnAuthClientInitializeCompleted(System.Threading.Tasks.Task <LiveLoginResult> task)
        {
            if (!CheckTaskCompleted(task, "Not connected. Failed to initialize client."))
            {
                RaiseLinkAbort(task.Exception);
                return;
            }

            LiveLoginResult result = task.Result;

            if (result.Status == LiveConnectSessionStatus.Connected)
            {
                Log("Connected. Moving on with client.");

                // We're online, get the client.
                MakeClientFromSession(result.Session);
            }
            else
            {
                // Checks if we need to auto login.
                bool shouldAutoLogin = false;
                lock (_syncRoot)
                {
                    shouldAutoLogin = _autoLoginOnInitFail;
                }

                // If we need to auto-login, do it.
                if (shouldAutoLogin)
                {
                    Log("Not connected. Starts LoginAsync (auto-login)");
                    StartTaskAndContinueWith(() => _authClient.LoginAsync(_Scopes), OnAuthClientLoginCompleted);
                }
                else
                {
                    Log("Not connected. Auto-login not requested.");
                }
            }
        }
示例#21
0
        public async Task InitializeAsync()
        {
            shouldUploadPlots = applicationSettings.Get <bool>("ShouldAutomaticallyUploadPlots").GetOrElse(false);

            Message = "Authenticating";
            var auth = new LiveAuthClient("000000004C0EC1AB");

            var result = await auth.InitializeAsync(new[] { "wl.basic", "wl.offline_access", "wl.signin", "wl.skydrive_update" });

            if (result.Status != LiveConnectSessionStatus.Connected)
            {
                Message = "Logging in";
                result  =
                    await
                    auth.LoginAsync(new[] { "wl.basic", "wl.offline_access", "wl.signin", "wl.skydrive_update" });
            }

            if (result.Status == LiveConnectSessionStatus.Connected)
            {
                client        = new LiveConnectClient(result.Session);
                IsInitialized = true;
            }
        }
示例#22
0
        public static async Task <LiveConnectSessionStatus> LoginAsync()
        {
            try
            {
                var result = await _authClient.InitializeAsync(_scopes);

                if (result.Status != LiveConnectSessionStatus.Connected)
                {
                    result = await _authClient.LoginAsync(_scopes);
                }

                if (result.Status == LiveConnectSessionStatus.Connected)
                {
                    _session = result.Session;
                }

                return(result.Status);
            }
            catch (LiveAuthException ex)
            {
                throw new LiveAuthException(ex.ErrorCode, ex.Message, ex.InnerException);
            }
        }
示例#23
0
        private async void initialize()
        {
            try
            {
                authClient = new LiveAuthClient();
                LiveLoginResult authLogResult = await authClient.LoginAsync(new List <string>() { "wl.signin", "wl.basic", "wl.skydrive_update" });

                if (authLogResult.Status == LiveConnectSessionStatus.Connected)
                {
                    client = new Microsoft.Live.LiveConnectClient(authClient.Session);

                    LiveOperationResult opResult = await client.GetAsync("me");

                    dynamic result = opResult.Result;

                    //tblUserName.Text = result.name;
                }
            }
            catch (Exception e)
            {
                //tblUserName.Text = "Error";
            }
        }
        public override async Task <AuthenticationResult> AuthenticateAsync()
        {
            var result = await _authClient.LoginAsync(this.AuthorizationScopesList.ToArray());

            if (result != null && result.Status == LiveConnectSessionStatus.Connected)
            {
                _result = result;
                return(AuthenticationResult.Success);
            }
            if (result.Status == LiveConnectSessionStatus.Unknown)
            {
                return(AuthenticationResult.Unknown);
            }
            else if (result.Status == LiveConnectSessionStatus.NotConnected)
            {
                return(AuthenticationResult.Failed);
            }

            return(AuthenticationResult.Unknown);
            //A really bad status to talk about!
            //var client = new LiveConnectClient(result.Session);
            //dynamic result2 = await client.GetAsync("me/skydrive/files");
        }
示例#25
0
        private async void uploadButton_Click(object sender, RoutedEventArgs e)//上传
        {
            try
            {
                msgText.Text = "亲:正在上传";
                var authClient = new LiveAuthClient();
                var authResult = await authClient.LoginAsync(new string[] { "wl.skydrive", "wl.skydrive_update" });

                if (authResult.Session != null)
                {
                    var liveConnectClient = new LiveConnectClient(authResult.Session);

                    StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(fileName);

                    //String fileText = await FileIO.ReadTextAsync(file);

                    LiveUploadOperation uploadOperation = await liveConnectClient.CreateBackgroundUploadAsync(
                        "me/skydrive", file.Name, file, OverwriteOption.Overwrite);

                    LiveOperationResult uploadResult = await uploadOperation.StartAsync();

                    if (uploadResult.Result != null)
                    {
                        msgText.Text = "恭喜:您已成功同步记事至OneDrive!";
                    }
                }
            }
            catch (LiveAuthException ex)
            {
                msgText.Text = ex.Message;
            }
            catch (LiveConnectException ex)
            {
                msgText.Text = ex.Message;
            }
        }
示例#26
0
        public async static Task <bool> LoginAsync()
        {
            try
            {
                _auth = new LiveAuthClient(ClientId);
                LiveLoginResult result = await _auth.InitializeAsync(Scopes);

                if (result.Status != LiveConnectSessionStatus.Connected)
                {
                    result = await _auth.LoginAsync(Scopes);
                }
                if (result.Status == LiveConnectSessionStatus.Connected)
                {
                    _client         = new LiveConnectClient(result.Session);
                    CurrentUserName = await GetUserNameAsync();

                    return(true);
                }
            }
            catch (Exception) { }
            _client = null;
            _auth   = null;
            return(false);
        }
示例#27
0
        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            //if (this.liveClient == null) return;
            if (this.SkySignInBtn.Session == null)
            {
                MessageBox.Show("session is null"); return;
            }
            //this.liveClient = new LiveConnectClient(this.SkySignInBtn.Session);
            try
            {
                LiveAuthClient  auth        = new LiveAuthClient("00000000440FBD35");
                LiveLoginResult loginResult = await auth.LoginAsync(new string[] { "wl.basic" });

                if (loginResult.Status == LiveConnectSessionStatus.Connected)
                {
                    MessageBox.Show("signed in");
                    this.liveClient = new LiveConnectClient(loginResult.Session);
                }
            }
            catch (LiveAuthException exception)
            {
                MessageBox.Show("error: " + exception.Message);
            }
        }
        public async Task SignIn()
        {
            // you should call this from UI thread
            if (_liveSession == null)
            {
                _liveAuth   = new LiveAuthClient(_clientId);
                _liveResult = await _liveAuth.InitializeAsync(_requiredScopes);

                if (_liveResult.Status != LiveConnectSessionStatus.Connected)
                {
                    _liveResult = await _liveAuth.LoginAsync(_requiredScopes);
                }

                _liveSession = _liveResult.Session;
                _liveClient  = new LiveConnectClient(_liveSession);

                _liveClient.BackgroundTransferPreferences = BackgroundTransferPreferences.AllowCellularAndBattery;
            }

            if (_folderId == null)
            {
                await GetSkyDriveFolder();
            }
        }
示例#29
0
        /// <summary>
        /// Performs login via Live Connect and then via Mobile Services
        /// </summary>
        private async Task Login()
        {
            // Force the user to login on app startup
            LiveLoginResult result = await _liveAuthClient.LoginAsync(new string[] { "wl.signin", "wl.basic", "wl.postal_addresses" });

            if (result.Session == null)
            {
                await _popupService.ShowDialogAsync("You must login to use doto.", "Not logged in");

                SetViewState(ViewState.LoggedOut);
                return;
            }

            await _mobileServiceClient.LoginAsync(result.Session.AuthenticationToken);

            var profiles = await _profilesTable.Where(p => p.UserId == _mobileServiceClient.CurrentUser.UserId).ToListAsync();

            if (profiles.Count == 0)
            {
                LiveConnectClient lcc = new LiveConnectClient(result.Session);
                var me = await lcc.GetAsync("me");

                dynamic pic = await lcc.GetAsync("me/picture");

                RegisterUser(me.Result, pic.Result, _mobileServiceClient.CurrentUser.UserId);
            }
            else
            {
                User = profiles.First();
                RegisterDevice();
                LoadLists(true);
                LoadInvites();
            }

            return;
        }
示例#30
0
        private async void RunButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Validate parameters
                string path        = pathTextBox.Text;
                string destination = destinationTextBox.Text;
                string requestBody = requestBodyTextBox.Text;
                var    scope       = (authScopesComboBox.SelectedValue as ComboBoxItem).Content as string;
                var    method      = (methodsComboBox.SelectedValue as ComboBoxItem).Content as string;

                // acquire auth permissions
                var authClient = new LiveAuthClient();
                var authResult = await authClient.LoginAsync(new string[] { scope });

                if (authResult.Session == null)
                {
                    throw new InvalidOperationException("You need to login and give permission to the app.");
                }

                var liveConnectClient = new LiveConnectClient(authResult.Session);
                LiveOperationResult operationResult = null;
                switch (method)
                {
                case "GET":
                    operationResult = await liveConnectClient.GetAsync(path);

                    break;

                case "POST":
                    operationResult = await liveConnectClient.PostAsync(path, requestBody);

                    break;

                case "PUT":
                    operationResult = await liveConnectClient.PutAsync(path, requestBody);

                    break;

                case "DELETE":
                    operationResult = await liveConnectClient.DeleteAsync(path);

                    break;

                case "COPY":
                    operationResult = await liveConnectClient.CopyAsync(path, destination);

                    break;

                case "MOVE":
                    operationResult = await liveConnectClient.MoveAsync(path, destination);

                    break;
                }

                if (operationResult != null)
                {
                    Log("Operation succeeded: \r\n" + operationResult.RawResult);
                }
            }
            catch (Exception ex)
            {
                Log("Got error: " + ex.Message);
            }
        }
示例#31
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void SkydriveSignIn_Click(object sender, System.Windows.RoutedEventArgs e)
 {
     _auth = new LiveAuthClient(SkydriveSignIn.ClientId);
     _auth.LoginCompleted += new System.EventHandler <LoginCompletedEventArgs>(auth_LoginCompleted);
     _auth.LoginAsync(new string[] { "wl.signin", "wl.basic" });
 }
示例#32
0
        private async Task <LiveConnectSessionStatus> Connect(bool includeEmailAddress = false)
        {
            if (client != null)
            {
                return(LiveConnectSessionStatus.Connected);
            }

            LiveAuthException liveConnectException = null;

            try
            {
                var liveAuth       = new LiveAuthClient(Constants.MICROSOFT_LIVE_CLIENTID);
                var liveAuthResult = includeEmailAddress
                                        ? await liveAuth.InitializeAsync(new[]
                {
                    Constants.MICROSOFT_LIVE_SCOPE_BASIC,
                    Constants.MICROSOFT_LIVE_SCOPE_EMAILS,
                    Constants.MICROSOFT_LIVE_SCOPE_SIGNIN,
                    Constants.MICROSOFT_LIVE_SCOPE_OFFLINEACCESS,
                    Constants.MICROSOFT_LIVE_SCOPE_SKYDRIVE,
                    Constants.MICROSOFT_LIVE_SCOPE_SKYDRIVEUPDATE
                })
                                        : await liveAuth.InitializeAsync(new[]
                {
                    Constants.MICROSOFT_LIVE_SCOPE_BASIC,
                    Constants.MICROSOFT_LIVE_SCOPE_SIGNIN,
                    Constants.MICROSOFT_LIVE_SCOPE_OFFLINEACCESS,
                    Constants.MICROSOFT_LIVE_SCOPE_SKYDRIVE,
                    Constants.MICROSOFT_LIVE_SCOPE_SKYDRIVEUPDATE
                });

                if (liveAuthResult.Status == LiveConnectSessionStatus.Connected)
                {
                    client = CreateClientForSession(liveAuth.Session);
                }
                else
                {
                    liveAuthResult = includeEmailAddress
                                        ? await liveAuth.LoginAsync(new[]
                    {
                        Constants.MICROSOFT_LIVE_SCOPE_BASIC,
                        Constants.MICROSOFT_LIVE_SCOPE_EMAILS,
                        Constants.MICROSOFT_LIVE_SCOPE_SIGNIN,
                        Constants.MICROSOFT_LIVE_SCOPE_OFFLINEACCESS,
                        Constants.MICROSOFT_LIVE_SCOPE_SKYDRIVE,
                        Constants.MICROSOFT_LIVE_SCOPE_SKYDRIVEUPDATE
                    })
                                        : await liveAuth.LoginAsync(new[]
                    {
                        Constants.MICROSOFT_LIVE_SCOPE_BASIC,
                        Constants.MICROSOFT_LIVE_SCOPE_SIGNIN,
                        Constants.MICROSOFT_LIVE_SCOPE_OFFLINEACCESS,
                        Constants.MICROSOFT_LIVE_SCOPE_SKYDRIVE,
                        Constants.MICROSOFT_LIVE_SCOPE_SKYDRIVEUPDATE
                    });

                    client   = liveAuthResult.Status == LiveConnectSessionStatus.Connected ? CreateClientForSession(liveAuth.Session) : null;
                    meResult = null;
                }
                return(liveAuthResult.Status);
            }
            catch (TaskCanceledException)
            {
                client = null;
                return(LiveConnectSessionStatus.NotConnected);
            }
            catch (LiveAuthException ex)
            {
                if (ex.ErrorCode.Equals("access_denied", StringComparison.OrdinalIgnoreCase))
                {
                    client = null;
                    return(LiveConnectSessionStatus.NotConnected);
                }
                liveConnectException = ex;
            }
            if (liveConnectException != null)
            {
                var extraCrashData = new BugSense.Core.Model.LimitedCrashExtraDataList();
                extraCrashData.Add("ErrorCode", liveConnectException.ErrorCode);
                extraCrashData.Add("Message", liveConnectException.Message);
                await BugSenseHandler.Instance.LogExceptionAsync(liveConnectException, extraCrashData);
            }
            return(LiveConnectSessionStatus.Unknown);
        }