I'm developing an extension for chrome. The extension allow to pick any proxy server from a list each proxy is required authorization. There is an issue when a user would like to connect to the same proxy server twice but with different credentials for example if a user was successfully logged it in the first time the chome remebers it and when the user whould try to connect with another credentails the chrome whould use credentilas that was inputed in the first login.
var authCredentials = { username: 'Jack', password: 'PassForJack' } var auth = function () { return { authCredentials }; }; chrome.webRequest.onAuthRequired.addListener(auth, { urls: ["<all_urls>"] }, ["blocking"]); // set a new proxy server for the first login chrome.proxy.settings.set({ value: { mode: 'fixed_servers', rules: { singleProxy: { host: 'some-proxy-server.com', port: 8000 } } }, scope: 'regular' }); // change credentails authCredentials = { username: 'Bob', password: 'PassForBob' }; // remove proxy configuration chrome.proxy.settings.set({ value: { mode: 'direct' }, scope: 'regular' }); // remove onAuthListener chrome.webRequest.onAuthRequired.removeListener(auth) chrome.webRequest.onAuthRequired.hasListener(auth) // returns false chrome.webRequest.onAuthRequired.addListener(auth, { urls: ["<all_urls>"] }, ["blocking"]); // lets re connect chrome.proxy.settings.set({ value: { mode: 'fixed_servers', rules: { singleProxy: { host: 'some-proxy-server.com', port: 8000 } } }, scope: 'regular' }); // that doesn't help the user would be loged as "Jack" but has to be as "Bob" 1 Answers
Answers 1
There are multiple possibilities here since the question is not very clear. I would suggest to walk through documentation for the chrome.webRequest first. But My question would be why don't you use interceptor method to check for server-credential pair ? There's a good article about adding interceptor in the background.js script of your extension which suggests to use the beforeRequest hook.
0 comments:
Post a Comment