如何验证由createCustomToken()创建的自定义Firebase验证令牌

问题描述 投票:1回答:1

我通过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/[email protected]抓取公钥并使用jsonwebtoken库来验证它...

firebase firebase-authentication google-cloud-functions
1个回答
1
投票

verifyIdToken喜欢的名字是验证IdToken,而不是自定义令牌。

CustomToken适用于sign in的客户。可以使用简单的JWT验证来验证此自定义令牌,例如您的解决方案(它在一小时后过期)。

IdToken是另一个故事,你需要使用firebase auth进行登录。

要在signIn之后从客户端获取Id Token,这取决于客户端是Android,Web还是IOS。获取IdToken的代码可以在this section中读取

© www.soinside.com 2019 - 2024. All rights reserved.