Closed Bug 59981 Opened 24 years ago Closed 24 years ago

Basic Authentication doesn't work from embedding.

Categories

(Core Graveyard :: Embedding: APIs, defect, P3)

x86
Windows NT
defect

Tracking

(Not tracked)

VERIFIED DUPLICATE of bug 61669

People

(Reporter: edburns, Assigned: adamlock)

References

Details

Hello,

I already provide an implementation of nsIPrompt to mozilla from my
embedding custom app, and I note that its PromptUsernameAndPassword()
method is invoked when I visit a site with authentication.  However,
even if I hard-code correct values for username and password, I still
get authorization failed:

NS_IMETHODIMP CBrowserContainer::PromptUsernameAndPassword(const PRUnichar 
*dialogTitle, 
                                                           const PRUnichar 
*text, 
                                                           const PRUnichar 
*passwordRealm, 
                                                           PRUint32 
savePassword, 
                                                           PRUnichar **user, 
                                                           PRUnichar **pwd, 
                                                           PRBool *_retval)
{
    nsresult rv = NS_ERROR_FAILURE;

    nsAutoString userStr(L"correctUser");
    nsAutoString pwdStr(L"correctPwd");

    *user = userStr.ToNewUnicode();
    *pwd = pwdStr.ToNewUnicode();
    rv = NS_OK;

    return rv;
}

Can you please help me?

Thanks,

Ed
Added ccs
Blocks: 59866
-> adam
Assignee: valeski → adamlock
Can you give me a sample URL that uses authentication?
Inside the Netscape firewall, you can use http://jrgm/basic-auth
(which grants access to a page that says "Congratulations").
The hardcoded implementation below works for me in the ActiveX control. Ed, did 
you set retval to PR_TRUE and return NS_OK in your code?

/* boolean promptUsernameAndPassword (in wstring text, out wstring user, out 
wstring pwd); */
NS_IMETHODIMP CWebBrowserContainer::PromptUsernameAndPassword(const PRUnichar* 
dialogTitle, const PRUnichar *text, 
                                                              const PRUnichar* 
passwordRealm, PRUint32 savePassword,
                                                              PRUnichar **user, 
PRUnichar **pwd, PRBool *_retval)
{
    nsAutoString response;
    response.AssignWithConversion("foo");
    *user = response.ToNewUnicode();
    response.AssignWithConversion("bar");
    *pwd = response.ToNewUnicode();
    *_retval = PR_TRUE;
    return NS_OK;
}
BTW, retval indicates whether the dialog was cancelled or not. If your code is 
like your original sample and does not set it, then Gecko probably thinks that 
the call was cancelled and sends no authentication info at all. It probably 
doesn't free the memory for the values you pass back either.
Yes, here's my implementation:

NS_IMETHODIMP CBrowserContainer::PromptUsernameAndPassword(const PRUnichar 
*dialogTitle, 
                                                           const PRUnichar 
*text, 
                                                           const PRUnichar 
*passwordRealm, 
                                                           PRUint32 
savePassword, 
                                                           PRUnichar **user, 
                                                           PRUnichar **pwd, 
                                                           PRBool *_retval)
{
    nsresult rv = NS_ERROR_FAILURE;

    nsAutoString userStr(L"foo");
    nsAutoString pwdStr(L"bar");

    *user = userStr.ToNewUnicode();
    *pwd = pwdStr.ToNewUnicode();
    *_retval = PR_TRUE;
    return NS_OK;
}

It just hangs on this.

*** This bug has been marked as a duplicate of 61669 ***
Status: NEW → RESOLVED
Closed: 24 years ago
Resolution: --- → DUPLICATE
Updating QA Contact
QA Contact: jrgm → mdunn
vrfy dup
Status: RESOLVED → VERIFIED
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.