Reputation: 27265
I'm coding a Firefox extension and want to get Basic Authentication information for a website (or for the current document).
How can I get Basic Authentication Information in a Firefox Extension?
Upvotes: 2
Views: 2257
Reputation: 4188
Here is some sample code for using nsIHttpAuthManager:
Instantiate the component:
var proxyAuthenticationComponent = Components.classes["@mozilla.org/network/http-auth-manager;1"].getService(Components.interfaces.nsIHttpAuthManager);
Set the information:
proxyAuthenticationComponent.setAuthIdentity('http','192.168.0.1',80,"basic","Some Realm","","","username","password");
Get the information:
var domain = {}; //Will contain {value: ""}
var username = {}; //Will contain {value: "username"}
var password = {}; //Will contain {value: "password"}
proxyAuthenticationComponent.getAuthIdentity('http','192.168.0.1',80,"basic","Some Realm","",domain,username,password);
I used this in a Thunderbird extension. Hope this help.
Upvotes: 3
Reputation: 15816
I couldn't find an exact answer and don't have time to experiment now, but it seems that the only way is to manually examine headers using NsIHttpChannel.
EDIT: Ok, I've found nsIHttpAuthManager:
This service provides access to cached HTTP authentication user credentials (domain, username, password) for sites visited during the current browser session.
Looks like exactly what you need.
Upvotes: 2