コード例 #1
0
        private void Authenticate(OAuth2ProviderType providerType)
        {
            oAuth2Authenticator            = OAuthAuthenticatorHelper.CreateOAuth2(providerType);
            oAuth2Authenticator.Completed += OAuth2Authenticator_Completed;
            oAuth2Authenticator.Error     += OAuth2Authenticator_Error;

            OAuth2ProviderType = providerType;
            var presenter = new OAuthLoginPresenter();

            // This is workaround for iOS because when open presenter on iOS,
            // view is not correctly shown. Then is necessary  modify view on
            // iOS LoginPageRenderer renderer. On Android, view is correctly shown.
            switch (Device.RuntimePlatform)
            {
            case Device.iOS:
                if (providerType == OAuth2ProviderType.FACEBOOK)
                {
                    OnPresenter?.Invoke(oAuth2Authenticator, EventArgs.Empty);
                }
                else
                {
                    presenter.Login(oAuth2Authenticator);
                }

                break;

            case Device.Android:
            case Device.UWP:
                presenter.Login(oAuth2Authenticator);
                break;
            }
        }
コード例 #2
0
        public void SignInAsync(string clientId,
                                Uri authUrl,
                                Uri callbackUrl,
                                Action <string> tokenCallback,
                                Action <string> errorCallback)
        {
            var presenter     = new OAuthLoginPresenter();
            var authenticator = new OAuth2Authenticator(clientId, "", authUrl, callbackUrl);

            authenticator.Completed += (sender, args) =>
            {
                if (args.Account != null && args.IsAuthenticated)
                {
                    tokenCallback?.Invoke(args.Account.Properties["access_token"]);
                }
                else
                {
                    errorCallback?.Invoke("Not authenticated");
                }
            };
            authenticator.Error += (sender, args) =>
            {
                errorCallback?.Invoke(args.Message);
            };
            presenter.Login(authenticator);
        }
コード例 #3
0
        protected override void OnStart()
        {
            var oAuth = new OAuth2AuthenticatorEx("xamarin-client", "offline_access hourregistrationapi",
                                                  new Uri("http://192.168.2.23:32772/connect/authorize"), new Uri("http://192.168.2.23:32772/grants"))
            {
                AccessTokenUrl = new Uri("http://192.168.2.23:32772/connect/token"),
                ShouldEncounterOnPageLoading = false
            };
            var account = AccountStore.Create().FindAccountsForService("AuthServer");

            if (account != null && account.Any())
            {
                AuthAccount = account.First();
                Client.DefaultRequestHeaders.Add("Authorization", $"Bearer {AuthAccount.Properties["access_token"]}");
            }
            else
            {
                try
                {
                    var presenter = new OAuthLoginPresenter();
                    presenter.Completed += Presenter_Completed;
                    presenter.Login(oAuth);
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }
            }
        }
コード例 #4
0
        private void OnTwitterLoginButtonClicked(object sender, EventArgs e)
        {
            _auth = new TwitterAuthenticator(Configuration.ClientId, Configuration.ClientSecret, this);
            var authenticator = _auth.GetAuthenticator();
            var presenter     = new OAuthLoginPresenter();

            presenter.Login(authenticator);
        }
コード例 #5
0
 public DefaultSecurityService(AccountStore accountStore, IConfigProvider configProvider, BitOAuth2Authenticator bitOAuth2Authenticator, OAuthLoginPresenter oAuthLoginPresenter, TokenClient tokenClient, IDateTimeProvider dateTimeProvider)
 {
     _configProvider        = configProvider;
     _accountStore          = accountStore;
     _oAuthLoginPresenter   = oAuthLoginPresenter;
     _tokenClient           = tokenClient;
     _dateTimeProvider      = dateTimeProvider;
     BitOAuth2Authenticator = _bitOAuth2Authenticator = bitOAuth2Authenticator;
 }
