morrislaptop / firestore-php

Firestore SDK for PHP without gRPC
MIT License
67 stars 31 forks source link

openssl_sign(): supplied key param cannot be coerced into a private key #16

Closed ronlinet closed 4 years ago

ronlinet commented 4 years ago

I can't add a document into a collection.

$serviceAccount = ServiceAccount::fromJsonFile( storage_path()  . '/app/google-services.json');

        $firestore = (new Factory)
            ->withServiceAccount($serviceAccount)
            ->createFirestore();

        $collection = $firestore->collection('alerts');

        $doc = $collection->document('name of new document');
        $doc->set(['body' => 'est','date' => 'est','image' => 'est','headline' => 'est' ] );

The above code throws open_ssl() error :

In ApiClient.php line 58:

  openssl_sign(): supplied key param cannot be coerced into a private key  

In JWT.php line 199:

  openssl_sign(): supplied key param cannot be coerced into a private 

I am using the bellow json format for google-services.json

{
  "project_id": "xxxx",
  "private_key": "xxxx",
  "client_id": "xxxx",
  "client_email": "xxx"
}
ronlinet commented 4 years ago

Sorted out by generating the JSON credential file through https://console.cloud.google.com/iam-admin/serviceaccounts instead of https://console.firebase.google.com/u/0/project .