gpt4 book ai didi

firebase 身份验证/无效的自定义 token

转载 作者:行者123 更新时间:2023-12-02 09:11:46 25 4
gpt4 key购买 nike

我正在尝试使用 firebase admin sdk 生成自定义 token

const uid = '91f0bf4c-3e3c-441c-a21d-6a7fee341db5'
firebaseAdmin.auth().createCustomToken(uid)

使用这个特定的 uid 有时自定义 token 可以工作,其他时候在客户端使用 authWithCustomToken() 时我会收到此错误:

“auth/invalid-custom-token” The custom token format is incorrect. Please check the documentation."

有什么方法可以调试 token 发生的情况吗?从表面上看,“好”标记和“坏”标记看起来相同:

它们有 3 个部分,由 分隔。

  • 第一部分长 36 个字符,在工作情况和损坏情况下都是完全相同的
  • 在这两个示例中,第二部分都是 392 个字符,并且几乎完全相同
  • 这两个示例中,第三部分的长度都是 342 个字符,并且它们是不同的。

最佳答案

你可以去https://jwt.io吗?并解码您的自定义 token 。它应该看起来像这样:

{
"uid": "some-uid",
"iat": 1500147255,
"exp": 1500150855,
"aud": "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit",
"iss": "firebaseserviceaccount@YOUR_PROJECT_ID.iam.gserviceaccount.com",
"sub": "firebaseserviceaccount@YOUR_PROJECT_ID.iam.gserviceaccount.com"
}

YOUR_PROJECT_ID 应与客户端项目上的同一项目匹配。

关于firebase 身份验证/无效的自定义 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45110441/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com