public static FbAccessToken GetCurrentAccessToken() { try { var token = new FbAccessToken(); if (Application.Current.Properties.ContainsKey("fb_access_token_string")) { token.Token = (string)Application.Current.Properties["fb_access_token_string"]; token.ApplicationId = (string)Application.Current.Properties["fb_access_token_app_id"]; token.UserId = (string)Application.Current.Properties["fb_access_token_user_id"]; token.ExpirationTime = (DateTime)Application.Current.Properties["fb_access_token_expiry"]; token.LastRefreshTime = (DateTime)Application.Current.Properties["fb_access_token_refresh"]; return(token); } else { return(null); } } catch (Exception) { System.Diagnostics.Debug.WriteLine("No access token found"); return(null); } }
public async Task <bool> SocialLoginFacebook() { try { FbAccessToken token = await Xamarin.Forms.DependencyService.Get <IFacebookLogin>().LogIn(permissions); if (token != null) { // save token await token.Save(); IGraphRequest request = Xamarin.Forms.DependencyService.Get <IGraphRequest>().NewRequest(token, "/me", parameters); IGraphResponse response = await request.ExecuteAsync(); SocialModel socialModel = GetFBData(JObject.Parse(response.RawResponse)); socialModel.AuthType = AuthType.Facebook; await RegisterAndUpdate(socialModel); return(true); } else { System.Diagnostics.Debug.WriteLine("======================token was null"); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.ToString()); } return(false); }
public async void Logout() { Helpers.Settings.Current.UserName = string.Empty; Helpers.Settings.Current.SocialUserID = string.Empty; if (Helpers.Settings.Current.UserAuth == AuthType.Facebook) { await FbAccessToken.Current.Logout(); FbAccessToken.Clear(); var account = AccountStore.Create().FindAccountsForService("Facebook").FirstOrDefault(); if (account != null) { AccountStore.Create().Delete(account, "Facebook"); } } if (Helpers.Settings.Current.UserAuth == AuthType.Twitter) { var account = AccountStore.Create().FindAccountsForService(AccountServiceTwitter).FirstOrDefault(); if (account != null) { AccountStore.Create().Delete(account, AccountServiceTwitter); } } if (Helpers.Settings.Current.UserAuth == AuthType.Google) { var account = AccountStore.Create().FindAccountsForService(AccountServiceGoogle).FirstOrDefault(); if (account != null) { AccountStore.Create().Delete(account, AccountServiceGoogle); } } await m_NavigationService.NavigateAsync("/LoginPage"); }
public async Task <bool> HandleAlreadyLoggedIn(FbAccessToken token) { IGraphRequest request = Xamarin.Forms.DependencyService.Get <IGraphRequest>().NewRequest(token, "/me", parameters); IGraphResponse response = await request.ExecuteAsync(); if (response.RawResponse != null) { SocialModel socialModel = GetFBData(JObject.Parse(response.RawResponse)); socialModel.AuthType = AuthType.Facebook; await RegisterAndUpdate(socialModel); return(true); } return(false); }
public static void Clear() { _currentAccessToken = null; }