2016-05-24 21 views
3

私は新しいGoogleのfirebaseサービスを開始してアプリを作っています。google firebase phpでサーバを認証する方法

私のバックエンドサービスはPHPで書かれていますが、firebaseデータベースで私のサーバを認証する方法は見つかりません。

GoogleがJavaの提供/ Node.jsのは、次のようにサーバーをのauthする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); 
} 

}); RESTセクション、述べていない認証方法では

、と私はPHPのヘルパーlibaryが見つかりました: https://github.com/ktamas77/firebase-php

認証のサンプルコードは、URLを使用することで、トークン

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); 

は、新しいGoogleのためにこの作品ですファイヤーベースサービス? Google Developer Consoleで作成した「serviceAccountCredentials.json」ファイルを使用してサーバーを認証するにはどうすればよいですか?ありがとう!

+0

あなたはPHPライブラリに対して認証するためのトークンを取得する方法を知りましたか? – Simon

答えて

0

必要なのは、それは私が使用しているものだが、このPHP firebaseクラスであり、私はそれが動作を伝えることができ、でも、ローカルホスト上の

のGithub:https://github.com/eosobande/php-firebase-class

作業のほとんどは、クラスによって行われています、それをインポートしてreadmeを確認してください

+0

これがどのようにOPに役立つのか説明してください。リンクのみの回答は誰にも役立ちません。 –

関連する問題