'Access Firebase access token through Firebase Admin PHP SDK

I have generated myself a service account with .json file for Firebase Admin PHP SDK authorization.

Aside from that, I would want to use the same service account for authenticating Clodfunctions API calls, without the need for authorizing another service account and getting token for it (that'll be used in API calls).

Is there a way to extract the access token from Factory object I initialized with my service account .json file?

More on Factory initialization is explained here. I went through source code but none of the methods exist that would give me this option. Some of them could potentially store this data, but they are all private; used only inside core classes used for communication with Firebase database.



Solution 1:[1]

With version 6.x of the SDK, you can use the Factory::createApiClient() method to create an API client that you should be able to use for custom calls to the Firebase APIs.

https://github.com/kreait/firebase-php/blob/dba320d74f6529dab8fe33978b9a37fa83286e35/src/Firebase/Factory.php#L587

As an alternative, you can directly use the google/auth library and use the same Service Account to create your own API client.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jeromegamez