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

GuzzleHttp configuration of Auth module does not work #735

Closed
mayonghui opened this issue Sep 26, 2022 · 10 comments
Closed

GuzzleHttp configuration of Auth module does not work #735

mayonghui opened this issue Sep 26, 2022 · 10 comments
Assignees
Labels

Comments

@mayonghui
Copy link

Describe the bug

GuzzleHttp configuration of Auth module does not work.
goto code

Installed packages

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "php": "^7.3|^8.0",
        "ext-bcmath": "*",
        "ext-curl": "*",
        "ext-exif": "*",
        "ext-json": "*",
        "ext-libxml": "*",
        "ext-openssl": "*",
        "ext-pdo": "*",
        "ext-redis": "*",
        "ext-simplexml": "*",
        "aliyuncs/oss-sdk-php": "~2.4",
        "fruitcake/laravel-cors": "^2.0",
        "google/cloud-logging": "dev-main",
        "guzzlehttp/guzzle": "^7.0.1",
        "hhxsv5/laravel-s": "~3.7.0",
        "iidestiny/laravel-filesystem-oss": "^2",
        "kreait/laravel-firebase": "^4.2",
        "laravel/framework": "^8.75",
        "laravel/sanctum": "^2.11",
        "laravel/tinker": "^2.5",
        "php-mqtt/client": "^1.4",
        "sendgrid/sendgrid": "dev-main"
    },
    "require-dev": {
        "facade/ignition": "^2.5",
        "fakerphp/faker": "^1.9.1",
        "guanguans/laravel-dump-sql": "^2.2",
        "laravel/sail": "^1.0.1",
        "laravel/telescope": "^4.9",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^5.10",
        "phpunit/phpunit": "^9.5.10"
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        },
        "files": ["app/functions.php"]
    },
    "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": [
                "laravel/telescope"
            ]
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true,
        "platform": {
            "ext-pcntl": "7.4",
            "ext-posix": "7.4"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

PHP version and extensions

composer               2.4.2    Composer package
composer-plugin-api    2.3.0    The Composer Plugin API
composer-runtime-api   2.2.2    The Composer Runtime API
ext-bcmath             7.4.30   The bcmath PHP extension
ext-calendar           7.4.30   The calendar PHP extension
ext-ctype              7.4.30   The ctype PHP extension
ext-curl               7.4.30   The curl PHP extension
ext-date               7.4.30   The date PHP extension
ext-dom                20031129 The dom PHP extension
ext-exif               7.4.30   The exif PHP extension
ext-ffi                7.4.30   The FFI PHP extension
ext-fileinfo           7.4.30   The fileinfo PHP extension
ext-filter             7.4.30   The filter PHP extension
ext-gd                 7.4.30   The gd PHP extension
ext-hash               7.4.30   The hash PHP extension
ext-iconv              7.4.30   The iconv PHP extension
ext-json               7.4.30   The json PHP extension
ext-libxml             7.4.30   The libxml PHP extension
ext-mbstring           7.4.30   The mbstring PHP extension
ext-mysqlnd            0        The mysqlnd PHP extension (actual version: mysqlnd 7.4.30)
ext-openssl            7.4.30   The openssl PHP extension
ext-pcntl              7.4      Package overridden via config.platform
ext-pcre               7.4.30   The pcre PHP extension
ext-pdo                7.4.30   The PDO PHP extension
ext-pdo_mysql          7.4.30   The pdo_mysql PHP extension
ext-pdo_sqlite         7.4.30   The pdo_sqlite PHP extension
ext-phar               7.4.30   The Phar PHP extension
ext-posix              7.4      Package overridden via config.platform
ext-readline           7.4.30   The readline PHP extension
ext-redis              5.3.7    The redis PHP extension
ext-reflection         7.4.30   The Reflection PHP extension
ext-session            7.4.30   The session PHP extension
ext-simplexml          7.4.30   The SimpleXML PHP extension
ext-sodium             7.4.30   The sodium PHP extension
ext-spl                7.4.30   The SPL PHP extension
ext-tokenizer          7.4.30   The tokenizer PHP extension
ext-xdebug             3.1.5    The xdebug PHP extension
ext-xml                7.4.30   The xml PHP extension
ext-xmlreader          7.4.30   The xmlreader PHP extension
ext-xmlwriter          7.4.30   The xmlwriter PHP extension
ext-zip                1.15.6   The zip PHP extension
ext-zlib               7.4.30   The zlib PHP extension
lib-curl               7.70.0   The curl library
lib-curl-libssh2       1.9.0    curl libssh2 version
lib-curl-openssl       1.1.1.15 curl OpenSSL version (1.1.1.15)
lib-curl-zlib          1.2.12   curl zlib version
lib-date-timelib       2018.04  date timelib version
lib-date-zoneinfo      2022.1   zoneinfo ("Olson") database for date
lib-fileinfo-libmagic  537      fileinfo libmagic version
lib-gd                 2.0.35   The gd library
lib-gd-freetype        2.9.1    freetype version for gd
lib-gd-libjpeg         9.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-pcre-unicode       13.0.0   PCRE Unicode version support
lib-pdo_sqlite-sqlite  3.31.1   The pdo_sqlite-sqlite library
lib-zip-libzip         1.7.1    The zip-libzip library
lib-zlib               1.2.12   The zlib library
php                    7.4.30   The PHP interpreter
php-64bit              7.4.30   The PHP interpreter, 64bit
php-ipv6               7.4.30   The PHP interpreter, with IPv6 support

Steps to reproduce the issue.

composer create-project laravel/laravel test-app
composer require kreait/laravel-firebase
$fcm = Firebase::messaging();
$message = CloudMessage::fromArray([
      'token' => "f-Dh7O*****",
            'notification' => [
                'title' => "title",
                'body' => "body",
            ],
            'data' => [
                'id' => '1',
            ],
]);
$fcm->send($message);

Error message/Stack trace

/src/Firebase/Factory.php 
function "createApiClient"

Additional information

Insert a $config

$authTokenHandler = HttpHandlerFactory::build(new Client($config));
@jeromegamez
Copy link
Member

Hey there 👋🏻

  • What does "does not work" mean
  • Could you please provide a stack trace?
  • What do you mean by "Insert a $config"?

Please be aware that the SDK is stable and tested. If the Guzzle configuration of the Auth Module didn't work, the integration tests would have failed and there would be many more bug reports 😅

mayonghui added a commit to mayonghui/firebase-php that referenced this issue Sep 26, 2022
@mayonghui
Copy link
Author

I have set the environment variable "FIREBASE_HTTP_CLIENT_PROXY" as an available proxy server

Kreait\Firebase\Exception\Messaging\ApiConnectionFailed` : Unable to connect to the API: cURL error 35: OpenSSL SSL_connect: Connection was reset in connection to oauth2.googleapis.com:443  (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://oauth2.googleapis.com/token
vendor\kreait\firebase-php\src\Firebase\Exception\MessagingApiExceptionConverter.php:49
vendor\kreait\firebase-php\src\Firebase\Messaging\ApiClient.php:41
vendor\kreait\firebase-php\src\Firebase\Messaging.php:60
tests\Feature\ExampleTest.php:45
 
 Caused by
 GuzzleHttp\Exception\ConnectException: cURL error 35: OpenSSL SSL_connect: Connection was reset in connection to oauth2.googleapis.com:443  (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://oauth2.googleapis.com/token
 
 
vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:210
vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:158
vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:110
vendor\guzzlehttp\guzzle\src\Handler\CurlHandler.php:47
vendor\guzzlehttp\guzzle\src\Handler\Proxy.php:28
vendor\guzzlehttp\guzzle\src\Handler\Proxy.php:48
vendor\guzzlehttp\guzzle\src\PrepareBodyMiddleware.php:64
vendor\guzzlehttp\guzzle\src\Middleware.php:31
vendor\guzzlehttp\guzzle\src\RedirectMiddleware.php:71
vendor\guzzlehttp\guzzle\src\Middleware.php:63
vendor\guzzlehttp\guzzle\src\HandlerStack.php:75
vendor\guzzlehttp\guzzle\src\Client.php:331
vendor\guzzlehttp\guzzle\src\Client.php:107
vendor\guzzlehttp\guzzle\src\Client.php:123
vendor\google\auth\src\HttpHandler\Guzzle6HttpHandler.php:47
vendor\google\auth\src\OAuth2.php:544
vendor\google\auth\src\Credentials\ServiceAccountCredentials.php:205
vendor\google\auth\src\FetchAuthTokenCache.php:79
vendor\google\auth\src\Middleware\AuthTokenMiddleware.php:122
vendor\google\auth\src\Middleware\AuthTokenMiddleware.php:102
vendor\guzzlehttp\guzzle\src\PrepareBodyMiddleware.php:64
vendor\guzzlehttp\guzzle\src\Middleware.php:31
vendor\guzzlehttp\guzzle\src\RedirectMiddleware.php:71
vendor\guzzlehttp\guzzle\src\Middleware.php:63
vendor\guzzlehttp\guzzle\src\HandlerStack.php:75
vendor\guzzlehttp\guzzle\src\Client.php:331
vendor\guzzlehttp\guzzle\src\Client.php:107
vendor\guzzlehttp\guzzle\src\Client.php:123
vendor\kreait\firebase-php\src\Firebase\Messaging\ApiClient.php:39
vendor\kreait\firebase-php\src\Firebase\Messaging.php:60
tests\Feature\ExampleTest.php:45

@jeromegamez
Copy link
Member

Thanks for the additional information. Have you had a chance to look at https://firebase-php.readthedocs.io/en/6.2.0_a/troubleshooting.html#curl-error-xx ?

If updating the CA root certificates doesn't help, connection resets with proxies can have multiple reasons, most of them are in the transport layer between your application and the proxy and the proxy and the target of the request. Perhaps something in these search results can help figuring out the problem:

https://www.google.com/search?q=https+connection+reset+proxy

@jeromegamez
Copy link
Member

jeromegamez commented Sep 26, 2022

Since this doesn't seem to be a problem with the Laravel package or the SDK, I'm going to close the issue now, but feel free to add further comments with your findings so that others can benefit from them.

Unfortunately, my limited resources don't permit providing free individual support that doesn't directly relate to the Firebase libraries. If you'd like me to look further into this, please consider becoming a GitHub sponsor.

@jeromegamez jeromegamez removed their assignment Sep 26, 2022
@mayonghui
Copy link
Author

But I changed new Client() to new Client($config) to solve this problem.
goto source

@jeromegamez
Copy link
Member

Ah, this wasn't clear from your original post, thanks for clearing this up! I'll have a closer look. 🙏🏻

@jeromegamez jeromegamez reopened this Sep 26, 2022
@jeromegamez
Copy link
Member

Again, sorry for not recognizing the issue earlier. I'll implement the fix and release it shortly.

@mayonghui
Copy link
Author

Thank you. I didn't describe the problem clearly.

@jeromegamez jeromegamez self-assigned this Sep 26, 2022
@jeromegamez
Copy link
Member

It's just late where I am, it's very much possible that I could have seen it at another time of day 😅

Anyway, sorry again for being so quick to close this bug - you were right, and this is a bug that effectively breaks the SDK, so thank you very much for discovering it!

https://github.com/kreait/firebase-php/releases/tag/6.9.1 will hopefully make it work for you again! 🤞

@jeromegamez
Copy link
Member

Also, I have to say this: dismissing the problem and saying "the SDK is tested and works for everyone else" is a shitty sign for my privilege not having to use a proxy, which is the reason why this is a part of the SDK that is actually not tested, despite me saying otherwise.

@mayonghui I would like to express my sincere apologies for not considering the bug initially. I hope this will not stop you from reporting bugs in the future!

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

Successfully merging a pull request may close this issue.

2 participants