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

Message: No service account has been found #79

Closed
Greg767 opened this issue Apr 18, 2017 · 11 comments
Closed

Message: No service account has been found #79

Greg767 opened this issue Apr 18, 2017 · 11 comments

Comments

@Greg767
Copy link

Greg767 commented Apr 18, 2017

Hi,
I've installed the latest package and I am on PHP 7 and I am getting the following message:
Type: Firebase\Exception\LogicException Message: No service account has been found. Please set the path to a service account credentials file with Firebase\Factory::withCredentials($path)()

I don't quite understand why since I put the file in a folder that is in the root of the website, I can access the file from a browser.
Here is how I call it:
$this->firebase = (new \Firebase\Factory())->withCredentials(self::AUTH_JSON)->create();
Any idea how could I debug this?
Thanks very much.
Greg

@jeromegamez
Copy link
Member

The Service Account-JSON should never be publicly accessible, please move it out of the web root, or disallow access to it.

I don't know what self::AUTH_JSON refers to, but the path to the JSON file must be accessible by the PHP process on the file system - again: not in the browser.

@Greg767
Copy link
Author

Greg767 commented Apr 18, 2017

Yeah, I didn't mean to leave it public, but only for debugging the problem.
self::AUTH_JSON is the absolute path to the file, like /folder/config.json.
If the file has 777 permissions it is accessible by the process, but it still throws the exception. This is what I don't understand.

@Greg767
Copy link
Author

Greg767 commented Apr 18, 2017

Well I am debugging this and it has nothing to do with your package. For some reason PHP not accessing the file. So I am closing this. Thanks

@Greg767 Greg767 closed this as completed Apr 18, 2017
@sfxworks
Copy link

sfxworks commented Apr 25, 2017

Hi,
I'm running into the same issue with my json file set to 777.

[root@centos-512mb-nyc3-01 firebase]# dir
Admin.json     composer.lock  FirebaseTest2.php  Kreait
composer.json  composer.phar  FirebaseTest.php   vendor
[root@centos-512mb-nyc3-01 firebase]# chmod 777
chmod: missing operand after ‘777’
Try 'chmod --help' for more information.
[root@centos-512mb-nyc3-01 firebase]# chmod 777 Admin.json
[root@centos-512mb-nyc3-01 firebase]# printenv |grep FIREBASE_CREDENTIALS
FIREBASE_CREDENTIALS=/firebase/Admin.json
[root@centos-512mb-nyc3-01 firebase]# clear
[root@centos-512mb-nyc3-01 firebase]# printenv |grep FIREBASE_CREDENTIALS
FIREBASE_CREDENTIALS=/firebase/Admin.json
[root@centos-512mb-nyc3-01 firebase]# chmod 777 Admin.json
[root@centos-512mb-nyc3-01 firebase]# dir
Admin.json  composer.json  composer.lock  composer.phar  FirebaseTest2.php  FirebaseTest.php  Kreait  vendor
[root@centos-512mb-nyc3-01 firebase]# php FirebaseTest2.php
PHP Fatal error:  Uncaught Kreait\Firebase\Exception\LogicException: No service account has been found. Please set the path to a service account credentials file with Kreait\Firebase\Factory::withCredentials($path)() in /var/www/html/firebase/vendor/kreait/firebase-php/src/Firebase/Factory.php:99
Stack trace:
#0 /var/www/html/firebase/vendor/kreait/firebase-php/src/Firebase/Factory.php(73): Kreait\Firebase\Factory->getServiceAccount()
#1 /var/www/html/firebase/FirebaseTest2.php(12): Kreait\Firebase\Factory->create()
#2 {main}
  thrown in /var/www/html/firebase/vendor/kreait/firebase-php/src/Firebase/Factory.php on line 99

