In fact, for authentication you will need to use a regular firebase api, not an admin.
This will first give you an updated firebase token, not a custom token. If you like, you can do the same to get a custom token, if you need a custom token, I also have an example.
npm install firebase --save
const firebase = require("firebase"); const config = { apiKey: "", authDomain: "", databaseURL: "", projectId: "", storageBucket: "", messagingSenderId: "" }; firebase.initializeApp(config);
I host my firebase function for login, but you can easily change it.
exports.login = functions.https.onRequest((req, rsp)=>{ const email = req.body.email; const password = req.body.password; const key = req.body.key; const _key = '_my_key_'; let token = ''; if(key === _key){ firebase.auth().signInWithEmailAndPassword(email,password).then((user)=>{ //The promise sends me a user object, now I get the token, and refresh it by sending true (obviously another promise) user.getIdToken(true).then((token)=>{ rsp.writeHead(200, {"Content-Type": "application/json"}); rsp.end(JSON.stringify({token:token})); }).catch((err)=>{ rsp.writeHead(500, {"Content-Type": "application/json"}); rsp.end(JSON.stringify({error:err})); }); }).catch((err)=>{ rsp.writeHead(500, {"Content-Type": "application/json"}); rsp.end(JSON.stringify({error:err})); }); } else { rsp.writeHead(500, {"Content-Type": "application/json"}); rsp.end(JSON.stringify('error - no key')); } });
NOTE. I use this login function to test my other functions with Postman, so I send the key, so I can use it privately.
Now, combining ADMIN and FIREBASE node apy, I can do a lot of interesting things with the HTTP functions on my Firebase.
Hope this helps.