skip to Main Content

I’m on Symfony 6 + PHP8.
I am using the kreait/firebase-bundle for Symfony, I would like to retrieve the list of my users from Firebase to use them on API Platform.

Only when I query my API path, it shows me the error:
"Invalid service account: The file at ‘firebase_credentials.json’ does not exist"

I think I have configured the path correctly, with the firebase.yaml file and edited my .env.local. I can’t find what is blocking. All help appreciated, thanks. Code below.

// composer.json
        "php": ">=8.1",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "api-platform/core": "^2.6",
        "doctrine/annotations": "^1.0",
        "doctrine/doctrine-bundle": "^2.7",
        "doctrine/doctrine-migrations-bundle": "^3.2",
        "doctrine/orm": "^2.12",
        "kreait/firebase-bundle": "^4.1",
        "lexik/jwt-authentication-bundle": "^2.16",
        "nelmio/cors-bundle": "^2.2",
        "phpdocumentor/reflection-docblock": "^5.3",
        "phpstan/phpdoc-parser": "^1.6",
        "sensio/framework-extra-bundle": "^6.1",
        "symfony/asset": "6.1.*",
        "symfony/console": "6.1.*",
        "symfony/doctrine-messenger": "6.1.*",
        "symfony/dotenv": "6.1.*",
        "symfony/expression-language": "6.1.*",
        "symfony/flex": "^2",
        "symfony/form": "6.1.*",
        "symfony/framework-bundle": "6.1.*",
        "symfony/http-client": "6.1.*",
        "symfony/intl": "6.1.*",
        "symfony/mailer": "6.1.*",
        "symfony/mime": "6.1.*",
        "symfony/monolog-bundle": "^3.0",
        "symfony/notifier": "6.1.*",
        "symfony/process": "6.1.*",
        "symfony/property-access": "6.1.*",
        "symfony/property-info": "6.1.*",
        "symfony/proxy-manager-bridge": "6.1.*",
        "symfony/runtime": "6.1.*",
        "symfony/security-bundle": "6.1.*",
        "symfony/serializer": "6.1.*",
        "symfony/string": "6.1.*",
        "symfony/translation": "6.1.*",
        "symfony/twig-bundle": "6.1.*",
        "symfony/validator": "6.1.*",
        "symfony/web-link": "6.1.*",
        "symfony/yaml": "6.1.*",
        "twig/extra-bundle": "^2.12|^3.0",
        "twig/twig": "^2.12|^3.0"
// my_project/config/packages/firebase.yaml
kreait_firebase:
  projects:
    my_project:
      public: true
      default: true
      credentials: '%env(FIREBASE_CREDENTIALS)%'
      verifier_cache: cache.app
      auth_token_cache: cache.app
// .env.local, json file is at root of project
###> kreait/firebase-bundle ###
FIREBASE_CREDENTIALS="firebase_credentials.json"
###< kreait/firebase-bundle ###
// FirebaseDataProvider for FirebaseUser entity endpoint
use KreaitFirebaseContractAuth;

class FirebaseDataProvider implements ContextAwareCollectionDataProviderInterface, RestrictedDataProviderInterface
{
    private Auth $auth;

    public function __construct(Auth $firebase)
    {
        $this->auth = $firebase;
    }

    public function getCollection(string $resourceClass, string $operationName = null, array $context = [])
    {
        dd($this->auth->listUsers());
    }

    public function supports(string $resourceClass, string $operationName = null, array $context = []): bool
    {
        return $resourceClass === FirebaseUser::class;
    }
}

2

Answers


  1. Chosen as BEST ANSWER

    If anyone comes across this problem as well, I solved it by giving them my absolute path. It obviously does not accept the relative path, nor the path noted with %kernel.project_dir%.

    Maybe submit an issue on this, but maybe I forgot something myself.

    // Linux absolute path
    ###> kreait/firebase-bundle ###
    FIREBASE_CREDENTIALS="/home/your_user/PhpstormProjects/my_project/config/firebase/firebase_credentials.json"
    ###< kreait/firebase-bundle ###
    

  2. **

    I think the error is coming from setting your account

    **

    I get an error like you when i try to list of set of users stored in real time database , i fix it by giving the full path of my credential just like this /home/username/your json file

    *

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search