private async void SignOutClick(object sender, RoutedEventArgs e)
        {
            try
            {
                // Initialize access to the Live Connect SDK.
                LiveAuthClient  LCAuth        = new LiveAuthClient();
                LiveLoginResult LCLoginResult = await LCAuth.InitializeAsync();

                // Sign the user out, if he or she is connected;
                //  if not connected, skip this and just update the UI
                if (LCLoginResult.Status == LiveConnectSessionStatus.Connected)
                {
                    LCAuth.Logout();
                }

                // At this point, the user should be disconnected and signed out, so
                //  update the UI.
                this.userName.Text = "You're not signed in.";

                // Show sign-in button.
                signInBtn.Visibility  = Windows.UI.Xaml.Visibility.Visible;
                signOutBtn.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }
            catch (LiveConnectException)
            {
                // Handle exception.
            }
        }
        private async Task SetNameField(Boolean login)
        {
            // If login == false, just update the name field.
            await App.updateUserName(this.userName, login);

            // Test to see if the user can sign out.
            Boolean userCanSignOut = true;

            LiveAuthClient  LCAuth        = new LiveAuthClient();
            LiveLoginResult LCLoginResult = await LCAuth.InitializeAsync();

            if (LCLoginResult.Status == LiveConnectSessionStatus.Connected)
            {
                userCanSignOut = LCAuth.CanLogout;
            }

            if (this.userName.Text.Equals("You're not signed in."))
            {
                // Show sign-in button.
                signInBtn.Visibility  = Visibility.Visible;
                signOutBtn.Visibility = Visibility.Collapsed;
            }
            else
            {
                // Show sign-out button if they can sign out.
                signOutBtn.Visibility = (userCanSignOut ? Visibility.Visible : Visibility.Collapsed);
                signInBtn.Visibility  = Visibility.Collapsed;
            }
        }
Example #3
0
        public async Task <bool> LiveLoginSilent()
        {
            LiveLoginResult result;

            try
            {
                if (_session == null || _session.Expires.CompareTo(DateTimeOffset.Now) < 0)
                {
                    result = await _liveIdClient.InitializeAsync(LiveConfig.Scopes);

                    if (result.Status == LiveConnectSessionStatus.Connected)
                    {
                        _session = result.Session;
                        return(true);
                    }
                    else
                    {
                        _session = null;
                        return(false);
                    }
                }
                else
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                _log.LogException(ex, "Sync Exception");
                return(false);
            }
        }
        protected async Task <LiveConnectClient> GetConnectClientAsync(params string[] scopes)
        {
            if (scopes != null && scopes.Length > 0)
            {
                AppendScope(scopes);
            }

            if (Scopes == null)
            {
                throw new ArgumentNullException("Scopes");
            }

            LiveAuthClient  auth        = null;
            LiveLoginResult initResult  = null;
            LiveLoginResult loginResult = null;

            auth       = new LiveAuthClient();
            initResult = await auth.InitializeAsync();

            loginResult = await auth.LoginAsync(Scopes);

            if (loginResult.Session != null)
            {
                LiveConnectClient connect = new LiveConnectClient(auth.Session);
                return(connect);
            }
            throw new InvalidOperationException("Fail to fetch the Live Connect Client");
        }