コード例 #6
0
        protected void Authenticate(string provider)
        {
            Authenticator.AcrValues = $"idp:{provider}";

            Helper.RunOnMainThreadIfRequired(() =>
            {
                OAuthLoginPresenter presenter = new OAuthLoginPresenter();
                presenter.Login(Authenticator);
            });
        }
コード例 #7
0
        private void Authenticate()
        {
            oAuth2Authenticator            = OAuthAuthenticatorHelper.CreateOAuth2();
            oAuth2Authenticator.Completed += OAuth2Authenticator_Completed;
            oAuth2Authenticator.Error     += OAuth2Authenticator_Error;
            var presenter = new OAuthLoginPresenter();

            AuthenticationState.Authenticator = oAuth2Authenticator;
            presenter.Login(oAuth2Authenticator);
        }
コード例 #8
0
        public Task <(string IdToken, string AccessToken)> LoginWithGoogle()
        {
            string clientId    = null;
            string redirectUri = null;

            switch (Device.RuntimePlatform)
            {
            case Device.iOS:
                clientId    = AppConstans.IosGoogleClientId;
                redirectUri = AppConstans.IosReversedGoogleClientId;
                break;

            case Device.Android:
                clientId    = AppConstans.AndroidGoogleClientId;
                redirectUri = AppConstans.AndroidReversedGoogleClientId;
                break;
            }
            redirectUri += ":/oauth2redirect";

            _authenticator = new OAuth2Authenticator(clientId,
                                                     null,
                                                     "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile",
                                                     new Uri("https://accounts.google.com/o/oauth2/auth"),
                                                     new Uri(redirectUri),
                                                     new Uri("https://www.googleapis.com/oauth2/v4/token"),
                                                     null,
                                                     true);

            var tcs = new TaskCompletionSource <(string IdToken, string AccessToken)>();

            _authenticator.Completed += (sender, e) =>
            {
                if (e.IsAuthenticated && e.Account != null && e.Account.Properties != null)
                {
                    var properties = e.Account.Properties;

                    tcs.TrySetResult((IdToken: properties["id_token"], AccessToken: properties["access_token"]));
                }
                else
                {
                    tcs.TrySetResult((null, null));
                }
            };

            _authenticator.Error += (sender, e) =>
            {
                tcs.TrySetException(e.Exception ?? new Exception(e.Message));
            };

            var presenter = new OAuthLoginPresenter();

            presenter.Login(_authenticator);

            return(tcs.Task);
        }
コード例 #9
0
        public void Builder <T>(T authenticator)
        {
            // after initialization (creation and event subscribing) exposing local object
            if (typeof(T) == typeof(OAuth2Authenticator))
            {
                AuthenticationState.Authenticator = authenticator as OAuth2Authenticator;
            }
            OAuthLoginPresenter presenter = null;

            presenter = new OAuthLoginPresenter();
            presenter.Login(authenticator as Authenticator);
        }
コード例 #10
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            LoadApplication(new App());

            Xamarin.Auth.Presenters.OAuthLoginPresenter.PlatformLogin = (authenticator) =>
            {
                var oAuthLogin = new OAuthLoginPresenter();
                oAuthLogin.Login(authenticator);
            };

            return(base.FinishedLaunching(app, options));
        }
コード例 #11
0
        public void LoginUser(bool force = false)
        {
            if (!force)
            {
                var account = AccountStore.Create().FindAccountsForService(ZibaobaoLibContext.Instance.AppName)
                              .FirstOrDefault();
                if (account != null)
                {
                    LoginUser(account).Forget();
                    return;
                }
            }

            string clientId    = null;
            string redirectUri = "";

            switch (Device.RuntimePlatform)
            {
            case Device.Android:
                clientId    = Constants.AndroidClientId;
                redirectUri = Constants.AndroidRedirectUrl;
                break;

            default:
                clientId    = Constants.iOSClientId;
                redirectUri = Constants.iOSRedirectUrl;
                break;
            }

            _authenticator = new OAuth2Authenticator(
                clientId,
                null,
                Constants.Scope,
                new Uri(Constants.AuthorizeUrl),
                new Uri(redirectUri),
                new Uri(Constants.AccessTokenUrl),
                null,
                true)
            {
                AllowCancel = true
            };
            _authenticator.Completed += OnAuthCompleted;
            _authenticator.Error     += OnAuthError;

            AuthenticationState.Authenticator = _authenticator;
            var presenter = new OAuthLoginPresenter();

            presenter.Login(_authenticator);
        }
