Firebase 云功能“您的客户端无权从此服务器获取 URL/200" [英] Firebase cloud function "Your client does not have permission to get URL /200 from this server"
问题描述
我刚刚做了一个firebase云功能:
I just made a firebase cloud function :
exports.deleteAfterSevenDays = functions.https.onRequest((req, res) => {...
我部署了函数并获得了函数 URL.当我从浏览器请求此 url 时,我收到以下消息:
I deployed the function and got a function URL. When I request this url from my browser I get the following message :
"Error: Forbidden 您的客户端无权获取 URL/200从这个服务器."
"Error: Forbidden Your client does not have permission to get URL /200 from this server."
我刚刚更新到 firebase Blaze 计划,因为我认为 Spark 计划存在限制,但它仍然无法正常工作.
I have just updated to firebase Blaze plan because I thought there were limitations with Spark plan, but it still doesn't work.
在我的 firebase 云函数日志中写着函数执行耗时 572 毫秒,以状态码完成:302".
In my firebase cloud function logs it is written "Function execution took 572 ms, finished with status code: 302".
我的 cron 作业由于执行失败次数过多而被自动禁用".
My cron job "has been disabled automatically because of too many failed executions".
你知道有什么问题吗?
推荐答案
云函数应该有一个名为所有用户"的角色,可以从任何地方/任何人调用此函数,而无需考虑授权.
Cloud function should have a role with member called "All users" to invoke this function from anywhere/anyone irrespective of an authorization.
未经授权:
- 转到云功能标签
- 选择您的云功能(复选框)
- 点击右侧权限标签下的添加成员"
- 在新成员"下输入allUsers"
- 将角色选择为Cloud Functions -> Cloud Functions Invoker"
- 保存
- 只需将其粘贴到浏览器中即可测试您的云功能
授权:
在您的云功能上设置授权总是一个好习惯
It's always a good practice to set authorization on your cloud functions
注意:云函数抛出错误403 Forbidden - Your client does not have permission to get URL"应由授权用户调用.
Note: Cloud functions throwing error with "403 Forbidden - Your client does not have permission to get URL" should be called by authorized users.
简单测试:
点击顶部的 Cloud shell(icon) 终端
Click on Cloud shell(icon) terminal in the top
type - gcloud auth print-identity-token
type - gcloud auth print-identity-token
复制生成的令牌
在调用云函数时形成要传递的授权密钥4.1 授权:bearer generated_token
forming Authorization key to be passed while calling cloud function 4.1 Authorization: bearer generated_token
在调用云函数时使用上述授权密钥
Use above Authorization key while calling your cloud function
注意:
- 永远不要让所有用户都可以使用云功能
这篇关于Firebase 云功能“您的客户端无权从此服务器获取 URL/200"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!