【问题标题】:Firebase Functions - getting a 403 Forbidden error after deploying my functionsFirebase 函数 - 部署我的函数后出现 403 Forbidden 错误
【发布时间】:2021-10-05 11:40:31
【问题描述】:

我刚刚开始使用 Firebase 函数。我已经使用模拟器套件成功测试,并且看到我的功能运行良好。但是,在部署我的函数并尝试访问为我的函数生成的 URL 时,我收到 403 Forbidden 错误。

我检查了 Google Cloud IAM 控制台,发现我当前的帐户被设置为该函数的 Owner 角色,但我还添加了“Cloud Functions Admin”角色。

尽管有这些权限,但我在尝试访问我的函数时仍然看到 403 Forbidden 错误。

我不希望公开我的函数,尽管我确实在启用公共访问的情况下执行了一个测试,并且我能够访问我的函数并且它成功运行。不过,我在此测试后撤销了公共访问权限,并希望将该功能保持为私有。我看到的这个问题的大多数答案只是说通过将“allUsers”成员设置为具有“调用云功能”角色来打开该功能以供公众访问。

我不确定还可以尝试什么。任何帮助将不胜感激!

【问题讨论】:

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


    【解决方案1】:

    如果您的函数中没有login authentication or verifying identity of the users,则您无法直接访问需要身份验证的 Cloud/Firebase 函数,这意味着您需要为其构建/编码一个函数。

    您可以通过 CLI 使用 curl 测试您的 Cloud Function,但您将使用 gcloud auth print-identity-token 进行身份验证,例如:

    curl https://REGION-PROJECT_ID.cloudfunctions.net/FUNCTION_NAME \
      -H "Authorization: bearer $(gcloud auth print-identity-token)"
    

    要访问您的 Cloud/Firebase 函数,您可以集成 Google Sign-In with Firebase Authentication,Stack Overflow 中有很多示例和说明如何访问需要身份验证的 Cloud/Firebase 函数,这取决于您的情况:

    1. Callable Function
    2. Generate Token(google-auth-library)
    3. from `firebase-admin
    4. Another example of Cloud Function with Firebase Authentication
    5. Limit access to your Cloud Function Answer/Explanation
    6. Background Information

    【讨论】:

      猜你喜欢
      • 2021-06-16
      • 2022-01-09
      • 2017-12-12
      • 2018-09-13
      • 1970-01-01
      • 2018-08-04
      • 2021-05-06
      • 2022-08-21
      • 1970-01-01
      相关资源
      最近更新 更多