コード例 #12
0
 /// <summary>
 /// Logins this instance.
 /// </summary>
 public void Login()
 {
     try
     {
         _authenticator            = new OAuth2Authenticator(ClientId, Scope, AuthorizationUri, RedirectUri);
         _authenticator.Completed += OnAuthenticationCompletedCallback;
         var presenter = new OAuthLoginPresenter();
         presenter.Login(_authenticator);
     }
     catch (Exception)
     {
         _authenticator.Completed -= OnAuthenticationCompletedCallback;
         NotifyOnCompletedEvent(new AuthenticatedUserResponseEventArgs(false));
     }
 }
コード例 #13
0
        void ImplicitButtonClicked(object sender, EventArgs e)
        {
            var authenticator = new OAuth2Authenticator
                                (
                ServerInfo.ClientId,
                Scope,
                ServerInfo.AuthorizationEndpoint,
                ServerInfo.RedirectionEndpoint
                                );

            authenticator.Completed += OnAuthCompleted;
            authenticator.Error     += OnAuthError;

            var presenter = new OAuthLoginPresenter();

            presenter.Login(authenticator);
        }
コード例 #14
0
        private void GoogleLogin()
        {
            oAuth2            = OAuthenticationService.CreateOAuth2(OAuth2ProviderType.GOOGLE);
            oAuth2.Completed += OAuth2_Completed;
            oAuth2.Error     += OAuth2_Error;

            //Change: 03 Aug, 2020
            //var view = oAuth2.GetUI();
            //PresentViewController(view, true, null);

            // This is workaround for iOS because when open presenter on iOS,
            // view is not correctly shown. Then is necessary  modify view on
            // iOS LoginPageRenderer renderer. On Android, view is correctly shown.
            var presenter = new OAuthLoginPresenter();

            presenter.Login(oAuth2);
        }
コード例 #15
0
        private void FacebookLogin()
        {
            var authenticator = new OAuth2Authenticator
                                (
                OAuthServerInfo.FacebookClientId,
                OAuthServerInfo.FacebookScope,
                OAuthServerInfo.FacebookAuthorizationEndpoint,
                OAuthServerInfo.FacebookRedirectionEndpoint
                                );

            authenticator.Completed += Authenticator_Completed;
            authenticator.Error     += Authenticator_Error;

            var presenter = new OAuthLoginPresenter();

            presenter.Login(authenticator);
        }
コード例 #16
0
        private void DiscordLogin_Clicked(object sender, EventArgs e)
        {
            canLogin = false;

            auth = new OAuth2Authenticator(
                clientId: "700549643045568522",
                scope: "identify email guilds",
                authorizeUrl: new Uri("https://discord.com/api/oauth2/authorize"),
                redirectUrl: new Uri("https://pukeko.yiays.com/app/account/callback/"),
                isUsingNativeUI: true
                );
            auth.Completed += auth_Completed;
            auth.Error     += auth_Failed;

            presenter = new OAuthLoginPresenter();
            presenter.Login(auth);
        }
コード例 #17
0
        async void GoogleLogin(object sender, EventArgs e)
        {
            var authenticator = new OAuth2Authenticator(
                Secrets.GoogleAuthKey,
                null,
                Secrets.GoogleScope,
                new Uri("https://accounts.google.com/o/oauth2/auth"),
                new Uri(Secrets.GoogleRedirectUrl),
                new Uri("https://www.googleapis.com/oauth2/v4/token"),
                null,
                true);

            authenticator.Completed += Authenticator_Completed;
            var presenter = new OAuthLoginPresenter();

            presenter.Login(authenticator);
            await Navigation.PushAsync(new Exercises.Exercise1());
        }
