我正在使用 firebase 身份验证来处理我的 Web 应用程序的用户帐户。当用户输入有效的登录凭据时,我使用 firebase admin SDK 在云函数中生成 JWT,该 JWT 被发送回客户端,然后使用 firebase 进行身份验证。我遇到了由 firebase admin SDK 生成的 JWT 无效的问题。更具体地说,当令牌被解码时(我使用jwt.io https://jwt.io),我得到以下信息:
Header: {
"alg": "none",
"typ": "JWT"
}
Payload: {
"aud": "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit",
"iat": 1614367953,
"exp": 1614371553,
"iss": "[email protected] /cdn-cgi/l/email-protection",
"sub": "[email protected] /cdn-cgi/l/email-protection",
"uid": "some uid here"
}
该令牌不仅缺少签名,而且还缺少iss and sub价值观是错误的。我在用admin.auth().createCustomToken(uid)
生成令牌,并且正在使用具有服务令牌创建权限的有效服务帐户初始化应用程序。
编辑:
我刚刚发现,只有当所有内容都使用 firebase 模拟器在本地运行时,令牌才会错误生成。当我部署应用程序时,令牌会生成并验证得很好。
确保你是检测您的应用程序以与身份验证模拟器对话 https://firebase.google.com/docs/emulator-suite/connect_auth#instrumentauth...并这样做before身份验证监听器做他们的事情。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)