小编Eri*_*eng的帖子

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

我正在使用新推出的 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)

php firebase-authentication firebase-realtime-database

6
推荐指数
0
解决办法
4260
查看次数