admin管理员组文章数量:1410697
I'm initializing my firebase functions like so:
admin.initializeApp(functions.config().firebase)
I've generated a service account key which I believe I need to do for auth purpouses.
It gave me a json table with various key/values.
The instructions were to add that in admin.initializeApp like so:
var serviceAccount = require("path/to/serviceAccountKey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://<DATABASE_NAME>.firebaseio"
});
Which is very different to how I'md oing it.
I'm not even sure I need to do this though because I do have access to firestore using my previous method, however auth with valid user id tokens is not working giving me the following error in firebase:
ERROR: Error: Decoding Firebase ID token failed. Make sure you passed the entire string JWT which represents an ID token. See for details on how to retrieve an ID token.
and from sniffing around it looked like the missing thing was the admin sdk service account..
I'm initializing my firebase functions like so:
admin.initializeApp(functions.config().firebase)
I've generated a service account key which I believe I need to do for auth purpouses.
It gave me a json table with various key/values.
The instructions were to add that in admin.initializeApp like so:
var serviceAccount = require("path/to/serviceAccountKey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://<DATABASE_NAME>.firebaseio."
});
Which is very different to how I'md oing it.
I'm not even sure I need to do this though because I do have access to firestore using my previous method, however auth with valid user id tokens is not working giving me the following error in firebase:
ERROR: Error: Decoding Firebase ID token failed. Make sure you passed the entire string JWT which represents an ID token. See https://firebase.google./docs/auth/admin/verify-id-tokens for details on how to retrieve an ID token.
and from sniffing around it looked like the missing thing was the admin sdk service account..
Share edited Dec 17, 2017 at 4:50 Frank van Puffelen 601k85 gold badges890 silver badges860 bronze badges asked Dec 17, 2017 at 2:47 medsmeds 23k42 gold badges175 silver badges337 bronze badges 1-
Looks like the ID token passed to
verifyIdToken()
is malformed somehow. Can you try logging it in the server-side and see what turns up? – Hiranya Jayathilaka Commented Dec 17, 2017 at 6:11
1 Answer
Reset to default 5This snippet is a general way to initialize the Firebase Admin SDK for Node.js:
var serviceAccount = require("path/to/serviceAccountKey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://<DATABASE_NAME>.firebaseio."
});
As you've seen, it requires that you download a JSON file from the console, and add it to the path.
This is a bit finicky, and some developers find it hard to get working. Since the Cloud Functions environment is fully under Firebase's control, it was made a bit easier there. Your other snippet shows how:
admin.initializeApp()
Both snippets acplish the same thing, but the latter only works in Cloud Functions for Firebase.
本文标签:
版权声明:本文标题:javascript - How do I include my firebase service account key when using functions.config().firebase to init? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744917315a2632072.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论