Issue #19 open

PromptService not working

Barun Debnath
created an issue

Hi, I was testing the GeckoFxTest which was given with main geckofx source file. But when I was testing the customPrompt for private proxies, unfortunately its not working. I uncommented these lines :

GeckoWebBrowser.UseCustomPrompt();
GeckoPreferences.User["browser.xul.error_pages.enabled"] = false;

and for private proxy I used these codes :

Gecko.GeckoPreferences.User["network.proxy.http"] = host; Gecko.GeckoPreferences.User["network.proxy.http_port"] = port; Gecko.GeckoPreferences.User["network.proxy.ssl"] = host; Gecko.GeckoPreferences.User["network.proxy.ssl_port"] = port; Gecko.GeckoPreferences.User["network.proxy.type"] = 1;

Without "GeckoWebBrowser.UseCustomPrompt()" it is prompting for username and password, but after doing uncomment it - its keep showing "Access to requested resource disallowed by administrator or you need valid username/password to use this resource". Am I missing anything ?

Thanks Barun

Comments (18)

  1. hindlemail

    Are custom prompts working in general for you? try something like javascript:alert("hi")

    if they are then:

    try putting breakpoints in all Gecko.PromptService methods to see if they are being called.

  2. Barun Debnath reporter

    Yes javascript's alert is working. Also I checked it putting break point into PrompService's methods. And its not entering into any of these methods at all. Also I checked the PromptFactory.GetPrompt(..) method. It seems its returing zero when required.

  3. hindlemail

    Are you saying that PromptFactory.GetPrompt(nsIDOMWindow, Guid) is returning IntPtr.Zero? If so that doesn't look right. but that would be odd if javascript:alert('hi') display a in winform message box.

  4. Barun Debnath reporter

    Yes it looks like nsIPrompt's all methods are working perfectly. But nsIPromptService2's methods are not responding. And PromptFactory.GetPrompt() returning IntPtr.Zero when Xulrunner asking for nsIPromptService2.PromptAuth(..) reference.

  5. Barun Debnath reporter

    I implemented the nsIAuthPrompt2. Now its calling the AsyncPromptAuth(..) method. But nothing is happening after that. Browser just keep waiting for something forever. Btw its sending nsISupports aContext as null, this may be the problem. Please see my code and let me know if anything is wrong.

    public nsICancelable AsyncPromptAuth(nsIChannel aChannel, nsIAuthPromptCallback aCallback, nsISupports aContext, uint level, nsIAuthInformation authInfo)
    {
        string userName = nsString.Get(authInfo.GetUsernameAttribute);
        string password = nsString.Get(authInfo.GetPasswordAttribute);
    
        string realm = nsString.Get(authInfo.GetRealmAttribute);
    
        if (PromptUsernameAndPassword(null, "Server Authentication", "The server '" + realm + "' requires a user name and password.", ref userName, ref password))
         {
            nsString.Set(authInfo.SetUsernameAttribute, userName);
            nsString.Set(authInfo.SetPasswordAttribute, password);
            aCallback.OnAuthAvailable(aContext, authInfo);
        }
        else
        {
            aCallback.OnAuthCancelled(aContext, true);
        }
        Cancelable cancel = new Cancelable();
        return cancel;
    }
    
    public class Cancelable : nsICancelable
    {
        public int Reason { set; get; }
        public void Cancel(int aReason)
        {
            Reason = aReason;
        }
    }
    
  6. Barun Debnath reporter

    I have tried non-modal dialog, even I tried it without any window (ie. just passing hard coded username and password without any user input). And still same result. Browser is showing blank and busy. Any suggestion ?

  7. hindlemail

    I've tested this and both these ways work for me:

    Option 1: throw exception in async method to force FF to fall back to sync method.

    public bool PromptAuth(nsIChannel aChannel, uint level, nsIAuthInformation authInfo)
    {
      nsString.Set(authInfo.SetUsernameAttribute, "USERNAME");
      nsString.Set(authInfo.SetPasswordAttribute, "PASSWORD");			
      return true;
    }
    
    
    public nsICancelable AsyncPromptAuth(nsIChannel aChannel, nsIAuthPromptCallback aCallback, nsISupports aContext, uint level, nsIAuthInformation authInfo)
    {
    throw new COMException();
    }
    
    

    Option2: use timer to delay calling of callback until after method returned.

    public nsICancelable AsyncPromptAuth(nsIChannel aChannel, nsIAuthPromptCallback aCallback, nsISupports aContext, uint level, nsIAuthInformation authInfo)
    		{
    			string userName = nsString.Get(authInfo.GetUsernameAttribute);
    			string password = nsString.Get(authInfo.GetPasswordAttribute);
    
    			string realm = nsString.Get(authInfo.GetRealmAttribute);
    
    			Timer t = new Timer();
    			t.Interval = 1000;
    			t.Start();
    			t.Tick += (s,e) =>
    				{
    					nsString.Set(authInfo.SetUsernameAttribute, "USERNAME");
    					nsString.Set(authInfo.SetPasswordAttribute, "PASSWORD");
    					aCallback.OnAuthAvailable(aContext, authInfo);
    					t.Stop();
    				};
    
    			Cancelable cancel = new Cancelable();
    			return cancel;
    		}
    
    

    Obviously neither of these code samples are production quality, but they demonstrate the technique.

    Also note that if a wrong username/password is supplied FF seems to repeatably call AsyncPromptAuth.

  8. M Vlad Cristian

    Hello, I have been trying to make this work for over 5 days, but no luck. I am trying to display a custom user/password box (when trying to connect to a private proxy).

    If I do not use GeckoWebBrowser.UseCustomPrompt();, the default prompt is displayed, but when I use GeckoWebBrowser.UseCustomPrompt(); (to implement a custom prompt for example, by editing the source), nothing appears on the screen. I tried with GeckoFx 14,19,22,29 ... no success :(

    Any tips are appreciated. What I am trying to do is auto fill the password/username for private proxies. If the above does not work, maybe someone can tell me way to add 1 custom header (to all requests, not just the navigate request) to the webbrowser.

    Thanks!

  9. Log in to comment