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
        }
Esempio n. 2
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


		}
Esempio n. 3
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
        }
Esempio n. 4
0
		public WebAuthenticator (Authenticator 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
		}
Esempio n. 5
0
			public WebViewDelegate (WebAuthenticator controller)
			{
				this.Controller = controller;
			}
Esempio n. 6
0
 public WebViewDelegate(WebAuthenticator controller)
 {
     this.Controller = controller;
 }