geenenauth

3.0.0 • Public • Published

GeenenAuth Hapi Plugin

Build Status

This is a Hapi plugin wrapper around hapi-auth-jwt2 with a specific setup as used by GeenenTijd. Compatible with Glue.

Install

npm i geenenauth --save

Register

server.register({
  plugin: require('geenenauth'),
  options: {
    secret: 'MyJWTSecret',
    issuer: 'MyIssuer', // Default GeenenTijd
    audience: 'MyAudience',
    strategies: [{
      name: 'isUser',
      roles: ['user', 'editor', 'admin', 'superadmin'],
    }, {
      name: 'isEditor',
      roles: ['editor'],
    }, {
      name: 'isAdmin',
      roles: ['admin', 'superadmin'],
    }]
  }
});

Strategies

User Authentication:

server.route({
  method: 'GET',
  path: '/me',
  config: {
    auth: {
      strategy: 'strategyName'
    }
  },
  handler: function (request, reply) {
  }
});

getToken(user, [secret, options,] callback)

Options: jsonwebtoken

  • expiresIn
  • notBefore
  • noTimestamp

Usage:

function (request, reply) {

  const user = {
    userid: 'c0cb1883-e8c6-4efa-8561-4ad4f4c14518',
    username: 'glenn',
    role: 'user'
  };

  request.server.methods.getToken(user, {
    expiresIn: '1d'
  } (err, token) => {

    // We have token here
  });
}

verifyToken(user, [secret, options,] callback)

Options: jsonwebtoken

  • expiresIn
  • notBefore
  • noTimestamp

Package Sidebar

Install

npm i geenenauth

Weekly Downloads

1

Version

3.0.0

License

MIT

Unpacked Size

6.59 kB

Total Files

6

Last publish

Collaborators

  • glenngeenen