Fatal error: Uncaught Kreait\Firebase\Exception\LogicException: No service account has been found. Please set the path to a service account credentials file with Kreait\Firebase\Factory::withCredentials($path)() in /var/www/html/firebase/vendor/kreait/firebase-php/src/Firebase/Factory.php:99
Stack trace:
#0 /var/www/html/firebase/vendor/kreait/firebase-php/src/Firebase/Factory.php(73): Kreait\Firebase\Factory->getServiceAccount()
#1 /var/www/html/firebase/FirebaseTest2.php(12): Kreait\Firebase\Factory->create()
#2 {main}
  thrown in /var/www/html/firebase/vendor/kreait/firebase-php/src/Firebase/Factory.php on line 99

I am using this test script.

<?php

error_reporting(E_ALL);
ini_set('display_errors', 'on');

require __DIR__.'/vendor/autoload.php';

use Kreait\Firebase;

$firebase = (new Firebase\Factory())
    ->withCredentials(__DIR__.'/Admin.json')
    ->create();
	
$database = $firebase->getDatabase();

$db->getReference('config/website')
   ->set([
       'name' => 'My Application',
       'emails' => [
           'support' => 'support@domain.tld',
           'sales' => 'sales@domain.tld',
       ],
       'website' => 'https://app.domain.tld',
      ]);

$db->getReference('config/website/name')->set('New name');

How do I allow php to access this file?

@jeromegamez
Copy link
Member

You have set the environment variable to/firebase/Admin.json instead of /var/www/html/firebase/Admin.json

@jeromegamez
Copy link
Member

By the way, when you set the environment variable, you don't need to use withCredentials().

@sfxworks
Copy link

Sorry, I forgot to mention I have a copy of admin.json located at /firebase and my attempt to use the demo that didn't use withCredentials with my var set also failed. Any idea why?

I had also set it to the path in my HTML folder and that returned the same result.

@jeromegamez
Copy link
Member

@sfxworks I just released a new version (https://github.com/kreait/firebase-php/releases/tag/3.0.1) which should be more informative when the credentials could not be loaded. Please update to this version and try again. The message should read something like

No service account has been found. Tried [/some/path]. Please set the path to a service account credentials file with Kreait\Firebase\Factory::withCredentials($path)

Just to make sure it tries to access the correct file, and you can check if at least that's okay. As far as the permissions go, I'm afraid this is out of scope of this library, but I hope the new release helps to debug further.

@sfxworks
Copy link

Same thing. I don't understand what the problem is. If there is a json file there the path is correct and it's being pointed at properly what is the problem.

<?php

error_reporting(E_ALL);
ini_set('display_errors', 'on');

require __DIR__.'/vendor/autoload.php';

use Kreait\Firebase;

echo "Path = " .  __DIR__.'/Admin.json';

$firebase = (new Firebase\Factory())
    ->withCredentials(__DIR__.'/Admin.json')
    ->create();

$database = $firebase->getDatabase();

$db->getReference('config/website')
   ->set([
       'name' => 'My Application',
       'emails' => [
           'support' => 'support@domain.tld',
           'sales' => 'sales@domain.tld',
       ],
       'website' => 'https://app.domain.tld',
      ]);

$db->getReference('config/website/name')->set('New name');
?>
Path = /var/www/html/firebase/firebase-php-3.0.1/src/Admin.json
Fatal error: Uncaught Kreait\Firebase\Exception\LogicException: No service account has been found. Please set the path to a service account credentials file with Kreait\Firebase\Factory::withCredentials($path)() in /var/www/html/firebase/firebase-php-3.0.1/src/vendor/kreait/firebase-php/src/Firebase/Factory.php:99 Stack trace: #0 /var/www/html/firebase/firebase-php-3.0.1/src/vendor/kreait/firebase-php/src/Firebase/Factory.php(73): Kreait\Firebase\Factory->getServiceAccount() #1 /var/www/html/firebase/firebase-php-3.0.1/src/FirebaseTest2.php(14): Kreait\Firebase\Factory->create() #2 {main} thrown in /var/www/html/firebase/firebase-php-3.0.1/src/vendor/kreait/firebase-php/src/Firebase/Factory.php on line 99

@Greg767
Copy link
Author

Greg767 commented Apr 28, 2017 via email

@lock
Copy link

lock bot commented Mar 15, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Mar 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants