private async Task<dynamic> GetUserLogged() 
        {
            var liveIdClient = new LiveAuthClient();
            Task<LiveLoginResult> tskLoginResult = liveIdClient.LoginAsync(new string[] { "wl.signin" });
            tskLoginResult.Wait();

            switch (tskLoginResult.Result.Status)
            {
                case LiveConnectSessionStatus.Connected:
                    try
                    {
                        LiveConnectClient client = new LiveConnectClient(tskLoginResult.Result.Session);
                        LiveOperationResult liveOperationResult = await client.GetAsync("me");

                        dynamic operationResult = liveOperationResult.Result;
                        return operationResult;
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(string.Format("ERRO, {0}", ex.Message), ex);
                    }
                case LiveConnectSessionStatus.NotConnected:
                    break;
            }

            return null;
        }
Esempio n. 2
0
        public async Task<bool> LoginAsync(bool isSilent = true)
        {
            bool result = false;
            LastError = null;
            RestoreData = null;

            IsInProgress = true;

            try
            {
                var authClient = new LiveAuthClient();
                LiveLoginResult res = isSilent ? await authClient.InitializeAsync(scopes) : await authClient.LoginAsync(scopes);
                Session = res.Status == LiveConnectSessionStatus.Connected ? res.Session : null;

                result = true;
            }
            catch (LiveAuthException ex)
            {
                LastError = ex.Message;
            }

            IsInProgress = false;

            return result;
            //CheckPendingBackgroundOperations();
        }
Esempio n. 3
0
        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            var liveIdClient = new LiveAuthClient();
            Task<LiveLoginResult> tskLoginResult = liveIdClient.LoginAsync(new string[] { "wl.signin" });
            tskLoginResult.Wait();

            switch (tskLoginResult.Result.Status)
            {
                case LiveConnectSessionStatus.Connected:

                    try
                    {
                        LiveConnectClient client = new LiveConnectClient(tskLoginResult.Result.Session);
                        LiveOperationResult liveOperationResult = await client.GetAsync("me");

                        dynamic operationResult = liveOperationResult.Result;
                        string name = string.Format("Hello {0} ", operationResult.first_name);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(string.Format("ERRO, {0}", ex.Message), ex);
                    }

                    break;
                case LiveConnectSessionStatus.NotConnected:
                    int j = 10;
                    break;
                default:
                    int z = 10;
                    break;
            }
        }
Esempio n. 4
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);
                    StorageFolder localFolder = ApplicationData.Current.LocalFolder;
                    StorageFile file = await localFolder.GetFileAsync(App.WordBookFileName);
                    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;
            }

        }
Esempio n. 5
0
 private async Task<LiveConnectClient> ensureConnection()
 {
     if (connection != null)
     {
         return connection;
     }
     // Initialize access to the Live Connect SDK.
     LiveAuthClient LCAuth = new LiveAuthClient("https://chivalry.azure-mobile.net/");
     LiveLoginResult LCLoginResult = await LCAuth.InitializeAsync();
     // Sign in to the user's Microsoft account with the required scope.
     //    
     //  This call will display the Microsoft account sign-in screen if the user 
     //  is not already signed in to their Microsoft account through Windows 8.
     // 
     //  This call will also display the consent dialog, if the user has 
     //  has not already given consent to this app to access the data described 
     //  by the scope.
     // 
     LiveLoginResult loginResult = await LCAuth.LoginAsync(new string[] { "wl.basic", "wl.emails" });
     if (loginResult.Status == LiveConnectSessionStatus.Connected)
     {
         // Create a client session to get the profile data.
         connection = new LiveConnectClient(LCAuth.Session);
         mobileServiceUser = await App.MobileService.LoginAsync(loginResult.Session.AuthenticationToken);
         return connection;
     }
     if (LoginFailed != null)
     {
         LoginFailed(this, null);
     }
     return null;
 }
Esempio n. 6
0
 //인스턴스 생성용 method
 private async void login_Client()
 {
     try
     {
         //Client 생성
         authClient = new LiveAuthClient();
         //초기화
         result = await authClient.InitializeAsync();
         //로그인
         loginResult = await authClient.LoginAsync(scope);
         //로그인 할 떄 cancel을 누르면 뒤로 돌아가기
     }
     catch (NullReferenceException ex)
     {
         //로그인 할 때 cancel을 누르면 nullreferenceException 발생
         //뒤로가기
         ex.Message.ToString();
         messagePrint(false);
         if (Frame.CanGoBack)
         {
             Frame.GoBack();
         }
     }
     catch (Exception ex)
     {
         //기타 Exception을 위한 catch
         ex.Message.ToString();
         messagePrint(false);
         if(Frame.CanGoBack)
         {
             Frame.GoBack();
         }
     }
 }
