void BeginLoadingInitialUrl() { activity.StartAnimating(); authenticator.GetInitialUrlAsync().ContinueWith(t => { if (t.IsFaulted) { keepTryingAfterError = false; authenticator.OnError(t.Exception); activity.StopAnimating(); } else { // Delete cookies so we can work with multiple accounts if (this.authenticator.ClearCookiesBeforeLogin) { WebAuthenticator.ClearCookies(); } // // Begin displaying the page // LoadInitialUrl(t.Result); } }, TaskScheduler.FromCurrentSynchronizationContext()); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { layout = new FrameLayout(Activity); layout.SetBackgroundColor(Color.White); // // Build the UI // webView = new WebView(Activity) { Id = 42 }; webView.Settings.JavaScriptEnabled = true; webView.SetWebViewClient(new Client(this)); layout.AddView(webView); // // Restore the UI state or start over // if (savedInstanceState != null) { webView.RestoreState(savedInstanceState); } else { if (Activity.Intent.GetBooleanExtra("ClearCookies", false)) { WebAuthenticator.ClearCookies(); } } return(layout); }
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, }; 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(); } }
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.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; }