add fallback for using metadata fallback
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
var _ = require('underscore'); // AUTH_FALLBACK
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {PgConnection} pgConnection
|
||||
@@ -45,10 +47,10 @@ AuthApi.prototype.authorizedBySigner = function(res, callback) {
|
||||
};
|
||||
|
||||
function isValidApiKey(apikey) {
|
||||
return apikey.type !== null &&
|
||||
apikey.user !== null &&
|
||||
apikey.databasePassword !== null &&
|
||||
apikey.databaseRole !== null;
|
||||
return apikey.type &&
|
||||
apikey.user &&
|
||||
apikey.databasePassword &&
|
||||
apikey.databaseRole;
|
||||
}
|
||||
|
||||
// Check if a request is authorized by api_key
|
||||
@@ -72,6 +74,19 @@ AuthApi.prototype.authorizedByAPIKey = function(user, req, callback) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
//Remove this block when Auth fallback is not used anymore
|
||||
// AUTH_FALLBACK
|
||||
if (!apikey.databaseRole && apikey.user_id && global.environment.postgres_auth_user) {
|
||||
apikey.databaseRole = _.template(global.environment.postgres_auth_user, apikey);
|
||||
}
|
||||
|
||||
//Remove this block when Auth fallback is not used anymore
|
||||
// AUTH_FALLBACK
|
||||
if (!apikey.databasePassword && global.environment.postgres.password) {
|
||||
apikey.databasePassword = global.environment.postgres.password;
|
||||
}
|
||||
|
||||
if ( !isValidApiKey(apikey)) {
|
||||
const error = new Error('Unauthorized');
|
||||
error.type = 'auth';
|
||||
|
||||
Reference in New Issue
Block a user