Esempio n. 7
0
        private  async void loginButton_Click(object sender, RoutedEventArgs e)//登录
        {
            try
            {
                msgText.Text = "亲:正在登录";
                var authClient = new LiveAuthClient();

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

                if (result.Status == LiveConnectSessionStatus.Connected)
                {

                    var connectClient = new LiveConnectClient(result.Session);
                    var meResult = await connectClient.GetAsync("me");
                    msgText.Text = "亲爱的:" + meResult.Result["name"].ToString() + "  您已成功登录OneDrive!";
                }
                updateButton.Visibility = Visibility.Visible;
                uploadButton.Visibility = Visibility.Visible;
                downButton.Visibility = Visibility.Visible;


            }
            catch (LiveAuthException ex)
            {
                msgText.Text = ex.Message;
            }
            catch (LiveConnectException ex)
            {
                msgText.Text = ex.Message;
            }
        }
        /// <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");
            }
        }
Esempio n. 9
0
		private async void InitAuth()
		{
			if (!Windows.ApplicationModel.DesignMode.DesignModeEnabled)
			{
				var authClient = new LiveAuthClient();
				LiveLoginResult authResult =
					await authClient.LoginAsync(new List<string>() { "wl.signin", "wl.basic", "wl.skydrive" });
				if (authResult.Status == LiveConnectSessionStatus.Connected)
				{
					// An app-level property for the session.
					App.Session = authResult.Session;
				}
			}
		}
        /// <summary>
        /// The login async.
        /// </summary>
        /// <returns>
        /// The <see cref="Task"/> object.
        /// </returns>
        /// 
        public async Task<AuthenticationSession> LoginAsync()
        {
            Exception rException = null;
            try
            {
                _authClient = new LiveAuthClient();
                // Rui: https://msdn.microsoft.com/en-us/library/hh694244.aspx
                //var loginResult = await _authClient.InitializeAsync(_scopes);
                
                // Rui: https://msdn.microsoft.com/en-us/library/hh533677.aspx
                var result = await _authClient.LoginAsync(_scopes);

                //if (loginResult.Status == LiveConnectSessionStatus.Connected)
                if (result.Status == LiveConnectSessionStatus.Connected)
                {
                    
                    //_liveSession = loginResult.Session;
                    _liveSession = result.Session;
                    var meResult = await GetUserInfo();
                    var session = new AuthenticationSession
                    {
                        AccessToken = result.Session.AccessToken,
                        //AccessToken = loginResult.Session.AccessToken,
                        Provider = Constants.MicrosoftProvider,
                        UserInfo = meResult["name"].ToString()
                    };
                    return session;
                }

            }

            catch (LiveAuthException authExp)
            {
                System.Diagnostics.Debug.WriteLine("LiveAuthException = " + authExp.ToString());
            }

            catch (LiveConnectException connExp)
            {
                System.Diagnostics.Debug.WriteLine("LiveConnectException = " + connExp.ToString());
            }

            catch (Exception ex)
            {
                rException = ex;
                System.Diagnostics.Debug.WriteLine("rException = " + rException.ToString());
            }
            await _logManager.LogAsync(rException);

            return null;
        }
 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;
 }
Esempio n. 12
0
            public async void LoadProfile(String SkyDriveFolderName = GenericName)
            {
                LiveOperationResult meResult;
                dynamic result;
                bool createLiveFolder = false;

               try
               {
                    LiveAuthClient authClient = new LiveAuthClient();
                    LiveLoginResult authResult = await authClient.LoginAsync(new List<String>() { "wl.skydrive_update" });

                    if (authResult.Status == LiveConnectSessionStatus.Connected)
                    {
                        try
                        {
                            meClient = new LiveConnectClient(authResult.Session);
                            meResult = await meClient.GetAsync("me/skydrive/" + SkyDriveFolderName);
                            result = meResult.Result;
                        }
                        catch (LiveConnectException)
                        {
                            createLiveFolder = true;
                        }
                        if (createLiveFolder == true)
                        {
                            try
                            {
                                var skyDriveFolderData = new Dictionary<String, Object>();
                                skyDriveFolderData.Add("name", SkyDriveFolderName);
                                LiveConnectClient LiveClient = new LiveConnectClient(meClient.Session);
                                LiveOperationResult operationResult = await LiveClient.PostAsync("me/skydrive/", skyDriveFolderData);
                                meResult = await meClient.GetAsync("me/skydrive/");

                            }
                            catch (LiveConnectException)
                            {
                            }
                        }

                    }

               }

               catch (LiveAuthException)
               {
               }

            }
 private async void btnConnect_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         LiveAuthClient auth = new LiveAuthClient(this.ViewModel.LiveClientId);
         LiveLoginResult loginResult = await auth.LoginAsync(new string[] { "wl.signin", "wl.basic" });
         if (loginResult.Status == LiveConnectSessionStatus.Connected)
         {
             this.infoTextBlock.Text = "Signed in.";
         }
     }
     catch (LiveConnectException exception)
     {
         this.infoTextBlock.Text = "Error calling API: " + exception.Message;
     }
 }
