Avoid HTTP auth popup in a chrome extension (digest)

前端 未结 3 1720
[愿得一人]
[愿得一人] 2021-02-01 09:39

I\'m currently developing a chrome extension, I need to access some http-auth protected resources (webdav). The HTTP auth is using (in the best case) a digest authentication.

3条回答
  •  甜味超标
    2021-02-01 10:32

    Google Chrome teams has implented the onAuthRequired event in Google Chrome 22, so now is possible detect when the HTTP Basic Authentication is required.

    In fact I wrote a extension that automatically sends the HTTP Basic Authentication credentials using the onAuthRequired event.

    It is available for free in the official Google Chrome web store: https://chrome.google.com/webstore/detail/basic-authentication-auto/dgpgkkfheijbcgjklcbnokoleebmeokn

    Usage example of onAuthRequired event:

    sendCredentials = function(status)
    {   
        console.log(status);
        return {username: "foo", password: "bar"};
    }
    
    chrome.webRequest.onAuthRequired.addListener(sendCredentials, {urls: [""]}, ["blocking"]);
    

    You need to add the right permissions to the manifest file in order to use the onAuthRequired.

    "permissions": [ "http://*/*", "https://*/*", "webRequest", "webRequestBlocking", "tabs" ],
    

    Download the extensions and check the source code for a better approach.

    It should work even if the request was initiated from another extension.

提交回复
热议问题