Example #5
0
        public async Task <Session> LoginAsync()
        {
            try
            {
                authClient = new LiveAuthClient();
                var loginResult = await authClient.InitializeAsync(scopes);

                var result = await authClient.LoginAsync(scopes);

                if (result.Status == LiveConnectSessionStatus.Connected)
                {
                    liveSession = loginResult.Session;
                    var session = new Session
                    {
                        AccessToken = result.Session.AccessToken,
                        Provider    = Constants.MicrosoftProvider,
                    };
                    return(session);
                }
            }
            catch (LiveAuthException ex)
            {
                throw new InvalidOperationException("Login canceled.", ex);
            }

            return(null);
        }
        public async Task <ConnectionResult> DisconnectAsync()
        {
            var authClient = new LiveAuthClient();

            try
            {
                var loginResult = await authClient.InitializeAsync();

                // Sign the user out, if he or she is connected;
                //  if not connected, skip this and just update the UI
                if (loginResult.Status == LiveConnectSessionStatus.Connected && authClient.CanLogout)
                {
                    authClient.Logout();
                    UpdateSession(null);
                }
                var result = new ConnectionResult
                {
                    SessionStatus = LiveConnectSessionStatus.NotConnected,
                    CanLogout     = authClient.CanLogout,
                };

                return(result);
            }
            catch (LiveConnectException ex)
            {
                // TODO - Handle exception.
                throw new InvalidOperationException("Failed to disconnect.", ex);
            }
        }
    private async Task SkydriveLogin()
    {
        try
        {
            //----------------------------------------------------------------------
            // Initialize our auth client with the client Id for our specific application
            //----------------------------------------------------------------------
            LiveAuthClient authClient = new LiveAuthClient("**your client id here**");
            //----------------------------------------------------------------------
            // Using InitializeAsync we can check to see if we already have an connected session
            //----------------------------------------------------------------------
            _login = await authClient.InitializeAsync(_scopes);

            //----------------------------------------------------------------------
            // If not connected, bring up the login screen on the device
            //----------------------------------------------------------------------
            if (_login.Status != LiveConnectSessionStatus.Connected)
            {
                _login = await authClient.LoginAsync(_scopes);
            }
            //----------------------------------------------------------------------
            // Initialize our connection client with our login result
            //----------------------------------------------------------------------
            _connection = new LiveConnectClient(_login.Session);
        }
        catch (Exception ex)
        {
            //TODO: Add connection specific exception handling
        }
    }
        void LoginToSkyDrive(bool login = false)
        {
            if (!NetworkInterface.GetIsNetworkAvailable() || NetworkInterface.NetworkInterfaceType == NetworkInterfaceType.None)
            {
                //MessageBox.Show("No internet connection is available.  Try again later.");
                txtLoginResult.Text   = "No network";
                TitlePanel.Background = new SolidColorBrush(Colors.Red);
                _syncAnim.Stop();
                _clickSyncBtn = false;
                return;
            }


            var auth = new LiveAuthClient("00000000480C5667");

            if (login)
            {
                _syncAnim.Stop();
                auth.LoginCompleted += auth_LoginCompleted;
                auth.LoginAsync(new[] { "wl.offline_access", "wl.signin", "wl.skydrive_update" });//,
            }
            else
            {
                _syncAnim.Start();
                auth.InitializeAsync(new[] { "wl.offline_access", "wl.signin", "wl.skydrive_update" });
                auth.InitializeCompleted += auth_LoginCompleted;
            }
        }
        public async Task AuthenticateUserThroughLive()
        {
            try
            {
                // Open Live Connect SDK client.
                LiveAuthClient  LCAuth        = new LiveAuthClient();
                LiveLoginResult LCLoginResult = await LCAuth.InitializeAsync();

                try
                {
                    LiveLoginResult loginResult = null;
                    loginResult = await LCAuth.LoginAsync(new string[] { "wl.signin", "wl.basic", "wl.calendars", "wl.skydrive", "wl.skydrive_update" });

                    if (loginResult.Status == LiveConnectSessionStatus.Connected)
                    {
                        this.LiveSession = loginResult.Session;
                    }
                }
                catch (LiveAuthException)
                {
                    // Handle exceptions.
                }
            }
            catch (LiveAuthException)
            {
                // Handle exceptions.
            }
        }
Example #10
0
        public static async void InitialAsync()
        {
            if (string.IsNullOrEmpty(ClientId))
            {
                throw new ArgumentNullException("OneDriveSession.ClientId", "ClientID Is Not Set");
            }
            if (string.IsNullOrEmpty(Scopes))
            {
                throw new ArgumentNullException("OneDriveSession.Scopes", "Scopes Is Not Set");
            }
            if (IsLogged)
            {
                Logout();
            }
            try
            {
                var authClient = new LiveAuthClient(ClientId);
                var result     = await authClient.InitializeAsync();

                if (result.Status == LiveConnectSessionStatus.Connected && !IsLogged)
                {
                    Login(result.Session);
                }
            }
            catch (LiveAuthException e)
            {
                Debug.WriteLine("Error Code{0}\nMessage {1}\nStackTrace {2}", e.ErrorCode, e.Message, e.StackTrace);
            }
        }
