Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Admin Auth Token Revoked

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.
like image 990
genghiskhan Avatar asked Nov 09 '22 04:11

genghiskhan


1 Answers

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.

like image 95
genghiskhan Avatar answered Nov 15 '22 11:11

genghiskhan