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AM,EAAe,MAGjD,IAFI,KAVA,IAcX,SAAS,IACL,GAAG,EAAW,CACV,IAAI,EAAkB,QAClB,EAAY,EAAM,GAEnB,IACC,GAAmB,WAAa,EAAY,KAEhD,EAAI,IAAI,mBAAoB,EAChC,CAGA,MAAM,EAAW,EAAgB,GAEjC,MAAsB,iBAAZ,EACC,EAAI,OAAO,KAAK,KAAK,GAEzB,EAAI,OAAO,KAAK,KAAK,EAChC,CAUJ,CACJ,CAEA,gBAAgB,YAAc,YAC9B,OAAO,QAAU","file":"/npm/express-basic-auth@1.2.1/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/express-basic-auth@1.2.1/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const auth = require('basic-auth')\nconst assert = require('assert')\nconst timingSafeEqual = require('crypto').timingSafeEqual\n\n// Credits for the actual algorithm go to github/@Bruce17\n// Thanks to github/@hraban for making me implement this\nfunction safeCompare(userInput, secret) {\n    const userInputLength = Buffer.byteLength(userInput)\n    const secretLength = Buffer.byteLength(secret)\n\n    const userInputBuffer = Buffer.alloc(userInputLength, 0, 'utf8')\n    userInputBuffer.write(userInput)\n    const secretBuffer = Buffer.alloc(userInputLength, 0, 'utf8')\n    secretBuffer.write(secret)\n\n    return !!(timingSafeEqual(userInputBuffer, secretBuffer) & userInputLength === secretLength)\n}\n\nfunction ensureFunction(option, defaultValue) {\n    if(option == undefined)\n        return function() { return defaultValue }\n\n    if(typeof option != 'function')\n        return function() { return option }\n\n    return option\n}\n\nfunction buildMiddleware(options) {\n    var challenge = options.challenge != undefined ? !!options.challenge : false\n    var users = options.users || {}\n    var authorizer = options.authorizer || staticUsersAuthorizer\n    var isAsync = options.authorizeAsync != undefined ? !!options.authorizeAsync : false\n    var getResponseBody = ensureFunction(options.unauthorizedResponse, '')\n    var realm = ensureFunction(options.realm)\n\n    assert(typeof users == 'object', 'Expected an object for the basic auth users, found ' + typeof users + ' instead')\n    assert(typeof authorizer == 'function', 'Expected a function for the basic auth authorizer, found ' + typeof authorizer + ' instead')\n\n    function staticUsersAuthorizer(username, password) {\n        for(var i in users)\n            if(safeCompare(username, i) & safeCompare(password, users[i]))\n                return true\n\n        return false\n    }\n\n    return function authMiddleware(req, res, next) {\n        var authentication = auth(req)\n\n        if(!authentication)\n            return unauthorized()\n\n        req.auth = {\n            user: authentication.name,\n            password: authentication.pass\n        }\n\n        if(isAsync)\n            return authorizer(authentication.name, authentication.pass, authorizerCallback)\n        else if(!authorizer(authentication.name, authentication.pass))\n            return unauthorized()\n\n        return next()\n\n        function unauthorized() {\n            if(challenge) {\n                var challengeString = 'Basic'\n                var realmName = realm(req)\n\n                if(realmName)\n                    challengeString += ' realm=\"' + realmName + '\"'\n\n                res.set('WWW-Authenticate', challengeString)\n            }\n\n            //TODO: Allow response body to be JSON (maybe autodetect?)\n            const response = getResponseBody(req)\n\n            if(typeof response == 'string')\n                return res.status(401).send(response)\n\n            return res.status(401).json(response)\n        }\n\n        function authorizerCallback(err, approved) {\n            assert.ifError(err)\n\n            if(approved)\n                return next()\n\n            return unauthorized()\n        }\n    }\n}\n\nbuildMiddleware.safeCompare = safeCompare\nmodule.exports = buildMiddleware\n"]}