【问题标题】:Changing credentials to a proxy server on the fly即时将凭据更改为代理服务器
【发布时间】:2018-08-10 11:24:24
【问题描述】:

我正在为 chrome 开发一个扩展。该扩展允许从列表中选择任何代理服务器,每个代理都需要授权。当用户想要两次连接到同一个代理服务器但使用不同的凭据时会出现问题,例如,如果用户在第一次 chrome 记住它时成功登录,并且当用户尝试使用其他凭据连接时 chrome将使用在第一次登录时输入的凭据。

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 logged as "Jack" but has to be as "Bob"

【问题讨论】:

  • 你能澄清你的问题吗?我不确定应该发生什么与正在发生什么。

标签: javascript google-chrome-extension proxy


【解决方案1】:

这里有多种可能性,因为问题不是很清楚。我建议先浏览documentation 的 chrome.webRequest。但我的问题是你为什么不使用拦截器方法来检查服务器凭据对?有一个很好的 article 关于在扩展程序的 background.js 脚本中添加拦截器,它建议使用 beforeRequest 钩子。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-06
    • 2012-04-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多