Exemple #1
0
        static OAuthApi()
        {
            //Setup default ShowAuthenticator
#if __IOS__
            OAuthApi.ShowAuthenticator = WebAuthenticatorWindow.PresentAuthenticator;
#elif __ANDROID__
            OAuthApi.ShowAuthenticator = (authenticator) =>
            {
                try
                {
                    var context = Android.App.Application.Context;
                    var i       = new global::Android.Content.Intent(context, typeof(WebAuthenticatorActivity));
                    var state   = new WebAuthenticatorActivity.State
                    {
                        Authenticator = authenticator,
                    };
                    i.SetFlags(Android.Content.ActivityFlags.NewTask);
                    i.PutExtra("StateKey", WebAuthenticatorActivity.StateRepo.Add(state));
                    context.StartActivity(i);
                }
                catch (Exception ex)
                {
                    authenticator.OnError(ex.Message);
                }
            };
#elif __OSX__
            OAuthApi.ShowAuthenticator = (authenticator) =>
            {
                var invoker = new Foundation.NSObject();
                invoker.BeginInvokeOnMainThread(() =>
                {
                    try
                    {
                        var vc = new SimpleAuth.Mac.WebAuthenticatorWebView(authenticator);
                        SimpleAuth.Mac.WebAuthenticatorWebView.ShowWebivew(vc);
                    }
                    catch (Exception ex)
                    {
                        authenticator.OnError(ex.Message);
                    }
                });
            };
#elif WINDOWS_UWP
            OAuthApi.ShowAuthenticator = async(authenticator) =>
            {
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
                                                                                                            { try
                                                                                                              {
                                                                                                                  var vc = new SimpleAuth.UWP.WebAuthenticatorWebView(authenticator);
                                                                                                                  await vc.ShowAsync();
                                                                                                              }
                                                                                                              catch (Exception ex)
                                                                                                              {
                                                                                                                  authenticator.OnError(ex.Message);
                                                                                                              } });
            };
#endif
        }
Exemple #2
0
		static OAuthApi ()
		{
			//Setup default ShowAuthenticator
			#if __IOS__
			OAuthApi.ShowAuthenticator = (authenticator) => {
				var invoker = new Foundation.NSObject ();
				invoker.BeginInvokeOnMainThread (() => {
					var vc = new iOS.WebAuthenticatorViewController (authenticator);
					var window = UIKit.UIApplication.SharedApplication.KeyWindow;
					var root = window.RootViewController;
					if (root != null) {
						var current = root;
						while (current.PresentedViewController != null) {
							current = current.PresentedViewController;
						}
						current.PresentViewControllerAsync (new UIKit.UINavigationController (vc), true);
					}
				});
			};

			#elif __ANDROID__
			OAuthApi.ShowAuthenticator = (authenticator) =>
			{
				var context = Android.App.Application.Context;
				var i = new global::Android.Content.Intent(context, typeof(WebAuthenticatorActivity));
				var state = new WebAuthenticatorActivity.State
				{
					Authenticator = authenticator,
				};
				i.SetFlags(Android.Content.ActivityFlags.NewTask);
				i.PutExtra("StateKey", WebAuthenticatorActivity.StateRepo.Add(state));
				context.StartActivity(i);
			};
			#elif __OSX__
			OAuthApi.ShowAuthenticator = (authenticator) =>
			{
				var invoker = new Foundation.NSObject();
				invoker.BeginInvokeOnMainThread(() =>
				{
					var vc = new SimpleAuth.Mac.WebAuthenticatorWebView(authenticator);
					SimpleAuth.Mac.WebAuthenticatorWebView.ShowWebivew(vc);
				});
			};

            #elif WINDOWS_UWP
			OAuthApi.ShowAuthenticator = async (authenticator) =>
			{
				await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
				{
					var vc = new SimpleAuth.UWP.WebAuthenticatorWebView(authenticator);
					await vc.ShowAsync();
				});
			};

			#endif
		}
