private async void SignOutButton_OnClick(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. var loader = new Windows.ApplicationModel.Resources.ResourceLoader(); this.UserNameTextBlock.Text = loader.GetString("MicrosoftAccount/Text"); // Show sign-in button. SignInButton.Visibility = Visibility.Visible; SignOutButton.Visibility = Visibility.Collapsed; } catch (LiveConnectException x) { // Handle exception. } }
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."; Connection.User = null; // Show sign-in button. signInBtn.Visibility = Windows.UI.Xaml.Visibility.Visible; signOutBtn.Visibility = Windows.UI.Xaml.Visibility.Collapsed; new MessageDialog("The app is exiting since you are no longer logged in.").ShowAsync(); App.Current.Exit(); } catch (LiveConnectException x) { // Handle exception. } }
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 x) { // Handle exception. this.userName.Text = x.Message.ToString(); throw new NotImplementedException(); } }
/// <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); }
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(); } } }
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; } } }
public async Task DisconnectAsync() { var cl = new LiveAuthClient(CLIENT_ID); await cl.Initialize(); if (cl.Session != null) { cl.Logout(); } }
// Remove user and record public void SignOut() { LiveAuthClient liveAuthClient = new LiveAuthClient(LIVE_CLIENT_ID); liveAuthClient.Logout(); App.ApplicationSettings.Remove(ONE_DRIVE_SIGN_IN_KEY); StorageExplorer.RemoveKey(this.GetStorageName()); this.LiveClient = null; this.CurrentAccount = null; }
/// <summary> /// Loggt den aktuellen Nutzer aus. /// </summary> internal static void Logout() { LiveAuthClient liveAuthClient = new LiveAuthClient(APIKeys.LiveClientId); liveAuthClient.Logout(); }
public async Task Authenticate() { var liveIdClient = new LiveAuthClient(); while (_session == null) { // // ToDo: Determine if this code is necessary: // 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", "wl.emails"}); if (result.Status == LiveConnectSessionStatus.Connected) { _session = result.Session; var client = new LiveConnectClient(result.Session); LiveOperationResult meResult = await client.GetAsync("me"); dynamic dynamicResult = meResult.Result; string userName = ""; string email = ""; try { userName = string.Format("{0} {1}", dynamicResult.first_name, dynamicResult.last_name); email = dynamicResult.emails.preferred; Settings.EmailAddress = email; //Settings.EmailAddress = "*****@*****.**"; var roomManager = RoomManager.GetInstance(); roomManager.AddMemberToRoom(Settings.userInstance); roomManager.ChangeRoomHost(Settings.userInstance); } catch { // Todo: determine what to do here if this fails... } var mainPageViewModel = MainPageViewModel.GetInstance(); mainPageViewModel.UserName = string.Format("Welcome {0}!", meResult.Result["first_name"]); } else { _session = null; var dialog = new MessageDialog("You must log in.", "Login Required"); dialog.Commands.Add(new UICommand("OK")); await dialog.ShowAsync(); } } }
public void Disconnect() { var cl = new LiveAuthClient("00000000480F4F1E"); cl.Logout(); }
public override void Cleanup() { var aC = new LiveAuthClient(ClientId, RedirectUri); aC.Logout(); base.Cleanup(); }