コード例 #18
0
        public MainPage()
        {
            InitializeComponent();

            var mainViewModel = new MainViewModel();

            BindingContext = mainViewModel;

            Button1.Clicked += (sender, args) =>
            {
                var presenter = new OAuthLoginPresenter();
                AuthenticationState.Authenticator            = GetOAuth2Authenticator();
                AuthenticationState.Authenticator.Completed += (object a, AuthenticatorCompletedEventArgs e) =>
                {
                    mainViewModel.IsAuthenticated = e.IsAuthenticated;

                    if (e.IsAuthenticated)
                    {
                        var accessToken = e.Account.Properties.SingleOrDefault(p => p.Key == "access_token").Value;
                        mainViewModel.AccessToken = accessToken;

                        var refreshToken = e.Account.Properties.SingleOrDefault(p => p.Key == "refresh_token").Value;
                        mainViewModel.RefreshToken = refreshToken;

                        var token = e.Account.Properties.SingleOrDefault(p => p.Key == "id_token").Value;
                        AuthenticationState.UserInformation = GetUserInformation(token);

                        mainViewModel.Name    = AuthenticationState.UserInformation.Name;
                        mainViewModel.Email   = AuthenticationState.UserInformation.Email;
                        mainViewModel.Picture = AuthenticationState.UserInformation.Picture;

                        //TODO En IOS excepción
                        //AccountStore.Create().SaveAsync(e.Account, ServiceId);
                    }
                };
                AuthenticationState.Authenticator.Error += (a, e) =>
                {
                };

                presenter.Login(AuthenticationState.Authenticator);
            };
        }
コード例 #19
0
        public static void KimlikDogrula()
        {
            string IstemciKimligi   = null;
            string GeriDonusLinkUrl = null;

            switch (Device.RuntimePlatform)
            {
            case Device.iOS:
                IstemciKimligi   = KimlikSaglayiciBilgileri.IstemciKimligiiOS;
                GeriDonusLinkUrl = KimlikSaglayiciBilgileri.GeriDonusLinkUrliOS;
                break;

            case Device.Android:
                IstemciKimligi   = KimlikSaglayiciBilgileri.IstemciKimligiAndroid;
                GeriDonusLinkUrl = KimlikSaglayiciBilgileri.GeriDonusLinkUrlAndroid;
                break;
            }

            oAuth2Authenticator = new OAuth2Authenticator(
                clientId: IstemciKimligi,
                clientSecret: KimlikSaglayiciBilgileri.ClientSecret,
                scope: KimlikSaglayiciBilgileri.Scope,
                authorizeUrl: new Uri(KimlikSaglayiciBilgileri.KimlikDogrulamaLinkUrl),
                redirectUrl: new Uri(GeriDonusLinkUrl),
                getUsernameAsync: null,
                isUsingNativeUI: KimlikSaglayiciBilgileri.PlatformOzguUIKullanimi,
                accessTokenUrl: new Uri(KimlikSaglayiciBilgileri.GecisJetonTokenLinkUrl))
            {
                AllowCancel             = true,
                ShowErrors              = false,
                ClearCookiesBeforeLogin = true
            };

            oAuth2Authenticator.Completed += OAuth2Authenticator_Tamamlandi;
            oAuth2Authenticator.Error     += OAuth2Authenticator_Hata;


            var kullaniciGirisGorunumu = new OAuthLoginPresenter();

            kullaniciGirisGorunumu.Login(oAuth2Authenticator);
        }
