Firebase令牌错误,“自定义令牌对应于其他受众". [英] Firebase token error, "The custom token corresponds to a different audience."

查看:53
本文介绍了Firebase令牌错误,“自定义令牌对应于其他受众".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用服务器上的Ruby为Firebase生成JWT令牌.在3.0之前的版本中,我们使用了令牌生成器,但升级后它停止了工作.我通过下面的代码获得的令牌给出了错误:

I'm trying to generate JWT token for Firebase using Ruby on the server. Before 3.0 we used token generator but it stopped working after the upgrade. The token I get with code below gives an error:

自定义标记对应于不同的受众.

The custom token corresponds to a different audience.

我什么地方都找不到.

private_key = OpenSSL::PKey::RSA.new <<-PEM
-----BEGIN PRIVATE KEY-----
..redacted..
-----END PRIVATE KEY-----
PEM

service_account_email = 'redacted@redacted.iam.gserviceaccount.com'
now_seconds = Time.now.to_i

payload = {
  iss: service_account_email,
  sub: service_account_email,
  aud: 'https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit',
  iat: now_seconds,
  exp: now_seconds + (60 * 60),
  uid: self.id.to_s,
  debug: true,
  claims: {
    userId: self.id,
    slug: self.slug,
    username: self.username,
    avatar: self.profile.avatar.url,
    group: self.group,
    debug: true
  }
}

JWT.encode payload, private_key, 'RS256'

谢谢

推荐答案

我也遇到了此错误, 我之所以这样,是因为我使用了与Firebase项目无关的服务帐户. 在firebase项目下使用新密钥创建新的服务帐户后,它开始工作.

I got this error too, I got that because I used a service account that was not related to the firebase project. After creating new service account with new key under the firebase project its started to work.

要创建服务帐户,您可以按照以下说明进行操作: https://firebase.google.com /docs/server/setup

For creating service account you can follow the instructions here : https://firebase.google.com/docs/server/setup

这篇关于Firebase令牌错误,“自定义令牌对应于其他受众".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