title: firebase server Authenticate with admin privileges
body: <p>I am trying to setup firebase server using nodejs as discussed <a href="https://firebase.google.com/docs/database/server/start" rel="nofollow">Here</a>. However my code is not able to read or wite data from/to any tables using admin privileges even the ones with public read and write access.</p>
  
  <p>This is my code from the server side: </p>
  
  <pre><code>var firebase = require('firebase');
  firebase.initializeApp({
  serviceAccount: "./App.json",
  databaseURL: "https://userPosts.firebaseio.com"
  });
  //
  var db = firebase.database();
  var ref = db.ref("testPosts");
  
  ref.once("value", function(snapshot){
      console.log(snapshot.val());
  }, function(error){
      console.log(error);
  });
  </code></pre>
  
  <p>The code below is how the security is set on the server:</p>
  
  <pre><code>"rules": {
    "users": {
      "$uid": {
        ".read": "auth != null &amp;&amp; auth.uid == $uid",
        ".write": "auth != null &amp;&amp; auth.uid == $uid"
      }
    },
  "testPosts": {
      ".read": "auth != null",
      ".write": "auth != null"
    }
  }
  </code></pre>
  
  <p>If I comment the serviceAccount line on the server side, the data will be read with no issue and access will be denied when I try to access a node that it does not have access ( which is normal behaviour).</p>
  
  <p>My understanding of Firebase admin privileges is that I should have access to all table nodes regardless of the access privilege.</p>
  
  <p>I would really appreciate if someone can help with this issue. I have been stuck on it for a while now. </p>
  
  <p>-----------------------Edit----------------</p>
  
  <p>I have enabled debugging by adding</p>
  
  <pre><code>firebase.database.enableLogging(true);
  </code></pre>
  
  <p>and I get the following error: </p>
  
  <pre><code>p:0: Listen called for /posts default
  p:0: Making a connection attempt
  p:0: Failed to get token: Error: Error refreshing access token:     invalid_grant (Invalid JWT: Token must be a short-lived token and in a reasonable timeframe)
  p:0: data client disconnected
  p:0: Trying to reconnect in 77.64995932509191ms
  0: onDisconnectEvents
  </code></pre>
  
  <p>Can anybody help with the error and what it really means?</p>