1.0.3 • Published 3 years ago
@pager/hapi-firebase-armor v1.0.3
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();
})();