kreait / firebase-php

Unofficial Firebase Admin SDK for PHP
https://firebase-php.readthedocs.io/
MIT License
2.29k stars 432 forks source link

I can't get my account information properly anymore. #649

Closed Yuki311 closed 3 years ago

Yuki311 commented 3 years ago

Describe the issue you are experiencing

Nice to meet you. As you can see in the title of this article, the following error suddenly occurred when a user logged in on August 15 (Sunday).

What should I do first to find out for sure what is causing this? I would appreciate it if you could help me.

We are using CentOS Stream as our OS.

Installed packages

asm89/stack-cors v2.0.2 Cross-origin resource sharing library and stack middleware aws/aws-sdk-php 3.171.19 AWS SDK for PHP - Use Amazon Web Services in your PHP project bensampo/laravel-enum v1.38.0 Simple, extensible and powerful enumeration implementation for Laravel. cache/adapter-common 1.2.0 Common classes for PSR-6 adapters cache/hierarchical-cache 1.1.0 A helper trait and interface to your PSR-6 cache to support hierarchical keys. cache/tag-interop 1.0.1 Framework interoperable interfaces for tags cache/void-adapter 1.1.0 A PSR-6 cache implementation using Void. This implementation supports tags clue/stream-filter v1.5.0 A simple and modern approach to stream filtering in PHP composer/package-versions-deprecated 1.11.99.1 Composer plugin that provides efficient querying for installed package versions (no runtime IO) contentful/contentful 6.0.5 SDK for the Contentful Content Delivery API contentful/core 3.0.5 Foundation library for Contentful PHP SDKs contentful/laravel 8.0.1 Integrates the Contentful PHP SDK with Laravel. contentful/rich-text 3.1.2 Utilities for the Contentful Rich Text defuse/php-encryption v2.2.1 Secure PHP Encryption Library dnoegel/php-xdg-base-dir v0.1.1 implementation of xdg base directory specification for php doctrine/inflector 2.0.3 PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plura... doctrine/instantiator 1.4.0 A small, lightweight utility to instantiate objects in PHP without invoking their constructors doctrine/lexer 1.2.1 PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers. dompdf/dompdf v1.0.2 DOMPDF is a CSS 2.1 compliant HTML to PDF converter dragonmantank/cron-expression v2.3.1 CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due egulias/email-validator 2.1.25 A library for validating emails against several RFCs facade/flare-client-php 1.3.7 Send PHP errors to Flare facade/ignition 1.16.4 A beautiful error page for Laravel applications. facade/ignition-contracts 1.0.2 Solution contracts for Ignition fideloper/proxy 4.4.1 Set trusted proxies for Laravel fig/http-message-util 1.1.5 Utility classes and constants for use with PSR-7 (psr/http-message) filp/whoops 2.9.1 php error handling for cool kids firebase/php-jwt v5.2.0 A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec. fruitcake/laravel-cors v2.0.3 Adds CORS (Cross-Origin Resource Sharing) headers support in your Laravel application fzaninotto/faker v1.9.2 Faker is a PHP library that generates fake data for you. giggsey/libphonenumber-for-php 8.12.16 PHP Port of Google's libphonenumber giggsey/locale 1.9 Locale functions required by libphonenumber-for-php google/auth v1.14.3 Google Auth Library for PHP google/cloud-core v1.41.0 Google Cloud PHP shared dependency, providing functionality useful to all components. google/cloud-storage v1.23.1 Cloud Storage Client for PHP google/crc32 v0.1.0 Various CRC32 implementations guzzlehttp/guzzle 7.2.0 Guzzle is a PHP HTTP client library guzzlehttp/promises 1.4.0 Guzzle promises library guzzlehttp/psr7 1.7.0 PSR-7 message implementation that also provides common utility methods hamcrest/hamcrest-php v2.0.1 This is the PHP port of Hamcrest Matchers hanneskod/classtools 1.2.1 Find, extract and process classes from file system http-interop/http-factory-guzzle 1.0.0 An HTTP Factory using Guzzle PSR7 jakub-onderka/php-console-color v0.2
jakub-onderka/php-console-highlighter v0.4 Highlight PHP code in terminal jean85/pretty-package-versions 1.5.1 A wrapper for ocramius/package-versions to get pretty versions strings kreait/clock 1.1.0 A PHP 7.0 compatible clock abstraction kreait/firebase-php 5.14.1 Firebase Admin SDK kreait/firebase-tokens 1.14.0 A library to work with Firebase tokens kreait/laravel-firebase 2.4.0 A Laravel package for the Firebase PHP Admin SDK laminas/laminas-code 3.5.1 Extensions to the PHP Reflection API, static code scanning, and code generation laminas/laminas-diactoros 2.5.0 PSR HTTP Message implementations laminas/laminas-eventmanager 3.3.0 Trigger and listen to events within a PHP application laminas/laminas-zendframework-bridge 1.1.1 Alias legacy ZF class names to Laminas Project equivalents. laravel/cashier v12.6.2 Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services. laravel/framework v6.20.12 The Laravel Framework. laravel/passport v9.4.0 Laravel Passport provides OAuth2 server support to Laravel. laravel/slack-notification-channel v2.3.0 Slack Notification Channel for laravel. laravel/tinker v2.5.0 Powerful REPL for the Laravel framework. lcobucci/jwt 3.4.2 A simple library to work with JSON Web Token and JSON Web Signature league/commonmark 1.5.7 Highly-extensible PHP Markdown parser which fully supports the CommonMark spec and Github-Flavored Markdown (GFM) league/event 2.2.0 Event package league/flysystem 1.1.3 Filesystem abstraction: Many filesystems, one API. league/flysystem-aws-s3-v3 1.0.29 Flysystem adapter for the AWS S3 SDK v3.x league/mime-type-detection 1.5.1 Mime-type detection for Flysystem league/oauth2-client 2.6.0 OAuth 2.0 Client Library league/oauth2-server 8.2.4 A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants... linecorp/line-bot-sdk 4.6.0 SDK of the LINE BOT API for PHP macsidigital/laravel-api-client 2.1.3 Laravel API Client Builder package macsidigital/laravel-oauth2-client 1.1.1 Laravel OAuth2 Client macsidigital/laravel-zoom 3.0.0 Laravel Zoom package mockery/mockery 1.4.2 Mockery is a simple yet flexible PHP mock object framework moneyphp/money v3.3.1 PHP implementation of Fowler's Money pattern monolog/monolog 2.2.0 Sends your logs to files, sockets, inboxes, databases and various web services mtdowling/jmespath.php 2.6.0 Declaratively specify how to extract elements from a JSON document myclabs/deep-copy 1.10.2 Create deep copies (clones) of your objects nesbot/carbon 2.43.0 An API extension for DateTime that supports 281 different languages. nikic/php-parser v4.10.4 A PHP parser written in PHP nunomaduro/collision v3.1.0 Cli error handling for console/command-line PHP applications. nyholm/psr7 1.3.2 A fast PHP7 implementation of PSR-7 omniphx/forrest v2.11.0 A Laravel library for Salesforce opis/closure 3.6.1 A library that can be used to serialize closures (anonymous functions) and arbitrary objects. paragonie/random_compat v9.99.99 PHP 5.x polyfill for random_bytes() and random_int() from PHP 7 phar-io/manifest 2.0.1 Component for reading phar.io manifest information from a PHP Archive (PHAR) phar-io/version 3.0.4 Library for handling version information and constraints phenx/php-font-lib 0.5.2 A library to read, parse, export and make subsets of different types of font files. phenx/php-svg-lib v0.3.3 A library to read, parse and export to PDF SVG files. php-http/client-common 2.3.0 Common HTTP Client implementations and tools for HTTPlug php-http/discovery 1.13.0 Finds installed HTTPlug implementations and PSR-7 message factories php-http/httplug 2.2.0 HTTPlug, the HTTP client abstraction for PHP php-http/message 1.10.0 HTTP Message related tools php-http/message-factory v1.0.2 Factory interfaces for PSR-7 HTTP Message php-http/promise 1.1.0 Promise used for asynchronous HTTP requests phpdocumentor/reflection-common 2.2.0 Common reflection classes used by phpdocumentor to reflect the code structure phpdocumentor/reflection-docblock 5.2.2 With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedd... phpdocumentor/type-resolver 1.4.0 A PSR-5 based resolver of Class names, Types and Structural Element Names phpoption/phpoption 1.7.5 Option Type for PHP phpseclib/phpseclib 2.0.30 PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc. phpspec/prophecy 1.12.2 Highly opinionated mocking framework for PHP 5.3+ phpunit/php-code-coverage 7.0.14 Library that provides collection, processing, and rendering functionality for PHP code coverage information. phpunit/php-file-iterator 2.0.3 FilterIterator implementation that filters files based on a list of suffixes. phpunit/php-text-template 1.2.1 Simple template engine. phpunit/php-timer 2.1.3 Utility class for timing phpunit/php-token-stream 4.0.4 Wrapper around PHP's tokenizer extension. phpunit/phpunit 8.5.14 The PHP Unit Testing framework. psr/cache 1.0.1 Common interface for caching libraries psr/container 1.0.0 Common Container Interface (PHP FIG PSR-11) psr/http-client 1.0.1 Common interface for HTTP clients psr/http-factory 1.0.1 Common interfaces for PSR-7 HTTP message factories psr/http-message 1.0.1 Common interface for HTTP messages psr/log 1.1.3 Common interface for logging libraries psr/simple-cache 1.0.1 Common interfaces for simple caching psy/psysh v0.10.6 An interactive shell for modern PHP. ralouphie/getallheaders 3.0.3 A polyfill for getallheaders. ramsey/uuid 3.9.3 Formerly rhumsaa/uuid. A PHP 5.4+ library for generating RFC 4122 version 1, 3, 4, and 5 universally unique identifiers (UUID). riverline/multipart-parser 2.0.8 One class library to parse multipart content with encoding and charset support. rize/uri-template 0.3.2 PHP URI Template (RFC 6570) supports both expansion & extraction sabberworm/php-css-parser 8.3.1 Parser for CSS Files written in PHP scrivo/highlight.php v9.18.1.6 Server side syntax highlighter that supports 185 languages. It's a PHP port of highlight.js sebastian/code-unit-reverse-lookup 1.0.2 Looks up which function or method a line of code belongs to sebastian/comparator 3.0.3 Provides the functionality to compare PHP values for equality sebastian/diff 3.0.3 Diff implementation sebastian/environment 4.2.4 Provides functionality to handle HHVM/PHP environments sebastian/exporter 3.1.3 Provides the functionality to export PHP variables for visualization sebastian/global-state 3.0.1 Snapshotting of global state sebastian/object-enumerator 3.0.4 Traverses array structures and object graphs to enumerate all referenced objects sebastian/object-reflector 1.1.2 Allows reflection of object attributes, including inherited and non-public ones sebastian/recursion-context 3.0.1 Provides functionality to recursively process PHP variables sebastian/resource-operations 2.0.2 Provides a list of PHP built-in functions that operate on resources sebastian/type 1.1.4 Collection of value objects that represent the types of the PHP type system sebastian/version 2.0.1 Library that helps with managing the version number of Git-hosted PHP projects sentry/sdk 3.1.0 This is a metapackage shipping sentry/sentry with a recommended HTTP client. sentry/sentry 3.1.2 A PHP SDK for Sentry (http://sentry.io) sentry/sentry-laravel 2.3.1 Laravel SDK for Sentry (https://sentry.io) stripe/stripe-php v7.68.0 Stripe PHP Library swiftmailer/swiftmailer v6.2.5 Swiftmailer, free feature-rich PHP mailer symfony/console v4.4.18 Symfony Console Component symfony/css-selector v5.2.1 Symfony CssSelector Component symfony/debug v4.4.18 Symfony Debug Component symfony/deprecation-contracts v2.2.0 A generic function and convention to trigger deprecation notices symfony/error-handler v4.4.18 Symfony ErrorHandler Component symfony/event-dispatcher v4.4.18 Symfony EventDispatcher Component symfony/event-dispatcher-contracts v1.1.9 Generic abstractions related to dispatching event symfony/filesystem v5.2.1 Symfony Filesystem Component symfony/finder v4.4.18 Symfony Finder Component symfony/http-client v5.2.1 Symfony HttpClient component symfony/http-client-contracts v2.3.1 Generic abstractions related to HTTP clients symfony/http-foundation v4.4.18 Symfony HttpFoundation Component symfony/http-kernel v4.4.18 Symfony HttpKernel Component symfony/intl v5.2.1 A PHP replacement layer for the C intl extension that includes additional data from the ICU library. symfony/mime v5.2.1 A library to manipulate MIME messages symfony/options-resolver v5.2.1 Symfony OptionsResolver Component symfony/polyfill-ctype v1.22.0 Symfony polyfill for ctype functions symfony/polyfill-iconv v1.22.0 Symfony polyfill for the Iconv extension symfony/polyfill-intl-icu v1.22.0 Symfony polyfill for intl's ICU-related data and classes symfony/polyfill-intl-idn v1.22.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions symfony/polyfill-intl-normalizer v1.22.0 Symfony polyfill for intl's Normalizer class and related functions symfony/polyfill-mbstring v1.22.0 Symfony polyfill for the Mbstring extension symfony/polyfill-php72 v1.22.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions symfony/polyfill-php73 v1.22.0 Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions symfony/polyfill-php80 v1.22.0 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions symfony/polyfill-uuid v1.22.0 Symfony polyfill for uuid functions symfony/process v4.4.18 Symfony Process Component symfony/psr-http-message-bridge v2.0.2 PSR HTTP message bridge symfony/routing v4.4.18 Symfony Routing Component symfony/service-contracts v2.2.0 Generic abstractions related to writing services symfony/translation v4.4.18 Symfony Translation Component symfony/translation-contracts v2.3.0 Generic abstractions related to translation symfony/var-dumper v4.4.18 Symfony mechanism for exploring and dumping PHP variables theseer/tokenizer 1.2.0 A small library for converting tokenized PHP source code into XML and potentially other formats tijsverkoyen/css-to-inline-styles 2.2.3 CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very ... vlucas/phpdotenv v3.6.7 Loads environment variables from .env to getenv(), $_ENV and $_SERVER automagically. webmozart/assert 1.9.1 Assertions to validate method input/output with nice error messages.

