![](/img/trans.png)
[英]Flutter Firebase Auth - Your client does not have permission to get URL
[英]getting error : Your client does not have permission to get URL in firebase functions
我是firebase的新人,我已经部署了一个function,它使用的是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());
});
从文档中,参数--allow-unauthenticated
:
指定 function 不需要身份验证即可调用。 默认情况下 HTTP 功能需要身份验证。 如果您在第一次部署 HTTP function 时未包含此标志,系统会提示您允许未经身份验证的调用。 后续调用不会提示您。
因此,如果您不需要身份验证,则需要使用此参数部署云功能。 例如
一个简单的云 function, index.js
:
exports.helloHttp = (req, res) => {
res.send(`Hello ${req.body.name || 'World'}!`);
};
不使用--allow-unauthenticated
进行部署:
gcloud beta functions deploy helloHttp --trigger-http --runtime nodejs10
当您访问此云 function 的端点时: 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!
我今天遇到了这个(或非常类似的问题)。 当我从 Postman 调用我的一个函数时,我得到:
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>401 Unauthorized</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Unauthorized</h1>
<h2>Your client does not have permission to the requested URL
<code>/myApi/somePath?</code>.</h2>
<h2></h2>
</body>
</html>
我尝试重新部署这些功能,但没有奏效。
解决方案:删除您的函数并重新部署它们。
我所做的是:
functions/index.ts
中导出了一个虚拟 function 并删除了我原来的函数。背景和可能的原因
我有一个新的Firebase
项目,我尝试多次部署我的功能,但遇到了一些与权限相关的错误。 我想这把函数留在了一个奇怪的 state 中......
后来我设法成功部署了这些功能,但它们不在一个好的 state 中,当我打电话给其中一个时,我从Postman
收到了错误响应。
我得到的错误如下:
错误一:
Error: Missing permissions required for functions deploy. You must have permission iam.serviceAccounts.ActAs on service account some-sa@appspot.gserviceaccount.com.
错误2:
Error: Missing permissions required for functions deploy. You must have permission iam.serviceAccounts.ActAs on service account some-sa@appspot.gserviceaccount.com.
错误 3:
Unable to set the invoker for the IAM policy on the following functions:
someFunction1(us-central1)
someFunction2(us-central1)
Some common causes of this:
- You may not have the roles/functions.admin IAM role. Note that roles/functions.developer does not allow you to change IAM policies.
在尝试删除个别功能并再次上传它们之后,我最终不得不删除所有以前部署的功能并将它们全部部署。
一旦我这样做了几次,就部署了这些功能。
我可以想到有两个可能的原因导致了这种情况,两者都非常模棱两可。
我发现有一个有问题的文件,修复部署的唯一方法是更改文件名的长度。 是的,文件名的长度。 一个字符太长,部署失败。 如果这是一台 windows 95 机器,我会说 inheritance 链路径对于编译器来说太长了。 但是,在模拟器上编译和运行工作正常。 那么谁知道呢。
我曾尝试设置云构建,并将该部分完成了一半。 作为其中的一部分,我已经更新了.firebaserc。 也许,只是也许,部署不喜欢默认项目列表已更改的事实,并且与现有功能不匹配。
我完全猜测原因,但由于错误是如此模棱两可,没有明显的原因,因此认为这可能有助于人们找到原因。
如果您使用了错误的子路径,也会发生这种情况。 对我来说,url 有点错误,它试图调用 resendConfirmEmail%20 而不是 resendConfirmEmail。 function 不存在,谷歌以 403 响应:
https://europe-west1-my-project.cloudfunctions.net/resendConfirmEmail%20?userId=imFeBoV...&email=gr...%40...com
应该是什么时候:
https://europe-west1-my-project.cloudfunctions.net/resendConfirmEmail?userId=imFeBoV...&email=gr...%40...com
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.