gpt4 book ai didi

javascript - Firebase 云功能中的权限被拒绝

转载 作者:行者123 更新时间:2023-11-29 19:03:56 25 4
gpt4 key购买 nike

在 firebase 云功能中,我在 admin-firebase 上读取或写入实时数据库时被拒绝访问。这https://github.com/firebase/firebase-functions/issues/16没有解决我的问题,App 引擎默认服务帐户权限设置为编辑器。

我还使用服务帐户 key 配置了 Node.js admin sdk,一切都按预期进行。

我在数据库中设置了默认的安全规则。

这是一个示例函数

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
admin.database.enableLogging(true);

//event fires properly
exports.sendNotif = functions.database.ref('/messages/{roomId}/{msgKey}')
.onWrite(event => {
const message = event.data.val().text;
//this executes as expected
console.log(message);

//here I am getting access denied and consequently function timeout after 60 seconds.
return admin.database().ref('/userFCMTokens').once('value')
.then(snap => console.log(snap.val()));
});

这是来自 firebase 实时数据库的日志片段

Realtime connection established.  
2017-06-08T15:19:03.168Z I sendNotif: p:0: connection ready
2017-06-08T15:19:03.168Z I sendNotif: p:0: {"r":28,"a":"gauth","b":{"cred”:”********************”}}
2017-06-08T15:19:03.169Z I sendNotif: p:0: Listen on /userFCMTokens for default
2017-06-08T15:19:03.169Z I sendNotif: p:0: {"r":29,"a":"q","b":{"p":"/userFCMTokens","h":""}}
2017-06-08T15:19:03.538Z I sendNotif: p:0: from server: {"r":28,"b":{"s":"permission_denied","d":"Access denied."}}
2017-06-08T15:19:03.538Z I sendNotif: Auth token revoked: permission_denied/Access denied.
2017-06-08T15:19:03.538Z I sendNotif: c:0:13: Closing realtime connection.
2017-06-08T15:19:03.538Z I sendNotif: c:0:13: Shutting down all connections
2017-06-08T15:19:03.538Z I sendNotif: c:0:13:0 WebSocket is being closed

为简洁起见,这里没有登录实时数据库:

2017-06-08T15:26:23.164035495Z D sendNotif: Function execution started
2017-06-08T15:26:23.164076543Z D sendNotif: Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
2017-06-08T15:26:23.539Z I sendNotif: message console logged
2017-06-08T15:27:23.165321703Z D sendNotif: Function execution took 60002 ms, finished with status: 'timeout'

为什么在云函数中使用admin无法读写?

最佳答案

尝试在 https://console.cloud.google.com/iam-admin/iam/project 上检查“App Engine 默认服务帐户”的权限,并确保它显示“编辑器”。

关于javascript - Firebase 云功能中的权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44440897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com