javascript - How do I include my firebase service account key when using functions.config().firebase to init? - Stack Overflow

I'm initializing my firebase functions like so:admin.initializeApp(functions.config().firebase)I&#

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
Add a ment  | 

1 Answer 1

Reset to default 5

This 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744917315a4600912.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信