How to use Firebase Auth Admin SDK via Rest Api? - php

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.

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.

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

Related

Each user can connect their own google drive in laravel app

I've already setup a global google drive in my project where everyone is getting files from one google drive for which i had to setup keys in google console.
Now it is required to allow users to connect their own google drives. I just want it to be simpler so users do not have to do all the process on google console to get their keys to set it up.
Any guidance from seniors is much apprecaited.
I’d recommend starting by reading about how account authentication works using Google APIs client for PHP.
Given your issue description, I believe you can achieve the desired behavior by using a Service Account.
Quoting the article above:
Google APIs such as the Prediction API and Google Cloud Storage can act on behalf of your application without accessing user information. In these situations your application needs to prove its own identity to the API, but no user consent is necessary. Similarly, in enterprise scenarios, your application can request delegated access to some resources.
In case you do need to access sensitive user information from you application in a Workspace environment, then I’d recommend having a look into Domain-wide delegation.
In this section of the github repo readme, you can find an example on how to authenticate with Google backend using a service account credentials via the client.
On additional note, I’d also recommend adhering to the How to Ask guidelines in order for your questions to be properly answered by the community. If you could also provide a minimal reproducible scenario as well as the code used and which difficulties you had with it would greatly help and improve your chances to get a meaningful answer in the future.

How to create user and link to existing nexmo application?

Is posible to create user and link user to existsing application using vonage-php-sdk-core package?
https://github.com/Vonage/vonage-php-sdk-core
i can make application and user with Vonage CLI, but i need to make it with PHP. is there a way?
nexmo app:create "My Sample App" --capabilities=voice,rtc --voice-answer-url=https://example.com/webhooks/answer --voice-event-url=https://example.com/webhooks/event --rtc-event-url=https://example.com/webhooks/rtc --keyfile=private.key
with vonage-php-sdk-core i can make application as well, but seems like i can't find method to create user.
The Conversation API (which encompasses Users, Members, and Conversations) isn't supported in the PHP SDK at the moment since the API is still in beta. Once that API goes fully live we will support it in SDKs other than the NodeJS SDK.
There are some vestiges of the Conversation and User APIs in the SDK, but we've marked them as deprecated since it's an older version of the API.
For the moment you should access the APIs using Guzzle or whatever HTTP client you are using (if you aren't specifying one, we should be pulling in Guzzle from Laravel).
As for working directly with the API, https://developer.nexmo.com/conversation/overview is the entrypoint for the Conversations API. General API documentation is available at https://developer.nexmo.com/api/conversation, and demo code from cURL, which can be useful for seeing URL structures as well as payloads, is available at https://developer.nexmo.com/conversation/code-snippets/user/create-user/curl.
Why don't we support this API?
As a rule we don't add support in our stable SDKs for beta APIs, as that could lead to a lot of major releases with breaking changes, as the beta APIs only have a 6 month stability SLA and can change rapidly. We are looking at better ways to handle our beta APIs (the PHP SDK now supports a module system as of v2.2.0) so that devs can get access to these types of APIs quicker.

Can you get a short-lived OAuth 2.0 access token for Firebase in PHP?

i am currently working on a Project with Firebase and i am trying to Implement the Firebase Cloud messaging service. I manage to make it work with a combination of PHP and Javascript (Javascript sends a Requiest to the server, where php makes a call to the Firebase API to send out a Notification).
The problem here is, that the code i use is for the old version, so its not using the HTTP v1.
When i looked at the docs on how to upgrade to the new version, i found out you need a short-lived OAuth 2.0 access token.
Thing is, the docs only show how you can get it via node.js, java, python, c# and go.
So my question is, is there a way to get the short-lived OAuth 2.0 access token with php or do i have to use something like node.js for it?
I'm not sure I fully understand your requirements, but if you want to send FCM notification from a PHP backend, I'd suggest checking out this (unofficial) Admin SDK for PHP (Disclaimer: I'm the creator of that library)
In its current state, you would need a Firebase Service Account (with Admin access) to be able to send notifications with it, but I'm currently working on a feature that will allow you to retrieve an OAuth access token for a given user (https://github.com/kreait/firebase-php/pull/390) in case you really need this.
I'd like to invite you to join https://discord.gg/nbgVfty (the Discord-Community around the PHP Admin SDK) to discuss your use case and process further.
Even if the SDK is not for you, looking through the code might could give you some ideas...
An alternative could be to use the Google PHP Api Client Services library, in which you can find a FirebaseCloudMessaging service.
I hope this helps!

Youtube Analytics PHP cron

I want to start developing a tool that runs daily via cron for getting daily analytical data from one channel, or video, etc.. through the "Youtube Analytics API". And not what is the best way to approach it.
I have read the documentation of Google and and I have several questions:
I created the project in the console (https://code.google.com/apis/console/) but I doubt what kind of application I have to choose when I create a Client ID (Web Application, Service Account or Installed aplplication).
What PHP library use?
It's a very new API and not much information.
In the Google GData site there is a warning about that "Most newer Google APIs Google Data APIs are not Google Data APIs." and in the google-api-php-client, no examples of this API.
What is the best method for authentication in a cron?
As you can see I am very confuse, can someone help me, please?
Thank you.
1) It will be an installed application unless you will run it in a web server.
2) Use the official library, add the ytanalytics php library. Samples: https://github.com/youtube/yt-samples-php
3) You can do so by getting a refresh token from OAuth2 Playground and setting it in your youtube object.
Here it explains a little more.
And a step by step video.

Any luck with Drupal 6 and Quickbooks inventory export

Looking at the Quickbooks API I only see options to sync users. I may just need to export the fields I need directly from the database? Just hoping someone had some scripts/templates to work with this already. I am not too worried about sync as long as the client could manually import web transactions at the beginning of the day
The QuickBooks SDK has the ability to import and export inventory items, including quantity on hand and cost information. Just to be clear, I speaking here about the classic SDK and not the Partner Platform. Using the SDK it is possible to connect to a QuickBooks online company using XML over SSL, or to a desktop company file (still the most popular option for most users) using XML or Intuit's QBFC framework, which is compatible with .NET.
There is no way to access the QuickBooks "database" directly. QODBC give you the ability to run SQL against QuickBooks company file data via ODBC, but it is implemented using the SDK. QODBC is the best way to get up and running fast with QuickBooks, and it's also great for custom reporting. But for most sync applications, the actual data access is a minor part of the overall scope, and the control that you get from going directly to the SDK and bypassing QODBC is worth it.
Most developers who have experience with QuickBooks have a library to help with common SDK tasks. There are also some offerings at code.intuit.com. In addition to library code, it also helps to understand the behavior of both QuickBooks and the SDK. The SDK is well documented and if you haven't visited the SDK section of the Intuit Developer site I would highly recommend it.

Categories