google firebase 如何使用 php 验证服务器

Eri*_*eng 6 php firebase-authentication firebase-realtime-database

我正在使用新推出的 google firebase 服务制作应用程序。

我的后端服务是用 PHP 编写的,但我没有找到如何使用 Firebase 数据库对我的服务器进行身份验证。

Google 向身份验证服务器提供 java/node.js sdk,如下所示:

https://firebase.google.com/docs/database/server/start#authenticate-with-limited-privileges

// Initialize the app with a custom auth variable, limiting the server's access
Map<String, Object> auth = new HashMap<String, Object>();
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);
}
});
Run Code Online (Sandbox Code Playgroud)

在 REST 部分,没有提到身份验证方法,我找到了一个 php helper 库:https : //github.com/ktamas77/firebase-php

auth示例代码是使用url和token

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->set(DEFAULT_PATH . '/' . $dateTime->format('c'), $test);
Run Code Online (Sandbox Code Playgroud)

这适用于新的 google firebase 服务吗?如何使用在 google 开发者控制台中创建的“serviceAccountCredentials.json”文件对我的服务器进行身份验证?谢谢!