(req, res, next)
| 106 | */ |
| 107 | function authorizationParser(options) { |
| 108 | function parseAuthorization(req, res, next) { |
| 109 | req.authorization = {}; |
| 110 | req.username = 'anonymous'; |
| 111 | |
| 112 | if (!req.headers.authorization) { |
| 113 | return next(); |
| 114 | } |
| 115 | |
| 116 | var pieces = req.headers.authorization.split(' ', 2); |
| 117 | |
| 118 | if (!pieces || pieces.length !== 2) { |
| 119 | var e = new InvalidHeaderError('BasicAuth content is invalid.'); |
| 120 | return next(e); |
| 121 | } |
| 122 | |
| 123 | req.authorization.scheme = pieces[0]; |
| 124 | req.authorization.credentials = pieces[1]; |
| 125 | |
| 126 | try { |
| 127 | switch (pieces[0].toLowerCase()) { |
| 128 | case 'basic': |
| 129 | req.authorization.basic = parseBasic(pieces[1]); |
| 130 | req.username = req.authorization.basic.username; |
| 131 | break; |
| 132 | |
| 133 | case 'signature': |
| 134 | req.authorization.signature = parseSignature(req, options); |
| 135 | req.username = req.authorization.signature.keyId; |
| 136 | break; |
| 137 | |
| 138 | default: |
| 139 | break; |
| 140 | } |
| 141 | } catch (e2) { |
| 142 | return next(e2); |
| 143 | } |
| 144 | |
| 145 | return next(); |
| 146 | } |
| 147 | |
| 148 | return parseAuthorization; |
| 149 | } |
nothing calls this directly
no test coverage detected