in provider/lib/utils.js [408:443]
this.authorize = function(req, res, next) {
var method = 'authorize';
if (self.endpointAuth) {
if (!req.headers.authorization) {
res.set('www-authenticate', 'Basic realm="Private"');
res.status(HttpStatus.UNAUTHORIZED);
return res.send('');
}
var parts = req.headers.authorization.split(' ');
if (parts[0].toLowerCase() !== 'basic' || !parts[1]) {
return sendError(method, HttpStatus.BAD_REQUEST, 'Malformed request, basic authentication expected', res);
}
var auth = new Buffer(parts[1], 'base64').toString();
auth = auth.match(/^([^:]*):(.*)$/);
if (!auth) {
return sendError(method, HttpStatus.BAD_REQUEST, 'Malformed request, authentication invalid', res);
}
var uuid = auth[1];
var key = auth[2];
var endpointAuth = self.endpointAuth.split(':');
if (endpointAuth[0] === uuid && endpointAuth[1] === key) {
next();
}
else {
logger.warn(method, 'Invalid key');
return sendError(method, HttpStatus.UNAUTHORIZED, 'Invalid key', res);
}
}
else {
next();
}
};