My end goal is to add ROLES and ORGS and whatever other data to the AUTH token for use in the firebase security rules. Below is some pseudo code, thinking about just wrapping the token generation in a simple api. Any suggestions or other ways of doing this would be greatly appreciated.
require('dotenv').load();
var Promise = require('bluebird');
var Firebase = require('firebase');
var FirebaseTokenGenerator = require("firebase-token-generator");
var tokenGenerator = new FirebaseTokenGenerator(process.env.FIREBASE_SECRET);
var express = require('express');
var fb = new Firebase(process.env.FIREBASE_URL);
var fbAuth = Promise.promisify(fb.auth, fb);
var app = express();
app.post('/auth', function (req, res) {
fbAuth(req.token)
.then(function(result) {
// add ROLES to valid token, by firebase query
// add other data valid token, by firebase query
var token = tokenGenerator.createToken({uid: result.auth.uid, some: "arbitrary", data: "here"});
res.json(token);
})
.catch(function(err) {
res.error('bad auth', err);
});
});
app.listen(3000);