Exemple #3
0
 static OAuthApi()
 {
     //Setup default ShowAuthenticator
                 #if __IOS__
     OAuthApi.ShowAuthenticator = (authenticator) => {
         var invoker = new Foundation.NSObject();
         invoker.BeginInvokeOnMainThread(() => {
             var vc     = new iOS.WebAuthenticatorViewController(authenticator);
             var window = UIKit.UIApplication.SharedApplication.KeyWindow;
             var root   = window.RootViewController;
             if (root != null)
             {
                 var current = root;
                 while (current.PresentedViewController != null)
                 {
                     current = current.PresentedViewController;
                 }
                 current.PresentViewControllerAsync(new UIKit.UINavigationController(vc), true);
             }
         });
     };
                 #elif __ANDROID__
     OAuthApi.ShowAuthenticator = (authenticator) =>
     {
         var context = Android.App.Application.Context;
         var i       = new global::Android.Content.Intent(context, typeof(WebAuthenticatorActivity));
         var state   = new WebAuthenticatorActivity.State
         {
             Authenticator = authenticator,
         };
         i.SetFlags(Android.Content.ActivityFlags.NewTask);
         i.PutExtra("StateKey", WebAuthenticatorActivity.StateRepo.Add(state));
         context.StartActivity(i);
     };
                 #elif __OSX__
     OAuthApi.ShowAuthenticator = (authenticator) =>
     {
         var invoker = new Foundation.NSObject();
         invoker.BeginInvokeOnMainThread(() =>
         {
             var vc = new SimpleAuth.Mac.WebAuthenticatorWebView(authenticator);
             SimpleAuth.Mac.WebAuthenticatorWebView.ShowWebivew(vc);
         });
     };
     #elif WINDOWS_UWP
     OAuthApi.ShowAuthenticator = async(authenticator) =>
     {
         await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
         {
             var vc = new SimpleAuth.UWP.WebAuthenticatorWebView(authenticator);
             await vc.ShowAsync();
         });
     };
                 #endif
 }
Exemple #4
0
		protected OAuthApi(string identifier, string clientId, string clientSecret, HttpMessageHandler handler = null) : base(identifier, handler)
		{
			this.ClientId = clientId;
			this.ClientSecret = clientSecret;
#if __IOS__
			Api.ShowAuthenticator = (authenticator) =>
			{
				var invoker = new Foundation.NSObject();
				invoker.BeginInvokeOnMainThread(() =>
				{
					var vc = new iOS.WebAuthenticator(authenticator);
					var window = UIKit.UIApplication.SharedApplication.KeyWindow;
					var root = window.RootViewController;
					if (root != null)
					{
						var current = root;
						while (current.PresentedViewController != null)
						{
							current = current.PresentedViewController;
						}
						current.PresentViewControllerAsync(new UIKit.UINavigationController(vc), true);
					}
				});
			};

#elif __ANDROID__
			Api.ShowAuthenticator = (authenticator) =>
			{
				var context = Android.App.Application.Context;
				var i = new global::Android.Content.Intent(context, typeof(WebAuthenticatorActivity));
				var state = new WebAuthenticatorActivity.State
				{
					Authenticator = authenticator,
				};
				i.SetFlags(Android.Content.ActivityFlags.NewTask);
				i.PutExtra("StateKey", WebAuthenticatorActivity.StateRepo.Add(state));
				context.StartActivity(i);
			};
#elif __OSX__
			Api.ShowAuthenticator = (authenticator) =>
			{
				var invoker = new Foundation.NSObject();
				invoker.BeginInvokeOnMainThread(() =>
				{
					var vc = new SimpleAuth.Mac.WebAuthenticator(authenticator);
					SimpleAuth.Mac.WebAuthenticator.ShowWebivew(vc);
				});
			};
#endif


		}
