diff options
Diffstat (limited to 'dgbuilder/dgeflows/node_modules/morgan/node_modules/basic-auth/index.js')
-rw-r--r-- | dgbuilder/dgeflows/node_modules/morgan/node_modules/basic-auth/index.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/dgbuilder/dgeflows/node_modules/morgan/node_modules/basic-auth/index.js b/dgbuilder/dgeflows/node_modules/morgan/node_modules/basic-auth/index.js new file mode 100644 index 00000000..3ef1ff17 --- /dev/null +++ b/dgbuilder/dgeflows/node_modules/morgan/node_modules/basic-auth/index.js @@ -0,0 +1,28 @@ + +/** + * Parse the Authorization header field of `req`. + * + * @param {Request} req + * @return {Object} with .name and .pass + * @api public + */ + +module.exports = function(req){ + req = req.req || req; + + var auth = req.headers.authorization; + if (!auth) return; + + // malformed + var parts = auth.split(' '); + if ('basic' != parts[0].toLowerCase()) return; + if (!parts[1]) return; + auth = parts[1]; + + // credentials + auth = new Buffer(auth, 'base64').toString(); + auth = auth.match(/^([^:]*):(.*)$/); + if (!auth) return; + + return { name: auth[1], pass: auth[2] }; +}; |