0

I'm trying to handle proxy authentication though chrome extensions.

On the one hand I have chrome extension (with all permissions established) that sends CONNECT request with onAuthRequired handler (background.js)

chrome.webRequest.onAuthRequired.addListener(
    (details, callback) => {
        console.log('onAuthRequired', details) // <- this has never been displayed
        callback({
            authCredentials: {
                username: 'someid',
                password: 'somepwd'
            }
        })
    },{
        urls: ['<all_urls>']
    },
    ['asyncBlocking']
)

const config = {
    mode: "pac_script",
    pacScript: {
        data: "function FindProxyForURL(url, host) {\n if (shExpMatch(host, \"*.pandora.com\"))\n return 'PROXY 127.0.0.1:8124';\n return 'DIRECT';\n }"
    }
}

chrome.proxy.settings.set({
    value: config,
    scope: 'regular',
}, function(){})

And on the other hand I have NodeJS proxy server that always sends the 407 status code as described in the specifications

const http = require('http');

const proxy = http.createServer()
proxy.on('connect', (req, clientSocket, head) => {
    clientSocket.write('HTTP/1.1 407 Proxy Authentication Required')
    clientSocket.write('Proxy-Authenticate: Basic realm="Access to site"\r\n\n')
});

proxy.listen(8124)

Finally, the browser returns ERR_PROXY_AUTH_UNSUPPORTED which means that the status code is sent correcly...

The fact is onAuthRequired is never triggered, can anyone tell me why ?

Thank you in advance

Community
  • 1
  • 1
Sufhal
  • 13
  • 1
  • 5

1 Answers1

0

Chrome aggressively caches the authentication calls to proxy servers. So you will only see your console.log call once per browser session (you need to restart Chrome completely, if you've got more than one profile open you'll need to close ALL instances of Chrome before the authentication cache is cleared).

I'm currently trying to figure out how to clear or empty said cache.

See also (How to delete Proxy-Authorization Cache on Chrome extension?)

werehamster
  • 116
  • 2
  • 2