Auth seems to work, not tested

This commit is contained in:
Ilya Ig. Petrov 2017-10-31 23:30:42 +05:00
parent e4bf2292b4
commit 8f1ce3b6ea

View File

@ -12,8 +12,9 @@
const ifIncontinence = 'if-incontinence'; const ifIncontinence = 'if-incontinence';
const modsKey = 'mods'; const modsKey = 'mods';
const proxyHostToCredsList = { window.proxyHostToCredsList = {
// One host may be used several times with different creds. // One host may be used several times with different creds.
/*
'blablabla:6110': [ 'blablabla:6110': [
{ username: 'foo', password: 'bar' }, { username: 'foo', password: 'bar' },
{ username: 'foo1', password: 'bar' }, { username: 'foo1', password: 'bar' },
@ -23,6 +24,7 @@
{ username: 'foo5', password: 'bar' }, { username: 'foo5', password: 'bar' },
{ username: 'foo6', password: 'bar' }, { username: 'foo6', password: 'bar' },
], ],
*/
}; };
const ifAuthSupported = chrome.webRequest && chrome.webRequest.onAuthRequired && !window.apis.version.ifMini; const ifAuthSupported = chrome.webRequest && chrome.webRequest.onAuthRequired && !window.apis.version.ifMini;
if (ifAuthSupported) { if (ifAuthSupported) {
@ -31,7 +33,7 @@
const requestIdToTries = {}; const requestIdToTries = {};
chrome.webRequest.onAuthRequired.addListener( chrome.webRequest.onAuthRequired.addListener(
window.utils.getOrDie((details) => { (details) => {
console.log('AUTH REQUIRED.'); console.log('AUTH REQUIRED.');
if (!details.isProxy) { if (!details.isProxy) {
@ -51,12 +53,12 @@
return {}; // All creds for this proxy were tried already. return {}; // All creds for this proxy were tried already.
} }
requestIdToTries[requestId] = tries + 1; requestIdToTries[requestId] = tries + 1;
console.log('TRIES=', tries, 'for', requestId); console.log('TRIES=', tries, 'for', requestId, 'CREDS', credsList[tries]);
return { return {
authCredentials: credsList[tries], authCredentials: credsList[tries],
}; };
}), },
{urls: ['<all_urls>']}, {urls: ['<all_urls>']},
['blocking'], ['blocking'],
); );
@ -241,7 +243,36 @@
} }
// Hanlde protected proxies in customProxyArray. // Hanlde protected proxies in customProxyArray.
// TODO: const protectedProxies = [];
customProxyArray = customProxyArray.map((proxyScheme) => {
if (proxyScheme.includes('@')) {
const proxy = window.utils.parseProxyScheme(proxyScheme);
protectedProxies.push(proxy);
return `${proxy.type} ${proxy.hostname}:${proxy.port}`;
}
return proxyScheme;
});
if (!ifAuthSupported && protectedProxies.length) {
return [new Error('Запароленные прокси не поддерживатюся в данной версии/платформе!')];
}
proxyHostToCredsList = {};
protectedProxies.forEach(({ hostname, port, username, password }) => {
proxyHostToCredsList[`${hostname}:${port}`] =
proxyHostToCredsList[`${hostname}:${port}`] || [];
const tries = proxyHostToCredsList[`${hostname}:${port}`];
tries.push({
username,
password: password || '',
});
});
self.filteredCustomsString = ''; self.filteredCustomsString = '';
if (customProxyArray.length) { if (customProxyArray.length) {