void IFacebookApiClient.SignIn(Action <string, bool, Error> completionHandler)
        {
            // get current VC
            UIViewController mainVC = UIApplication.SharedApplication.KeyWindow.RootViewController;
            var currentPresentedVC  = mainVC;

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

            // show Facebook login flow
            var manager = new Facebook.LoginKit.LoginManager();

            manager.LogInWithReadPermissions(new string[] { "public_profile" }, currentPresentedVC, delegate(Facebook.LoginKit.LoginManagerLoginResult result, Foundation.NSError error)
            {
                if (error != null)
                {
                    completionHandler(null, false, new Error(ErrorCode.Facebook_iOS_LoginError, error.LocalizedDescription));
                }
                else if (result.IsCancelled)
                {
                    completionHandler(null, true, null);
                }
                else
                {
                    completionHandler(result.Token.TokenString, false, null);
                }
            });
        }
Exemplo n.º 2
0
        public override void Share(string text, EventHandler <bool> done)
        {
            try
            {
                var login = new Facebook.LoginKit.LoginManager();
                login.LogInWithPublishPermissions(new[] { "publish_actions" }, async(result, error) =>
                {
                    if (error != null)
                    {
                        done(this, false);
                        return;
                    }

                    // Handle if the user cancelled the request
                    if (result.IsCancelled)
                    {
                        done(this, false);
                        return;
                    }

                    string publishToken = result.Token.TokenString;
                    await doAGraphReqest_Status(text, publishToken, done);
                });
                //Facebook.ShareKit.ShareOpenGraphAction share = Facebook.ShareKit.ShareOpenGraphAction.Action("like", )
            }
            catch (Exception)
            {
                done(this, false);
            }
        }
Exemplo n.º 3
0
        public static async void Login(WebAuthenticator authenticator)
        {
            var fbAuth = authenticator as FacebookAuthenticator;

            try
            {
                fb.CoreKit.Settings.AppID = fbAuth.ClientId;
                var loginManager = new fb.LoginKit.LoginManager();
                var window       = UIKit.UIApplication.SharedApplication.KeyWindow;
                var root         = window.RootViewController;
                if (root != null)
                {
                    var current = root;
                    while (current.PresentedViewController != null)
                    {
                        current = current.PresentedViewController;
                    }

                    var resp = await loginManager.LogInWithReadPermissionsAsync(authenticator.Scope.ToArray(), current);

                    if (resp.IsCancelled)
                    {
                        authenticator.OnCancelled();
                        return;
                    }
                    var date      = (DateTime)resp.Token.ExpirationDate;
                    var expiresIn = (long)(date - DateTime.Now).TotalSeconds;
                    fbAuth.OnRecievedAuthCode(resp.Token.TokenString, expiresIn);
                }
            }
            catch (Exception ex)
            {
                authenticator.OnError(ex.Message);
            }
        }
Exemplo n.º 4
0
        public async Task LoginUser(MobileServiceClient client)
        {
            msClient = client;

            bool useFBSDK = true;

            var viewController = UIApplication.SharedApplication.KeyWindow.RootViewController;

            if (useFBSDK)
            {
                var fbLoginMgr    = new Facebook.LoginKit.LoginManager();
                var fbLoginResult = await fbLoginMgr.LogInWithReadPermissionsAsync(
                    new string[] { "public_profile" }, viewController);

                string token = fbLoginResult.Token.TokenString;

                JObject tokenPayload = new JObject();
                tokenPayload.Add("access_token", token);

                var user = await client.LoginAsync(MobileServiceAuthenticationProvider.Facebook,
                                                   tokenPayload);

                CacheUserCredentials(client.MobileAppUri.OriginalString, user);
            }
            else
            {
                var user = await client.LoginAsync(viewController, MobileServiceAuthenticationProvider.Facebook,
                                                   Constants.LOGIN_RETURN_URI_SCHEME);

                CacheUserCredentials(client.MobileAppUri.OriginalString, user);
            }
        }
Exemplo n.º 5
0
		public static async void Login (WebAuthenticator authenticator)
		{
			var fbAuth = authenticator as FacebookAuthenticator;
			try
			{
				fb.CoreKit.Settings.AppID = fbAuth.ClientId;
				var loginManager = new fb.LoginKit.LoginManager();
				var window = UIKit.UIApplication.SharedApplication.KeyWindow;
				var root = window.RootViewController;
				if (root != null)
				{
					var current = root;
					while (current.PresentedViewController != null)
					{
						current = current.PresentedViewController;
					}

					var resp = await loginManager.LogInWithReadPermissionsAsync(authenticator.Scope.ToArray(),current);
					if (resp.IsCancelled)
					{
						authenticator.OnCancelled();
						return;
					}
					var date = (DateTime)resp.Token.ExpirationDate;
					var expiresIn = (long)(date - DateTime.Now).TotalSeconds;
					fbAuth.OnRecievedAuthCode(resp.Token.TokenString,expiresIn);
				}
			}
			catch (Exception ex)
			{
				authenticator.OnError(ex.Message);
			}
		}
 public void Login(string[] permission)
 {
     Facebook.LoginKit.LoginManager manager = new Facebook.LoginKit.LoginManager();
     manager.LogInWithReadPermissions(permission, UIApplication.SharedApplication.KeyWindow.RootViewController, (result, error) =>
     {
         if (error != null)
         {
             MessagingCenter.Send <string, FacebookLoginResult>("FacebookSDK", "OnLogin", new FacebookLoginResult
             {
                 isSuccess = false,
                 message   = error.LocalizedDescription
             });
         }
         else if (result.IsCancelled)
         {
             MessagingCenter.Send <string, FacebookLoginResult>("FacebookSDK", "OnLogin", new FacebookLoginResult
             {
                 isSuccess = false,
                 message   = "User cancel"
             });
         }
         else
         {
             var accessToken = result.Token;
             MessagingCenter.Send <string, FacebookLoginResult>("FacebookSDK", "OnLogin", new FacebookLoginResult
             {
                 isSuccess = true,
                 message   = "Success"
             });
         }
     });
 }
Exemplo n.º 7
0
        public static void  Logout()
        {
            var manager = new fb.LoginKit.LoginManager();

            manager.LogOut();
        }