コード例 #20
0
        public HomeViewModel()
        {
            var auth = new OAuth2Authenticator(
                Constants.AndroidClientId,
                null,
                Constants.Scope,
                new Uri(Constants.AuthorizeUrl),
                new Uri(Constants.AndroidRedirectUrl),
                new Uri(Constants.AccessTokenUrl),
                null,
                true
                );

            auth.Completed += OnAuthCompleted;
            auth.Error     += OnAuthError;
            AuthenticationState.Authenticator = auth;

            var presenter = new OAuthLoginPresenter();

            presenter.Login(auth);
        }
コード例 #21
0
        private void Button_OnClicked(object sender, EventArgs e)
        {
            var auth = new OAuth2Authenticator(
                clientId: "******",
                clientSecret: "***********",
                scope: "wl.basic",
                authorizeUrl: new Uri("https://login.live.com/oauth20_authorize.srf"),
                redirectUrl: new Uri("https://xamarin.com"),
                accessTokenUrl: new Uri("https://login.live.com/oauth20_token.srf")
                );

            auth.ShowErrors              = false;
            auth.AllowCancel             = true;
            auth.ClearCookiesBeforeLogin = true;

            auth.Completed += AuthOnCompleted;
            auth.Error     += AuthOnError;

            var presenter = new OAuthLoginPresenter();

            presenter.Login(auth);
        }
コード例 #22
0
        protected override void OnStart()
        {
            var oAuth = new OAuth2AuthenticatorEx("xamarin-client", "offline_access values-api",
                                                  new Uri("http://ipaddress:5000/connect/authorize"), new Uri("http://ipaddress:5000/grants"))
            {
                AccessTokenUrl = new Uri("http://ipaddress:5000/connect/token"),
                ShouldEncounterOnPageLoading = false
            };
            var account = AccountStore.Create().FindAccountsForService("AuthServer");

            if (account != null && account.Any())
            {
                AuthAccount = account.First();
                Client.DefaultRequestHeaders.Add("Authorization", $"Bearer {AuthAccount.Properties["access_token"]}");
                MainPage = new ValuesPage();
            }
            else
            {
                var presenter = new OAuthLoginPresenter();
                presenter.Completed += Presenter_Completed;
                presenter.Login(oAuth);
            }
        }
コード例 #23
0
        /// <summary>
        ///     The navigate to login async.
        /// </summary>
        public void NavigateToLoginAsync()
        {
            string clientId    = null;
            string redirectUri = null;

            switch (Device.RuntimePlatform)
            {
            case Device.iOS:
                clientId    = Constant.IOSClientId;
                redirectUri = Constant.IOSRedirectUrl;
                break;

            case Device.Android:
                clientId    = Constant.AndroidClientId;
                redirectUri = Constant.AndroidRedirectUrl;
                break;
            }

            // TODO : add Native UI = true.
            var authenticator = new OAuth2AuthenticatorWithGrant(
                clientId,
                Constant.ClientIdSecret,
                Constant.Scope,
                new Uri(Constant.AuthorizeUrl),
                new Uri(Constant.AndroidRedirectUrl),
                new Uri(Constant.AccessTokenUrl),
                isUsingNativeUI: true);

            authenticator.Completed += this.OnAuthCompleted;
            authenticator.Error     += this.OnAuthError;

            AuthenticationState.Authenticator = authenticator;

            var presenter = new OAuthLoginPresenter();

            presenter.Login(authenticator);
        }
コード例 #24
0
        private async void Login_Clicked(object sender, EventArgs e)
        {
            var oAuth = new OAuth2AuthenticatorEx("xamarin-client", "offline_access values-api",
                                                  new Uri(EndPoints.IS4domain + "/connect/authorize"), new Uri(EndPoints.IS4domain + "/grants"))
            {
                AccessTokenUrl = new Uri(EndPoints.IS4domain + "/connect/token"),
                ShouldEncounterOnPageLoading = false
            };

            var account = await SecureStorageAccountStore.FindAccountsForServiceAsync("AuthServer");

            if (account != null && account.Any())
            {
                AuthAccount = account.First();
                Client.DefaultRequestHeaders.Add("Authorization", $"Bearer {AuthAccount.Properties["access_token"]}");
                await Navigation.PushAsync(new ValuesPage());
            }
            else
            {
                var presenter = new OAuthLoginPresenter();
                presenter.Completed += Presenter_Completed;
                presenter.Login(oAuth);
            }
        }
