public static void Handler(LoginManagerLoginResult result, NSError error, ISocialAuth interactor, LoginManager loginManager)
        {
            _loginManager = loginManager;
            _interactor   = interactor;

            if (error != null)
            {
                _interactor.OnError(error.LocalizedDescription, ESocialType.Facebook);
            }
            else if (result.IsCancelled)
            {
                _interactor.OnCancel(ESocialType.Facebook);

                _loginManager.LogOut();
                var r = new Facebook.CoreKit.GraphRequest("me/permissions", null, "DELETE");
                r.Start((connection, result1, error1) => {
                    Console.WriteLine("GraphRequest");
                });
            }
            else
            {
                var token = result.Token.TokenString;
                _interactor.OnSuccess(token, ESocialType.Facebook);
            }
        }
Beispiel #2
0
        public async Task <AccountResponse> LoginWithFacebook()
        {
            TaskCompletionSource <string> tokenTask = new TaskCompletionSource <string>();
            var topVC = GetViewController();

            new Facebook.LoginKit.LoginManager().LogInWithReadPermissions(
                new string[] { "public_profile email" },
                topVC,
                (Facebook.LoginKit.LoginManagerLoginResult result, NSError error) =>
            {
                if (error != null)
                {
                    //NSLog(@"Process error");
                }
                else if (result.IsCancelled)
                {
                    tokenTask.SetCanceled();
                    //NSLog(@"Cancelled");
                }
                else
                {
                    var token = Facebook.CoreKit.AccessToken.CurrentAccessToken;
                    tokenTask.SetResult(token.TokenString);
                }
            });

            string accessToken = await tokenTask.Task;

            TaskCompletionSource <string> getEmailTask = new TaskCompletionSource <string>();
            // gets the email & name for this user
            var graphRequest = new Facebook.CoreKit.GraphRequest("me", NSDictionary.FromObjectAndKey(new NSString("id,email"), new NSString("fields")));

            graphRequest.Start((connection, result, error) =>
            {
                if (error != null)
                {
                    //result.
                }
                var email = (NSString)result.ValueForKey(new NSString("email"));

                getEmailTask.SetResult(email);
            });

            string emailAddress = await getEmailTask.Task;

            // Get access token for the signed-in user and exchange it for a Firebase credential
            var credential     = Firebase.Auth.FacebookAuthProvider.GetCredential(accessToken);
            var firebaseResult = await LoginToFirebase(credential);

            if (firebaseResult.Success)
            {
                Settings.Current.AuthType = "facebook";
                firebaseResult.User.Email = emailAddress;
            }

            return(firebaseResult);
        }
Beispiel #3
0
        public void Login(Action <FacebookUser, string> onLoginComplete)
        {
            _onLoginComplete = onLoginComplete;
            var window = UIApplication.SharedApplication.KeyWindow;
            var vc     = window.RootViewController;

            while (vc.PresentedViewController != null)
            {
                vc = vc.PresentedViewController;
            }

            var          tcs     = new TaskCompletionSource <FacebookUser>();
            LoginManager manager = new LoginManager();

            manager.LogOut();
            manager.LoginBehavior = LoginBehavior.SystemAccount;
            manager.LogInWithReadPermissions(new string[] { "public_profile", "email" }, vc, (result, error) =>
            {
                if (error != null || result == null || result.IsCancelled)
                {
                    if (error != null)
                    {
                        _onLoginComplete?.Invoke(null, error.LocalizedDescription);
                    }
                    if (result.IsCancelled)
                    {
                        _onLoginComplete?.Invoke(null, "User Cancelled!");
                    }

                    tcs.TrySetResult(null);
                }
                else
                {
                    var request = new Facebook.CoreKit.GraphRequest("me", new NSDictionary("fields", "id, first_name, email, last_name, picture.width(1000).height(1000)"));
                    request.Start((connection, result1, error1) =>
                    {
                        if (error1 != null || result1 == null)
                        {
                            Debug.WriteLine(error1.LocalizedDescription);
                            tcs.TrySetResult(null);
                        }
                        else
                        {
                            var id         = string.Empty;
                            var first_name = string.Empty;
                            var email      = string.Empty;
                            var last_name  = string.Empty;
                            var url        = string.Empty;

                            try
                            {
                                id = result1.ValueForKey(new NSString("id"))?.ToString();
                            }
                            catch (Exception e)
                            {
                                Debug.WriteLine(e.Message);
                            }

                            try
                            {
                                first_name = result1.ValueForKey(new NSString("first_name"))?.ToString();
                            }
                            catch (Exception e)
                            {
                                Debug.WriteLine(e.Message);
                            }

                            try
                            {
                                email = result1.ValueForKey(new NSString("email"))?.ToString();
                            }
                            catch (Exception e)
                            {
                                Debug.WriteLine(e.Message);
                            }

                            try
                            {
                                last_name = result1.ValueForKey(new NSString("last_name"))?.ToString();
                            }
                            catch (Exception e)
                            {
                                Debug.WriteLine(e.Message);
                            }

                            try
                            {
                                url = ((result1.ValueForKey(new NSString("picture")) as NSDictionary).ValueForKey(new NSString("data")) as NSDictionary).ValueForKey(new NSString("url")).ToString();
                            }
                            catch (Exception e)
                            {
                                Debug.WriteLine(e.Message);
                            }
                            if (tcs != null)
                            {
                                tcs.TrySetResult(new FacebookUser(id, result.Token.TokenString, first_name, last_name, email, url));
                                _onLoginComplete?.Invoke(new FacebookUser(id, result.Token.TokenString, first_name, last_name, email, url), string.Empty);
                            }
                        }
                    });
                }
            });
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            this.loginView = new LoginButton(new CGRect(10, 10, 300, 40))
            {
                ReadPermissions = new[] { "email" }
            };
            this.loginView.Completed += (sender, e) =>
            {
                if (e.Error == null)
                {
                    var request = new Facebook.CoreKit.GraphRequest("me", null);
                    request.Start((con, result, error) =>
                    {
                        if (error == null)
                        {
                            this.EmailInputField.Text = ((NSDictionary)result).ValueForKeyPath(new NSString("email")).ToString();
                        }
                    });
                }
            };

            this.Add(this.loginView);

            this.BuyButton.TouchUpInside += async(sender, e) =>
            {
                LeanplumBindings.Leanplum.SetUserId(this.UserEmail);
                LeanplumBindings.Leanplum.Track("Purchase intent", 10);
                Insights.Identify(this.UserEmail, "a", "b");
                TaperecorderBinding.TapeRecorder.SetUserID(this.UserEmail);

                try
                {
                    this.BuyButton.Enabled = false;

                    var endpoint = string.Format("{0}/payment/token", Constants.ServerApiAddress);
                    var token    = await HttpRequestHelper.Post <string>(endpoint, this.UserEmail);

                    var braintree = Braintree.Create(token);
                    var btVC      = braintree.CreateDropInViewController(this.braintreeDelegate);
                    btVC.FetchPaymentMethods();

                    btVC.SummaryTitle       = "New subscription";
                    btVC.SummaryDescription = "New subscription for June for everything!";
                    btVC.DisplayAmount      = "$10.00";
                    btVC.CallToActionText   = "Get it now!";

                    var nav = new UINavigationController(btVC);

                    btVC.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Cancel, (_, __) =>
                    {
                        this.PaymentFailure();
                    });
                    this.PresentViewController(nav, true, null);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    this.BuyButton.Enabled = true;
                }
            };
        }
