laravel-firebase: No such file or directory for service account json

Hi, I’m trying to use this package but I get this error:

Kreait\Firebase\Exception\InvalidArgumentException
google-service-account.json can not be read: SplFileObject::__construct(google-service-account.json): 
failed to open stream: No such file or directory

I set the firebase service account json path in the env file in this way FIREBASE_CREDENTIALS=google-service-account.json and FIREBASE_CREDENTIALS=/google-service-account.json

but it doesn’t work, I’m trying to run this code in a HTTP Controller class FirebaseAuth::listUsers();

The google-service-account.json file is in the Laravel project root folder along with composer.json etc.

What’s the issue ? Thanks

UPDATE: I’m on windows 10 and if I give the full path like so FIREBASE_CREDENTIALS="C:\\xampp\\htdocs\\my-laravel-app\\google-service-account.json" It works, how do I make it work with relative path ?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 21 (10 by maintainers)

Most upvoted comments

@chimit @ulver2812 Could you please try the two following alternatives?

'credentials' => [
    'file' => base_path().DIRECTORY_SEPARATOR.env('FIREBASE_CREDENTIALS'),
],

or

'credentials' => [
    'file' => base_path(env('FIREBASE_CREDENTIALS'))
],

Please also make sure that, if on Windows, you use \\ instead of / in your .env file, I think otherwise the paths will not be resolved

If somebody of you guys is still having this issue in Laravel 5.8. You can use the php function realpath to do the following in the config/firebase.php file:

'credentials' => [
        // For this example the FIREBASE_CREDENTIALS_FILENAME is in the project 's root folder
        'file' => realpath('.' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . env('FIREBASE_CREDENTIALS_FILENAME')),
        'auto_discovery' => true,
    ],

Ah, sorry! My mistake! Just realized that I forgot to apply config in the bootstrap/app.php (Lumen):

$app->configure('firebase');

So yes, this config works:

'credentials' => [
        'file' => base_path(env('FIREBASE_CREDENTIALS')),