コード例 #25
0
        public MainViewModel()
        {
            var auth = new OAuth2Authenticator(
                this.clientId,
                string.Empty,
                scope,
                new Uri("https://accounts.google.com/o/oauth2/v2/auth"),
                new Uri(redirectUrl),
                new Uri("https://www.googleapis.com/oauth2/v4/token"),
                isUsingNativeUI: true);

            AuthenticatorHelper.OAuth2Authenticator = auth;
            auth.Completed += async(sender, e) =>
            {
                if (e.IsAuthenticated)
                {
                    var initializer = new GoogleAuthorizationCodeFlow.Initializer
                    {
                        ClientSecrets = new Google.Apis.Auth.OAuth2.ClientSecrets()
                        {
                            ClientId = clientId,
                        }
                    };
                    initializer.Scopes    = new[] { scope };
                    initializer.DataStore = new FileDataStore("Google.Apis.Auth");
                    var flow  = new GoogleAuthorizationCodeFlow(initializer);
                    var user  = "******";
                    var token = new TokenResponse()
                    {
                        AccessToken      = e.Account.Properties["access_token"],
                        ExpiresInSeconds = Convert.ToInt64(e.Account.Properties["expires_in"]),
                        RefreshToken     = e.Account.Properties["refresh_token"],
                        Scope            = e.Account.Properties["scope"],
                        TokenType        = e.Account.Properties["token_type"]
                    };
                    UserCredential userCredential = new UserCredential(flow, user, token);
                    var            driveService   = new DriveService(new BaseClientService.Initializer()
                    {
                        HttpClientInitializer = userCredential,
                        ApplicationName       = "XamarinDriveTest",
                    });


                    //test google drive
                    DriveServiceHelper helper = new DriveServiceHelper(driveService);
                    var id = await helper.CreateFile();

                    await helper.SaveFile(id, "test", "test save content");

                    var content = await helper.ReadFile(id);
                }
            };
            auth.Error += (sender, e) =>
            {
            };

            this.OnGoogleDrive = new Command(() =>
            {
                var presenter = new OAuthLoginPresenter();
                presenter.Login(auth);
            });
        }
コード例 #26
0
        public static void Login()
        {
            var presenter = new OAuthLoginPresenter();

            presenter.Login(Authenticator);
        }
コード例 #27
0
ファイル: BasePage.cs プロジェクト: MarioRguezz/ADMIC
        void FBLogin()
        {
            var authenticator = new OAuth2Authenticator(
                clientId: OAuthSettingsFacebook.ClientId,
                //clientSecret: OAuthSettingsFacebook.ClientSecret,   // null or ""
                authorizeUrl: new Uri(OAuthSettingsFacebook.AuthorizeUrl),
                //accessTokenUrl: new Uri(OAuthSettingsFacebook.AccessTokenUrl),
                redirectUrl: new Uri($"fb{OAuthSettingsFacebook.ClientId}://authorize"),
                scope: OAuthSettingsFacebook.Scope,
                isUsingNativeUI: true
                )
            {
                AllowCancel = true,
            };

            authenticator.Completed +=
                async(s, ea) =>
            {
                var sb = new StringBuilder();

                if (ea.Account != null && ea.Account.Properties != null)
                {
                    sb.Append("Token = ").AppendLine($"{ea.Account.Properties["access_token"]}");

                    var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me?locale=en_US&fields=id,first_name,last_name,email,picture"), null, ea.Account);
                    var res     = await request.GetResponseAsync();

                    string json = res.GetResponseText();
                    System.Diagnostics.Debug.WriteLine(json);
                    try
                    {
                        var user = Newtonsoft.Json.JsonConvert.DeserializeObject <FacebookUserModel>(json);
                        if (FBLoginResponse != null)
                        {
                            FBLoginResponse(user);
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                    }
                }
                else
                {
                    sb.Append("Not authenticated ").AppendLine($"Account.Properties does not exist");
                }

                //DisplayAlert
                //		(
                //			"Authentication Results",
                //			sb.ToString(),
                //			"OK"
                //		);

                return;
            };

            authenticator.Error +=
                (s, ea) =>
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("Error = ").AppendLine($"{ea.Message}");

                DisplayAlert
                (
                    "Authentication Error",
                    sb.ToString(),
                    "OK"
                );
                return;
            };

            AuthenticationState.Authenticator = authenticator;

            OAuthLoginPresenter presenter = null;

            presenter = new OAuthLoginPresenter();
            presenter.Login(authenticator);

            //Xamarin.Auth.XamarinForms.AuthenticatorPage ap;
            //ap = new Xamarin.Auth.XamarinForms.AuthenticatorPage()
            //{
            //	Authenticator = authenticator,
            //};

            //NavigationPage np = new NavigationPage(ap);
            //await Navigation.PushModalAsync(np);
        }
