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