Hellow,
I had the same issue while trying to authenticate with a service account credentials (those one should bypass the firestore rules if you gived them necesary permissions to performs certains actions, you can do this in the service account configuration).
To solve this issue I change the way that I was specifiying the key file path:
This way was given me exactly the above error, specifying the key file path with global variable GOOGLE_APPLICATION_CREDENTIALS just as Google quicstart documentation recommend you.
//
use Google\Cloud\Firestore\FirestoreClient;
/**
* Initialize Cloud Firestore with default project ID.
*/
function setup_client_create(string $projectId = null)
{
// This was working fine till I change my firestore rules
// to a more secure configuration
$_SERVER["GOOGLE_APPLICATION_CREDENTIALS"] = "/path/to/your/keyfile.json";
// Create the Cloud Firestore client
if (empty($projectId)) {
// The `projectId` parameter is optional and represents which project the
// client will act on behalf of. If not supplied, the client falls back to
// the default project inferred from the environment.
$db = new FirestoreClient();
printf('Created Cloud Firestore client with default project ID.' . PHP_EOL);
} else {
$db = new FirestoreClient([
'projectId' => $projectId
]);
printf('Created Cloud Firestore client with project ID: %s' . PHP_EOL, $projectId);
}
}
Then I try with this other way which allow me go through firestore rules.
In their repository you can see that FirestoreClient constructor have a configuration array as a parameter,
in this configuration array you can use the key "keyFilePath" to specify the path to your service account key file.
It's just the same thing that global variable GOOGLE_APPLICATION_CREDENTIALS was doing.
use Google\Cloud\Firestore\FirestoreClient;
/**
* Initialize Cloud Firestore with default project ID.
*/
function setup_client_create(string $projectId = null)
{
// Create the Cloud Firestore client
if (empty($projectId)) {
// The `projectId` parameter is optional and represents which project the
// client will act on behalf of. If not supplied, the client falls back to
// the default project inferred from the environment.
$db = new FirestoreClient();
printf('Created Cloud Firestore client with default project ID.' . PHP_EOL);
} else {
// I specified the key file path in the configuration array of
// FirestoreClient constructor
// Doing it this way worked nice for me and
// my requests started going through firestore rules
$db = new FirestoreClient([
'keyFilePath' => '/path/to/your/keyfile.json'
'projectId' => $projectId,
]);
printf('Created Cloud Firestore client with project ID: %s' . PHP_EOL, $projectId);
}
}
I hope it helps you and everyone having the same issue.