Beispiel #5
0
        private bool LoadChallengeDetail()
        {
            UIViewController controller = null;

            if (Challenge.TypeCode == "SHARE")
            {
                controller = LoadChallengeDetail("ShareViewController");
                ShareViewController shareViewController = controller as ShareViewController;
                shareViewController.SubmitButton = SubmitButton;
            }
            else if (Challenge.TypeCode == "INVITE")
            {
                SL.Manager.RefreshShareTemplate(Challenge.ShareTemplateURL, SendInviteMessage);
            }
            else if (Challenge.TypeCode == "POSTERING")//else if (Challenge.TypeCode == "COLLATERAL TRACKING" && Challenge.TypeCodeDisplayName == "Postering")
            {
                controller = LoadChallengeDetail("PosteringViewController");
            }
            else if (Challenge.TypeCode == "COLLATERAL TRACKING")
            {
                //controller = LoadChallengeDetail("CollateralViewController");
                controller = LoadChallengeDetail("PosteringViewController");//display always Postering
            }
            else if (Challenge.TypeCode == "FB ENGAGEMENT")
            {//controller = LoadChallengeDetail("FacebookEngagementViewController");
                var permissions  = new string[] { "user_posts" };
                var loginManager = new LoginManager();

                if (Facebook.CoreKit.AccessToken.CurrentAccessToken != null)
                {
                    var graphRequest = new Facebook.CoreKit.GraphRequest("me/permissions", null);
                    graphRequest.Start(new Facebook.CoreKit.GraphRequestHandler(
                                           (Facebook.CoreKit.GraphRequestConnection connection, NSObject result, NSError error) =>
                    {
                        bool hasPermission = false;
                        if (error == null)
                        {
                            NSArray permissions1 = (NSArray)result.ValueForKey(new NSString("data"));
                            foreach (NSDictionary dict in NSArray.FromArray <NSObject>(permissions1))
                            {
                                if (dict.ValueForKey(new NSString("permission")).Description == permissions[0])
                                {
                                    if (dict.ValueForKey(new NSString("status")).Description == "granted")
                                    {
                                        hasPermission = true;
                                    }
                                }
                            }
                        }
                        if (hasPermission)
                        {
                            if (Challenge?.IsReshareReq ?? false)
                            {
                                CheckFacebookSharingEnabled(permissions);
                            }
                            else
                            {
                                SubmitEngagement();
                            }
                        }
                    }
                                           ));
                }
                else
                {
                    loginManager.LogInWithReadPermissions(permissions, this,
                                                          (LoginManagerLoginResult result, NSError error) =>
                    {
                        LogHelper.LogUserMessage("FB_USER_POST", "asking for permissions");
                        if (result?.GrantedPermissions != null && result.GrantedPermissions.Contains(permissions[0]))
                        {
                            LogHelper.LogUserMessage("FB_USER_POST", "permission failed");
                            if (Challenge?.IsReshareReq ?? false)
                            {
                                CheckFacebookSharingEnabled(permissions);
                            }
                            else
                            {
                                SubmitEngagement();
                            }
                        }
                        else
                        {
                            LogHelper.LogUserMessage("FB_USER_POST", "permission failed");
                            new UIAlertView(null, "There was a problem getting permission for " + permissions[0], this, "Ok").Show();
                        }
                    });
                }
            }

            if (controller != null)
            {
                NavigationController.PushViewController(controller, true);
            }
            return(controller != null);
        }