You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter/Firebase Cloud Function IAM认证401错误求助

Cloud Functions私有认证函数调用401错误问题

无法为Cloud Function配置安全防护,使用HttpsCallable或HttpsCallableFromUrl调用时始终返回401错误,尽管服务账户配置看似正确。我希望我的函数是带认证的私有函数。

Flutter调用代码

final result = await firebaseFunctions
          .httpsCallableFromUrl(
            'https://us-central1-NAME_PROJECT.cloudfunctions.net/Prova'
          )
          .call();

Cloud Function代码

const { logger } = require("firebase-functions/v2");
const { initializeApp } = require("firebase-admin/app");
const { getFirestore } = require("firebase-admin/firestore");
const { onCall } = require("firebase-functions/v2/https");

initializeApp();

exports.Prova = onCall(async (data) => {
  try {
    return { success: true, message: 'ok' };
  } catch (error) {
    logger.error(error.message);
    return{ message: 'Error' };
    //res.status(500).send({ message: 'Internal Error' });
  }
});

Cloud Function日志

2024-11-25 18:33:09.832 CET
POST401 0 B 0 ms com.TEAM.NAMEAPP.dev/0.0.18 iPhone/17.4 hw/sim  https://us-central1-NAME_PROJECT.cloudfunctions.net/Prova 
{
httpRequest: {14}
insertId: "6744b4d5000ce64c3251f6a2"
jsonPayload: null
labels: {1}
logName: "projects/NAME_PROJECT/logs/run.googleapis.com%2Frequests"
operation: null
payload: "textPayload"
protoPayload: null
receiveLocation: "us-central1"
receiveTimestamp: "2024-11-25T17:33:09.853205510Z"
resource: {2}
severity: "WARNING"
sourceLocation: null
spanId: "5d2908f5a604aad7"
split: null
textPayload: "The request was not authorized to invoke this service. Read more at https://cloud.google.com/run/docs/securing/authenticating Additional troubleshooting documentation can be found at: https://cloud.google.com/run/docs/troubleshooting#401"
timestamp: "2024-11-25T17:33:09.832156Z"
trace: "projects/NAME_PROJECT/traces/d0f2a1b62b9b9d729cb95b03ad853ca5"
traceSampled: true
}

附带日志堆栈追踪截图。


内容的提问来源于stack exchange,提问作者Luciano d'Agostino

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 22:46:10