【问题标题】:Firebase Functions: setup Admin Sdk without service-account.json fileFirebase 功能:设置没有 service-account.json 文件的 Admin Sdk
【发布时间】:2017-12-28 06:59:39
【问题描述】:

我正在尝试在 Firebase 上部署我的功能而不需要将 service-account.json 文件添加到我的项目中。这在部署时会在某些功能上随机出现以下错误:

编译环境出错

我正在使用的解决方案在firebase docs中给出使用

admin.initializeApp(functions.config().firebase);

如果使用上述初始化的所有函数的部署都成功,那么当我尝试使用 admin sdk 在我的函数中创建自定义令牌时它会失败,并出现以下错误:

Error: createCustomToken() requires a certificate with "private_key" set.
    at FirebaseAuthError.Error (native)
    at FirebaseAuthError.FirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:39:28)
    at FirebaseAuthError.PrefixedFirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:85:28)

使用这个解决方案有什么问题吗?或者如果我们需要铸造自定义令牌,我们是否需要包含 service-account.json 文件?

【问题讨论】:

  • 嗨 Umar,使用默认身份验证 admin.initializeApp(functions.config().firebase) 应该可以工作,并且不需要私有凭据 json 文件。可能是您不止一次初始化 Firebase 应用程序吗?根据我的经验,这可能会导致部署问题。应该为您的所有功能只启动一个 firebase 应用实例。
  • 我尝试降级版本的函数和管理库,现在它们工作正常。
  • 我认为问题在于较新版本的库
  • 您好,部署成功,但是在铸造自定义令牌时仍然存在上述错误,当触发函数时,它显示与需要私钥相同的错误。

标签: firebase google-cloud-functions


【解决方案1】:

来自firebase admin node js docs

警告:自定义令牌创建仅在 SDK 使用服务帐户(证书)凭据进行身份验证时有效。

看来您必须使用显式 JSON 身份验证才能在函数中生成令牌。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-25
    • 2022-11-02
    • 2019-12-30
    • 1970-01-01
    • 1970-01-01
    • 2017-12-13
    相关资源
    最近更新 更多