Пример #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);
                Finish();
            };
            state.Authenticator.Error += (s, e) =>
            {
                if (!state.Authenticator.ShowErrors)
                {
                    return;
                }

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

            //
            // Build the UI
            //
            BuildUI();

            //
            // Restore the UI state or start over
            //
            if (savedInstanceState != null)
            {
            }
        }
Пример #2
0
        protected override void OnCreate(Bundle bundle)
        {
            RequestWindowFeature(WindowFeatures.NoTitle);

            base.OnCreate(bundle);

            _adapter    = new DeviceListAdapter(this);
            ListAdapter = _adapter;

            var stateKey         = Intent.GetStringExtra(Authorizer);
            var completionSource = StateRepo.Remove(stateKey);

            completionSource.SetResult(this);
        }
Пример #3
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(Android.Accounts.AccountManager.KeyAccountType, accountResult.AccountType);
                        result.PutString(Android.Accounts.AccountManager.KeyAccountName, accountResult.Name);
                        result.PutString(Android.Accounts.AccountManager.KeyAuthtoken, accountResult.Token);
                        result.PutString(Android.Accounts.AccountManager.KeyAccountAuthenticatorResponse, e.Account.Serialize());

                        SetAccountAuthenticatorResult(result);
                    }
                }
                ///-------------------------------------------------------------------------------------------------
                # endregion
Пример #4
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;
            //
            // Build the UI
            //

            SetContentView(Resource.Layout.login);
            username     = FindViewById <EditText> (Resource.Id.username);
            password     = FindViewById <EditText> (Resource.Id.password);
            login        = FindViewById <Button> (Resource.Id.loginButton);
            login.Click += async(s, e) => {
                var  oauth   = state.Authenticator as OAuthPasswordAuthenticator;
                bool success = false;
                if (oauth != null)
                {
                    success = await oauth.VerifyCredentials(username.Text, password.Text);
                }

                var basic = state.Authenticator as BasicAuthAuthenticator;
                if (basic != null)
                {
                    success = await basic.CheckCredentails(username.Text, password.Text);
                }
                if (success)
                {
                    Finish();
                }
            };
        }
Пример #5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            RequestWindowFeature(WindowFeatures.NoTitle);

            base.OnCreate(savedInstanceState);

            View = new WebView(this);

            View.Settings.JavaScriptEnabled   = true;
            View.Settings.BuiltInZoomControls = true;
            View.Settings.SetSupportZoom(true);
            View.ScrollBarStyle         = ScrollbarStyles.OutsideOverlay;
            View.ScrollbarFadingEnabled = false;

            SetContentView(View);

            var stateKey   = Intent.GetStringExtra(Authorizer);
            var authorizer = StateRepo.Remove(stateKey);

            authorizer.SetResult(this);
        }
        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

                Finish();
            };

            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
            //
            webView = new WebView(this)
            {
                Id = 42,
            };
            webView.Settings.JavaScriptEnabled = true;
            webView.SetWebViewClient(new Client(this));
            SetContentView(webView);
            //---------------------------------------------------------------------------------

            //
            // Restore the UI state or start over
            //
            if (savedInstanceState != null)
            {
                webView.RestoreState(savedInstanceState);
            }
            else
            {
                if (Intent.GetBooleanExtra("ClearCookies", true))
                {
                    WebAuthenticator.ClearCookies();
                }

                BeginLoadingInitialUrl();
            }

            return;
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            //--------------------------------------------------------------
            // Azure Mobile Services Team uses simplified code
            // this is for testing purposes of their launch only
            LaunchCunstomTabsWithUrl =
                //LaunchCunstomTabsWithUrlDefault
                LaunchCunstomTabsWithUrlAzureMobileServiceClientTeamCode
            ;
            //--------------------------------------------------------------

            //
            // 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();

            return;
        }
Пример #8
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);
                Finish();
            };
            state.Authenticator.Error += (s, e) => {
                if (e.Exception != null)
                {
                    this.ShowError("Authentication Error", e.Exception);
                }
                else
                {
                    this.ShowError("Authentication Error", e.Message);
                }
            };

            //
            // Build the UI
            //
            var relativeLayout = new RelativeLayout(this);

            relativeLayout.SetBackgroundColor(Color.White);

            var linearLayout = new LinearLayout(this)
            {
                Orientation      = Orientation.Vertical,
                LayoutParameters = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.FillParent,
                    LinearLayout.LayoutParams.MatchParent)
            };

            linearLayout.SetGravity(GravityFlags.Bottom);

            var progressBar = new ProgressBar(this)
            {
                LayoutParameters = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.FillParent,
                    dpToPx(40))
            };

            linearLayout.AddView(progressBar);

            var textView = new TextView(this)
            {
                LayoutParameters = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WrapContent,
                    LinearLayout.LayoutParams.WrapContent)
                {
                    Gravity = GravityFlags.CenterHorizontal
                },
                Text = "Logging in..."
            };

            ((ViewGroup.MarginLayoutParams)textView.LayoutParameters).BottomMargin = dpToPx(75);
            linearLayout.AddView(textView);

            relativeLayout.AddView(linearLayout);

            AddContentView(relativeLayout, new LinearLayout.LayoutParams(
                               Android.Views.ViewGroup.LayoutParams.FillParent,
                               Android.Views.ViewGroup.LayoutParams.MatchParent)
            {
                Gravity = GravityFlags.Bottom
            });

            var details             = WebAuthenticatorFragment.NewInstance(state.Authenticator);
            var fragmentTransaction = this.FragmentManager.BeginTransaction();

            fragmentTransaction.Add(Android.Resource.Id.Content, details);
            fragmentTransaction.Commit();

            details.BeginLoadingInitialUrl();
        }
Пример #9
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;
        }