【发布时间】:2019-07-04 23:14:04
【问题描述】:
我通过 createCustomToken() 创建了自定义 Auth Token,请参阅 https://firebase.google.com/docs/auth/admin/create-custom-tokens。
但稍后当我尝试通过 verifyIdToken() 函数验证此令牌时,它会引发以下错误
Error: verifyIdToken() expects an ID token, but was given a custom token. See https://firebase.google.com/docs/auth/admin/verify-id-tokens for details on how to retrieve an ID token.
这是合理的,因为没有这样的ID...但是我需要的-只是简单地验证令牌,类似于jwt.verify()...
有没有人遇到过这个问题,找到了什么解决方案?是否可以通过 jsonwebtoken 库验证 Firebase 身份验证令牌?
附:我将在 Google Cloud Function 端点中使用验证
解决方案:看起来我刚刚找到了解决方案 https://firebase.google.com/docs/auth/admin/verify-id-tokens#verify_id_tokens_using_a_third-party_jwt_library 只需要从 https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com 获取公钥并使用 jsonwebtoken 库来验证它...
【问题讨论】:
标签: firebase firebase-authentication google-cloud-functions