remove step and check existance of proper api key

This commit is contained in:
Eneko Lakasta
2018-02-07 18:20:56 +01:00
parent 6b5d6648de
commit a4dbc1bac2
+17 -14
View File
@@ -47,6 +47,13 @@ AuthApi.prototype.authorizedBySigner = function(res, callback) {
});
};
function isValidApiKey(apikey) {
return apikey.type !== null &&
apikey.user !== null &&
apikey.databasePassword !== null &&
apikey.databaseRole !== null;
}
// Check if a request is authorized by api_key
//
// @param user
@@ -61,23 +68,19 @@ AuthApi.prototype.authorizedByAPIKey = function(user, req, callback) {
givenKey = req.body.api_key || req.body.map_key;
}
if ( ! givenKey ) {
return callback(null, 0); // no api key, no authorization...
return callback(null, false); // no api key, no authorization...
}
var self = this;
step(
function () {
self.metadataBackend.getUserMapKey(user, this);
},
function checkApiKey(err, val){
assert.ifError(err);
return val && givenKey === val;
},
function finish(err, authorized) {
callback(err, authorized);
this.metadataBackend.getApikey(user, givenKey, (err, apikey) => {
if (err) {
return callback(err);
}
);
if ( !isValidApiKey(apikey)) {
return callback(null, false);
}
return callback(null, true);
});
};
/**