示例#1
0
        void BeginLoadingInitialUrl()
        {
            authenticator.GetInitialUrlAsync().ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    keepTryingAfterError = false;
                    authenticator.OnError(t.Exception);
                }
                else
                {
                    // Delete cookies so we can work with multiple accounts
                    if (this.authenticator.ClearCookiesBeforeLogin)
                    {
                        WebAuthenticator.ClearCookies();
                    }

                    //
                    // Begin displaying the page
                    //
                    Uri uri = t.Result;
                    LoadInitialUrl(uri);
                }
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
示例#2
0
        private async Task Logout(bool internalAppLogoutOnly)
        {
            Account account = GetAccount();

            if (account != null)
            {
                await _accountStore.DeleteAsync(account, _configProvider.AppName);
            }

            if (internalAppLogoutOnly == false)
            {
                WebAuthenticator.ClearCookies(); // This won't work due security reasons >> We need to store id_token + calling InvokeLogout?id_token=...
            }
        }
示例#3
0
 public void Logout()
 {
     this.CurrentUser = null;
     WebAuthenticator.ClearCookies();
 }
示例#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;

            //
            // 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;
        }