title: google firebase how to authentication server with php
body: <p>I'm making an app with new launched google firebase service. </p>
  
  <p>My backend service written with PHP, but I do not find how to authenticate my server with firebase database.</p>
  
  <p>Google provide java/node.js sdk to auth server like following:</p>
  
  <p><a href="https://firebase.google.com/docs/database/server/start#authenticate-with-limited-privileges" rel="nofollow noreferrer">https://firebase.google.com/docs/database/server/start#authenticate-with-limited-privileges</a></p>
  
  <pre><code>// Initialize the app with a custom auth variable, limiting the server's access
  Map&lt;String, Object&gt; auth = new HashMap&lt;String, Object&gt;();
  auth.put("uid", "my-service-worker");
  
  FirebaseOptions options = new FirebaseOptions.Builder()
  .setDatabaseUrl("https://databaseName.firebaseio.com")
  .setServiceAccount(new     FileInputStream("path/to/serviceAccountCredentials.json"))
  .setDatabaseAuthVariableOverride(auth)
  .build();
  FirebaseApp.initializeApp(options);
  
  // The app only has access as defined in the Security Rules
  DatabaseReference ref = FirebaseDatabase
  .getInstance()
  .getReference("/some_resource");
  ref.addListenerForSingleValueEvent(new ValueEventListener() {
  @Override
  public void onDataChange(DataSnapshot dataSnapshot) {
      String res = dataSnapshot.getValue();
      System.out.println(res);
  }
  });
  </code></pre>
  
  <p>In REST section, no auth method mentioned, and I found a php helper libary :
  <a href="https://github.com/ktamas77/firebase-php" rel="nofollow noreferrer">https://github.com/ktamas77/firebase-php</a></p>
  
  <p>The auth sample code is to use url and token</p>
  
  <pre><code>const DEFAULT_URL = 'https://kidsplace.firebaseio.com/';
  const DEFAULT_TOKEN = 'MqL0c8tKCtheLSYcygYNtGhU8Z2hULOFs9OKPdEp';
  const DEFAULT_PATH = '/firebase/example';
  
  $firebase = new \Firebase\FirebaseLib(DEFAULT_URL, DEFAULT_TOKEN);
  
  
  $dateTime = new DateTime();
  $firebase-&gt;set(DEFAULT_PATH . '/' . $dateTime-&gt;format('c'), $test);
  </code></pre>
  
  <p>Is this work for new google firebase service ?  How can I auth my server with the "serviceAccountCredentials.json" file created in google developer console? thanks!</p>