PHP version and extensions

composer-plugin-api 1.1.0 The Composer Plugin API composer-runtime-api 1.0.0 The Composer Runtime API ext-bz2 7.4.14 The bz2 PHP extension ext-calendar 7.4.14 The calendar PHP extension ext-ctype 7.4.14 The ctype PHP extension ext-curl 7.4.14 The curl PHP extension ext-date 7.4.14 The date PHP extension ext-dom 20031129 The dom PHP extension ext-exif 7.4.14 The exif PHP extension ext-fileinfo 7.4.14 The fileinfo PHP extension ext-filter 7.4.14 The filter PHP extension ext-ftp 7.4.14 The ftp PHP extension ext-gd 7.4.14 The gd PHP extension ext-gettext 7.4.14 The gettext PHP extension ext-hash 7.4.14 The hash PHP extension ext-iconv 7.4.14 The iconv PHP extension ext-json 7.4.14 The json PHP extension ext-libxml 7.4.14 The libxml PHP extension ext-mbstring 7.4.14 The mbstring PHP extension ext-mysqli 7.4.14 The mysqli PHP extension ext-mysqlnd 0 The mysqlnd PHP extension (actual version: mysqlnd 7.4.14) ext-openssl 7.4.14 The openssl PHP extension ext-pcntl 7.4.14 The pcntl PHP extension ext-pcre 7.4.14 The pcre PHP extension ext-PDO 7.4.14 The PDO PHP extension ext-pdo_mysql 7.4.14 The pdo_mysql PHP extension ext-pdo_sqlite 7.4.14 The pdo_sqlite PHP extension ext-Phar 7.4.14 The Phar PHP extension ext-readline 7.4.14 The readline PHP extension ext-Reflection 7.4.14 The Reflection PHP extension ext-session 7.4.14 The session PHP extension ext-SimpleXML 7.4.14 The SimpleXML PHP extension ext-sockets 7.4.14 The sockets PHP extension ext-sodium 7.4.14 The sodium PHP extension ext-SPL 7.4.14 The SPL PHP extension ext-sqlite3 7.4.14 The sqlite3 PHP extension ext-tokenizer 7.4.14 The tokenizer PHP extension ext-xml 7.4.14 The xml PHP extension ext-xmlreader 7.4.14 The xmlreader PHP extension ext-xmlwriter 7.4.14 The xmlwriter PHP extension ext-xsl 7.4.14 The xsl PHP extension ext-Zend-OPcache 7.4.14 The Zend OPcache PHP extension ext-zlib 7.4.14 The zlib PHP extension lib-curl 7.61.1 The curl PHP library lib-iconv 2.28 The iconv PHP library lib-libxml 2.9.7 The libxml PHP library lib-openssl 1.1.1.7 OpenSSL 1.1.1g FIPS 21 Apr 2020 lib-pcre 10.32 The pcre PHP library lib-xsl 1.1.32 The xsl PHP library php 7.4.14 The PHP interpreter php-64bit 7.4.14 The PHP interpreter, 64bit php-ipv6 7.4.14 The PHP interpreter, with IPv6 support

