Firefox Extension Set Proxy Auth
I am trying to develop and a Firefox extension that sets up a proxy and does some other things after that. So I know how to set up proxy and port.
var prefManager = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
prefManager.setIntPref("network.proxy.type", 1);
prefManager.setCharPref("network.proxy.http",aProxy[0]);
prefManager.setIntPref("network.proxy.http_port",aProxy[1]);
But I couldn't find properties for username and password. It seems this will need to be set in a different way.
Can anyone please help?
source to share
Have you tried saving passwords with nsILoginManager
? Firefox treats proxy passwords like any other password.
let LoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1", Components.interfaces.nsILoginInfo, "init");
let loginInfo = new LoginInfo(
hostname,
null,
realm,
user,
password,
'',
''
);
let loginManager = Components.classes["@mozilla.org/login-manager;1"].getService(Components.interfaces.nsILoginManager);
loginManager.addLogin(loginInfo);
Proxies have no schema, so I saw that the code in Firefox does something like this (code from https://hg.mozilla.org/mozilla-central/file/69d61e42d5df/toolkit/components/passwordmgr/nsLoginManagerPrompter.js# l1400 ):
// Proxies don't have a scheme, but we'll use "moz-proxy://"
// so that it more obvious what the login is for.
var idnService = Cc["@mozilla.org/network/idn-service;1"].
getService(Ci.nsIIDNService);
hostname = "moz-proxy://" +
idnService.convertUTF8toACE(info.host) +
":" + info.port;
realm = aAuthInfo.realm;
if (!realm)
realm = hostname;
I think this is just for readability (when the user opens the password manager), but it is not required.
PS: There is also a preference signon.autologin.proxy
that makes Firefox not ask for authentication if the password is saved.
source to share