blob: 3ef1ff17133c194308be00fe203c779d8bd0ea69 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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] };
};
|