简体   繁体   中英

JSZipUtils with bearer/token authentication

I want to use the JSZipUtils to pull files from my API and zip the files. The API uses a Token authentication.

However, I noticed JSZipUtils has Basic Authentication hard code in their library :

if (auth) {
            xhr.setRequestHeader("Authorization", "Basic " + auth);
        }

without modifying their code, does anyone know how to override this?

One solution where you technically don't modify their code, but override it, is to copy the function from the source file and do like this

JSZipUtils.getBinaryContent = function (path, callback, auth){
    //Exactly the same code as in the source file, but with your auth modification
}

This should be directly after loading the original class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM