public WebAuthenticatorViewController(WebAuthenticator authenticator)
        {
            Dismiss            = () => this.DismissViewControllerAsync(true);
            Shared             = this;
            this.Authenticator = authenticator;
            MonitorAuthenticator();
            //
            // Create the UI
            //
            Title = authenticator.Title;

            if (authenticator.AllowsCancel)
            {
                NavigationItem.LeftBarButtonItem = new UIBarButtonItem(
                    UIBarButtonSystemItem.Cancel,
                    delegate {
                    Cancel();
                });
            }

            var activityStyle = UIActivityIndicatorViewStyle.White;

            if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
            {
                activityStyle = UIActivityIndicatorViewStyle.Gray;
            }

            activity = new UIActivityIndicatorView(activityStyle);
            var rightBarButtonItems = new List <UIBarButtonItem> {
                                #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                new UIBarButtonItem(UIBarButtonSystemItem.Refresh, (s, e) => BeginLoadingInitialUrl()),
                                #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                new UIBarButtonItem(activity),
            };

            if (RightButtonItem != null)
            {
                rightBarButtonItems.Insert(0, RightButtonItem);
            }

            NavigationItem.RightBarButtonItems = rightBarButtonItems.ToArray();

            webView = new WKWebView(View.Bounds, new WKWebViewConfiguration())
            {
                Frame = View.Bounds,
                NavigationDelegate = new WebViewDelegate(this),
                AutoresizingMask   = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight,
            };
            View.AddSubview(webView);
            View.BackgroundColor = UIColor.Black;

            //
            // Locate our initial URL
            //
#pragma warning disable 4014
            BeginLoadingInitialUrl();
#pragma warning restore 4014
        }
예제 #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
		}
예제 #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
 }
예제 #4
0
        protected OAuthApi(string identifier, string clientId, string clientSecret, HttpMessageHandler handler = null) : base(identifier, handler)
        {
            this.ClientId     = clientId;
            this.ClientSecret = clientSecret;
#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);
                });
            };
#endif
        }
		public WebAuthenticatorViewController (WebAuthenticator authenticator)
		{
			Shared = this;
			this.Authenticator = authenticator;
			MonitorAuthenticator ();
			//
			// Create the UI
			//
			Title = authenticator.Title;

			if (authenticator.AllowsCancel) {
				NavigationItem.LeftBarButtonItem = new UIBarButtonItem (
					UIBarButtonSystemItem.Cancel,
					delegate {
						Cancel ();
					});				
			}

			var activityStyle = UIActivityIndicatorViewStyle.White;
			if (UIDevice.CurrentDevice.CheckSystemVersion (7, 0))
				activityStyle = UIActivityIndicatorViewStyle.Gray;

			activity = new UIActivityIndicatorView (activityStyle);
			var rightBarButtonItems = new List<UIBarButtonItem> {
				#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
				new UIBarButtonItem (UIBarButtonSystemItem.Refresh, (s, e) => BeginLoadingInitialUrl ()),
				#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
				new UIBarButtonItem (activity),
			};
			if(RightButtonItem != null)
				rightBarButtonItems.Insert(0,RightButtonItem);

			NavigationItem.RightBarButtonItems = rightBarButtonItems.ToArray();

			webView = new UIWebView (View.Bounds) {
				Delegate = new WebViewDelegate (this),
				AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight,
			};
			View.AddSubview (webView);
			View.BackgroundColor = UIColor.Black;

			//
			// Locate our initial URL
			//
			#pragma warning disable 4014
			BeginLoadingInitialUrl ();
			#pragma warning restore 4014
		}
 public WebViewDelegate(WebAuthenticatorViewController controller)
 {
     this.Controller = controller;
 }
			public WebViewDelegate (WebAuthenticatorViewController controller)
			{
				this.Controller = controller;
			}