Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
rest-crud-generator
Advanced tools
Bearer
authentication to the individual routesconst Api = require('rest-crud-generator')
Bookshelf
models to the generate method to create the API calls, with: Api.generate(User)
Adding Authentication:
To enable authentication and change the allowedRole array, run: Api.addBearerAuthentication(validateFunction)
, the validateFunction looks like this:
function (token, callback) {
// correct authentication
return callback(null, true, {});
// error authenticating
return callback(null, false);
}
generates the CRUD routes for the given model
{
routes: {
findOne: {
allowedRoles: [],
isEnabled: true
},
findAll: {
allowedRoles: [],
isEnabled: true
},
create: {
allowedRoles: [],
isEnabled: true
},
delete: {
allowedRoles: [],
isEnabled: true
},
update: {
allowedRoles: [],
isEnabled: true
}
}
}
Adds the bearer authentication to the server authentication. This requires the route to have a Bearer: <token>
header that specifies if the user is allowed access to the route.
The validateFunction
specifies if this given <token>
is correct and access is allowed (boolean). You will want to check this against the UserSession table to see if the token matches an entry.
An example of a fully fledged authentication function:
exports.validateFunction = function (token, callback) {
UserSessionModel
.where({ token: token })
.fetch()
.then(function (userSession) {
if (!userSession) {
return Promise.reject(Boom.badRequest('INVALID_TOKEN'));
}
return UserModel.where({ id: userSession.get('user_id') })
.fetch();
})
.then(function (user) {
if (!user) {
return Promise.reject(Boom.badRequest('INVALID_TOKEN'));
}
var userObj = user;
userObj.scope = [ user.get('scope') ];
return callback(null, true, userObj);
})
.catch(function (err) {
return callback(err);
});
};
Routes are generated on the plural name of the base model separated by _ on the capital letters.
Example: User becomes /user Example: BaseUnit becomes /base_units
CarEngine
, CarModel
, CarBody
, ... that we combine in the Car Facade
which has a method: `assembleCar``FAQs
REST API Generator for Bookshelf.js
We found that rest-crud-generator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.