kreait / laravel-firebase

A Laravel package for the Firebase PHP Admin SDK
https://github.com/kreait/firebase-php
MIT License
981 stars 162 forks source link

Unresolvable dependency resolving [Parameter #0 [ <required> string $projectId ]] in class Kreait\Firebase\Messaging #172

Closed dijitalbrains-dev closed 1 year ago

dijitalbrains-dev commented 1 year ago

Describe the bug

when trying to use cloud messaging this error is triggered not sure why I have the same thing set up in another project just with a previous version 2.3 as it is an old laravel project its working just fine there

Installed packages

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "php": "^8.1",
        "google/apiclient": "^2.13",
        "guzzlehttp/guzzle": "^7.2",
        "kreait/laravel-firebase": "^5.1",
        "laravel/framework": "^10.0",
        "laravel/sanctum": "^3.2",
        "laravel/tinker": "^2.8"
    },
    "require-dev": {
        "fakerphp/faker": "^1.9.1",
        "laravel/pint": "^1.0",
        "laravel/sail": "^1.18",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^7.0",
        "phpunit/phpunit": "^10.0",
        "spatie/laravel-ignition": "^2.0"
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi --force"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true,
        "allow-plugins": {
            "pestphp/pest-plugin": true,
            "php-http/discovery": true
        }
    },
    "minimum-stability": "stable",
    "prefer-stable": true
}

PHP version and extensions

composer               2.5.4    Composer package
composer-plugin-api    2.3.0    The Composer Plugin API
composer-runtime-api   2.2.2    The Composer Runtime API
ext-bcmath             8.1.9    The bcmath PHP extension
ext-bz2                8.1.9    The bz2 PHP extension
ext-calendar           8.1.9    The calendar PHP extension
ext-com_dotnet         8.1.9    The com_dotnet PHP extension
ext-ctype              8.1.9    The ctype PHP extension
ext-curl               8.1.9    The curl PHP extension
ext-date               8.1.9    The date PHP extension
ext-dom                20031129 The dom PHP extension
ext-exif               8.1.9    The exif PHP extension
ext-fileinfo           8.1.9    The fileinfo PHP extension
ext-filter             8.1.9    The filter PHP extension
ext-gd                 8.1.9    The gd PHP extension
ext-gettext            8.1.9    The gettext PHP extension
ext-gmp                8.1.9    The gmp PHP extension
ext-hash               8.1.9    The hash PHP extension
ext-iconv              8.1.9    The iconv PHP extension
ext-imap               8.1.9    The imap PHP extension
ext-intl               8.1.9    The intl PHP extension
ext-json               8.1.9    The json PHP extension
ext-ldap               8.1.9    The ldap PHP extension
ext-libxml             8.1.9    The libxml PHP extension
ext-mbstring           8.1.9    The mbstring PHP extension
ext-mysqli             8.1.9    The mysqli PHP extension
ext-mysqlnd            0        The mysqlnd PHP extension (actual version: mysqlnd 8.1.9)
ext-openssl            8.1.9    The openssl PHP extension
ext-pcre               8.1.9    The pcre PHP extension
ext-pdo                8.1.9    The PDO PHP extension
ext-pdo_mysql          8.1.9    The pdo_mysql PHP extension
ext-pdo_sqlite         8.1.9    The pdo_sqlite PHP extension
ext-phar               8.1.9    The Phar PHP extension
ext-readline           8.1.9    The readline PHP extension
ext-reflection         8.1.9    The Reflection PHP extension
ext-session            8.1.9    The session PHP extension
ext-simplexml          8.1.9    The SimpleXML PHP extension
ext-soap               8.1.9    The soap PHP extension
ext-sockets            8.1.9    The sockets PHP extension
ext-sodium             8.1.9    The sodium PHP extension
ext-spl                8.1.9    The SPL PHP extension
ext-sqlite3            8.1.9    The sqlite3 PHP extension
ext-tokenizer          8.1.9    The tokenizer PHP extension
ext-xdebug             3.1.5    The xdebug PHP extension
ext-xml                8.1.9    The xml PHP extension
ext-xmlreader          8.1.9    The xmlreader PHP extension
ext-xmlwriter          8.1.9    The xmlwriter PHP extension
ext-xsl                8.1.9    The xsl PHP extension
ext-zend-opcache       8.1.9    The Zend OPcache PHP extension
ext-zip                1.19.5   The zip PHP extension
ext-zlib               8.1.9    The zlib PHP extension
lib-bz2                1.0.8    The bz2 library
lib-curl               7.77.0   The curl library
lib-curl-libssh2       1.10.0   curl libssh2 version
lib-curl-openssl       1.1.1.17 curl OpenSSL version (1.1.1.17)
lib-curl-zlib          1.2.12   curl zlib version
lib-date-timelib       2021.12  date timelib version
lib-date-zoneinfo      2022.1   zoneinfo ("Olson") database for date
lib-fileinfo-libmagic  540      fileinfo libmagic version
lib-gd                 2.0.35   The gd library
lib-gd-freetype        2.9.1    freetype version for gd
lib-gd-libjpeg         8.0      libjpeg version for gd
lib-gd-libpng          1.6.34   libpng version for gd
lib-gd-libxpm          3.5.12   libxpm version for gd
lib-gmp                6.0.0    The gmp library
lib-iconv              1.16     The iconv library
lib-icu                70.1     The ICU unicode and globalization support library
lib-icu-cldr           40       ICU CLDR project version
lib-icu-unicode        14.0.0   ICU unicode version
lib-ldap-openldap      2.4.47   OpenLDAP version of ldap
lib-libsodium          1.0.18   The libsodium library
lib-libxml             2.9.12   libxml library version
lib-libxslt            1.1.34   The libxslt library
lib-libxslt-libxml     2.9.10   libxml version libxslt is compiled against
lib-mbstring-libmbfl   1.3.2    mbstring libmbfl version
lib-mbstring-oniguruma 6.9.7    mbstring oniguruma version
lib-openssl            1.1.1.17 OpenSSL 1.1.1q  5 Jul 2022
lib-pcre               10.39    The pcre library
lib-pcre-unicode       14.0.0   PCRE Unicode version support
lib-pdo_sqlite-sqlite  3.36.0   The pdo_sqlite-sqlite library
lib-sqlite3-sqlite     3.36.0   The sqlite3-sqlite library
lib-zip-libzip         1.7.1    The zip-libzip library
lib-zlib               1.2.12   The zlib library
php                    8.1.9    The PHP interpreter
php-64bit              8.1.9    The PHP interpreter, 64bit
php-ipv6               8.1.9    The PHP interpreter, with IPv6 support
php-zts                8.1.9    The PHP interpreter, with Zend Thread Safety

