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);
				}
				BeginLoadingInitialUrl ();
			};

			//
			// Build the UI
			//
			webView = new WebView (this) {
				Id = 42,
			};

			JavascriptInterceptor jsInterceptor = new JavascriptInterceptor (this);
			webView.AddJavascriptInterface (jsInterceptor, "jsInterceptor");

			webView.Settings.JavaScriptEnabled = true;
			webView.SetWebViewClient (new Client (this));
			webView.SetWebChromeClient (new ChromeClient ());

			SetContentView (webView);

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

				BeginLoadingInitialUrl ();
			}
		}
Esempio n. 2
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

                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,
            };
            JavascriptInterceptor jsInterceptor = new JavascriptInterceptor(this);
            webView.AddJavascriptInterface(jsInterceptor, "jsInterceptor");

            webView.Settings.UserAgentString = WebViewConfiguration.Android.UserAgent;
            Client web_view_client = new Client(this);  // UserAgent set in the class

            webView.Settings.JavaScriptEnabled = true;
            webView.SetWebViewClient(web_view_client);
            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);

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

            //
            // Build the UI
            //
            webView = new WebView(this)
            {
                Id = 42,
            };

            JavascriptInterceptor jsInterceptor = new JavascriptInterceptor(this);

            webView.AddJavascriptInterface(jsInterceptor, "jsInterceptor");

            webView.Settings.JavaScriptEnabled = true;
            webView.SetWebViewClient(new Client(this));
            webView.SetWebChromeClient(new ChromeClient());

            SetContentView(webView);

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

                BeginLoadingInitialUrl();
            }
        }