Exemple #5
0
        static BasicAuthApi()
        {
            //Setup default ShowAuthenticator
#if __IOS__
            ShowAuthenticator = (auth) => {
                var invoker = new Foundation.NSObject();
                invoker.BeginInvokeOnMainThread(() => {
                    var controller = new BasicAuthController(auth);
                    controller.Show();
                });
            };
#endif
        }
Exemple #6
0
        protected OAuthApi(string identifier, string clientId, string clientSecret, HttpMessageHandler handler = null) : base(identifier, handler)
        {
            this.ClientId     = clientId;
            this.ClientSecret = clientSecret;
#if __IOS__
            Api.ShowAuthenticator = (authenticator) =>
            {
                var invoker = new Foundation.NSObject();
                invoker.BeginInvokeOnMainThread(() =>
                {
                    var vc     = new iOS.WebAuthenticator(authenticator);
                    var window = UIKit.UIApplication.SharedApplication.KeyWindow;
                    var root   = window.RootViewController;
                    if (root != null)
                    {
                        var current = root;
                        while (current.PresentedViewController != null)
                        {
                            current = current.PresentedViewController;
                        }
                        current.PresentViewControllerAsync(new UIKit.UINavigationController(vc), true);
                    }
                });
            };
#elif __ANDROID__
            Api.ShowAuthenticator = (authenticator) =>
            {
                var context = Android.App.Application.Context;
                var i       = new global::Android.Content.Intent(context, typeof(WebAuthenticatorActivity));
                var state   = new WebAuthenticatorActivity.State
                {
                    Authenticator = authenticator,
                };
                i.SetFlags(Android.Content.ActivityFlags.NewTask);
                i.PutExtra("StateKey", WebAuthenticatorActivity.StateRepo.Add(state));
                context.StartActivity(i);
            };
#elif __OSX__
            Api.ShowAuthenticator = (authenticator) =>
            {
                var invoker = new Foundation.NSObject();
                invoker.BeginInvokeOnMainThread(() =>
                {
                    var vc = new SimpleAuth.Mac.WebAuthenticator(authenticator);
                    SimpleAuth.Mac.WebAuthenticator.ShowWebivew(vc);
                });
            };
#endif
        }
Exemple #7
0
        public BasicAuthApi(string identifier, string loginUrl, HttpMessageHandler handler = null) : base(identifier, handler)
        {
            LoginUrl      = loginUrl;
            authenticator = new BasicAuthAuthenticator(Client, loginUrl);

#if __IOS__
            ShowAuthenticator = (auth) =>
            {
                var invoker = new Foundation.NSObject();
                invoker.BeginInvokeOnMainThread(() =>
                {
                    var controller = new BasicAuthController(auth);
                    controller.Show();
                });
            };
#endif
        }
        public static void ShowError(this Foundation.NSObject obj, Exception ex, string title = "")
        {
            if (ex == null)
            {
                return;
            }

            Error(ex);

            try {
                if (string.IsNullOrEmpty(title))
                {
                    title = "Error";
                }
                var message = GetUserErrorMessage(ex);
#if DEBUG
                message += "\n\n" + ((ex.GetType() == typeof(Exception)) ? "" : ex.GetType().Name);
                message += " " + ex.StackTrace;
#endif
                if (obj != null)
                {
                    obj.BeginInvokeOnMainThread(() => {
                        try {
                            var alert = new UIKit.UIAlertView(
                                title,
                                message,
                                (UIKit.IUIAlertViewDelegate)null,
                                "OK");
                            alert.Show();
                        } catch (Exception ex3) {
                            Error(ex3);
                        }
                    });
                }
            } catch (Exception ex2) {
                Error(ex2);
            }
        }
Exemple #9
0
 public static void Init(UIKit.UIApplication app, Foundation.NSDictionary launchOptions)
 {
     FacebookApi.IsUsingNative = true;
     fb.CoreKit.ApplicationDelegate.SharedInstance.FinishedLaunching(app, launchOptions);
     FacebookApi.ShowFacebookAuthenticator = (a) => invoker.BeginInvokeOnMainThread(() => Login(a));
 }