Improve naming
This commit is contained in:
parent
3e0981978a
commit
62deda6470
@ -62,7 +62,7 @@ function isValidApiKey(apikey) {
|
||||
//
|
||||
AuthApi.prototype.authorizedByAPIKey = function(user, res, callback) {
|
||||
const apikeyToken = res.locals.api_key;
|
||||
const apikeyUsername = res.locals.apikeyUsername;
|
||||
const basicAuthUsername = res.locals.basicAuthUsername;
|
||||
|
||||
if ( ! apikeyToken ) {
|
||||
return callback(null, false); // no api key, no authorization...
|
||||
@ -91,7 +91,7 @@ AuthApi.prototype.authorizedByAPIKey = function(user, res, callback) {
|
||||
return callback(error);
|
||||
}
|
||||
|
||||
if (!usernameMatches(apikeyUsername, res.locals.user)) {
|
||||
if (!usernameMatches(basicAuthUsername, res.locals.user)) {
|
||||
const error = new Error('Forbidden');
|
||||
error.type = 'auth';
|
||||
error.subtype = 'api-key-username-mismatch';
|
||||
@ -149,8 +149,8 @@ function isNameNotFoundError (err) {
|
||||
return err.message && -1 !== err.message.indexOf('name not found');
|
||||
}
|
||||
|
||||
function usernameMatches (apikeyUsername, requestUsername) {
|
||||
return !(apikeyUsername && (apikeyUsername !== requestUsername));
|
||||
function usernameMatches (basicAuthUsername, requestUsername) {
|
||||
return !(basicAuthUsername && (basicAuthUsername !== requestUsername));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,8 +3,10 @@
|
||||
module.exports = function apikeyToken () {
|
||||
return function apikeyTokenMiddleware(req, res, next) {
|
||||
const apikeyCredentials = getApikeyCredentialsFromRequest(req);
|
||||
|
||||
res.locals.api_key = apikeyCredentials.token;
|
||||
res.locals.apikeyUsername = apikeyCredentials.username;
|
||||
res.locals.basicAuthUsername = apikeyCredentials.username;
|
||||
|
||||
return next();
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user