Ejemplo n.º 1
0
        /// <summary>
        /// Called on the IO thread when the browser needs credentials from the user.
        /// </summary>
        /// <param name="isProxy">Indicates whether the <paramref name="host"/> is a proxy server.</param>
        /// <param name="host">The hostname.</param>
        /// <param name="port">The port number.</param>
        /// <param name="realm">
        /// The realm is used to describe the protected area or to indicate the scope of protection.
        /// </param>
        /// <param name="scheme">The authentication scheme.</param>
        /// <param name="callback">
        /// The callback used to asynchronous continuation/cancellation of authentication requests.
        /// </param>
        /// <returns>
        /// Return true to continue the request and call <see cref="CefAuthCallback.Continue"/>
        /// when the authentication information is available. If the request has an associated
        /// browser/frame then returning false will result in a call to GetAuthCredentials on the
        /// <see cref="CefReadHandler"/> associated with that browser, if any. Otherwise,
        /// returning false will cancel the request immediately.
        /// </returns>
        /// <remarks>
        /// This function will only be called for requests initiated from the browser process.
        /// </remarks>
        protected internal override bool GetAuthCredentials(bool isProxy, string host, int port, string realm, string scheme, CefAuthCallback callback)
        {
            if (_authentication is null)
            {
                return(false);
            }

            RequestOperation op = _activeOperation;

            if (op is null)
            {
                return(false);
            }

            Task <NetworkCredential> getCredentialTask = _authentication.GetCredentialAsync(isProxy, host, port, realm, scheme, op.cancellationToken);

            if (getCredentialTask is null)
            {
                return(false);
            }

            getCredentialTask.ContinueWith(t =>
            {
                NetworkCredential credential = (t.Status == TaskStatus.RanToCompletion) ? t.Result : null;
                if (credential is null)
                {
                    callback.Cancel();
                }
                else
                {
                    callback.Continue(credential.UserName, credential.Password);
                }
            }, op.cancellationToken, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.DenyChildAttach, TaskScheduler.Default);
            return(true);
        }
        bool ICefWebBrowserInternal.OnGetAuthCredentials(CefBrowser browser, CefFrame frame, bool isProxy, string host, int port, string realm, string scheme, CefAuthCallback callback)
        {
            bool retVal = false;

            this.DispatchIfRequired(() =>
            {
                try
                {
                    LoginAuthenticationForm authForm = new LoginAuthenticationForm(host);
                    WindowInteropHelper wih          = new WindowInteropHelper(authForm);
                    wih.Owner  = Handle;
                    var result = authForm.ShowDialog();
                    if (result != null && result.HasValue && result.Value)
                    {
                        callback.Continue(authForm.UserName, authForm.Password);
                        retVal = true;
                    }
                    else
                    {
                        callback.Cancel();
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error("Error in GetAuthCredentials.", ex);
                }
            });
            return(retVal);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Called on the IO thread when the browser needs credentials from the user.
        /// </summary>
        /// <param name="isProxy">Indicates whether the <paramref name="host"/> is a proxy server.</param>
        /// <param name="host">The hostname.</param>
        /// <param name="port">The port number.</param>
        /// <param name="realm">
        /// The realm is used to describe the protected area or to indicate the scope of protection.
        /// </param>
        /// <param name="scheme">The authentication scheme.</param>
        /// <param name="callback">
        /// The callback used to asynchronous continuation/cancellation of authentication requests.
        /// </param>
        /// <returns>
        /// Return true to continue the request and call <see cref="CefAuthCallback.Continue"/>
        /// when the authentication information is available. If the request has an associated
        /// browser/frame then returning false will result in a call to GetAuthCredentials on the
        /// <see cref="CefReadHandler"/> associated with that browser, if any. Otherwise,
        /// returning false will cancel the request immediately.
        /// </returns>
        /// <remarks>
        /// This function will only be called for requests initiated from the browser process.
        /// </remarks>
        protected internal override bool GetAuthCredentials(bool isProxy, string host, int port, string realm, string scheme, CefAuthCallback callback)
        {
            if (_authentication is null)
            {
                return(false);
            }

            RequestOperation op = _activeOperation;

            if (op is null)
            {
                return(false);
            }

            Task <NetworkCredential> getCredentialTask = _authentication.GetCredentialAsync(isProxy, host, port, realm, scheme, op.cancellationToken);

            if (getCredentialTask is null)
            {
                return(false);
            }

            getCredentialTask.ContinueWith(t =>
            {
                NetworkCredential credential = (t.Status == TaskStatus.RanToCompletion) ? t.Result : null;
                if (credential is null)
                {
                    callback.Cancel();
                }
                callback.Continue(credential.UserName, credential.Password);
            }).ConfigureAwait(false);
            return(true);
        }
Ejemplo n.º 4
0
 public void Cancel() => _callback?.Cancel();