Using OAuth with Github on my client, I send a fetch request with the resulting token to my server. I'm getting the token as expected, but am unable to execute firebase.auth().verifyIdToken to get the token. My SDK is authenticated with a certificate credential following the the admin SDK setup.
My clientAuth middleware:
const firebase = require('firebase-admin');
const db = require('../db');
module.exports = async (req, res, next) => {
try {
const tokenId = req.get('Authorization').split('Bearer ')[1];
console.log(tokenId) //yay, token
const validToken = await firebase.auth().verifyIdToken(tokenId);
console.log(validToken.uid) //error
return (validToken && validTeam) ? next() : res.status(401).end();
} catch (e) {
res.status(401).end();
}
};
The error I get is 'Decoding Firebase ID token failed. Make sure you passed the entire string JWT which represents an ID token.' How do I go about verifying/ decoding this token?
console.log(tokenId)is a valid JWT? You can use a tool like jwt.io to help with that. If it is a valid JWT, does theaudclaim match up with theproject-idin the certificate credential json file? - Carlos Gomez