【问题标题】:Firebase createCustomToken() returns an invalid token in local emulatorsFirebase createCustomToken() 在本地模拟器中返回无效令牌
【发布时间】:2021-05-29 04:59:02
【问题描述】:

我正在使用 firebase 身份验证来处理我的 Web 应用程序的用户帐户。当用户输入有效的登录凭据时,我正在使用 firebase admin SDK 在云函数中生成 JWT,然后将其发送回客户端,然后通过 firebase 进行身份验证。我遇到了由 firebase admin SDK 生成的 JWT 无效的问题。更具体地说,当令牌被解码(我使用jwt.io)时,我得到以下信息:

Header: {
  "alg": "none",
  "typ": "JWT"
}

Payload: {
  "aud": "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit",
  "iat": 1614367953,
  "exp": 1614371553,
  "iss": "firebase-auth-emulator@example.com",
  "sub": "firebase-auth-emulator@example.com",
  "uid": "some uid here"
}

令牌不仅缺少签名,而且 isssub 值错误。我正在使用admin.auth().createCustomToken(uid) 生成令牌,并且正在使用具有服务令牌创建权限的有效服务帐户初始化应用程序。

编辑: 我刚刚发现只有在使用 firebase 模拟器在本地运行所有内容时才会错误地生成令牌。当我部署应用程序时,生成并验证了令牌就好了。

【问题讨论】:

    标签: firebase-authentication google-cloud-functions jwt firebase-tools


    【解决方案1】:

    确保您是instrumenting your app to talk to the authentication emulator ...并在身份验证侦听器执行其操作之前执行此操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-29
      • 1970-01-01
      相关资源
      最近更新 更多