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(); } }
private async Task SetNameField(Boolean login) { // If login == false, just update the name field. await App.updateUserName(this.UserNameTextBlock, login); // Test to see if the user can sign out. Boolean userCanSignOut = true; var LCAuth = new LiveAuthClient(); LiveLoginResult LCLoginResult = await LCAuth.InitializeAsync(); if (LCLoginResult.Status == LiveConnectSessionStatus.Connected) { userCanSignOut = LCAuth.CanLogout; } var loader = new Windows.ApplicationModel.Resources.ResourceLoader(); if (String.IsNullOrEmpty(UserNameTextBlock.Text) || UserNameTextBlock.Text.Equals(loader.GetString("MicrosoftAccount/Text"))) { // Show sign-in button. SignInButton.Visibility = Visibility.Visible; SignOutButton.Visibility = Visibility.Collapsed; } else { // Show sign-out button if they can sign out. SignOutButton.Visibility = userCanSignOut ? Visibility.Visible : Visibility.Collapsed; SignInButton.Visibility = Visibility.Collapsed; } }
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; }
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 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 Task SetNameField(Boolean login) { // await App.updateUserName(this.userName, login); this.userName.Text = Connection.UserName; 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 = Windows.UI.Xaml.Visibility.Visible; signOutBtn.Visibility = Windows.UI.Xaml.Visibility.Collapsed; } else { // Show sign-out button if they can sign out. signOutBtn.Visibility = (userCanSignOut ? Windows.UI.Xaml.Visibility.Visible : Windows.UI.Xaml.Visibility.Collapsed); signInBtn.Visibility = Windows.UI.Xaml.Visibility.Collapsed; } }
/// <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); }
//인스턴스 생성용 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(); } } }
/// <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"); } }
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(); }
/// <summary> /// Initializes the auth client and detects if a user is already signed in. /// If a user is already signed in, this method creates a valid Session. /// This call is UI-less. /// </summary> /// <param name="client">The LiveAuthClient object this method is attached to.</param> /// <param name="scopes">The list of offers that the application is requesting user consent for.</param> public static Task <LiveLoginResult> Initialize(this LiveAuthClient client, IEnumerable <string> scopes) { var tcs = new TaskCompletionSource <LiveLoginResult>(); client.InitializeCompleted += OnInitializeCompleted; client.InitializeAsync(scopes, new OperationState(tcs, client)); return(tcs.Task); }
public async void DoLogin(string clientId) { var scopes = new List<string>(); scopes.Add("wl.calendars"); scopes.Add("http://outlook.office.com/Calendars.ReadWrite"); var sdk = new LiveAuthClient(clientId); var result = await sdk.InitializeAsync(scopes); var url = sdk.GetLoginUrl(scopes); var token = sdk.Session.AuthenticationToken; }
public async Task Activate() { var session = _cache.SkydriveSession; if (session == null) { var authClient = new LiveAuthClient(ApiKeys.SkyDriveClientId); var x = await authClient.InitializeAsync(); session = x.Session; } _liveClient = new LiveConnectClient(session); }
public async Task<LiveConnectSession> GetSession() { _client = new LiveAuthClient(_clientId, _tokenHandler); var existingToken = await _tokenHandler.RetrieveRefreshTokenAsync(); if (existingToken != null) { var loginResult = await _client.InitializeAsync(); return loginResult.Session; } return await LoginAsync(); }
protected async override Task OnActivate() { if (authClient == null) { authClient = new LiveAuthClient(ApiKeys.SkyDriveClientId); IEnumerable<string> scopes = ParseScopeString(Scopes); try { Task<LiveLoginResult> result = authClient.InitializeAsync(scopes); LiveLoginResult = await result; } catch (Exception exception) { //this.RaiseSessionChangedEvent(new LiveConnectSessionChangedEventArgs(exception)); } } }
private void SkyDriveLogin( string filePath ) { UpdateState( "Logging in..." ); mAuthClient = new LiveAuthClient( YOUR_APP_ID ); mAuthClient.InitializeCompleted += AuthClient_InitializeCompleted; mAuthClient.InitializeAsync( scopes, filePath ); }
/// <summary> /// The logout. /// </summary> public async void Logout() { if (_authClient == null) { _authClient = new LiveAuthClient(); var loginResult = await _authClient.InitializeAsync(_scopes); } if (_authClient.CanLogout) _authClient.Logout(); }
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; }
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) { } }
/// <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 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; } }
private async Task<LiveConnectSession> InitializeSkyDrive() { try { var liveAuthClient = new LiveAuthClient("CLIENTID"); var liveLoginResult = await liveAuthClient.InitializeAsync(); if (liveLoginResult.Status == LiveConnectSessionStatus.Connected) { return liveLoginResult.Session; } } catch (Exception ex) { Dispatcher.BeginInvoke(() => { MessageBox.Show("Unable to connect to SkyDrive\n" + ex.Message, "Error", MessageBoxButton.OK); }); } return null; }
public static async Task updateUserName(TextBlock userName, Boolean signIn) { try { // Open Live Connect SDK client. LiveAuthClient LCAuth = new LiveAuthClient(); LiveLoginResult LCLoginResult = await LCAuth.InitializeAsync(); try { LiveLoginResult loginResult = null; if (signIn) { // 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. // // Change the parameter of LoginAsync to include the scopes // required by your app. loginResult = await LCAuth.LoginAsync(new string[] { "wl.basic" }); } else { // If we don't want the user to sign in, continue with the current // sign-in state. loginResult = LCLoginResult; } if (loginResult.Status == LiveConnectSessionStatus.Connected) { // Create a client session to get the profile data. LiveConnectClient connect = new LiveConnectClient(LCAuth.Session); // Get the profile info of the user. LiveOperationResult operationResult = await connect.GetAsync("me"); dynamic result = operationResult.Result; if (result != null) { // Update the text of the object passed in to the method. userName.Text = string.Join(" ", "Hello", result.name, "!"); } else { // Handle the case where the user name was not returned. } } else { // The user hasn't signed in so display this text // in place of his or her name. userName.Text = "You're not signed in."; } } catch (LiveAuthException exception) { // Handle the exception. userName.Text = exception.Message.ToString(); throw new NotImplementedException(); } } catch (LiveAuthException exception) { // Handle the exception. userName.Text = exception.Message.ToString(); throw new NotImplementedException(); } catch (LiveConnectException exception) { // Handle the exception. userName.Text = exception.Message.ToString(); throw new NotImplementedException(); } }
// Normal Auth private async Task<MobileServiceUser> authenticate2(bool singleSignOn) { LiveAuthClient liveIdClient = new LiveAuthClient("https://debtor.azure-mobile.net/"); var reqs = new[] { "wl.signin", "wl.basic", "wl.offline_access" }; LiveLoginResult init = await liveIdClient.InitializeAsync(reqs); if (init.Status != LiveConnectSessionStatus.Connected) { try { await App.MobileService .LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount, singleSignOn); } catch (InvalidOperationException) { } } return App.MobileService.CurrentUser; }
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); }
private async Task<MobileServiceUser> singleSignOnAuthenticate2() { LiveAuthClient liveIdClient = new LiveAuthClient("https://debtor.azure-mobile.net/"); var reqs = new[] { "wl.signin", "wl.basic", "wl.offline_access"}; MobileServiceUser user = null; LiveLoginResult init = await liveIdClient.InitializeAsync(reqs); if(init.Status != LiveConnectSessionStatus.Connected) { LiveLoginResult logStatus = await liveIdClient.LoginAsync(reqs); if (logStatus.Status == LiveConnectSessionStatus.Connected) { session = logStatus.Session; user = await App.MobileService.LoginAsync(session.AuthenticationToken); } } return user; }
private async Task AuthenticateUser(bool silent) { string text = null; string firstName = string.Empty; bool connected = false; try { var authClient = new LiveAuthClient(); LiveLoginResult result = silent ? await authClient.InitializeAsync(_defaultAuthScopes) : await authClient.LoginAsync(_defaultAuthScopes); if (result.Status == LiveConnectSessionStatus.Connected) { connected = true; var connectClient = new LiveConnectClient(result.Session); var meResult = await connectClient.GetAsync("me"); dynamic meData = meResult.Result; firstName = meData.first_name; await LoadProfileImage(connectClient); } } catch (LiveAuthException ex) { text = "Error: " + ex.Message; } catch (LiveConnectException ex) { text = "Error: " + ex.Message; } if (text != null) { var dialog = new Windows.UI.Popups.MessageDialog(text); await dialog.ShowAsync(); } UpdateUI(connected, firstName); }
private async Task<MobileServiceUser> singleSignOnAuthenticate3() { MobileServiceUser user = null; try { LiveAuthClient auth = new LiveAuthClient("https://debtor.azure-mobile.net/"); LiveLoginResult result = await auth.InitializeAsync(new string[] { "wl.basic", "wl.offline_access", "wl.signin" }); if (result.Status != LiveConnectSessionStatus.Connected) result = await auth.LoginAsync(new string[] { "wl.basic", "wl.offline_access", "wl.signin" }); 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); Person person = await isExistedPerson(user.UserId); if (person == null) // First Login this.Frame.Navigate(typeof(NamingPage), user); else // Again Login { App.roamingSettings.Values[GlobalVariable.ID] = person.id; App.roamingSettings.Values[GlobalVariable.LIVE_ID] = person.person_live_id; App.roamingSettings.Values[GlobalVariable.NAME] = person.person_name; App.roamingSettings.Values[GlobalVariable.TOKEN] = user.MobileServiceAuthenticationToken; person.token = user.MobileServiceAuthenticationToken; await personTable.UpdateAsync(person); this.Frame.Navigate(typeof(TotalDebtPage), person); } } } catch (LiveAuthException exc) { } return user; }
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) { } }
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; }