Esempio n. 14
0
        /// <summary>
        /// Load videos from SkyDrive
        /// </summary>
        /// <returns></returns>
        static async public Task LoadAsyncFromSkydrive()
        {
            var scopes = new string[] { "wl.signin", "wl.skydrive", "wl.skydrive_update" };
            LiveAuthClient authClient = new LiveAuthClient();
            LiveLoginResult result = await authClient.LoginAsync(scopes);

            VideosDataSource.Unload();
            ObservableCollection<VideoDataCommon> videos = new ObservableCollection<VideoDataCommon>();

            if (result.Status == LiveConnectSessionStatus.Connected)
            {
                LiveConnectClient cxnClient = new LiveConnectClient(authClient.Session);

                // Get hold of the root folder from SkyDrive. 
                // NB: this does not traverse the network and get the full folder details.
                SkyDriveFolder root = new SkyDriveFolder(
                  cxnClient, SkyDriveWellKnownFolder.Root);
                
                var ArchiveFolder = await root.GetFolderAsync("Archive");
                if (ArchiveFolder == null)      // There is no Archive folder in the SkyDrive 
                    return;

                var files = await ArchiveFolder.GetFilesAsync();     // Get all files from SkyDrive 

                foreach (var file in files)
                {
                    try
                    {
                        
                        // Stream?
                        if(file.Name.Contains(".mp4"))
                        {
                            var video = new VideoDataCommon(file.Id, file.Name, file.Description, file.LinkLocation.ToString(), file.Description); 
                            videos.Add(video);

                            
                        }
                    }
                    catch { }
                }
            }

            var debugCollection = new ObservableCollection<VideoDataCommon>(videos);
            
            App.SkyDriveVideos = new ObservableCollection<VideoDataCommon>(videos); 
            //DataContractJsonSerializer des = new DataContractJsonSerializer(typeof(NoteDataCommon), types);
        }
Esempio n. 15
0
        public static async Task ZumoLogin(string redirectURL)
        {
            LiveAuthClient liveAuthClient;
            LiveLoginResult liveLoginResult;
            liveAuthClient = new LiveAuthClient(redirectURL);
            liveLoginResult = await liveAuthClient.LoginAsync(new string[] { "wl.signin", "wl.basic" });

            if (liveLoginResult.Session != null && liveLoginResult.Status == LiveConnectSessionStatus.Connected)
            {
                await App.MobileService.LoginAsync(liveLoginResult.Session.AuthenticationToken);
                LiveConnectClient client = new LiveConnectClient(liveLoginResult.Session);
                LiveOperationResult operationResult = await client.GetAsync("me");
                dynamic results = operationResult.Result;
                username = results.name;
            }
            else
                throw new Exception();

        }
Esempio n. 16
0
        private async void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            // 認証用インスタンスを生成
            var authClient = new LiveAuthClient();

            // スコープを設定
            var scopes = new List<string>() { "wl.signin", "wl.skydrive_update" };

            // ログイン用ダイアログを表示する
            var authResult = await authClient.LoginAsync(scopes);
            if (authResult.Status == LiveConnectSessionStatus.Connected)
            {
                Session = authResult.Session;
            }
            else
            {
                // サインインに失敗
                return;
            }
        }
Esempio n. 17
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);

        }
Esempio n. 18
0
        /// <summary>
        /// Create connection with scope Basic, SkyDrive.
        /// </summary>
        /// <returns>Return true if connect successful. Otherwise, return false.</returns>
        public async Task<bool> CreateConnectionAsync()
        {
            try
            {
                var auth = new LiveAuthClient();
                var loginResult = await auth.LoginAsync(new[] { "wl.basic", "wl.contacts_skydrive", "wl.skydrive_update", "wl.emails", "wl.contacts_photos" });

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

                    return true;
                }

                return false;
            }
            catch(LiveAuthException)
            {
                return true;
            }
        }
