/// <summary> /// Remet le token à firebase qui va crée un new user facebook. /// </summary> /// <param name="result"></param> public void OnFacebookLoggedIn(ILoginResult result) { if (FB.IsLoggedIn) { var tocken = AccessToken.CurrentAccessToken; Credential credential = FacebookAuthProvider.GetCredential(tocken.TokenString); auth.SignInWithCredentialAsync(credential).ContinueWithOnMainThread(task => { Debug.LogError("user Creer"); if (task.IsCanceled) { Debug.LogError("SignInWithCredentialAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception); return; } Firebase.Auth.FirebaseUser newUser = task.Result; Debug.Log($"User signed in successfully DisplayName:{ newUser.DisplayName}, UserId:{newUser.UserId}, Email:{newUser.Email}"); }); } else { Debug.Log($"{result.Error}"); } }
// 페이스북 토큰으로 앱 로그인 진행 IEnumerator coLogin(AccessToken aToken) { Debug.Log(string.Format("\nTry to get Token...{0}", aToken)); while (System.String.IsNullOrEmpty(aToken.TokenString)) { yield return(null); } Debug.Log(string.Format("\nTry Auth for Facebook...{0}", aToken.UserId)); Credential credential = FacebookAuthProvider.GetCredential(aToken.TokenString); AuthManager.firebaseAuth.SignInWithCredentialAsync(credential).ContinueWith(task => { Debug.Log($"Facebook Sign in status : {task.Status}"); AuthManager.IsSignInOnProgress = false; if (task.IsFaulted) { Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception); } else if (task.IsCanceled) { Debug.LogError("SignInWithCredentialAsync was canceled."); } else { AuthManager.User = task.Result; Debug.Log("Succeed to Sign-in: " + AuthManager.User.Email); //nickNameField.text = AuthManager.User.DisplayName; isFBloginDone = true; } }); }
public static async Task AuthWithFacebookAsync(AccessToken token) { var credential = FacebookAuthProvider.GetCredential(token.Token); CurrentFirebaseInstance.SignInWithCredential(credential); var user = CurrentFirebaseInstance.CurrentUser; QSN.Helpers.Settings.UserId = user.Uid; var tokenObject = await user.GetIdTokenAsync(false); QSN.Helpers.Settings.UserToken = tokenObject.Token; QSN.Helpers.Settings.UserImage = user.ProviderData.FirstOrDefault((x) => x.ProviderId == "facebook.com").PhotoUrl.ToString(); QSN.Helpers.Settings.UserName = user.DisplayName; Xamarin.Forms.Application.Current.MainPage = new Xamarin.Forms.MasterDetailPage() { Master = new MasterPage() { Title = "Main Page" }, Detail = new Xamarin.Forms.NavigationPage(new QuotesPage()) }; //Use, if email needed //GraphRequest request = GraphRequest.NewMeRequest(token, new GraphJsonCallback()); //Bundle parameters = new Bundle(); //request.Parameters.PutString("fields", "id,name,link,email"); //request.ExecuteAsync(); }
/** * Initializes Facebook App **/ private void SetInit() { if (FB.IsInitialized) { Debug.Log("Fb init is done"); // Signal an app activation App Event FB.ActivateApp(); //Check if they already logged in or not before, to update button text if (FB.IsLoggedIn) { this.loggedIn = true; loginOutbtn.GetComponentInChildren <Text>().text = "Logout"; datahandler.SetIsLoggedIn(true); FB.API("me?fields=name", Facebook.Unity.HttpMethod.GET, GetFacebookData); this.accessToken = AccessToken.CurrentAccessToken; credentials = FacebookAuthProvider.GetCredential(this.accessToken.TokenString); FirebaseLogin(); } else { this.loggedIn = false; loginOutbtn.GetComponentInChildren <Text>().text = "Login"; datahandler.SetIsLoggedIn(false); } } else { Debug.Log("Failed to Initialize the Facebook SDK"); } }
private void handleFacebookAccessToken(AccessToken accessToken) { //Facebook Credential AuthCredential credential = FacebookAuthProvider.GetCredential(accessToken.Token); _auth.SignInWithCredential(credential).AddOnCompleteListener(this, this); }
public void FacebookSignedIn(string accessToken, Action callback = null) { Credential credential = FacebookAuthProvider.GetCredential(accessToken); auth.SignInWithCredentialAsync(credential).ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("SignInWithCredentialAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception); return; } Firebase.Auth.FirebaseUser newUser = task.Result; Debug.LogFormat("User signed in successfully: {0} ({1})", newUser.DisplayName, newUser.UserId); if (callback != null) { callback(); } }); }
public static void FacebookAuth(string AccessToken) { Credential Credential = FacebookAuthProvider.GetCredential(AccessToken); Auth.SignInWithCredentialAsync(Credential).ContinueWith(Task => { if (Task.IsCanceled) { Debug.LogError("Firebase Auth - SignInWithCredentialAsync foi cancelado."); TecWolf.System.SystemInterface.Alert("O login da conta foi cancelado."); return; } if (Task.IsFaulted) { Debug.LogError("Firebase Auth - SignInWithCredentialAsync encontrou um erro: " + Task.Exception); TecWolf.System.SystemInterface.Alert("Erro ao logar conta, verifique Email e Senha."); return; } User = Task.Result; Debug.LogFormat("Firebase Auth - Usuário logado com sucesso: {0} ({1})", User.DisplayName, User.UserId); TecWolf.System.SystemInterface.Alert("Conta logada com sucesso."); }); }
public void FaceBookSteps(string JsonObject, string way) { FacebookGetBack obj = JsonAuthorizeData <FacebookGetBack> .FromJson(JsonObject.ToString()); AGConnectAuthCredential credential = FacebookAuthProvider.credentialWithToken(obj.Token); thirdPartySignIn(way, credential); }
public async Task <FirebaseUser> FirebaseLoginWithFacebookAsync(string token) { var taskCompletion = new TaskCompletionSource <FirebaseUser>(); Auth.DefaultInstance.SignIn(FacebookAuthProvider.GetCredential(token), (user, error) => Callback(taskCompletion, user, error)); return(await taskCompletion.Task); }
public async Task <string> LoginFacebookAsync(string token) { string user_name = ""; int count = 0; int max = 10; // 5s max // Get access token for the signed-in user and exchange it for a Firebase credential var credential = FacebookAuthProvider.GetCredential(token); // Authenticate with Firebase using the credential Auth.DefaultInstance.SignIn(credential, (user, error) => { if (error != null) { AuthErrorCode errorCode; if (IntPtr.Size == 8) // 64 bits devices { errorCode = (AuthErrorCode)((long)error.Code); } else // 32 bits devices { errorCode = (AuthErrorCode)((int)error.Code); } // Posible error codes that SignIn method with credentials could throw // Visit https://firebase.google.com/docs/auth/ios/errors for more information switch (errorCode) { case AuthErrorCode.InvalidCredential: case AuthErrorCode.InvalidEmail: case AuthErrorCode.OperationNotAllowed: case AuthErrorCode.EmailAlreadyInUse: case AuthErrorCode.UserDisabled: case AuthErrorCode.WrongPassword: default: // Print error break; } // stop waiting count = max; } else { // Do your magic to handle authentication result user_name = user.Email; } }); do { await Task.Delay(500); count++; } while (user_name == "" || count < max); return(user_name); }
public void OnSuccess(Java.Lang.Object result) { LoginResult loginResult = (LoginResult)result; Log.Debug("IFacebookCallback", "Facebook login successfuly. Access token: " + loginResult.AccessToken.Token); IAGConnectAuthCredential credential = FacebookAuthProvider.CredentialWithToken(loginResult.AccessToken.Token); loginActivity.SignIn(credential); }
public async Task <AccountResponse> LoginWithFacebook() { var mainActivity = Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity as MainActivity; var tokenTask = new TaskCompletionSource <AccessToken>(); var loginManager = DeviceLoginManager.Instance; loginManager.RegisterCallback( mainActivity.CallbackManager, new FacebookLoginCallback(tokenTask)); loginManager .LogInWithReadPermissions( Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity, new List <string> { "public_profile", "email" }); try { var accessToken = await tokenTask.Task; loginManager.UnregisterCallback(mainActivity.CallbackManager); TaskCompletionSource <string> getEmailTask = new TaskCompletionSource <string>(); Bundle parameters = new Bundle(); parameters.PutString("fields", "id,email"); var graphRequestResult = (await new GraphRequest(accessToken, "me", parameters, HttpMethod.Get) .ExecuteAsync() .GetAsync() as ArrayList).ToArray(); var graphResponse = graphRequestResult.FirstOrDefault() as GraphResponse; string emailAddress = graphResponse.JSONObject.GetString("email"); var credential = FacebookAuthProvider.GetCredential(accessToken.Token); var firebaseResult = await LoginToFirebase(credential); if (firebaseResult.Success) { Settings.Current.AuthType = "facebook"; firebaseResult.User.Email = emailAddress; } return(firebaseResult); } catch (System.Exception ex) { return(new AccountResponse { Success = false, Error = ex.Message }); } }
public IEnumerator LoginWithFacebook() { auth.SignOut(); LoadingScreen.Instance.Show("Siging in with Facebook..."); yield return(new WaitUntil(() => FB.IsInitialized)); string accessToken = ""; List <string> permissions = new List <string>(); permissions.Add("public_profile"); permissions.Add("email"); FB.LogInWithReadPermissions(permissions, delegate(ILoginResult result) { if (!string.IsNullOrEmpty(result.Error) || !FB.IsLoggedIn) { ILogger.Instance.ShowMessage("Failed to login in with facebook", LoggerType.error); LoadingScreen.Instance.Hide(); Debug.LogError(result.Error); return; } accessToken = AccessToken.CurrentAccessToken.TokenString; Debug.Log(accessToken); FB.API("me?fields=first_name", HttpMethod.GET, delegate(IGraphResult res) { if (res.Error == null) { Debug.Log(res.ResultDictionary["first_name"] + ": " + AccessToken.CurrentAccessToken.UserId + "\nExpires in: " + AccessToken.CurrentAccessToken.ExpirationTime); } }); Credential credential = FacebookAuthProvider.GetCredential(accessToken); auth.SignInWithCredentialAsync(credential).ContinueWith(task => { LoadingScreen.Instance.Hide(); if (task.IsCanceled) { Debug.LogError("SignInWithCredentialAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception); return; } User = task.Result; if (User != null) { string name = User.DisplayName; string email = User.Email; System.Uri photo_url = User.PhotoUrl; Debug.Log(name + ": " + email + ": " + photo_url); LoginScreenUI.Instance.AfterLogin(); } }); }); }
public async Task <FirebaseUser> FirebaseLoginWithFacebookAsync(string token) { var credential = FacebookAuthProvider.GetCredential(token); _user = (await _firebaseAuth.SignInWithCredentialAsync(credential)).User; SaveUser(); return(User); }
private void FacebookAuthComplete(object sender, AuthenticatorCompletedEventArgs e) { Log.Debug(Tag, "FacebookAuthComplete:" + e.IsAuthenticated); if (e.IsAuthenticated) { var token = e.Account.Properties["access_token"]; AuthCredential credential = FacebookAuthProvider.GetCredential(token); mAuth.SignInWithCredential(credential); } }
private void AuthCallback(ILoginResult result) { if (FB.IsLoggedIn) { // AccessToken class will have session details var aToken = AccessToken.CurrentAccessToken; // Print current access token's User Credential credential = FacebookAuthProvider.GetCredential(aToken.TokenString); user.LinkWithCredentialAsync(credential).ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("SignInWithCredentialAsync was canceled."); return; } if (task.IsFaulted) { auth.SignOut(); Debug.Log("Called1"); auth.SignInWithCredentialAsync(credential).ContinueWith(task2 => { if (task2.IsCanceled) { return; } if (task2.IsFaulted) { return; } if (task2.IsCompleted) { reference.Child("users").Child(deviceID).Child("online").SetValueAsync("false"); user = task2.Result; reload = true; } }); } else if (task.IsCompleted) { Debug.Log("Logged In"); user = task.Result; localUser = new User(userNametext, user.Email, aToken.UserId, user.UserId); writeNewUser(user.UserId, userNametext, user.Email, aToken.UserId); } }); } else { Debug.Log("User cancelled login"); } }
void FacebookLoginCallback(ILoginResult res) { if (FB.IsLoggedIn) { fb_token = AccessToken.CurrentAccessToken; fb_cred = FacebookAuthProvider.GetCredential(fb_token.TokenString); FB.API("/me?fields=name,email,friends", HttpMethod.GET, FacebookSignupCallback_ParseUser); } else { Debug.LogError("Couldn't log in! If you cancelled the login manually ignore this message!"); } }
public Task <AuthCredential> GetCredentialAsync(Activity activity) { var tcs = new TaskCompletionSource <AuthCredential>(); var callback = new FacebookCallback <LoginResult>( onSuccess: x => tcs.SetResult(FacebookAuthProvider.GetCredential(x.AccessToken.Token)), onCancel: tcs.SetCanceled, onError: tcs.SetException); LoginManager.Instance.RegisterCallback(_callbackManager, callback); LoginManager.Instance.LogInWithReadPermissions(activity, new List <string> { "public_profile", "email" }); return(tcs.Task); }
public void SignInWithFacebook(string accessToken, Action <FirebaseUserResult> callback) { if ((Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) && !Application.isEditor) { Credential credential = FacebookAuthProvider.GetCredential(accessToken); targetBehaviour.StartCoroutine(ProcessFirebaseUserTaskRoutine(auth.SignInWithCredentialAsync(credential), callback)); } else { WWWForm form = new WWWForm(); form.AddField("access_token", accessToken); WWW www = new WWW(serviceUrl + "/signInWithFacebook", form); targetBehaviour.StartCoroutine(ProcessWebServiceUserRoutine(www, callback)); } }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. // Handle actions once the user is logged in BtnLogin.Completed += BtnLogin_Completed; BtnLogin.ReadPermissions = readPermissions.ToArray(); if (AccessToken.CurrentAccessToken != null) { var credential = FacebookAuthProvider.GetCredential(AccessToken.CurrentAccessToken.TokenString); Auth.DefaultInstance.SignIn(credential, SignInOnCompletion); } }
public async Task <string> LoginWithFaceBook(string token) { var cred = FacebookAuthProvider.GetCredential(token); var user = await FirebaseAuth.Instance.SignInWithCredentialAsync(cred); if (user != null) { return(user.User.Uid); } else { return(null); } }
public Task <FirebaseUser> SignInUserWithFacebook(string accessToken) { Credential credential = FacebookAuthProvider.GetCredential(accessToken); if (auth.CurrentUser != null) { Task <FirebaseUser> task = auth.CurrentUser.LinkWithCredentialAsync(credential); task.ContinueWith(t => { if (t.IsCanceled) { Debug.Log("LinkWithCredentialAsync was canceled."); } if (t.IsFaulted) { Debug.Log("LinkWithCredentialAsync encountered an error: " + t.Exception); } Firebase.Auth.FirebaseUser newUser = t.Result; Debug.LogFormat("Credentials successfully linked to Firebase user: {0} ({1})", newUser.DisplayName, newUser.UserId); }); return(task); } else { Task <FirebaseUser> task = auth.SignInWithCredentialAsync(credential); task.ContinueWith(t => { if (t.IsCanceled) { Debug.Log("SignInWithCredentialAsync was canceled."); return; } if (t.IsFaulted) { Debug.Log("SignInWithCredentialAsync encountered an error: " + task.Exception); return; } Firebase.Auth.FirebaseUser newUser = t.Result; Debug.LogFormat("User signed in successfully: {0} ({1})", newUser.DisplayName, newUser.UserId); }); return(task); } }
public void OnSuccess(Java.Lang.Object result) { loginResult = result as LoginResult; var credentials = FacebookAuthProvider.GetCredential(loginResult.AccessToken.Token); SessionManager.GetFirebaseAuth().SignInWithCredential(credentials) .AddOnCompleteListener(new OncompleteListener((t) => { if (!t.IsSuccessful) { return; } OnboardingActivity.ShowSuccess(); })); }
private void OnFacebookLogin(ILoginResult result) { if (FB.IsLoggedIn) { var token = AccessToken.CurrentAccessToken.TokenString; var credential = FacebookAuthProvider.GetCredential(token); _showLoading.Raise(); _auth.SignInWithCredentialAsync(credential).ContinueWith(OnFacebookAuthenticationFinished); } else { Utils.ShowMessage("Login Failed"); } }
public async Task <string> LoginFacebookAsync(string token) { try { AuthCredential credential = FacebookAuthProvider.GetCredential(token); await _auth.SignInWithCredentialAsync(credential); return(_auth.CurrentUser.DisplayName); } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine("---> Error LoginFacebookAsync " + ex.Message); } return(""); }
public void OnSuccess(Java.Lang.Object result) { LoginResult loginResult = result as LoginResult; if (!usingFirebase) { usingFirebase = true; var authCredential = FacebookAuthProvider.GetCredential(loginResult.AccessToken.Token); mAuth.CurrentUser.LinkWithCredential(authCredential) .AddOnCompleteListener(this); } else { usingFirebase = false; SetFacebookData(loginResult); } }
private void HandleLogin(LoginManagerLoginResult result, NSError error) { if (error == null) { if (AccessToken.CurrentAccessToken != null) { facebookToken = AccessToken.CurrentAccessToken.TokenString; var credential = FacebookAuthProvider.GetCredential(AccessToken.CurrentAccessToken.TokenString); Auth.DefaultInstance.SignInWithCredential(credential, SignInOnCompletion); } } else { facebookToken = string.Empty; SetVerificationStatus(VerificationStatus.Failed, error.LocalizedDescription); } }
private void OnLogIn(ILoginResult result) { if (FB.IsLoggedIn) { AccessToken tocken = AccessToken.CurrentAccessToken; Debug.Log("login successful"); //userIdText.text = tocken.UserId; Credential credential = FacebookAuthProvider.GetCredential(tocken.TokenString); accessToken(credential); SceneManager.LoadScene("AfterLogin"); Debug.Log("Change of Scence"); } else { Debug.Log("Login Failed"); } }
public override bool FinishedLaunching(UIApplication app, NSDictionary options) { global::Xamarin.Forms.Forms.Init(); // Init the things SocialAuth.Init(); FacebookAuthProvider.Init(SocialKeys.FACEBOOK_APP_ID); //Register custom handlers SocialAuthManager.Current.RegisterProvider <FacebookAuthProvider>(ProviderType.Facebook); SocialAuthManager.Current.RegisterProvider <GoogleAuthProvider>(ProviderType.Google); SocialAuthManager.Current.RegisterProvider <TwitterSafariServicesAuthProvider>(ProviderType.Twitter); SocialAuthManager.Current.RegisterProvider <OAuth2SafariServicesProvider>("fitbit"); LoadApplication(new App()); return(base.FinishedLaunching(app, options)); }
private void onLogIn(ILoginResult result) { if (FB.IsLoggedIn) { DialogLoggedIn.SetActive(true); DialogLoggedOut.SetActive(false); FB.API("/me?fields=first_name", HttpMethod.GET, DisplayUsername); AccessToken tocken = result.AccessToken;//received access token userID.text = tocken.UserId; Credential credential = FacebookAuthProvider.GetCredential(tocken.TokenString); accessToken(credential);//invoke auth method } else { Debug.Log("log failed"); } }