Authentication with Service Account
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 could you show me how to do Authentication with Service Account? Many thanks.
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
Create
Kreait\Firebase\Factory()instance using your service account credentials and then createMrShan0\PHPFirestore\FirestoreClient('firebase-project-id', null). Yes, you can pushnullas your API Key. Then usesetHttpClient($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