public async void OnAppleSignInRequest() { try { IAppleSignInService appleSignInService = DependencyService.Get <IAppleSignInService>(); var account = await appleSignInService.SignInAsync(); if (account != null) { Preferences.Set(App.LoggedInKey, true); await SecureStorage.SetAsync(App.AppleUserIdKey, account.UserId); string email = ""; if (account.Email != null) { await SecureStorage.SetAsync(account.UserId, account.Email); Application.Current.Properties[account.UserId.ToString()] = account.Email; } else { email = await SecureStorage.GetAsync(account.UserId); if (email == null) { if (Application.Current.Properties.ContainsKey(account.UserId.ToString())) { email = (string)Application.Current.Properties[account.UserId.ToString()]; } else { email = ""; } } account.Email = email; } UserDialogs.Instance.ShowLoading("We are processing your request..."); var authenticationStatus = await client.UserVerification(null, account, "APPLE"); if (authenticationStatus == "EMAIL WAS NOT FOUND") { account.Email = "*****@*****.**"; account.UserId = ""; account.Name = ""; account.RealUserStatus = ""; account.Token = ""; authenticationStatus = await client.UserVerification(null, account, "APPLE"); } ProcessRequest(authenticationStatus); } } catch (Exception errorSignInRequest) { await Application.Current.MainPage.DisplayAlert("Error", errorSignInRequest.Message, "OK"); } }
public async void OnAppleSignInRequest() { var account = await appleSignInService.SignInAsync(); if (account != null) { Preferences.Set(App.LoggedInKey, true); await SecureStorage.SetAsync(App.AppleUserIdKey, account.UserId); // System.Diagnostics.Debug.WriteLine($"Signed in!\n Name: {account?.Name ?? string.Empty}\n Email: {account?.Email ?? string.Empty}\n UserId: {account?.UserId ?? string.Empty}"); var client = new HttpClient(); var socialLogInPost = new SocialLogInPost(); if (apple_token == null && apple_email == null) { apple_token = account.Token.Substring(0, 500); apple_email = account.Email; AppleUserProfileAsync(apple_token, apple_email, account.Name); } if (!apple_token.Equals(account.Token) && apple_token != null) { DateTime today = DateTime.Now; DateTime expirationDate = today.AddDays(Constant.days); Application.Current.Properties["time_stamp"] = expirationDate; apple_token = account.Token.Substring(0, 500); UpdateTokensPost updateTokens = new UpdateTokensPost(); updateTokens.access_token = apple_token; updateTokens.refresh_token = apple_token; updateTokens.uid = (string)Application.Current.Properties["uid"]; updateTokens.social_timestamp = expirationDate.ToString("yyyy-MM-dd HH:mm:ss"); var updatePostSerilizedObject = JsonConvert.SerializeObject(updateTokens); var updatePostContent = new StringContent(updatePostSerilizedObject, Encoding.UTF8, "application/json"); var RDSrespose = await client.PostAsync(Constant.UpdateTokensUrl, updatePostContent); if (RDSrespose.IsSuccessStatusCode) { AppleUserProfileAsync(apple_token, apple_email, string.Empty); } else { System.Diagnostics.Debug.WriteLine("We were not able to update your APPLE token"); } } } else { AppleError?.Invoke(this, default(EventArgs)); } }
// This function checks if the user was able to succesfully login to their Apple account. Once the // user autheticates throught Apple, we validate their credentials in our system. async void OnAppleSignInRequest() { try { IAppleSignInService appleSignInService = DependencyService.Get <IAppleSignInService>(); var account = await appleSignInService.SignInAsync(); if (account != null) { Preferences.Set(App.LoggedInKey, true); await SecureStorage.SetAsync(App.AppleUserIdKey, account.UserId); string email = ""; if (account.Email != null) { await SecureStorage.SetAsync(account.UserId, account.Email); Application.Current.Properties[account.UserId.ToString()] = account.Email; } else { email = await SecureStorage.GetAsync(account.UserId); if (email == null) { if (Application.Current.Properties.ContainsKey(account.UserId.ToString())) { email = (string)Application.Current.Properties[account.UserId.ToString()]; } else { email = ""; } } account.Email = email; } var client = new SignIn(); UserDialogs.Instance.ShowLoading("Retrieving your JD account..."); var status = await client.VerifyUserCredentials("", "", null, account, "APPLE"); RedirectUserBasedOnVerification(status, direction); } } catch (Exception errorAppleSignInRequest) { //var client = new Diagnostic(); //client.parseException(errorAppleSignInRequest.ToString(), user); Debug.WriteLine("ERROR IN 'OnAppleSignInRequest': " + errorAppleSignInRequest.Message); } }
public async Task OnAppleSignInRequest() { var account = await appleSignInService.SignInAsync(); if (account != null) { Preferences.Set(App.LoggedInKey, true); await SecureStorage.SetAsync(App.AppleUserIdKey, account.UserId); System.Diagnostics.Debug.WriteLine($"Signed in!\n Name: {account?.Name ?? string.Empty}\n Email: {account?.Email ?? string.Empty}\n UserId: {account?.UserId ?? string.Empty}"); OnSignIn?.Invoke(this, default(EventArgs)); } }
public async void OnAppleSignInRequest() { var account = await appleSignInService.SignInAsync(); if (account != null) { Preferences.Set(App.LoggedInKey, true); await SecureStorage.SetAsync(App.AppleUserIdKey, account.UserId); if (account.Token == null) { account.Token = ""; } if (account.Email != null) { if (Application.Current.Properties.ContainsKey(account.UserId.ToString())) { Application.Current.Properties[account.UserId.ToString()] = account.Email; } else { Application.Current.Properties[account.UserId.ToString()] = account.Email; } } if (account.Email == null) { account.Email = ""; } if (account.Name == null) { account.Name = ""; } System.Diagnostics.Debug.WriteLine((string)Application.Current.Properties[account.UserId.ToString()]); AppleUserProfileAsync(account.UserId, account.Token, (string)Application.Current.Properties[account.UserId.ToString()], account.Name); } else { AppleError?.Invoke(this, default(EventArgs)); } }
public async void OnAppleSignInRequest() { try { var account = await appleSignInService.SignInAsync(); if (account != null) { Preferences.Set(App.LoggedInKey, true); await SecureStorage.SetAsync(App.AppleUserIdKey, account.UserId); if (account.Token == null) { account.Token = ""; } if (account.Email != null) { if (Application.Current.Properties.ContainsKey(account.UserId.ToString())) { //Application.Current.Properties[account.UserId.ToString()] = account.Email; Debug.WriteLine((string)Application.Current.Properties[account.UserId.ToString()]); } else { Application.Current.Properties[account.UserId.ToString()] = account.Email; } } if (account.Email == null) { account.Email = ""; } if (account.Name == null) { account.Name = ""; } if (Application.Current.Properties.ContainsKey(account.UserId.ToString())) { account.Email = (string)Application.Current.Properties[account.UserId.ToString()]; //Application.Current.MainPage = new DeliveriesPage("","",null,account,"APPLE"); //AppleUserProfileAsync(account.UserId, account.Token, (string)Application.Current.Properties[account.UserId.ToString()], account.Name); } else { var client = new HttpClient(); var getAppleEmail = new AppleEmail(); getAppleEmail.social_id = account.UserId; var socialLogInPostSerialized = JsonConvert.SerializeObject(getAppleEmail); System.Diagnostics.Debug.WriteLine(socialLogInPostSerialized); var postContent = new StringContent(socialLogInPostSerialized, Encoding.UTF8, "application/json"); var RDSResponse = await client.PostAsync("https://tsx3rnuidi.execute-api.us-west-1.amazonaws.com/dev/api/v2/AppleEmail", postContent); var responseContent = await RDSResponse.Content.ReadAsStringAsync(); System.Diagnostics.Debug.WriteLine(responseContent); if (RDSResponse.IsSuccessStatusCode) { var data = JsonConvert.DeserializeObject <AppleUser>(responseContent); Application.Current.Properties[account.UserId.ToString()] = data.result[0].customer_email; account.Email = (string)Application.Current.Properties[account.UserId.ToString()]; //Application.Current.MainPage = new DeliveriesPage("", "", null, account, "APPLE"); //AppleUserProfileAsync(account.UserId, account.Token, (string)Application.Current.Properties[account.UserId.ToString()], account.Name); } else { await Application.Current.MainPage.DisplayAlert("Ooops", "Our system is not working. We can't process your request at this moment", "OK"); } } } else { AppleError?.Invoke(this, default(EventArgs)); } } catch (Exception apple) { await Application.Current.MainPage.DisplayAlert("Error", apple.Message, "OK"); } }
public async void OnAppleSignInRequest() { Console.WriteLine("in LoginViewModel, entered OnAppleSignInRequest"); //================================ //CARLOS UPDATE APPLE SOLUTION try { var account = await appleSignInService.SignInAsync(); if (account != null) { Debug.WriteLine("reached inside account"); Preferences.Set(App.LoggedInKey, true); await SecureStorage.SetAsync(App.AppleUserIdKey, account.UserId); if (account.Token == null) { account.Token = ""; } if (account.Email != null) { Debug.WriteLine("email not null: " + account.Email); if (Application.Current.Properties.ContainsKey(account.UserId.ToString())) { //Application.Current.Properties[account.UserId.ToString()] = account.Email; Debug.WriteLine((string)Application.Current.Properties[account.UserId.ToString()]); } else { Application.Current.Properties[account.UserId.ToString()] = account.Email; } } if (account.Email == null) { account.Email = ""; } if (account.Name == null) { account.Name = ""; } if (Application.Current.Properties.ContainsKey(account.UserId.ToString())) { AppleUserProfileAsync(account.UserId, account.Token, (string)Application.Current.Properties[account.UserId.ToString()], account.Name); } else { var client = new HttpClient(); var getAppleEmail = new AppleEmail(); getAppleEmail.social_id = account.UserId; var socialLogInPostSerialized = JsonConvert.SerializeObject(getAppleEmail); Debug.WriteLine(socialLogInPostSerialized); Debug.WriteLine("email:" + account.Email); Debug.WriteLine("userid:" + account.UserId); var postContent = new StringContent(socialLogInPostSerialized, Encoding.UTF8, "application/json"); var RDSResponse = await client.PostAsync(Constant.AppleEmailUrl, postContent); var responseContent = await RDSResponse.Content.ReadAsStringAsync(); Debug.WriteLine(responseContent); if (RDSResponse.IsSuccessStatusCode) { var data = JsonConvert.DeserializeObject <AppleUser>(responseContent); Debug.WriteLine("data:" + data); Debug.WriteLine("data:" + data.ToString()); Application.Current.Properties[account.UserId.ToString()] = data.result[0].customer_email; //Application.Current.Properties[account.UserId.ToString()] = "*****@*****.**"; AppleUserProfileAsync(account.UserId, account.Token, (string)Application.Current.Properties[account.UserId.ToString()], account.Name); } else { await Application.Current.MainPage.DisplayAlert("Ooops", "Our system is not working. We can't process your request at this moment", "OK"); } } } else { AppleError?.Invoke(this, default(EventArgs)); } } catch (Exception apple) { await Application.Current.MainPage.DisplayAlert("Error", apple.Message, "OK"); } //================================ }