On which operating system(s) does the issue occur?

Steps to reproduce the issue.

// If you try to use this code to get the user information, you will get an error. $user = \Auth::user();

Error message/Stack trace

Kreait\Firebase\Exception\Auth\ApiConnectionFailed
Unable to connect to the API: cURL error 52: Empty reply from server (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://oauth2.googleapis.com/token

Kreait\Firebase\Exception\Auth\ApiConnectionFailed
Unable to connect to the API: cURL error 52: Empty reply from server (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://www.googleapis.com/identitytoolkit/v3/relyingparty/getAccountInfo

Additional information

No response

jeromegamez commented 3 years ago

Auth::user() is a call to the Laravel Auth component - the Firebase Laravel package or the SDK itself doesn't hook into Laravel's authentication component, so there's unfortunately nothing I can tell you unless you can share how the Firebase SDK is involved here.

In general, if something used to be working and suddenly stops working, it's usually not because of a bug in the code, especially when it's related to a server call (as the error message suggests). The most likely reason is a server problem on Firebase's side (the service), and should resolve itself after some time.

Another reason could be a change in the environment of your application, e.g. when using a proxy that causes the connection to fail.

I'm closing the issue because it doesn't seem to relate to a bug in the SDK but feel free to share your findings in further comments so that other finding this might benefit from them.

Yuki311 commented 3 years ago

Thank you very much for answering my question promptly and politely.

As you said, the problem I reported has stopped occurring since about 6pm today.

Sorry, I didn't have enough information to tell you.

I am using the authentication function using Firebase. I am using the following code to login.

        $auth = app('firebase.auth');

        $idToken = $request->input('idToken');

        try {
            $verifiedIdToken = $auth->verifyIdToken($idToken);
        } catch (\InvalidArgumentException $e) { 

            return response()->json([
                'message' => 'Unauthorized - Can\'t parse the token: ' . $e->getMessage(),
            ], Response::HTTP_UNAUTHORIZED);
        } catch (InvalidToken $e) {

            return response()->json([
                'message' => 'Unauthorized - Token is invalide: ' . $e->getMessage(),
            ], Response::HTTP_UNAUTHORIZED);
        }
        $uid = $verifiedIdToken->getClaim('sub');
        $firebase_user = $auth->getUser($uid);

        $user = User::where('uid', $uid)->first();

        $tokenResult = $user->createToken('Hoge Token');
        $token = $tokenResult->token;

        $token->expires_at = Carbon::now()->addWeeks(1);
        $token->save();

        $access_token = $tokenResult->accessToken;

        return response(['hoge_token' => $access_token], Response::HTTP_OK)->withCookie(cookie('hoge_token', $access_token, 60 * 24 * 7));

I'm still not sure if the problem was caused by some kind of temporary failure in Firebase due to my lack of knowledge, or if it was caused by the VPS server we are using.

I will keep looking into it.

Your answers to the questions you gave me were very informative. I will definitely use this experience in my next project. Thank you again.

jeromegamez commented 3 years ago

You're welcome! 🌺 Your code indeed looks fine (and I didn't think it was something caused by your code in the first place). The most likely reason for these kind of errors in the past - when not caused by the Firebase Servers themselves - was when the application code was executed on a local computer and/or from a country that needs to use a proxy server to access the Firebase services (for example when the country is embargoed by the US), that's why I mentioned it at all 😅

Anyway, I'm glad the problem resolved itself in the end! Thank you for your kind words and all the best for your project!

Yuki311 commented 3 years ago

I see that the problem I faced can be caused by proxy servers. I'll keep that in mind.

Thanks to you, I was able to deal with the problem calmly. It also helped me to broaden my horizons.

I will also support your activities from behind the scenes😊