示例#1
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);
            }
        }
示例#2
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);
			}
		}
示例#3
0
        public async Task ShowAsync()
        {
            var url = await authenticator.GetInitialUrl();

            // Thw Windows WebAuthenticatorBroker uses the IE browser which doesn't behave well
            // for at least the Instagram authenticator. So, here we're using a custom borker.
            // https://peterfoot.net/2019/03/13/webauthenticationbroker-and-github/
            if (authenticator is InstagramAuthenticator)
            {
                // result here is of type SimpleAuth.UWP.WebAuthenticationResult
                var result = await CustomWebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, url, authenticator.RedirectUrl);

                if (result.ResponseStatus == WebAuthenticationStatus.UserCancel)
                {
                    authenticator.OnCancelled();
                    return;
                }
                if (result.ResponseStatus == WebAuthenticationStatus.ErrorHttp)
                {
                    throw new Exception(result.ResponseErrorDetail.ToString());
                }
                authenticator.CheckUrl(new Uri(result.ResponseData), new System.Net.Cookie[0]);
            }
            else
            {
                // result here is of type Windows.Security.Authentication.Web.WebAuthenticationResult
                var result = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, url, authenticator.RedirectUrl);

                if (result.ResponseStatus == WebAuthenticationStatus.UserCancel)
                {
                    authenticator.OnCancelled();
                    return;
                }
                if (result.ResponseStatus == WebAuthenticationStatus.ErrorHttp)
                {
                    throw new Exception(result.ResponseErrorDetail.ToString());
                }
                authenticator.CheckUrl(new Uri(result.ResponseData), new System.Net.Cookie[0]);
            }
        }
示例#4
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 tcs = new TaskCompletionSource <LoginManagerLoginResult> ();
                    loginManager.LogIn(authenticator.Scope.ToArray(), current, (LoginManagerLoginResult result, NSError error) => {
                        if (error != null)
                        {
                            tcs.TrySetException(new Exception(error.LocalizedDescription));
                        }
                        else
                        {
                            tcs.SetResult(result);
                        }
                    });

                    var resp = await tcs.Task;
                    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);
            }
        }
示例#5
0
        public async Task ShowAsync()
        {
            var url = await authenticator.GetInitialUrl();

            var result = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, url, authenticator.RedirectUrl);

            if (result.ResponseStatus == WebAuthenticationStatus.UserCancel)
            {
                authenticator.OnCancelled();
                return;
            }
            if (result.ResponseStatus == WebAuthenticationStatus.ErrorHttp)
            {
                throw new Exception(result.ResponseErrorDetail.ToString());
            }
            authenticator.CheckUrl(new Uri(result.ResponseData), new System.Net.Cookie[0]);
        }
示例#6
0
        static async void Login(WebAuthenticator authenticator)
        {
            currentHandler?.Cancel();
            try {
                currentHandler = new NativeHandler();

                var gAuth = authenticator as GoogleAuthenticator;
                var user  = await currentHandler.Authenticate(gAuth);

                gAuth.ServerToken  = user.ServerAuthCode;
                gAuth.IdToken      = user.Authentication.IdToken;
                gAuth.RefreshToken = user.Authentication.RefreshToken;
                gAuth.OnRecievedAuthCode(user.Authentication.AccessToken);
            } catch (TaskCanceledException) {
                authenticator?.OnCancelled();
            } catch (Exception ex) {
                Console.WriteLine(ex);
                authenticator.OnError(ex.Message);
            }
        }
示例#7
0
 void Cancel()
 {
     authenticator.OnCancelled();
 }