node.js - Firebase custom token authentication (firebase version 3) -
i have authentication server (nodejs) authenticate user , create custom firebase token
var token = firebase.auth().createcustomtoken(userid);
i used able verify user token (previous version), not simple...
i decoded userid token
firebase.auth().verifyidtoken(token).then(function)....
does not work server generated custom tokens.
does know how done?
you should using jsonwebtoken
validate token in case. need pass firebase private key additional parameter.
var jwt = require('jsonwebtoken'); var fbprivatekey = //your firebase key string here jwt.verify(token, fbprivatekey, { algorithms: ['rs256'] }, function(err, decoded) { console.log(decoded); //your token info available here. });
update:
you have use private_key
.json
config file set in firebase.initializeapp({
, use library convert key public pem format
. can use node-rsa trick
var nodersa = require('node-rsa'); var fbprivatekey = //key .json file. var key = new nodersa(fbprivatekey).exportkey('pkcs8-public-pem'); jwt.verify(token, key, { algorithms: ['rs256'] }, function(err, decoded) { console.log(err); console.log(decoded); //your token info available here. });
Comments
Post a Comment