Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Firebase Auth Admin SDK via Rest Api?

We have been developing a multi platform project which will eventually have an Android app, an iOS app and a web application. We are impressed with the features offered by Google Firebase therefore trying to leverage the opportunities.

Since our product is a multitenant software-as-a-service application we have custom authentication requirements. Therefore we followed the custom authentication implementation path of Firebase and it is functional now.

  • Our mobile clients send login requests to our API server,
  • Our API server issues customTokens and reponds them back to the clients,
  • Clients call signInWithCustomToken(customToken) method to sign in to Firebase.

So far so good.

What the issue is, our backend is in PHP and Firebase doesn't have an official Admin SDK for PHP. Yes, there is a package called kreait/firebase-php on Composer however it is far away from covering all of the Auth Admin SDK features. For example, there is a documented disable-user feature which is available on Firebase Admin SDK, however that operation is not implemented on the kreait/firebase-php package.

On the other hand Firebase has a Auth Rest API which just works with the API KEY. However, (I suppose ) it is designed to work on the client side therefore it just has operations for the authenticated user.

  • Our API server is already hosted on Google Compute Cloud and has the maximum set of access permissions on the Google Cloud services.
  • We have the Firebase service account file to work with the Firebase Auth services.

What we need is to consume all available Firebase Admin SDK features (possibly via Rest). For example, we would like to call revokeRefreshToken(uid) when a user changes his/her password on one of his/her devices.

Since at this specific issue there isn't any documentation, what would you advise us to do?

Update (25 January 2018)

The above mentioned missing endpoints on the Firebase unofficial PHP Admin SDK are now implemented by the maintainer after a productive discussion on a Github issue. However, I would like keep this question open since the nature of the question is asking for ideas for further collaboration and discussion.

like image 955
Lashae Avatar asked Jan 15 '18 13:01

Lashae


2 Answers

Maintainer of said unofficial PHP SDK here :). You already have updated your original post to include that the SDK now supports the features that were missing.

I am posting this as a dedicated answer to be visible to people arriving here and searching for answers as well.

Although the Admin SDK for PHP is still not feature complete, we are getting there. I added feature matrix to the README of the Github project so that you can quickly see what is available and what isn't.

Going forward, I will implement new features by either implementing things similarly to the official Admin SDKs (especially https://github.com/firebase/firebase-admin-node) and by using the existing libraries provided by the Google Cloud Platform Library.

At some point in the future, Google will certainly provide all the necessary building blocks to use Firebase efficiently with PHP, but until then, I am happy about every happy PHP developer using my library :).

FYI: I just released a new version (4.1.0) which includes support for Firebase Cloud Storage and did in fact use the google/cloud-storage for that.

like image 172
jeromegamez Avatar answered Nov 14 '22 21:11

jeromegamez


I think you can use the Identity Toolkit libraries provided by Google. Here's the one for PHP: https://github.com/google/identity-toolkit-php-client

like image 37
Hiranya Jayathilaka Avatar answered Nov 14 '22 22:11

Hiranya Jayathilaka