1.0.3 • Published 3 years ago

@pager/hapi-firebase-armor v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

hapi-firebase-armor

Firebase JWT authorization plugin for Hapi

build

npm run build

test

npm run test

lint

npm run lint npm run lint:fix

usage

const Hapi = require('@hapi/hapi');
const Armor = require('@pager/hapi-firebase-armor');

(async () => {
  const server = new Hapi.Server({ port: 3000 });

  await server.register({
      plugin: Armor.plugin,
      options: new Armor.Options({
        credentials: require(`../${process.env.NODE_ENV}.firebase.json`),
        claimsOverride: async (_token, decoded) => {
          // do some stuff with token here
          return decoded;
        }
      })
  });

  server.route({
      method: 'GET',
      path: '/',
      handler: (request, h) => 'Hello World'
  });

  await server.start();
})();
const Hapi = require('@hapi/hapi');
const Armor = require('@pager/hapi-firebase-armor');
const Admin = require('firebase-admin');

(async () => {
  const server = new Hapi.Server({ port: 3000 });

  // initialize firebase-admin application using service account credentials
  // that can be found in the firebase console
  const app = Admin.initializeApp({
      credential: Admin.credential.cert(require(`../${process.env.NODE_ENV}.firebase.json`))
  });

  await server.register({
      plugin: Armor.plugin,
      options: new Armor.Options({
        auth: app.auth(),
        claimsOverride: async (_token, decoded) => {
          // do some stuff with token here
          return decoded;
        }
      })
  });

  server.route({
      method: 'GET',
      path: '/',
      handler: (request, h) => 'Hello World'
  });

  await server.start();
})();

Useful Links

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago