Policies
Defining a policy
const { Policy } = require ('@onehilltech/blueprint');
/**
* This is a simple demonstration of a policy.
*/
module.exports = Policy.extend ({
/// The failure code used when the policy fails.
failureCode: 'invalid_secret',
/// The human readable message that can be displayed on the
/// client-side when this policy fails.
failureMessage: 'The request has an invalid secret.',
/**
* Run the policy.
*
* @param req The Express request object.
*/
runCheck (req) {
// Check the Secret-Key request header, but do not use something like this in
// a production environment.
return req.get ('Secret-Key') === 'ssshhh';
}
});
Attaching the policy to a route
Policies for resources
Policy
Location
Description
Testing your policies
Last updated