Esempio n. 1
0
 bool IRequestHandler.GetAuthCredentials(IWebBrowser browserControl, IBrowser browser, IFrame frame, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback)
 {
     if (this.string_0.Equals(string.Empty))
     {
         callback.Cancel();
     }
     else
     {
         callback.Continue(this.string_0, this.string_1);
     }
     return(true);
 }
        //http://cefsharp.github.io/api/51.0.0/html/M_CefSharp_IRequestHandler_GetAuthCredentials.htm
        //Return true to continue the request and call CefAuthCallback::Continue() when the authentication information is available. Return false to cancel the request.
        public bool GetAuthCredentials(IWebBrowser browserControl, IBrowser browser, IFrame frame, bool isProxy, string host, int port,
                                       string realm, string scheme, IAuthCallback callback)
        {
            bool success = false;

            foreach (var preparedHttpAuth in PreparedHttpAuths)
            {
                if (preparedHttpAuth.ExpectedSchemaType == GetHttpAuth.SchemaTypes.Nope ||
                    (preparedHttpAuth.ExpectedSchemaType.ToString() == scheme))
                {
                    if (preparedHttpAuth.ExpectedHost.Value.Value == "" ||
                        (preparedHttpAuth.ExpectedHost.IsRegex.Value &&
                         Regex.IsMatch(host, preparedHttpAuth.ExpectedHost.Value.Value) ||
                         !preparedHttpAuth.ExpectedHost.IsRegex.Value &&
                         host == preparedHttpAuth.ExpectedHost.Value.Value))
                    {
                        if (preparedHttpAuth.ExpectedRealm.Value.Value == "" ||
                            (preparedHttpAuth.ExpectedRealm.IsRegex.Value &&
                             Regex.IsMatch(realm, preparedHttpAuth.ExpectedRealm.Value.Value) ||
                             !preparedHttpAuth.ExpectedRealm.IsRegex.Value &&
                             realm == preparedHttpAuth.ExpectedRealm.Value.Value))
                        {
                            if (preparedHttpAuth.ExpectedPort == null ||
                                (preparedHttpAuth.ExpectedPort == port))
                            {
                                if (callback.IsDisposed)
                                {
                                    break;
                                }
                                if (preparedHttpAuth.Cancel)
                                {
                                    callback.Cancel();
                                }
                                else
                                {
                                    callback.Continue(preparedHttpAuth.Username /*.ReadString()*/, preparedHttpAuth.Password /*.ReadString()*/);
                                }

                                HandledHttpAuths.Add(new HttpAuth()
                                {
                                    Host  = host,
                                    Port  = port,
                                    Realm = realm,
                                    SuccessfullyHandled = true,
                                    Scheme = scheme,
                                });
                                return(true);
                            }
                        }
                    }
                }
            }
            HandledHttpAuths.Add(new HttpAuth()
            {
                Host   = host,
                Port   = port,
                Realm  = realm,
                Scheme = scheme,
                SuccessfullyHandled = false,
            });
            return(false);
        }