Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox Extension Set Proxy Auth

I am trying to develop and Firefox Extension, which sets a proxy and does some other things after doing that. So i know how to set proxy http 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 was not able to find the properties for username and password. Seems it will need to be set differently.

Someone can help?

like image 330
BlueZero Avatar asked Nov 23 '25 04:11

BlueZero


1 Answers

Have you tried saving the passwords using nsILoginManager? In Firefox, password for proxies are handled 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 don't have a scheme, so I've seen code in Firefox do 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's 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 it's just for readability (when the user opens the password manager), but it shouldn't be required.

P.S.: There's also a preference, signon.autologin.proxy, that makes Firefox not prompt for authentication if a password is saved.

like image 82
Marco Castelluccio Avatar answered Nov 24 '25 23:11

Marco Castelluccio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!