Example #11
0
        public async Task <bool> Login()
        {
            IsConnected = false;
            try
            {
                LiveLoginResult result = await _authClient.InitializeAsync(new string[] { "wl.signin", "wl.skydrive" });

                if (result.Status != LiveConnectSessionStatus.Connected)
                {
                    result = await _authClient.LoginAsync(new string[] { "wl.signin", "wl.skydrive" });
                }

                if (result.Status == LiveConnectSessionStatus.Connected)
                {
                    IsConnected    = true;
                    _connectClient = new LiveConnectClient(result.Session);
                    LiveOperationResult meResult = await _connectClient.GetAsync(_basePath + "/" + "files?filter=folders");

                    _pkFolderId = GetPKFolderId(meResult.Result["data"]);
                    if (_pkFolderId == null)
                    {
                        _pkFolderId = await CreateFolder(_connectClient);
                    }
                }
            }
            catch (LiveAuthException ex)
            {
                IsConnected = false;
            }
            catch (LiveConnectException ex)
            {
                IsConnected = false;
            }
            return(IsConnected);
        }
        public override async Task InitializeAsync(IList <string> scopes)
        {
            //AuthClient는 프로퍼티
            if (AuthClient == null)
            {
                AuthClient = _authClient = new LiveAuthClient();
            }
            else
            {
                _authClient = (LiveAuthClient)AuthClient;
            }

            try
            {
                var authResult = await _authClient.InitializeAsync(scopes);

                if (authResult != null && authResult.Status == LiveConnectSessionStatus.Connected)
                {
                    await LoadUser();
                }
            }
            catch (Exception ex)
            {
                EtcUtility.Instance.MsgBox("Not connected LiveID " + ex.Message);
            }
        }
Example #13
0
        /// <summary>
        /// Versucht Login, ohne einen entsprechenden Dialog zu zu zeigen.
        /// </summary>
        /// <returns>Ein MobileServiceUser, der awaited werden kann oder null bei Misserfolg.</returns>
        internal static async Task <MobileServiceUser> AuthenticateSilent(MobileServiceClient mobileService)
        {
            LiveAuthClient liveAuthClient = new LiveAuthClient(APIKeys.LiveClientId);

            session = (await liveAuthClient.InitializeAsync()).Session;
            return(await mobileService.LoginWithMicrosoftAccountAsync(session.AuthenticationToken));
        }
Example #14
0
        /// <summary>
        /// Tests logging into MobileService with Live SDK token. App needs to be assosciated with a WindowsStoreApp
        /// </summary>
        private async Task TestLiveSDKLogin()
        {
            try
            {
                LiveAuthClient  liveAuthClient = new LiveAuthClient(GetClient().MobileAppUri.ToString());
                LiveLoginResult result         = await liveAuthClient.InitializeAsync(new string[] { "wl.basic", "wl.offline_access", "wl.signin" });

                if (result.Status != LiveConnectSessionStatus.Connected)
                {
                    result = await liveAuthClient.LoginAsync(new string[] { "wl.basic", "wl.offline_access", "wl.signin" });
                }
                if (result.Status == LiveConnectSessionStatus.Connected)
                {
                    LiveConnectSession  session  = result.Session;
                    LiveConnectClient   client   = new LiveConnectClient(result.Session);
                    LiveOperationResult meResult = await client.GetAsync("me");

                    MobileServiceUser loginResult = await GetClient().LoginWithMicrosoftAccountAsync(result.Session.AuthenticationToken);

                    Log(string.Format("{0} is now logged into MobileService with userId - {1}", meResult.Result["first_name"], loginResult.UserId));
                }
            }
            catch (Exception exception)
            {
                Log(string.Format("ExceptionType: {0} Message: {1} StackTrace: {2}",
                                  exception.GetType().ToString(),
                                  exception.Message,
                                  exception.StackTrace));
                Assert.Fail("Log in with Live SDK failed");
            }
        }
        private void ApplicationBarMenuItem_Click_2(object sender, EventArgs e)
        {
            // Download the zip

            // Connect to live API
            LiveAuthClient auth = new LiveAuthClient("00000000440E7119");

            auth.InitializeAsync();
            auth.InitializeCompleted += (e1, e2) =>
            {
                // Show login dialog
                auth.LoginAsync(new string[] { "wl.skydrive_update", "wl.skydrive" });

                auth.LoginCompleted += (e3, e4) =>
                {
                    if (e4.Status == LiveConnectSessionStatus.Connected)
                    {
                        LiveConnectClient client = new LiveConnectClient(e4.Session);

                        // Upload that zip we just made
                        client.GetAsync("me/skydrive/files");
                        client.GetCompleted += (getSender, getEvents) =>
                        {
                            Dictionary <string, object> fileData = (Dictionary <string, object>)getEvents.Result;
                            List <object> files = (List <object>)fileData["data"];

                            foreach (object item in files)
                            {
                                Dictionary <string, object> file = (Dictionary <string, object>)item;
                                if (file["name"].ToString() == "wphfolders.zip")
                                {
                                    System.Diagnostics.Debug.WriteLine(file["name"]);
                                    client.DownloadAsync(file["id"].ToString() + "/content");
                                    client.DownloadCompleted += (downloadSender, downloadEventArgs) =>
                                    {
                                        SharpGIS.UnZipper unzipper = new SharpGIS.UnZipper(downloadEventArgs.Result);
                                        using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                                        {
                                            foreach (string name in unzipper.FileNamesInZip)
                                            {
                                                var storefile = store.OpenFile(name, FileMode.Create, FileAccess.Write);
                                                unzipper.GetFileStream(name).CopyTo(storefile);
                                                storefile.Close();
                                            }
                                        }
                                        MessageBox.Show("Restored.");
                                        regenerateList();
                                    };
                                }
                            }
                        };
                    }
                    else
                    {
                        MessageBox.Show("Not connected to SkyDrive");
                    }
                };
            };
        }
