Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No such file or directory for service account json #7

Closed
ulver2812 opened this issue Dec 29, 2019 · 21 comments
Closed

No such file or directory for service account json #7

ulver2812 opened this issue Dec 29, 2019 · 21 comments

Comments

@ulver2812
Copy link

ulver2812 commented Dec 29, 2019

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 ?

@ulver2812
Copy link
Author

Possible solution is to use base_path() in the config file:

'credentials' => [
        'file' => base_path() . '/' . env('FIREBASE_CREDENTIALS'),
        'auto_discovery' => true,
    ],

@jeromegamez
Copy link
Member

Sorry for the late reply! This is probably something that I should investigate in the main SDK - it seems to be a Windows issue, I just tried it with a relative path like yours, and it works on my machine(™).

@jeromegamez
Copy link
Member

jeromegamez commented Jan 7, 2020

After having begun to implement GitHub Actions, I can now confirm the issue 🎉 (see e.g. https://github.com/kreait/firebase-php/runs/378003314). As soon as I have finished the GitHub Actions setup, I will look for a way to fix the problem. 🤞

Update: I can confirm that there is an issue 😅, it's not the same as you described :)

@chimit
Copy link

chimit commented Jan 8, 2020

Modifying the config file doesn't help. Currently, the only way to make it work is to specify the full path in the .env file.

@jeromegamez
Copy link
Member

@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

@chimit
Copy link

chimit commented Jan 8, 2020

Both don't work. Apparently, this credentials.file parameter is just ignored.

@jeromegamez
Copy link
Member

It's not - (or) have you step-debugged the package's service provider to be able to see what the issue is/that this is the issue?

@chimit
Copy link

chimit commented Jan 8, 2020

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')),

@jeromegamez
Copy link
Member

@chimit Yessss 🎉 - can I assume that you are currently using the branch that I gave you in #8? Asking for a friend who would then create a new release 😅

@chimit
Copy link

chimit commented Jan 8, 2020

Yes, apparently, it's working with Lumen 6.3. Just want to finish push notifications to make sure there are no other problems. Will confirm it separately on that issue page.

Thanks a lot! 👍

@ulver2812
Copy link
Author

Hi @jeromegamez, sorry for the late reply (I didn't receive the github notification).
My current fix is this:

Possible solution is to use base_path() in the config file:

'credentials' => [
        'file' => base_path() . '/' . env('FIREBASE_CREDENTIALS'),
        'auto_discovery' => true,
    ],

On Windows it works, I didn't investigate further...

@chimit
Copy link

chimit commented Feb 1, 2020

@ulver2812 I updated Lumen instructions (#11). Do we need to add base_path() into the config/firebase.php now?

@jeromegamez
Copy link
Member

Unfortunately, it's not as easy. base_path() would break things if a full path is provided (like /full/path/to/service_account.json or C:\\full\path\to\service_account.json), it would only work for relative paths.

So, while this might work on your local machine, where you put the service account file in the project directory, it might break on a production machine where the file could be outside the project directory. Also, on one machine you could be on Windows, on the other on Linux... I'll try to come up with something, but I need it to be a stable solution 😅

@ulver2812
Copy link
Author

So, at the end the best thing to do is to use absolute paths 🤷‍♂️

@jeromegamez
Copy link
Member

Could you please check out and try #13 to see if this works for you on Windows?

@ulver2812
Copy link
Author

Sorry but I can't check right now, I will try as soon as possible. Thanks

@chimit
Copy link

chimit commented Feb 6, 2020

Using absolute paths is not very convenient when you deploy your project to many environments or change them. As for me, a relative path should be a default.

@jeromegamez
Copy link
Member

@chimit Could you please test if #13 works for you?

@jeromegamez
Copy link
Member

It's been long enough, I will merge #13 and if something doesn't work, someone will let me know for sure :)

@jeromegamez
Copy link
Member

Merged with 3213acc, released with 1.4.0

@eluar
Copy link

eluar commented Mar 29, 2021

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,
    ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants