示例#1
0
        protected override Boolean GetAuthCredentials(CefBrowser browser, CefFrame frame, Boolean isProxy,
                                                      String host, Int32 port, String realm, String scheme, CefAuthCallback callback)
        {
            if (this.Client.HandleUnauthorized != null)
            {
                String username, password;

                if (this.Client.HandleUnauthorized(host, port, realm, scheme, out username, out password))
                {
                    callback.Continue(username, password);
                    return(true);
                }
            }

            Log.Trace("RequestHandler.GetAuthCredentials( browser: {0}, frame: {1}, isProxy: {2}, host: {3}, port: {4}, realm: {5}, scheme: {6} )",
                      browser.Identifier,
                      frame.Identifier,
                      isProxy,
                      host,
                      port,
                      realm,
                      scheme);

            return(false);
            //return base.GetAuthCredentials( browser, frame, isProxy, host, port, realm, scheme, callback );
        }
        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);
        }
示例#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();
                }
                else
                {
                    callback.Continue(credential.UserName, credential.Password);
                }
            }, op.cancellationToken, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.DenyChildAttach, TaskScheduler.Default);
            return(true);
        }
示例#4
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);
        }
        protected override bool GetAuthCredentials(CefBrowser browser, string originUrl, bool isProxy, string host, int port, string realm,
                                                   string scheme, CefAuthCallback callback)
        {
            if (isProxy)
            {
                callback.Continue(proxySettings.Username, proxySettings.Password);
            }

            return(base.GetAuthCredentials(browser, originUrl, isProxy, host, port, realm, scheme, callback));
        }
 protected override bool GetAuthCredentials(CefBrowser browser, string originUrl, bool isProxy, string host, int port, string realm, string scheme, CefAuthCallback callback)
 {
     using (callback) {
         if (OwnerWebView.ProxyAuthentication != null)
         {
             callback.Continue(OwnerWebView.ProxyAuthentication.UserName, OwnerWebView.ProxyAuthentication.Password);
         }
         return(true);
     }
 }
示例#7
0
 public void Continue(string userName, string password) => _callback?.Continue(userName, password);