firestore-php icon indicating copy to clipboard operation
firestore-php copied to clipboard

Authentication with Service Account

Open universe-42 opened this issue 5 years ago • 3 comments

According to official Google library its the best way how to work with resources (at least for beginners). I can try write PR, but please tell me your opinion for this. Thanks.

Do not use API keys for local or production applications. For almost all cases, you should use service accounts. (Authentication DOC)

universe-42 avatar May 10 '20 06:05 universe-42

@universe-42 could you show me how to do Authentication with Service Account? Many thanks.

superbigsoft avatar Jun 30 '20 23:06 superbigsoft

Create Kreait\Firebase\Factory() instance using your service account credentials and then create MrShan0\PHPFirestore\FirestoreClient('firebase-project-id', null). Yes, you can push null as your API Key. Then use setHttpClient($FACTORY->createApiClient()); to use the Service Account credentials with FirestoreClient.

Example:-

$FACTORY = (new \Kreait\Firebase\Factory)->withServiceAccount('service-account-path.json');
$FIRESTORE_CLIENT = new MrShan0\PHPFirestore\FirestoreClient('project-id', null);
$FIRESTORE_CLIENT->setHttpClient($FACTORY->createApiClient());
var_dump($FIRESTORE_CLIENT->listDocuments('/some-collection/')); //Works Perfectly

itsyourap avatar Jan 19 '22 04:01 itsyourap

Create Kreait\Firebase\Factory() instance using your service account credentials and then create MrShan0\PHPFirestore\FirestoreClient('firebase-project-id', null). Yes, you can push null as your API Key. Then use setHttpClient($FACTORY->createApiClient()); to use the Service Account credentials with FirestoreClient.

Example:-

$FACTORY = (new \Kreait\Firebase\Factory)->withServiceAccount('service-account-path.json');
$FIRESTORE_CLIENT = new MrShan0\PHPFirestore\FirestoreClient('project-id', null);
$FIRESTORE_CLIENT->setHttpClient($FACTORY->createApiClient());
var_dump($FIRESTORE_CLIENT->listDocuments('/some-collection/')); //Works Perfectly

not working on lastest version

Saifallak avatar Sep 06 '22 15:09 Saifallak