identity
Version:
Identity client
30 lines (21 loc) • 786 B
JavaScript
exports.api_key = function(api, next){
var config = api.config.identity;
if(!config) return next();
//allow param api_key for all actions
api.params.globalSafeParams.push('api_key');
api.actions.addPreProcessor(function(connection, actionTemplate, next){
var api_key = connection.params.api_key;
if(api_key && actionTemplate.ApiKeyCheck !== false){
api.identity.application('identity').get('user', {api_key: api_key}, function(err, resp){
if(resp.data && resp.data.permissions.length > 0){
connection.user = resp.data;
connection.session_tmp = true;
}
next(connection, true);
})
}else{
next(connection, true);
}
}, 10);
next();
};