@guahanweb/hapi-jwt-plugin

0.0.2 • Public • Published

JWT Plugin for Hapi

Build Status

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();
});

Package Sidebar

Install

npm i @guahanweb/hapi-jwt-plugin

Weekly Downloads

1

Version

0.0.2

License

MIT

Last publish

Collaborators

  • guahanweb