Firebase: How to programmatically generate a jwt token for a particular user similar to ` firebase.auth().currentUser.getIdToken(false)`?

笑着哭i 提交于 2020-01-13 19:07:49

问题


I have a http Cloud Function that expects a jwt token to be passed in the Authorization header (similar to Will's answer in this question: How to protect firebase Cloud Function HTTP endpoint to allow only Firebase authenticated users?). This cloud function verifies the token with the function admin.auth().verifyIdToken(<token>). In my client code, I use the code firebase.auth().currentUser.getIdToken(false) to generate a token to include in the http request in the aforementioned header.

I want to be able to generate this token given a user's uid programmatically, preferably in Node, so that I can write tests for my function without having to go through my web app to get the token.

I tried using admin.auth().createCustomToken(<uid>) but that doesn't create a token that can be verified with admin.auth().verifyIdToken. I also tried following the steps in this guide https://firebase.google.com/docs/database/rest/auth, however the token generated is not one that verifyIDToken accepts, though I am able to make REST calls to the database using it (as mentioned in the guide).

来源:https://stackoverflow.com/questions/46839878/firebase-how-to-programmatically-generate-a-jwt-token-for-a-particular-user-sim

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!