Esempio n. 19
0
        private async System.Threading.Tasks.Task Authenticate()
        {
            LiveAuthClient liveIdClient = new LiveAuthClient("https://sendit.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"]);
                    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();
                }
            }


        }
Esempio n. 20
0
        /// <summary>
        /// Create connection with scope Basic, SkyDrive.
        /// </summary>
        /// <returns>Return true if connect successful. Otherwise, return false.</returns>
        public async Task<bool> CreateConnectionAsync()
        {
            try
            {
                var auth = new LiveAuthClient();
                var loginResult = await auth.LoginAsync(new[] { "wl.basic", "wl.contacts_skydrive", "wl.skydrive_update" });

                if (loginResult.Status == LiveConnectSessionStatus.Connected)
                {
                    _liveConnectClient = new LiveConnectClient(loginResult.Session);
                   
                    eSECID = ApplicationData.Current.RoamingSettings.Values[ESEC_ID] + string.Empty;

                    return true;
                }

                return false;
            }
            catch
            {
                return false;
            }
        }
Esempio n. 21
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)
            {
            }
        }
        private async Task<Boolean> LogInToSkydrive()
        {
            var hasErrors = false;

            do
            {
                try
                {
                    hasErrors = false;
                    this.retrySelected = false;

                    LiveAuthClient auth = new LiveAuthClient();
                    LiveLoginResult loginResult = await auth.LoginAsync(new string[] { "wl.signin", "wl.skydrive", "wl.skydrive_update" });

                    if (loginResult.Status == LiveConnectSessionStatus.Connected)
                    {
                        LiveSession = loginResult.Session;
                        return true;
                    }
                }
                catch (LiveAuthException)
                {
                    hasErrors = true;
                }

                if (hasErrors)
                {
                    var errorTitle = "Live Connect error";
                    await ShowMessage(errorTitle, "Exception occured while logging in to Skydrive.");
                }
            } while (this.retrySelected);

            return false;
        }
        public async Task Authenticate()
        {
            // For Microsoft ID to work in Windows 8, you need to associate the Windows 8 app
            // with a Windows 8 Store app (ie: create an app in the Store/reserve a name)
            // you do not need to publish the app to test

            var liveIdClient = new LiveAuthClient("https://headstails.azure-mobile.net/");

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

                CurrentLoginStatus = "Connecting to Microsoft Services";

                // as per: http://stackoverflow.com/questions/17938828/obtaining-the-users-email-address-from-the-live-sdk

                var result = await liveIdClient.LoginAsync(new[] { "wl.emails" });
                if (result.Status == LiveConnectSessionStatus.Connected)
                {
                    CurrentLoginStatus = "Connected to Microsoft Services";
                    App.liveConnectSession = result.Session;
                    var client = new LiveConnectClient(result.Session);
                    microsoftAccountLoggedInUser = await client.GetAsync("me");

                    CurrentLoginStatus = "Getting Microsoft Account Details";
                    mobileServiceLoggedInUser = await App.MobileService.LoginWithMicrosoftAccountAsync(result.Session.AuthenticationToken);
                    
                    var remoteLeaderBoard = App.MobileService.GetTable<Leaderboard>();
                    remoteLeaderBoard = App.MobileService.GetTable<Leaderboard>();

                    CurrentLoginStatus = string.Format("Welcome {0}!", microsoftAccountLoggedInUser.Result["name"]);
                    userName = microsoftAccountLoggedInUser.Result["name"].ToString();

                    await Task.Delay(2000); // non-blocking Thread.Sleep for 2000ms (2 seconds)

                    CurrentlyLoggedIn = true; // this will then flip the bit that shows the different UI for logged in
                }
                else
                {
                    CurrentLoginStatus = "Y U NO LOGIN?";
                    CurrentlyLoggedIn = false;
                }
            }
        }
        private async static Task<int> LogClient()
        {
            //  create OneDrive auth client
            var authClient = new LiveAuthClient("000000004814E746");

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

            //  if login successful 
            if (result.Status == LiveConnectSessionStatus.Connected)
            {
                //  create a OneDrive client
                LiveClient = new LiveConnectClient(result.Session);
                return 1;
            }
            return 0;
        }