Example #16
0
        public static async Task <LiveConnectSessionStatus> GetSessionStatusAsync()
        {
            try
            {
                var result = await _authClient.InitializeAsync(_scopes);

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

                return(result.Status);
            }
            catch (LiveAuthException ex)
            {
                throw new LiveAuthException(ex.ErrorCode, ex.Message, ex.InnerException);
            }
        }
Example #17
0
        /// <summary>
        /// Opens Microsoft Login page using live sdk
        /// </summary>
        private void MicrosoftLogin()
        {
            try
            {
                var auth = new LiveAuthClient(Entity.Models.Constant.LiveSdkClientIdWP);
                this.Dispatcher.BeginInvoke(async() =>
                {
                    LiveLoginResult result = await auth.InitializeAsync(new string[] { "wl.basic", "wl.signin" });
                    if (result.Status != LiveConnectSessionStatus.Connected)
                    {
                        try
                        {
                            result = await auth.LoginAsync(new string[] { "wl.basic", "wl.signin" });
                        }
                        catch (Exception)
                        {
                            App.ViewModel.CommentViewModel.IsDataLoading = false;
                            (this.ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = true;
                            (this.ApplicationBar.Buttons[1] as ApplicationBarIconButton).IsEnabled = true;
                            txtComment.IsEnabled = true;
                        }
                    }
                    if (result.Status == LiveConnectSessionStatus.Connected)
                    {
                        LiveConnectClient liveClient = new LiveConnectClient(result.Session);
                        var userDetails = await liveClient.GetAsync("me");
                        var userName    = userDetails.Result["name"];
                        //auth.Logout();
                        CommentData commentData      = new CommentData();
                        commentData.Author           = userName.ToString();
                        commentData.CityName         = this.city;
                        commentData.ReportName       = this.dataSetName;
                        commentData.Id               = this.compositeKey;
                        commentData.CommentPublishAt = DateTime.Now.ToUniversalTime();
                        commentData.CommentTitle     = "";
                        commentData.CommentMessage   = this.txtComment.Text.Trim();
                        App.ViewModel.CommentViewModel.AddComment(commentData);

                        App.ViewModel.CommentViewModel.CommentList.Add(commentData);
                        this.tbkNoResult.Visibility = Visibility.Collapsed;
                        IncreaseCommentsCount();
                        txtComment.Text = "";
                    }
                    App.ViewModel.CommentViewModel.IsDataLoading = false;
                    (this.ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = true;
                    (this.ApplicationBar.Buttons[1] as ApplicationBarIconButton).IsEnabled = true;
                    txtComment.IsEnabled = true;
                });
            }
            catch (LiveAuthException)
            {
                App.ViewModel.CommentViewModel.IsDataLoading = false;
                (this.ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = true;
                (this.ApplicationBar.Buttons[1] as ApplicationBarIconButton).IsEnabled = true;
                txtComment.IsEnabled = true;
            }
        }
 public void TestInitializeAsyncNullScopes()
 {
     var authClient = new LiveAuthClient();
     try
     {
         authClient.InitializeAsync(null);
         Assert.Fail("Expected ArgumentNullException to be thrown.");
     }
     catch (ArgumentNullException)
     {
     }
 }
        public static async Task updateUserName(TextBlock userName, Boolean signIn)
        {
            try
            {
                LiveAuthClient  LCAuth        = new LiveAuthClient();
                LiveLoginResult LCLoginResult = await LCAuth.InitializeAsync();

                try
                {
                    LiveLoginResult loginResult = null;
                    if (signIn)
                    {
                        loginResult = await LCAuth.LoginAsync(new string[] { "wl.basic" });
                    }
                    else
                    {
                        loginResult = LCLoginResult;
                    }
                    if (loginResult.Status == LiveConnectSessionStatus.Connected)
                    {
                        LiveConnectClient   connect         = new LiveConnectClient(LCAuth.Session);
                        LiveOperationResult operationResult = await connect.GetAsync("me");

                        dynamic result = operationResult.Result;
                        if (result != null)
                        {
                            userName.Text = string.Join(" ", "Hello", result.name, "!");
                        }
                        else
                        {
                            userName.Text = "You're signed in.";
                        }
                    }
                    else
                    {
                        userName.Text = "You're not signed in.";
                    }
                }
                catch (LiveAuthException)
                {
                    // Handle the exception.
                }
            }
            catch (LiveAuthException)
            {
                // Handle the exception.
            }
            catch (LiveConnectException)
            {
                // Handle the exception.
            }
        }
        public void TestInitializeAsyncNullScopes()
        {
            var authClient = new LiveAuthClient();

            try
            {
                authClient.InitializeAsync(null);
                Assert.Fail("Expected ArgumentNullException to be thrown.");
            }
            catch (ArgumentNullException)
            {
            }
        }
        public async Task UnAuthenticateUserThroughLive()
        {
            try
            {
                LiveAuthClient  LCAuth        = new LiveAuthClient();
                LiveLoginResult LCLoginResult = await LCAuth.InitializeAsync();

                // LCAuth.Logout();
                LiveSession = null;
            }
            catch (LiveAuthException)
            {
                // Handle exceptions.
            }
        }
Example #22
0
        private void BeginLink(bool autoLogin)
        {
            // Returns if already linked.
            if (IsLinked)
            {
                Log("Already linked, ignored.");
                return;
            }

            // Stores auto-login setting.
            lock (_syncRoot)
            {
                _autoLoginOnInitFail = autoLogin;
            }

            // Makes sure the auth client exists.
            if (_authClient == null)
            {
                string clientId = null;
                try
                {
                    clientId = (string)App.Current.Resources["LiveConnectClientID"];
                }
                catch (Exception ex)
                {
                    Log("Unable to fetch LiveConnectClientID from App resources.");
                    throw new InvalidOperationException("Unable to fetch LiveConnectClientID from App resources.", ex);
                }

                _authClient = new LiveAuthClient(clientId);
            }

            // Starts initializing.
            try
            {
                Log("Starts InitializeAsync");
                StartTaskAndContinueWith(() => _authClient.InitializeAsync(_Scopes), OnAuthClientInitializeCompleted);
            }
            catch (LiveAuthException ex)
            {
                // Ignores but dumps the exception.
                Log("LiveAuthException: " + ex.Message);
                Geowigo.Utils.DebugUtils.DumpException(ex, dumpOnBugSenseToo: false);

                // Raises an event.
                RaiseLinkAbort(ex);
            }
        }
        public async Task <bool> Init(string clientId)
        {
            clientId.NotNull("clientId");

            _authClient = new LiveAuthClient(clientId, this);

            var loginResult = await _authClient.InitializeAsync(_scopes);

            if (loginResult.Session != null)
            {
                _liveConnectClient = new LiveConnectClient(loginResult.Session);
            }

            SingInUrl = _authClient.GetLoginUrl(_scopes);
            return(true);
        }
Example #24
0
        async private Task <bool> userIsLoggedToOneDrive()
        {
            if (liveConnect == null)
            {
                return(false);
            }

            var auth   = new LiveAuthClient(App.LSKEY_LIVE_CLIENT_ID);
            var result = await auth.InitializeAsync(new[] { "wl.signin", "wl.SkyDrive_update" });

            if (result.Status == LiveConnectSessionStatus.NotConnected)
            {
                return(false);
            }

            return(true);
        }
Example #25
0
        public static async Task <string> upload(string filename)
        {
            string res = "";

            //diagLog("Uploading " + file);
            try
            {
                string[]       requiredScope = { "wl.offline_access", "wl.skydrive_update" };
                LiveAuthClient auth          = new LiveAuthClient(Secrets.ClientID);
                await auth.InitializeAsync(requiredScope);

                if (auth.Session == null)
                {
                    await auth.LoginAsync(requiredScope);
                }
                LiveConnectClient liveClient = new LiveConnectClient(auth.Session);

                string folderid = await GetSkyDriveFolderID(FOLDER, liveClient);

                if (folderid == null)
                {
                    folderid = await createSkyDriveFolder(FOLDER, liveClient);

                    res = "Created folder: " + FOLDER + "\n"; // , "ID:", folderid);
                }

                var store = IsolatedStorageFile.GetUserStoreForApplication();
                if (store.FileExists(filename))
                {
                    var file = store.OpenFile(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                    LiveOperationResult operationResult = await liveClient.UploadAsync(folderid, filename, file, OverwriteOption.Overwrite);

                    dynamic result = operationResult.Result;
                    res += "Uploaded :" + result.name; //, "ID:", result.id);
                }
                else
                {
                    throw new Exception("file does not exist");
                }
            }
            catch (Exception exception)
            {
                res = "Error uploading file: " + exception.Message;
            }
            return(res);
        }
        private async Task <LiveConnectClient> GetLiveConnectClientAsync()
        {
            LiveAuthClient liveAuthClient = new LiveAuthClient();

            string[]        scopes          = new[] { "wl.basic", "wl.signin", "wl.offline_access", "wl.skydrive", "wl.skydrive_update", "wl.contacts_skydrive" };
            LiveLoginResult liveLoginResult = null;

            // Get Current live connection session
            // If session doesn't exist, get new one.
            liveLoginResult = await liveAuthClient.InitializeAsync(scopes);

            if (liveLoginResult.Status != LiveConnectSessionStatus.Connected)
            {
                liveLoginResult = await liveAuthClient.LoginAsync(scopes);
            }
            return(new LiveConnectClient(liveLoginResult.Session));
        }
    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);
    }
Example #28
0
        private async void LoadPage()
        {
            try
            {
                LiveLoginResult loginResult = await _liveAuthClient.InitializeAsync(_scopes);

                if (loginResult.Status == LiveConnectSessionStatus.Connected)
                {
                    responseTextBlock.Text = "initialized";

                    signInButton.IsEnabled = true;
                }
            }
            catch (Exception ex)
            {
                responseTextBlock.Text = ex.ToString();
            }
        }
Example #29
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);
        }
        public async Task <ConnectionResult> UpdateConnectionAsync()
        {
            var authClient             = new LiveAuthClient();
            var sessionStatus          = LiveConnectSessionStatus.Unknown;
            LiveConnectSession session = null;

            try
            {
                // IMPORTANT!  The app MUST be associated with the store, or a (otherwise unhelpful) NullReferenceException
                // will be raised when calling the AuthClient methods.
                var loginResult = await authClient.InitializeAsync(_scopes);

                sessionStatus = loginResult.Status;
                session       = loginResult.Session;
            }
            catch (NullReferenceException)
            {
                // This is basically for the sake of example only, since an actual app obtained through the store will not have
                // the problem of not having been associated with the Windows Store.
                AppNotAssociatedWithStoreError(this, EventArgs.Empty);
                return(new ConnectionResult {
                    SessionStatus = LiveConnectSessionStatus.NotConnected, CanLogout = false
                });
            }
            catch (LiveAuthException ex)
            {
                // TODO - handle notification/display of error information
                //throw new InvalidOperationException("An error occurred during initialization.", ex);
            }

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

            UpdateSession(currentSession);

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

            return(result);
        }
Example #31
0
        public async static Task <bool> SilentLoginAsync()
        {
            try
            {
                _auth = new LiveAuthClient(ClientId);
                LiveLoginResult result = await _auth.InitializeAsync(Scopes);

                if (result.Status == LiveConnectSessionStatus.Connected)
                {
                    _client         = new LiveConnectClient(result.Session);
                    CurrentUserName = await GetUserNameAsync();

                    return(true);
                }
            }
            catch (Exception) { }
            _client = null;
            _auth   = null;
            return(false);
        }