In Firebase Cloud-Funktion bekomme ich Zugriff auf Admin-Firebase beim Lesen oder Schreiben in Echtzeit-Datenbank verweigert. Diese https://github.com/firebase/firebase-functions/issues/16 löst mein Problem nicht, App Engine Standard-Dienstkonto Rechte sind auf Editor festgelegt.Berechtigung in Firebase Cloud-Funktionen verweigert
Ich habe auch Node.js Admin SDK mit Service Account Key konfiguriert und dort funktioniert alles wie erwartet.
Ich habe Standard Sicherheitsregeln in db festgelegt.
Dies ist ein Beispiel Funktion
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()));
});
und hier ist log Schnipsel aus Feuerbasis in Echtzeit db
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
hier ohne Kürze halber auf Realtime db Anmeldung:
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'
Warum kann ich nicht lesen und schreiben mit Admin in Cloud-Funktionen?
Darf ich fragen, warum Sie das Firebase Admin SDK anstelle von event.data.adminRef.root verwenden und dann den Pfad zu '/ userFCMTokens' erstellen? –
Ich folge diesem Beispiel, https://github.com/firebase/functions-samples/blob/master/fcm-notifications/functions/index.js. Ich werde versuchen, wie Sie vorschlagen. –
Ich sehe! Nun, dies spricht nicht an, warum Sie den permission_denied-Fehler erhalten, aber ich würde empfehlen, event.data.adminRef.root anstelle von admin.database.ref() zu versuchen. –