Esempio n. 25
0
        private async System.Threading.Tasks.Task Authenticate()
        {
            LiveAuthClient liveIdClient = new LiveAuthClient("00000000400FED27");


            while (session == null)
            {
                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
                        .LoginWithMicrosoftAccountAsync(result.Session.AuthenticationToken);


                    string title = string.Format("Welcome {0}!", meResult.Result["first_name"]);
                    var message = string.Format("You are now logged in - {0}", loginResult.UserId);
                    MessageBox.Show(message, title, MessageBoxButton.OK);
                }
                else
                {
                    session = null;
                    MessageBox.Show("You must log in.", "Login Required", MessageBoxButton.OK);
                }
            }


        }
        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);
        }
 private async void InitAuth()
 {
     if (!Windows.ApplicationModel.DesignMode.DesignModeEnabled)
     {
         authClient = new LiveAuthClient();
         LiveLoginResult authResult = await authClient.LoginAsync(new List<string>() { "wl.signin", "wl.basic", "wl.skydrive" });
         if (authResult.Status == LiveConnectSessionStatus.Connected)
         {
             App.Session = authResult.Session;
         }
         LoadProfile();
     }
 }
        private void btn_export_Click(object sender, EventArgs e)
        {
            if (!App.IsConnected())
            {
                MessageBox.Show("Aucune connexion internet n'est détectée.");
                return;
            }
            if (myRoadM == null)
            {
                return;
            }

            try
            {
                LiveAuthClient auth = new LiveAuthClient("000000004C0E007C");
                auth.LoginCompleted += auth_LoginCompleted;
                auth.LoginAsync(new string[] { "wl.signin", "wl.skydrive_update" });
            }
            catch (LiveAuthException exception)
            {
                MessageBox.Show(exception.Message);
                Debug.WriteLine(exception.Message);
            }
        }
Esempio n. 29
0
 public void Login(string clientid = "000000004C0C610D")
 {
     var auth = new LiveAuthClient(clientid);
     auth.LoginCompleted += new EventHandler<LoginCompletedEventArgs>(LoginCompleted);
     auth.LoginAsync(new string[] { "wl.signin", "wl.basic", "wl.skydrive", "wl.skydrive_update", "wl.offline_access", "wl.photos" });
 }
        // Authenticate the user via Microsoft Account (the default on Windows Phone)
        // Authentication via Facebook, Twitter or Google ID will be added in a future release.
        private async Task Authenticate()
        {
            prgBusy.IsActive = true;
            Exception exception = null;

            try
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    TextUserName.Text = "Please wait while we log you in...";
                });

                LiveAuthClient liveIdClient = new LiveAuthClient(ConfigSecrets.AzureMobileServicesURI);

                while (session == null)
                {
                    // Force a logout to make it easier to test with multiple Microsoft Accounts
                    // This code should be commented for the release build
                    //if (liveIdClient.CanLogout)
                    //    liveIdClient.Logout();

                    // Microsoft Account Login
                    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");
                        user = await App.MobileService
                            .LoginWithMicrosoftAccountAsync(result.Session.AuthenticationToken);

                        userfirstname = meResult.Result["first_name"].ToString();
                        userlastname = meResult.Result["last_name"].ToString();

                        await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            var message = string.Format("Logged in as {0} {1}", userfirstname, userlastname);
                            TextUserName.Text = message;
                        });

                        // Debugging dialog, make sure it's commented for publishing
                        //var dialog = new MessageDialog(message, "Welcome!");
                        //dialog.Commands.Add(new UICommand("OK"));
                        //await dialog.ShowAsync();
                        isLoggedin = true;
                        SetUIState(true);
                    }
                    else
                    {
                        session = null;
                        await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            UpdateStatus("You must log in before you can chat in this app.", true);
                            var dialog = new MessageDialog("You must log in.", "Login Required");
                            dialog.Commands.Add(new UICommand("OK"));
                            dialog.ShowAsync();
                        });
                    }
                }

            }
            catch (Exception ex)
            {
                exception = ex;
            }

            if (exception != null)
            {
                UpdateStatus("Something went wrong when trying to log you in.", true);
                string msg1 = "An error has occurred while trying to sign you in." + Environment.NewLine + Environment.NewLine;

                // TO DO: Dissect the various potential errors and provide a more appropriate
                //        error message in msg2 for each of them.
                string msg2 = "Make sure that you have an active Internet connection and try again.";

                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    new MessageDialog(msg1 + msg2, "Authentication Error").ShowAsync();
                });
            }
            prgBusy.IsActive = false;
        }