@guahanweb/hapi-jwt-plugin
v0.0.2
Published
Hapi Plugin to enable JWT authorization
Downloads
1
Readme
JWT Plugin for Hapi
JSON Web Tokens provide an RFC compliant way to propogate data through requests. This plugin leverages Hapi's authorization model and creates a customizable way to validate inbound authorization headers using JWT.
Usage
Install and save your dependency:
$ npm i -S @guahanweb/hapi-jwt-plugin
The easiest way to leverage validation is to use the included authorization scheme in your routes:
const Hapi = require('hapi');
const server = new Hapi.Server();
server.connection({ port: 3000 });
server.register({
register: require('@guahanweb/hapi-jwt-plugin'),
options: {
secret: 'my app secret',
typ: 'jwt',
alg: 'sha256'
}
}, err => {
if (err) {
console.error(err);
process.exit(1);
}
server.route({
method: 'GET',
path: '/auth',
config: {
auth: 'jwt',
handler: function (request, reply) {
reply('ok');
}
}
});
server.start();
});