コード例 #28
0
ファイル: BasePage.cs プロジェクト: MarioRguezz/ADMIC
        async void GoogleLogin()
        {
            var authenticator = new OAuth2Authenticator(
                clientId: OAuthSettingsGoogle.ClientId,
                clientSecret: OAuthSettingsGoogle.ClientSecret,                   // null or ""
                authorizeUrl: new Uri(OAuthSettingsGoogle.AuthorizeUrl),
                accessTokenUrl: new Uri(OAuthSettingsGoogle.AccessTokenUrl),
                redirectUrl: new Uri(OAuthSettingsGoogle.RedirectUrl),
                scope: OAuthSettingsGoogle.Scope,
                getUsernameAsync: null,
                isUsingNativeUI: true
                )
            {
                AllowCancel = true,
            };

            authenticator.Completed +=
                async(s, ea) =>
            {
                var sb = new StringBuilder();

                if (ea.Account != null && ea.Account.Properties != null)
                {
                    sb.Append("Token = ").AppendLine($"{ea.Account.Properties["access_token"]}");

                    var userInfoUrl = "https://www.googleapis.com/oauth2/v2/userinfo";
                    var request     = new OAuth2Request("GET", new Uri(userInfoUrl), null, ea.Account);
                    var response    = await request.GetResponseAsync();

                    if (response != null)
                    {
                        string userJson = response.GetResponseText();
                        System.Diagnostics.Debug.WriteLine(userJson);
                        try
                        {
                            var user = Newtonsoft.Json.JsonConvert.DeserializeObject <GoogleUserModel>(userJson);
                            if (GoogleLoginResponse != null)
                            {
                                GoogleLoginResponse(user);
                            }
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Debug.WriteLine(ex.Message);
                        }
                    }
                }
                else
                {
                    sb.Append("Not authenticated ").AppendLine($"Account.Properties does not exist");
                }

                //DisplayAlert
                //		(
                //			"Authentication Results",
                //			sb.ToString(),
                //			"OK"
                //		);

                return;
            };

            authenticator.Error +=
                (s, ea) =>
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("Error = ").AppendLine($"{ea.Message}");

                DisplayAlert
                (
                    "Authentication Error",
                    sb.ToString(),
                    "OK"
                );
                return;
            };

            AuthenticationState.Authenticator = authenticator;

            OAuthLoginPresenter presenter = null;

            presenter = new OAuthLoginPresenter();
            presenter.Login(authenticator);

            //Xamarin.Auth.XamarinForms.AuthenticatorPage ap;
            //ap = new Xamarin.Auth.XamarinForms.AuthenticatorPage()
            //{
            //	Authenticator = authenticator,
            //};

            ////NavigationPage np = new NavigationPage(ap);
            //await Navigation.PushModalAsync(ap);
        }