hapijs - chaining request filters through plugins in hapi.js -
i need validate client-key jsonwebtoken header in requests hapi.js rest api.
i using hapi-auth-jwt plugin handle json web tokens - , i'd put in handler checks valid client key in api header upstream - before of web token checks , else - can return 401 if valid client-api-key not included.
should plugin in hapi? if how set order of plugins run - order register plugins?
how set plugin intercept http requests - should make auth scheme?
exports.register = function (server, options, next) { // somehow set default request handler here somehow? }
you can register extension function available extension points in hapi request lifecycle.
in case, since want request validated valid client-api-key before being authenticated, extension function can registered onrequest
or onpreauth
events.
exports.register = function (server, options, next) { server.ext('onrequest', function (request, reply){ //validate request object here. if (valid) reply.continue(); else reply(boom.unauthorized('invalid api key')); }); next(); }
Comments
Post a Comment