Firebase Admin Auth Token Revoked

602 views Asked by At

I am attempting to implement a node.js server to listen to changes in my firebase database. This is my code to initialize the server:

var admin = require('firebase-admin');
var serviceAccount = require('./SERVICE-ACCOUNT.json');

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://APP-NAME.firebaseio.com"
});

var db = admin.database();
admin.database.enableLogging(true);
var convRef = db.ref('conversations');
convRef.once('value', function(snapshot) {
  console.log("VALUE: " + snapshot.val());
}, function(error) {
  console.log("ERROR: " + error.code);
});

With debugging enabled, I receive the errors:

p:0: Listen called for /conversations default  
p:0: Making a connection attempt  
p:0: Auth token refreshed  
getToken() completed. Creating connection. 
c:0:0: Connection created  
c:0:0:0 Websocket connecting to wss://APP-NAME.firebaseio.com/.ws?v=5  
c:0:0:0 Websocket connected.  
c:0:0: Reset packet received.  New host: s-usc1c-nss-123.firebaseio.com  
c:0:0: Shutting down all connections  
c:0:0:0 WebSocket is being closed  
c:0:0:0 Websocket connection was disconnected.  
c:0:0:1 Websocket connecting to wss://s-usc1c-nss-123.firebaseio.com/.ws?v=5&ns=APP-NAME 
c:0:0:1 Websocket connected.  
c:0:0: Realtime connection established.  
p:0: connection ready  
p:0: reportStats {"c":{"sdk.js.4-0-4":1}}  
p:0: {"r":1,"a":"s","b":{"c":{"sdk.js.4-0-4":1}}}  
p:0: {"r":2,"a":"gauth","b":{"cred":"REDACTED"}}  
p:0: Listen on /conversations for default  
p:0: {"r":3,"a":"q","b":{"p":"/conversations","h":""}}  
p:0: from server: {"r":1,"b":{"s":"ok","d":""}}  
c:0:0: Primary connection is healthy.  
p:0: from server: {"r":2,"b":{"s":"permission_denied","d":"Access denied."}}  
Auth token revoked: permission_denied/Access denied.
1

There are 1 answers

0
genghiskhan On BEST ANSWER

I realized I created my service account in the wrong place. Since I wasn't the owner of the project, it wasn't valid. I got the owner of the project to create a service account for me and everything works now.