private async void Authenticator_Completed(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= Authenticator_Completed; authenticator.Error -= Authenticator_Error; } if (e.IsAuthenticated) { string accessToken = e.Account.Properties["id_token"]; try { var loginResponse = await mainContext.Services.Login(accessToken); await SetAccessToken(loginResponse.AccessToken, loginResponse.Name); Toast.LongAlert("Connected to Google"); } catch (ServiceException) { Toast.LongAlert("Unable to connect to Google\nTry again later"); } } }
async void OnGoogleAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnGoogleAuthCompleted; authenticator.Error -= OnGoogleAuthError; } if (e.IsAuthenticated) { // var request = new OAuth2Request("GET", new Uri(Constants.GoogleAPI.UserInfoUrl), null, e.Account); var response = await request.GetResponseAsync(); if (response != null) { string userJson = await response.GetResponseTextAsync(); GoogleUser user = JsonConvert.DeserializeObject <GoogleUser>(userJson); viewModel.SocialLogin(user); } else { await Shell.Current.DisplayAlert("", "Không thể kết nối đến Google !", "Đóng"); } } else { //await accountPage.DisplayAlert("", "Không thể kết nối đến Google .", "Đóng"); } await Task.Delay(2000); }
// AUTHETICATION HANDLERS _________________________________________________ // This function checks if the user was able to succesfully login to their Facebook account. Once the // user autheticates throught Facebook, we validate their credentials in our system. async void FacebookAuthenticatorCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= FacebookAuthenticatorCompleted; authenticator.Error -= FacebookAutheticatorError; } if (e.IsAuthenticated) { try { var client = new SignIn(); UserDialogs.Instance.ShowLoading("Retrieving your JD account..."); var status = await client.VerifyUserCredentials(e.Account.Properties["access_token"], "", null, null, "FACEBOOK"); RedirectUserBasedOnVerification(status, direction); } catch (Exception errorFacebookAuthenticatorCompleted) { //var client = new Diagnostic(); //client.parseException(errorFacebookAuthenticatorCompleted.ToString(), user); Debug.WriteLine("ERROR IN 'FacebookAuthenticatorCompleted': " + errorFacebookAuthenticatorCompleted.Message); } } }
// This function checks if the user was able to succesfully login to their Google account. Once the // user autheticates throught Google, we validate their credentials in our system. async void GoogleAuthenticatorCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= GoogleAuthenticatorCompleted; authenticator.Error -= GoogleAuthenticatorError; } if (e.IsAuthenticated) { try { var client = new SignIn(); UserDialogs.Instance.ShowLoading("Retrieving your JD account..."); var status = await client.VerifyUserCredentials(e.Account.Properties["access_token"], e.Account.Properties["refresh_token"], e, null, "GOOGLE"); RedirectUserBasedOnVerification(status, direction); } catch (Exception errorGoogleAutheticatorCompleted) { //var client = new Diagnostic(); //client.parseException(errorGoogleAutheticatorCompleted.ToString(), user); Debug.WriteLine("ERROR IN 'GoogleAuthenticatorCompleted': " + errorGoogleAutheticatorCompleted.Message); } } else { //Application.Current.MainPage = new LogInPage(); //await DisplayAlert("Error", "Google was not able to autheticate your account", "OK"); } }
private async void GoogleAuth_Completed(object sender, AuthenticatorCompletedEventArgs e) { // We presented the UI, so it's up to us to dimiss it on iOS. DismissViewController(true, null); if (e.IsAuthenticated) { var account = e.Account; var request = new OAuth2Request("GET", new Uri(UserInfoUrl), null, account); var response = await request.GetResponseAsync(); if (response != null) { string userJson = response.GetResponseText(); var user = JsonConvert.DeserializeObject <UserDetailsGoogleDto>(userJson); LblName.Text = user.Name; //IdLabel.Text += id; LblDescription.Text = user.Email; ImgVUser.Image = UIImage.LoadFromData(NSData.FromUrl(new NSUrl(user.Picture))); } } else { // The user cancelled } }
private async void OnAuthenticationCompleted(object sender, AuthenticatorCompletedEventArgs e) { if (e.IsAuthenticated) { var accessToken = e.Account.Properties["access_token"]; var profile = await getFacebookUserAsync(accessToken); try { int userId = await DBConnection.GetUserIdFromEmailAsync(profile.email); ((App)Application.Current).MainUser.Loged = true; LoginAccounPageChanges.ShowAccountPageInMenuSetup(); if (userId != -1) { try { ((App)Application.Current).MainUser = await DBConnection.GetUserDataAsync(userId); LoginAccounPageChanges.GoToAccountPage(); } catch (Exception) { await Application.Current.MainPage.DisplayAlert("Brak połączenia!", "Nie udało się połączyć z bazą danych. Upewnij się, że masz połączenie z internetem, " + "oraz że mam włączonego laptopa :>", "Ok"); } } else { try { userId = await DBConnection.StoreFacebookUserAsync(profile); ((App)Application.Current).MainUser.EmailAddress = profile.email; ((App)Application.Current).MainUser.FirstName = profile.first_name; ((App)Application.Current).MainUser.LastName = profile.last_name; ((App)Application.Current).MainUser.Id = userId.ToString(); LoginAccounPageChanges.GoToAccountPage(); } catch (Exception) { await Application.Current.MainPage.DisplayAlert("Brak połączenia!", "Nie udało się połączyć z bazą danych. Upewnij się, że masz połączenie z internetem, " + "oraz że mam włączonego laptopa :>", "Ok"); } } } catch (Exception) { await Application.Current.MainPage.DisplayAlert("Brak połączenia!", "Nie udało się połączyć z bazą danych. Upewnij się, że masz połączenie z internetem, " + "oraz że mam włączonego laptopa :>", "Ok"); } } }
async void LinkedInAuth_Completed(object sender, AuthenticatorCompletedEventArgs e) { if (e.IsAuthenticated) { var request = new OAuth2Request( "GET", new Uri("https://api.linkedin.com/v1/people/~:(id,firstName,lastName,headline,picture-url,summary,educations,three-current-positions,honors-awards,site-standard-profile-request,location,api-standard-profile-request,phone-numbers)?" + "format=json" + "&oauth2_access_token=" + e.Account.Properties["access_token"]), null, e.Account); var linkedInResponse = await request.GetResponseAsync(); var json = linkedInResponse.GetResponseText(); var linkedInUser = JsonValue.Parse(json); var name = linkedInUser["firstName"] + " " + linkedInUser["lastName"]; var id = linkedInUser["id"]; var description = linkedInUser["headline"]; var picture = linkedInUser["pictureUrl"]; LblName.Text += name; //IdLabel.Text += id; LblDescription.Text = description; ImgVUser.Image = UIImage.LoadFromData(NSData.FromUrl(new NSUrl(picture))); } DismissViewController(true, null); }
private void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { if (e.IsAuthenticated) { Log.Debug("tokentype", "" + e.Account.Properties["token_type"]); Log.Debug("accessToken", "" + e.Account.Properties["access_token"]); //UploadFileUsingResumable(e.Account.Properties["access_token"], ""); //GetGdriveItemsInfoAsync(e.Account.Properties["access_token"]); //Delete(e.Account.Properties["access_token"],"1EgR-GS5PxmIC92n2IruRuPFZJ8gLXKRzHzpZ9ZTKKJ8"); //CreateFolder(e.Account.Properties["access_token"], "Backup-MobileFitting"); //GetFoldersByBrand(e.Account.Properties["access_token"]); UploadFileUsingResumable(e.Account.Properties["access_token"], ""); // "17sZ12Rgrfd_zsvlxCnuQzHbedNS9uTnS", ""); //DownloadFile(e.Account.Properties["access_token"], "1_OUGARZznIekMIvJdUY92B6mcMcrev6L"); //CreateFolder(e.Account.Properties["access_token"]); // var a=System.Threading.Tasks.Task.Run(() => CreateFolder(e.Account.Properties["access_token"])); // UploadFile(e.Account.Properties["access_token"], "1HaEE_nmZQc95J9g_bGYMl-2DQ0pQ_R4m"); // SaveAccount(e.Account); // RetriveAccount(); //System.Threading.Tasks.Task.Run(() => CreateFolder(e.Account.Properties["access_token"]) ); // System.Threading.Tasks.Task.Run(() => GetFolders(e.Account.Properties["access_token"]) ); // System.Threading.Tasks.Task.Run(() => Delete(e.Account.Properties["access_token"])); //DownloadFile(e.Account.Properties["access_token"],""); } else { } }
public async Task <Account> OAuth2LoginAsync ( object activity, bool allowCancel, string client_id, string scope, Uri uri_authorize, Uri uri_redirect ) { var auth = new OAuth2Authenticator ( clientId: client_id, scope: scope, authorizeUrl: uri_authorize, redirectUrl: uri_redirect, getUsernameAsync: null ) { AllowCancel = allowCancel }; // If authorization succeeds or is canceled, .Completed will be fired. var tcs1 = new TaskCompletionSource <AuthenticatorCompletedEventArgs>(); EventHandler <AuthenticatorCompletedEventArgs> d1 = (o, e) => { try { tcs1.TrySetResult(e); } catch (Exception ex) { tcs1.TrySetResult(new AuthenticatorCompletedEventArgs(null)); } }; Account result = null; try { auth.Completed += d1; //var intent = auth.GetUI(activity); //activity.StartActivity(intent); AuthenticatorCompletedEventArgs ea = await tcs1.Task; result = ea.Account; } catch (Exception) { // todo you should handle the exception return(null); } finally { auth.Completed -= d1; } return(result); }
private async void authenticator_Completed(object sender, AuthenticatorCompletedEventArgs obj) { if (obj.IsAuthenticated) { var clientData = new HttpClient(); //call google api to fetch logged in user profile info var resData = await clientData.GetAsync("https://www.googleapis.com/oauth2/v3/userinfo?access_token=" + obj.Account.Properties["access_token"]); var jsonData = await resData.Content.ReadAsStringAsync(); // deserlize the jsondata and intilize in GoogleAuthClass GoogleAuthClass googleObject = JsonConvert.DeserializeObject <GoogleAuthClass>(jsonData); //you can access following property after login string email = googleObject.email; string photo = googleObject.picture; string name = googleObject.name; btnLogin.IsVisible = false; lblemail.Text = "Logged In as " + email; lblemail.FontSize = 30; lblemail.FontAttributes = FontAttributes.Bold; } else { //Authentication fail // write the code to handle when auth failed } }
async void OnAuthenticationCompleted(object sender, AuthenticatorCompletedEventArgs e) { if (e.IsAuthenticated) { // If the user is authenticated, request their basic user data from Google // UserInfoUrl = https://www.googleapis.com/oauth2/v2/userinfo var request = new OAuth2Request("GET", new Uri(EventbriteConstants.UserInfoUrl), null, e.Account); var response = await request.GetResponseAsync(); if (response != null) { // Deserialize the data and store it in the account store // The users email address will be used to identify data in SimpleDB string userJson = response.GetResponseText(); App.User = JsonConvert.DeserializeObject <User>(userJson); e.Account.Username = App.User.Email; AccountStore.Create().Save(e.Account, App.AppName); } } // If the user is logged in navigate to the TodoList page. // Otherwise allow another login attempt. //App.SuccessfulLoginAction.Invoke(); //MessagingCenter.Send((AuthenticationPage)Element, "UserAuthenticated", string.Empty); ((AuthenticationPageModel)((AuthenticationPage)Element).GetModel()).LoggedCommand.Execute(string.Empty); }
private void FacebookAuthorizationCompleted(object sender, AuthenticatorCompletedEventArgs e) { dialog.DismissViewController (true, null); if (!e.IsAuthenticated) { facebookStatus.Caption = "Not authorized"; dialog.ReloadData(); return; } String accessToken = String.Empty; e.Account.Properties.TryGetValue("access_token", out accessToken); var request = new OAuth2Request ("GET", new Uri ("https://graph.facebook.com/me"), null, e.Account); request.GetResponseAsync().ContinueWith (t => { if (t.IsFaulted) facebookStatus.Caption = "Error: " + t.Exception.InnerException.Message; else if (t.IsCanceled) facebookStatus.Caption = "Canceled"; else { //Parse Json result var obj = JsonValue.Parse (t.Result.GetResponseText()); facebookStatus.Caption = "Logged in as " + obj["name"]; } dialog.ReloadData(); }, uiScheduler); }
private async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } if (e.IsAuthenticated) { account = e.Account; string access_token = account.Properties["access_token"]; viewModel.Access_Token = access_token; viewModel.GoogleDriveFiles.Clear(); await viewModel.LoadFileFromGoogleDrive(); modalDriveFiles.IsVisible = true; } else { // huy ko dang nhap } gridLoading.IsVisible = false; }
/// <summary> /// Function to handle successful Google Login /// </summary> /// <param name="sender"></param> /// <param name="e"></param> async void OnGoogleAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnGoogleAuthCompleted; authenticator.Error -= OnGoogleAuthError; } if (e.IsAuthenticated) { DialogsHelper.ProgressDialog.Show(); try { var google_provider_authCredential = Plugin.FirebaseAuth.CrossFirebaseAuth.Current.GoogleAuthProvider.GetCredential(e.Account.Properties["id_token"], e.Account.Properties["access_token"]); var result = await Plugin.FirebaseAuth.CrossFirebaseAuth.Current.Instance.SignInWithCredentialAsync(google_provider_authCredential); await SaveUser(result); } catch (Plugin.FirebaseAuth.FirebaseAuthException ex) { Debug.WriteLine(ex.Message); DialogsHelper.HandleDialogMessage(DialogsHelper.Errors.UndefinedError); } DialogsHelper.ProgressDialog.Hide(); } }
private void ParseArgs(AuthenticatorCompletedEventArgs args) { if (Authenticated == null) { return; } if (!args.IsAuthenticated) { Authenticated(null, false); return; } string token = null; args.Account.Properties.TryGetValue("access_token", out token); if (token != null) { Authenticated(token, false); } else { Authenticated(null, true); } }
void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { OAuth2Authenticator authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } //if i authenticate successfuly I store the access token and i save it in properties if (e.IsAuthenticated) { //a note : Android delete all class attribute ! this is way i am doing that if (!Application.Current.Properties.ContainsKey("UserAccounts")) { Application.Current.Properties["UserAccounts"] = new UserAccounts(); } var userAccountsProperty = Application.Current.Properties["UserAccounts"] as UserAccounts; //check if the service does not exist in the 'UserAccount' property //we create a new one if (!userAccountsProperty.UserServices.ContainsKey(currentServiceName)) { userAccountsProperty.UserServices[currentServiceName] = new UserAccounts.Data(); } //save access token of a service userAccountsProperty.UserServices[currentServiceName].accessToken = e.Account.Properties["access_token"]; //System.Diagnostics.Debug.WriteLine(e.Account.Properties["access_token"]); //save service in property Application.Current.Properties["UserAccounts"] = userAccountsProperty; } }
/// <summary> /// Called when [authentication completed]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="AuthenticatorCompletedEventArgs" /> instance containing the event data.</param> private async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= this.OnAuthCompleted; authenticator.Error -= this.OnAuthError; } if (e.IsAuthenticated) { this.FillAuthCustomObject(e, ref this.authInfo); // TODO: Modify this section to make use of the user info from the id_token // The user info endpoint may not be used by any app ////if (this.authInfo != null) ////{ //// var userInfo = await this.GetUserDataAsync(Constant.UserInfoUrl, this.authInfo.AccessToken); //// await this.navigationService.NavigateAsync( //// "ProfilePage", //// new NavigationParameters { { "userInfo", userInfo } }); ////} ////if (this.account != null) this.store.Delete(this.account, Constant.AppName); ////await this.store.SaveAsync(this.account = e.Account, Constant.AppName); } }
async void OnAuthenticationCompleted(object sender, AuthenticatorCompletedEventArgs e) { if (e.IsAuthenticated) { await AuthenticationHelper.FetchGoogleEmailAndPicture(e.Account); } }
async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } User user = null; if (e.IsAuthenticated) { //UserInfo = https://www.googleapis,com/oaurh2/v2/userinfo var request = new OAuth2Request("GET", new Uri(Constants.UserInfoUrl), null, e.Account); var response = await request.GetResponseAsync(); if (response != null) { string userJson = await response.GetResponseTextAsync(); user = JsonConvert.DeserializeObject <User>(userJson); } if (account != null) { store.Delete(account, Constants.AppName); } await store.SaveAsync(account = e.Account, Constants.AppName); await DisplayAlert("Email address", user.Email, "OK"); } }
private void Auth_Completed(object sender, AuthenticatorCompletedEventArgs e) { try { if (e.IsAuthenticated) { AkHelper.TokenType = e.Account.Properties["token_type"]; AkHelper.ClientAccessToken = e.Account.Properties["access_token"]; _authenticatorService.OnAuthenticateCompleted(AkHelper.TokenType, AkHelper.ClientAccessToken); _isUserAuthenticated = true; RaisePropertyChanged(nameof(IsUserAuthenticated)); } else { _authenticatorService.OnAuthenticateFailed(); _isUserAuthenticated = false; RaisePropertyChanged(nameof(IsUserAuthenticated)); } } catch (Exception ex) { throw new Exception(ex.Message); } }
private void AuthenticatorOnCompleted(object sender, AuthenticatorCompletedEventArgs authenticatorCompletedEventArgs) { if (authenticatorCompletedEventArgs.IsAuthenticated) { Hub.ApiClient.TokenProvider = authenticatorCompletedEventArgs.Account; } }
/// <summary> /// Fills the authentication custom object. /// </summary> /// <param name="eventArgs">The <see cref="AuthenticatorCompletedEventArgs" /> instance containing the event data.</param> /// <param name="authInfoObj">The authentication information object.</param> /// <exception cref="ArgumentNullException">authInfoObj</exception> private void FillAuthCustomObject(AuthenticatorCompletedEventArgs eventArgs, ref AuthInfo authInfoObj) { if (authInfoObj == null) { throw new ArgumentNullException(nameof(authInfoObj)); } if (eventArgs.IsAuthenticated) { var accessToken = eventArgs.Account.Properties["access_token"]; var expiresIn = int.Parse(eventArgs.Account.Properties["expires_in"]); var tokenType = eventArgs.Account.Properties["token_type"]; var scope = eventArgs.Account.Properties["scope"]; var idToken = eventArgs.Account.Properties["id_token"]; authInfoObj = new AuthInfo { IsAuthenticated = eventArgs.IsAuthenticated, AccessToken = accessToken, ExpiresIn = expiresIn, Scope = scope, TokenType = tokenType, }; // TODO: Extract user info from id_token (jwt parsing) } else { authInfoObj = new AuthInfo { IsAuthenticated = eventArgs.IsAuthenticated }; } }
async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; GoogleUserInfo user = null; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } if (e.IsAuthenticated) { // If the user is authenticated, request their basic user data from Google var request = new OAuth2Request("GET", new Uri(Constants.UserInfoUrl), null, e.Account); var response = await request.GetResponseAsync(); if (response != null) { // Deserialize the data and store it in the account store // The users email address will be used to identify data in SimpleDB string userJson = await response.GetResponseTextAsync(); //await DisplayAlert("JSON", userJson, "OK"); debug user = JsonConvert.DeserializeObject <GoogleUserInfo>(userJson); } if (account != null) { store.Delete(account, Constants.AppName); } CreateAccountGoogleAuth(user); } }
private async void TwitterAuth_Completed(object sender, AuthenticatorCompletedEventArgs e) { if (e.IsAuthenticated) { Dictionary <string, string> param = new Dictionary <string, string>(); param.Add("include_email", "true"); var request = new OAuth1Request("GET", new Uri(Constants.TW_OAUTH_URI), param, e.Account); try { var response = await request.GetResponseAsync(); var json = response.GetResponseText(); var twitterUser = JsonConvert.DeserializeObject <TwitterUser>(json); string name = twitterUser.name; string email = twitterUser.email; string id = twitterUser.Id; RegisterResultCheck(name, email, "twitter_" + id); } catch { } } }
private static async void OAuth2Authenticator_Tamamlandi(object sender, AuthenticatorCompletedEventArgs e) { if (e.IsAuthenticated) { try { await SecureStorage.SetAsync("GOOGLE", JsonConvert.SerializeObject(e.Account.Properties)); } catch (Exception ex) { Debug.WriteLine(ex.Message); } string email = await GoogleEpostaGetirAsync(); await SecureStorage.SetAsync("Eposta", email); await SecureStorage.SetAsync("Saglayici", "GOOGLE"); await Application.Current.MainPage.Navigation.PushAsync(new NotGirisPage()); } else { oAuth2Authenticator.OnCancelled(); oAuth2Authenticator = default(OAuth2Authenticator); } }
private async void Auth_Completed(object sender, AuthenticatorCompletedEventArgs e) { if (e.IsAuthenticated) { var request = new OAuth2Request( "GET", new Uri("https://graph.facebook.com/me?fields=name"), null, e.Account); var fbResponse = await request.GetResponseAsync(); var fbUser = JsonValue.Parse(fbResponse.GetResponseText()); var name = fbUser["name"]; var id = fbUser["id"]; if (!(IsExistingUser(id))) { SaveUserLocally(id, name); } AddUserToDB(id, name); } DismissViewController(true, null); }
void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } if (e.IsAuthenticated) { if (this.account != null) { store.Delete(this.account, ServiceId); } store.Save(account = e.Account, ServiceId); statusText.Text = "Authentication succeeded"; } else { statusText.Text = "Authentication failed"; } }
async void VerifificaValidadeToken(AuthenticatorCompletedEventArgs eventArgs) { //TODO: Implementar refresh token se necessário. //var accessToken = eventArgs.Account.Properties["access_token"].ToString(); //var expiresIn = Convert.ToDouble(eventArgs.Account.Properties["expires_in"]); //var expiryDate = DateTime.Now + TimeSpan.FromSeconds(expiresIn); }
public async void FacebookAuthenticatorCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= FacebookAuthenticatorCompleted; authenticator.Error -= FacebookAutheticatorError; } if (e.IsAuthenticated) { UserDialogs.Instance.ShowLoading("We are processing your request..."); var authenticationStatus = await client.UserVerification(e, null, "FACEBOOK"); if (authenticationStatus == "EMAIL WAS NOT FOUND") { var account = new AppleAccount(); account.Email = "*****@*****.**"; account.UserId = ""; account.Name = ""; account.RealUserStatus = ""; account.Token = ""; authenticationStatus = await client.UserVerification(null, account, "APPLE"); } ProcessRequest(authenticationStatus); } }
async void AuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { var loggedInUser = e.Account; await _accountStore.Store(loggedInUser); MessagingCenter.Send(this, Constants.SetMainPageMessage); }
public async void Auth_Completed(object sender, AuthenticatorCompletedEventArgs ee) { string msg = ""; if (!ee.IsAuthenticated) { msg = "Not Authenticated"; } else { try { StringBuilder sb = new StringBuilder(); sb.Append("IsAuthenticated = ").Append(ee.IsAuthenticated) .Append(System.Environment.NewLine); sb.Append("Account.UserName = ").Append(ee.Account.Username) .Append(System.Environment.NewLine); } catch (Exception ex) { msg = ex.Message; } } //ee.Account.Properties; return; }
string GetEventAsString (AuthenticatorCompletedEventArgs e) { if (e.IsAuthenticated) { return e.Account.Serialize (); } else { return "Not Authenticated"; } }
void HandleCompleted (object sender, AuthenticatorCompletedEventArgs e) { if (e.IsAuthenticated) { Console.WriteLine ("AUTHENTICATED: " + e.Account.Serialize ()); } else { Console.WriteLine ("NOT AUTHENTICATED"); } }
void HandleCompleted (object sender, AuthenticatorCompletedEventArgs e) { AppDelegate.SharedViewController.DismissViewController (true, null); if (e.IsAuthenticated) { Console.WriteLine ("AUTHENTICATED: " + e.Account.Serialize ()); } else { Console.WriteLine ("NOT AUTHENTICATED"); } }
void OnAuthenticationCompleted (AuthenticatorCompletedEventArgs e) { if (!e.IsAuthenticated) { // TODO: Handle failed login scenario by re-presenting login form with error throw new Exception ("Login failed and we don't handle that."); } LoadAccounts (); Account = e.Account; Client.Save (Account); }
void auth_Completed(object sender, AuthenticatorCompletedEventArgs e) { if (e.Account != null) { userToken = e.Account.Properties["access_token"]; ISharedPreferencesEditor editor = prefs.Edit(); editor.PutString ("token", userToken); editor.Apply (); Intent intent= new Intent(this,typeof(SearchActivity)); StartActivityForResult(intent, 0); } }
async void OnAuthenticationCompleted (object sender, AuthenticatorCompletedEventArgs e) { if (e.IsAuthenticated) { // If the user is authenticated, request their basic user data from Google // UserInfoUrl = https://www.googleapis.com/oauth2/v2/userinfo var request = new OAuth2Request ("GET", new Uri (Constants.UserInfoUrl), null, e.Account); var response = await request.GetResponseAsync (); if (response != null) { // Deserialize the data and store it in the account store // The users email address will be used to identify data in SimpleDB string userJson = response.GetResponseText (); App.User = JsonConvert.DeserializeObject<User> (userJson); e.Account.Username = App.User.Email; AccountStore.Create (Context).Save (e.Account, App.AppName); } } // If the user is logged in navigate to the TodoList page. // Otherwise allow another login attempt. App.SuccessfulLoginAction.Invoke (); }
private void ParseArgs (AuthenticatorCompletedEventArgs args) { if (Authenticated == null) { return; } if (!args.IsAuthenticated) { Authenticated (null, false); return; } string token = null; args.Account.Properties.TryGetValue ("access_token", out token); if (token != null) { Authenticated (token, false); } else { Authenticated (null, true); } }
void OnAuthenticationCompleted (AuthenticatorCompletedEventArgs e) { if (!e.IsAuthenticated) { // TODO: Handle failed login scenario by re-presenting login form with error Client.CurrentUser.RequiresReauthentication = true; throw new Exception ("Login failed and we don't handle that."); } DismissViewController (true, () => { NavigationItem.RightBarButtonItem = null; LoadAccounts (); }); }
private void VkontakteAuthorizationCompleted(object sender, AuthenticatorCompletedEventArgs e) { dialog.DismissViewController (true, null); if (!e.IsAuthenticated) { vkontakteStatus.Caption = "Not authorized"; dialog.ReloadData(); return; } String accessToken = String.Empty; e.Account.Properties.TryGetValue("access_token", out accessToken); String userId = String.Empty; e.Account.Properties.TryGetValue("user_id", out userId); String uri = String.Format("https://api.vk.com/method/users.get?uid={0}&access_token={1}", userId, accessToken); var request = new OAuth2Request ("GET", new Uri (uri), null, e.Account); request.GetResponseAsync().ContinueWith (t => { if (t.IsFaulted) vkontakteStatus.Caption = "Error: " + t.Exception.InnerException.Message; else if (t.IsCanceled) vkontakteStatus.Caption = "Canceled"; else { //Parse Json result var obj = JsonObject.Parse (t.Result.GetResponseText()); var resp = obj["response"] as JsonArray; vkontakteStatus.Caption = "Logged in as " + resp.FirstOrDefault()["first_name"]; } dialog.ReloadData(); }, uiScheduler); }