[英]admin.auth().verifyIdToken(idToken) Error: Could not load the default credentials whith firebase-admin after to 8.0.0
I've got a problem when i'm trying use middleware in firebase当我尝试在 firebase 中使用中间件时遇到问题
this is my middleware (FBauth)这是我的中间件(FBauth)
const db = admin.firestore();
const FBAuth = (_req,_res,next) => {
let idToken;
if(_req.headers.authorization && _req.headers.authorization.startsWith('Bearer ')){
idToken = _req.headers.authorization.split ('Bearer ')[1];
console.log('ID TOKEN ------------>', idToken);
}else{
console.error('Nessun Token trovato')
return _res.status(403).json({ error: 'non-autorizzato'});
}
admin.auth().verifyIdToken(idToken)
.then(decodedToken => {
_req.user = decodedToken;
console.log(decodedToken);
return db.collection('users')
.where('userId', '==', _req.user.uid)
.limit(1)
.get();
})
.then(data=>{
console.log('****** reading data ******', data);
_req.user.handle = data.doc[0].data().handle;
return next();
})
.catch(err => {
console.error('********error while verifying token*********', err);
return _res.status(403).json({error: `${err}`});
}
);
};
When i try verify token I've got this error当我尝试验证令牌时出现此错误
Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information
I think my code is correctly bootstrap我认为我的代码是正确的引导程序
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const app = require('express')();
admin.initializeApp();
const firebaseConfig = {
apiKey: "**************",
authDomain: "***************",
databaseURL: "***************",
projectId: "***************",
storageBucket: "***************",
messagingSenderId: "***************",
appId: "***************",
measurementId: "***************"
};
const firebase = require('firebase');
firebase.initializeApp(firebaseConfig);
maybe is correlated whit this ISSUE ----> https://github.com/firebase/firebase-admin-node/issues/738 ?也许与此问题相关----> https://github.com/firebase/firebase-admin-node/issues/738 ? How i can solve?
我该如何解决?
PS: PS:
my depencies are these我的依赖是这些
"dependencies": {
"express": "^4.17.1",
"firebase": "^7.13.2",
"firebase-admin": "^8.9.0",
"firebase-functions": "^3.3.0"
},
I can solve following here https://stackoverflow.com/a/58140389/6414686我可以在这里解决https://stackoverflow.com/a/58140389/6414686
you must download file from here你必须从这里下载文件
YOURFILE.JSON https://console.firebase.google.com/u/0/project/[YOURPROJECTID]/settings/serviceaccounts/adminsdk YOURFILE.JSON https://console.firebase.google.com/u/0/project/[YOURPROJECTID]/设置/服务
var serviceAccount = require("./keys/YOURFILE.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "YOURURLFROMPAGE"
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.