Steps to reproduce the issue.

# Insert the commands issued in the terminal if they are needed
# to reproduce the issue. Otherwise, delete this code block.
// Insert the PHP code to reproduce the issue. Please ensure that it is code that
// can be copy pasted to reproduce it.

Error message/Stack trace

Unresolvable dependency resolving [Parameter #0 [ <required> string $projectId ]] in class Kreait\Firebase\Messaging

Additional information

No response

jeromegamez commented 1 year ago

That's an error I haven't seen so far, and I can't reproduce it - could you please share your (redacted where necessary) config and your code in which the error occurs?

Does your service account file contain this exact structure?

{
    "type": "service_account",
    "project_id": "my-project",
    "private_key_id": "xxx",
    "private_key": "-----BEGIN PRIVATE KEY-----xxx-----END PRIVATE KEY-----\n",
    "client_email": "xxx@yyy.iam.gserviceaccount.com",
    "client_id": "123456789",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/xxx.iam.gserviceaccount.com"
}

It's also a good idea to try this with a freshly created project with kreait/laravel-firebase as the only dependency.

alex-elivate commented 1 year ago

I started with this project: https://github.com/suhasrkms/laravel-with-firebase-auth composer require kreait/laravel-firebase:^4.0 -W Updated from version kreait/laravel-firebase:^3.0 and I got this error.
Unresolvable dependency resolving [Parameter #0 [ string $projectId ]] in class Kreait\Firebase\Auth\ApiClient Originally I was trying to migrate this config to Laravel 10 with kreait/laravel-firebase:^5.1, however, for the life of me, I can't see how to resolve this error. I have the config file loading in .env, I can use my firestore controller just fine. I was hoping to quickly get front end authentication going, but this error is halting progress. I'm guessing a config changed between version 3 and 4.

maanas commented 1 year ago

I also faced similar issue and the service account file has exact same structure

https://github.com/kreait/firebase-php/blob/b34b21c8b1ee337edb993ab1723d11d9cae27a7b/src/Firebase/Factory.php#L577

if ($projectId = Util::getenv('GOOGLE_CLOUD_PROJECT')) {
            return $this->projectId = $projectId;
}

Even if we provide GOOGLE_CLOUD_PROJECT in .env file it still give the error

jeromegamez commented 1 year ago

Concerning suhasrkms/laravel-with-firebase-auth, I'm sorry I can't provide support for other projects, even if they are based on my firebase libraries.

The SDK itself is covered by integration tests that use a credentials file and many projects use it, so I'm quite confident there's no bug there.

If it's a problem with the Laravel package, I'm unable to reproduce it - if you can provide a public example repo with your code where I can reproduce the problem, I can try to find something out. Otherwise, there are too many unknowns for me to be able to give recommendations.

maanas commented 1 year ago

Thanks the issue is resolved and there is no problem with the library. Great Work. How can we close the issue.