【问题标题】:getting error : Your client does not have permission to get URL in firebase functions出现错误:您的客户端无权在 firebase 函数中获取 URL
【发布时间】:2020-05-13 18:28:21
【问题描述】:

我是firebase的新手,我已经部署了一个功能,它正在使用get方法,

https://us-central******.cloudfunctions.net/addMessage

当我尝试运行这个 api 时,我遇到了错误

Error: Forbidden
Your client does not have permission to get URL /addMessage from this server.

谁能帮我解决这个问题?

exports.addMessage = functions.https.onRequest(async (req, res) => {
    // Grab the text parameter.
    const original = req.query.text;
    // Push the new message into the Realtime Database using the Firebase Admin SDK.
    const snapshot = await admin.database().ref('/messages').push({ original: original });
    // Redirect with 303 SEE OTHER to the URL of the pushed object in the Firebase console.
    res.redirect(303, snapshot.ref.toString());
});

【问题讨论】:

标签: node.js firebase firebase-realtime-database google-cloud-functions


【解决方案1】:

来自doc,参数--allow-unauthenticated

指定调用该函数不需要身份验证。默认情况下,HTTP 函数需要身份验证。如果您在首次部署 HTTP 函数时未包含此标志,系统会提示您允许未经身份验证的调用。后续调用不会提示您。

因此,如果您不需要身份验证,则需要使用此参数部署云功能。例如

一个简单的云函数,index.js

exports.helloHttp = (req, res) => {
  res.send(`Hello ${req.body.name || 'World'}!`);
};

在没有--allow-unauthenticated 的情况下部署:

gcloud beta functions deploy helloHttp --trigger-http --runtime nodejs10

当您访问此云函数的端点时:https://us-central1-xxxx-218801.cloudfunctions.net/helloHttp。你会得到这个403 Forbidden 错误:

错误:禁止 您的客户端无权从此服务器获取 URL /helloHttp。

部署 --allow-unauthenticated:

gcloud beta functions deploy helloHttp --trigger-http --runtime nodejs10 --allow-unauthenticated

您无需身份验证即可访问端点。

Hello World!

【讨论】:

    猜你喜欢
    • 2020-07-16
    • 1970-01-01
    • 2018-05-10
    • 2020-06-07
    • 2022-07-20
    • 1970-01-01
    • 2023-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多