What do we mean by secondary Firebase App? for instance, it is mentioned here in this documentation - https://firebase.flutter.dev/docs/auth/usage
Use multiple projects in your application
Sometimes you need to access
different projects using the same APIs - for example, accessing
multiple database instances. In most cases there is a central Firebase
application object that manages the configuration for all the Firebase
APIs. This object is initialized as part of your normal setup.
However, when you want to access multiple projects from a single
application, you’ll need a distinct Firebase application object to
reference each one individually. It’s up to you to initialize these
other instances.
In both cases, you need to first create a Firebase options object to
hold the configuration data for the Firebase application
you can read more here
Related
Using Google Firebase Functions as a backend of the small application.
Functions are accessing to the Firestore and Realtime database, therefore they need service account credentials file.
On the other hand, I'm trying to automate the deployment of the functions using Github Actions.
Currently I places the credentials file inside the repository. I know that it's not secure.
What is the proper way of storing service account credentials file in this case?
Firebase projects, are, in effect, Google Cloud Platform projects.
More specifically, when you create a Firebase project, an associated Google Cloud Platform project is created for it.
Therefore the process for storing credentials is the same as in Cloud Platform, which is to say in a file, somewhere relatively safe.
This file should be accessible to your Function if it is required, and should either have its path specified as part of an environment variable or explicitly declared in code.
You are already storing it the proper way, because the improper way would be to insert the contents of the JSON file directly into code.
To prevent others from seeing the contents of the JSON file, simply set the respository as private.
If I have multiple apps with Firebase (different types and kinds) but want to be able to have 1 user base for all of them (1 account for all apps, even if they only use 1) how would I do this? I was thinking either 1. cloud function (every time someone signs up, add them as a user in the other apps) or 2. A separate project for Auth only and configure both of them in the app, but that might mean requests to firestore, storage, and functions aren’t authorized. NOTE: I'm willing to use GCP products separate from firebase to accomplish this.
If the apps are all part of the same suite, you can add them to a single Firebase project. This is by far the easiest way to do this, but there is a hard limit on how many apps you can have in a project in this way (according to the FAQ, this is 30 at the moment).
If the apps are not all part of the same suite, or you need more than the limit, your only option is to use custom authentication. This means you'll create a custom authentication provider that takes the user's credentials, verifies them, and then creates a UID and token for that user to the client which then uses it to sign in to Firebase.
In the back-end you could possible use a single Firebase project for then generating all these users, although I'll admit it's been a few years since I did that.
I need to initialize potentially thousands of Firebase app instances server-side using firebase-admin with a service account and then listen to specific Realtime DB and Firestore events on these app instances. These instances have nothing to do with one another and the only access I have to them is through their service account credentials files.
My main concern is scaling because new project app instances will be initialized on the fly. It is important that the events listened to should not be duplicated, so I can not have multiple server instances initialize listen to the events of all the apps.
Ideally, I would love to have an auto-scaling serverless solution and to keep it inside the Google Cloud Platform family. If there was a way to work with the app instances, while they are auto-scaled behind the scenes - like a load balancer for a collection of app instances. I've looked at the Google Cloud Pub/Sub solution to potentially do something like this, but could not come up with something concrete.
The non-scaling solution I have so far, using cloud functions:
EDIT: After feedback regarding Cloud Functions
on startup of my project's cloud functions, initialize all the current app instances
have a cloud function listen to newly added service accounts and initialize a new app instance for it. Currently, I have no idea how many project instances I can keep in memory before it becomes a problem.
Start up a single Node server to initialize all the current app instances. As new projects are added, simply add a reference for it. Monitor the server closely to ensure it doesn't run out of memory. Scale vertically as far as possible. When it gets to the point where necessary, start up a second server instance, but manually distribute project instances between servers, so there are no duplicates.
Bonus question: are only the individual cloud functions scaled as needed? ie. what happens to other standard JS functions/objects created outside a cloud function but inside the cloud functions index.js file?
Any advice would be greatly appreciated. Happy to elaborate on anything.
Is it possible to trigger a cloud function on a database instance of another firebase project? From what I've read so far, the documents mention passing an instance name in the function but this would be an instance in the same project.
It's not possible. Both functions and database shards must be contained within a single project.
Is it possible to set up Firebase to allow Auth/DB access into a common/shared database instance - where that instance is setup to be a centralized storage location for some 3rd party service?
For example, let's say there's an analytics service called StackOverflowAnalytics.com .. and so anyone who signs up for that service, can add tracking to their app with some secret user key. And then all the tracking for that Key is pushed to the same Firebase DB instance. And then the user can login via Firebase auth and the rules will restrict that they can only access the node for their Key.
I'm working on a 3rd party analytics client for Android - along the lines https://mint.splunk.com - where I would like to provide users a small Java/Android library they can add to their Android project, and this will help them track different data points while their app is running. The data is made accessible by saving it to the cloud from the device.
I am currently using Firebase, but it seems in order for the Firebase Auth & DB of a given Firebase instance to be accessible - the "specific app signing key" (package name/etc combo) needs to be set in the console for that Firebase instance.
It seems sharing across across unknown apps is not possible on Firebase. And that if I want to support something like that with Firebase (and not have to go to another cloud storage option), then I need to set up some proxy REST client .. like in Java or PHP .. that can serve as a centralized access point to that Firebase instance. Just wanted to check with other folks first in case this has been encountered and perhaps there are best practices already established around this particular case. Thanks
Firebase client libraries are generally not meant to be repackaged for use in other libraries. They're meant to be used at the app level.
A unique SHA-1 key is required on Android for Authentication to work with a particular app identified by package name. This requirement will definitely become a problem for you if you want this to work with arbitrary apps, since you would have to manually enter one for each app that wants to integrate.
As far as I know it's not possible to do what you want without creating a proxy, as you mentioned. I assume that firebase has some app validation that make unfeasible to share the Auth/DB.
Maybe a solution for you is to make a proxy too to access data:
"It looks like in order to access Firebase Analytics data, you export it to BigQuery. This is working for me and is automated."