Beispiel #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            //
            // Load the state either from a configuration change or from the intent.
            //
            // *
            state = LastNonConfigurationInstance as State;
            if (state == null && Intent.HasExtra("StateKey"))
            {
                var stateKey = Intent.GetStringExtra("StateKey");
                state = StateRepo.Remove(stateKey);
            }

            if (state == null)
            {
                Finish();
                return;
            }

            //Title = state.Authenticator.Title;

            //
            // Watch for completion
            //
            state.Authenticator.Completed +=
                (s, e) =>
            {
                SetResult(e.IsAuthenticated ? Result.Ok : Result.Canceled);

                #region
                ///-------------------------------------------------------------------------------------------------
                /// Pull Request - manually added/fixed
                ///		Added IsAuthenticated check #88
                ///		https://github.com/xamarin/Xamarin.Auth/pull/88
                if (e.IsAuthenticated)
                {
                    if (state.Authenticator.GetAccountResult != null)
                    {
                        var accountResult = state.Authenticator.GetAccountResult(e.Account);

                        Bundle result = new Bundle();
                        result.PutString(global::Android.Accounts.AccountManager.KeyAccountType, accountResult.AccountType);
                        result.PutString(global::Android.Accounts.AccountManager.KeyAccountName, accountResult.Name);
                        result.PutString(global::Android.Accounts.AccountManager.KeyAuthtoken, accountResult.Token);
                        result.PutString(global::Android.Accounts.AccountManager.KeyAccountAuthenticatorResponse, e.Account.Serialize());

                        SetAccountAuthenticatorResult(result);
                    }
                }
                ///-------------------------------------------------------------------------------------------------
                #endregion

                CloseCustomTabs();
            };

            state.Authenticator.Error +=
                (s, e) =>
            {
                if (!state.Authenticator.ShowErrors)
                {
                    return;
                }

                if (e.Exception != null)
                {
                    this.ShowError("Authentication Error e.Exception = ", e.Exception);
                }
                else
                {
                    this.ShowError("Authentication Error e.Message = ", e.Message);
                }
                BeginLoadingInitialUrl();
            };

            // Build the UI
            CustomTabsConfiguration.Initialize(this);
            CustomTabsConfiguration.UICustomization();
            //.......................................................
            // Launching CustomTabs and url - minimal
            if
            (
                CustomTabsConfiguration.CustomTabActivityHelper != null
                &&
                CustomTabsConfiguration.CustomTabsIntent != null
                &&
                CustomTabsConfiguration.UriAndroidOS != null
            )
            {
                CustomTabsConfiguration.CustomTabsIntent
                .Intent.AddFlags
                (
                    global::Android.Content.ActivityFlags.NoHistory
                    |
                    global::Android.Content.ActivityFlags.SingleTop
                    |
                    global::Android.Content.ActivityFlags.NewTask
                );

                CustomTabsConfiguration
                .CustomTabActivityHelper
                .LaunchUrlWithCustomTabsOrFallback
                (
                    // Activity/Context
                    this,
                    // CustomTabIntent
                    CustomTabsConfiguration.CustomTabsIntent,
                    CustomTabsConfiguration.UriAndroidOS,
                    //  Fallback if CustomTabs do not exist
                    CustomTabsConfiguration.WebViewFallback
                );
            }
            else
            {
                // plain CustomTabs no customizations
                CustomTabsIntent i = new CustomTabsIntent.Builder().Build();
                i.Intent.AddFlags
                (
                    global::Android.Content.ActivityFlags.NoHistory
                    |
                    global::Android.Content.ActivityFlags.SingleTop
                    |
                    global::Android.Content.ActivityFlags.NewTask
                );
                i.LaunchUrl(this, CustomTabsConfiguration.UriAndroidOS);
            }
            //.......................................................
            // Launching CustomTabs and url - if WarmUp and Prefetching is used

            /*
             */
            //---------------------------------------------------------------------------------

            //
            // Restore the UI state or start over
            //

            /*
             * if (savedInstanceState != null)
             * {
             *  //webView.RestoreState(savedInstanceState);
             * }
             * else
             * {
             *  if (Intent.GetBooleanExtra("ClearCookies", true))
             *  {
             *      WebAuthenticator.ClearCookies();
             *  }
             *  BeginLoadingInitialUrl();
             * }
             */

            return;
        }
Beispiel #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            LaunchCunstomTabsWithUrl = LaunchCunstomTabsWithUrlDefault;

            //
            // Load the state either from a configuration change or from the intent.
            //
            // *
            state = LastNonConfigurationInstance as State;
            if (state == null && Intent.HasExtra("StateKey"))
            {
                var stateKey = Intent.GetStringExtra("StateKey");
                state = StateRepo.Remove(stateKey);
            }

            if (state == null)
            {
                Finish();
                return;
            }

            //Title = state.Authenticator.Title;

            //
            // Watch for completion
            //
            state.Authenticator.Completed +=
                (s, e) =>
            {
                SetResult(e.IsAuthenticated ? Result.Ok : Result.Canceled);

                #region
                ///-------------------------------------------------------------------------------------------------
                /// Pull Request - manually added/fixed
                ///		Added IsAuthenticated check #88
                ///		https://github.com/xamarin/Xamarin.Auth/pull/88
                if (e.IsAuthenticated)
                {
                    if (state.Authenticator.GetAccountResult != null)
                    {
                        var accountResult = state.Authenticator.GetAccountResult(e.Account);

                        Bundle result = new Bundle();
                        result.PutString(global::Android.Accounts.AccountManager.KeyAccountType, accountResult.AccountType);
                        result.PutString(global::Android.Accounts.AccountManager.KeyAccountName, accountResult.Name);
                        result.PutString(global::Android.Accounts.AccountManager.KeyAuthtoken, accountResult.Token);
                        result.PutString(global::Android.Accounts.AccountManager.KeyAccountAuthenticatorResponse, e.Account.Serialize());

                        SetAccountAuthenticatorResult(result);
                    }
                }
                ///-------------------------------------------------------------------------------------------------
                #endregion

                CloseCustomTabs();
            };

            state.Authenticator.Error +=
                (s, e) =>
            {
                if (!state.Authenticator.ShowErrors)
                {
                    return;
                }

                if (e.Exception != null)
                {
                    this.ShowError("Authentication Error e.Exception = ", e.Exception);
                }
                else
                {
                    this.ShowError("Authentication Error e.Message = ", e.Message);
                }
                BeginLoadingInitialUrl();
            };

            // Build the UI
            CustomTabsConfiguration.Initialize(this);
            CustomTabsConfiguration.UICustomization();

            LaunchCunstomTabsWithUrl();
            LaunchCunstomTabsWithUrlAzureMobileServiceClientTeamCode();

            return;
        }