Authenticating Firebase Database with Google API via Firebase Functions - firebase

here's the task I have and the resources I'm following to try to get it done.
Ultimately what I want is for users to be able to take pictures with my app (made with Ionic) and then those pictures get sorted and end up on the company's Google Team Drive.
What I originally started with was uploading the images to Firebase Storage, and then I was told they must be accessible to Team Drive.
Some of the people taking pictures aren't part of the company's G Suite, so I was thinking it would be easier to just have the database itself authenticate with the Team Drive and upload from there.
Here is an example from github that shows the same thing I want, except it uploads from Firebase Database to Google Sheets:
https://github.com/firebase/functions-samples/tree/master/google-sheet-sync
My plan was to follow this guide exactly to get it working, and then figure out how I can change it for Storage -> Team Drive.
However in following the instructions in the readme (they're pretty old) I've come across an error and now I'm stuck.
For Step #7 in that link where it says to run $ firebase functions:config:set googleapi.client_id="<id>" and the rest of the command, I get in terminal:
Error: HTTP Error: 403, The caller does not have permission
What should be the steps I'm looking at to get this working? I am also unsure if my current implementation makes sense anymore. It wouldn't be a big deal to make everyone using the app sign-in with a Google account so that they can be a member of the Team Drive and just upload directly from the app to Drive. Would that still include the sort of safety behaviour like if the connection drops the file upload will resume independently?

The answer to my first question is to install googleapis and google-auth-library. Run the command in the actual /functions/ directory of the sample.
There were a few other errors created by old code, but they aren't in the scope of this question and I raised them in the github Issues sections.

Related

Cannot access Firebase Storage after creating storage bucket in GCP Console

I noticed that Firebase wouldn't let me create a storage bucket asia-southeast1 so I upgraded my plan to blaze, went to the GCP console and created a bucket from there.
I did the same for Firestore and it's working fine.
However, after I created the storage bucket in GCP, and I came back to the Firebase console to access Firebase Cloud Storage, I keep receiving this error.
I don't see how creating a bucket in the GCP console may affect your Firebase project (unless you created a bucket named <your-project-name>.appspot.com).
These kinds of errors normally happen when a certain quota has been reached, and is usually solved by upgrading your project to a paid plan.
As you have already upgraded your project, please bear into account that billing updates usually take some time to be processed. Waiting a few hours, or maybe checking the next day whether your project has been successfully upgraded should do the trick.
If that does not help, verify whether you have actually upgraded your project - You can check that here. The Blaze Plan button should be grayed out with the message Current Plan.
The answer provided to this question may also be of help:
Try to activate this feature using an incognito window/private window
and disable all browser extensions
Try using a different browser (and make sure browser is supported)
Verify if there are any other programs that might be blocking your
connection such as antivirus, proxy or firewall. If yes, try to
disable them.
Connect using a different network.
Connect using a different device.
Check the Developer Tools Console for any errors.
For Safari: Safari > Preferences > Advanced > Check "Show Develop menu
in menu bar" Develop > Show Web Inspector > Console Tab
If none of these approaches work for you, consider contacting Firebase Support here.
I fixed mine by using the command to work on it using
firebase init storage
This would create the storage after that it would add a storage.rule in which you can update to your liking in your project .
Then you run this command
firebase deploy --only storage
This would initialize the Storage
If you are still having issues check out this link https://stackoverflow.com/a/74750337 which was also provided by firebase for me to fix the error

Unexpected error when querying Google Play Developer API

We have been trying to set up the sample app for Play Billing workflow with subscriptions as we are looking to introduce subscriptions in our app. We wanted to have the ClassyTaxi app running end to end in order to understand the flows better. Although for past 2 days, we are only trying to debug issues and/or missteps because of some really poor documentation on Google's front.
After ensuring every single step was correctly followed, we were able to make some progress and have the app working with the correct Skus as configured in Play Console. But now the backend server (ClassyTaxiServer) is throwing below error:
"Unexpected error when querying Google Play Developer API. Please check if you use a correct service account" - "OtherError: The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console.".
We have relooked, recreated the service account on the Cloud Console several times, but no luck.
The Play Console is correctly linked with the Google Cloud project and the access is correctly granted to the service account.
Anyone has any suggestions? How can a sample app be so difficult to set up and function as expected? Or are we doing something terribly stupid?
Please help.
Thanks.
I passed trough similar situation, and I get same issue. After checking I found a note in google documentation saying the following:
Note: As of December 1, 2019, the Google Play Developer API is available only for version 3 and higher. If you're using a lower version of the API, you must migrate to version 3 by this date. For more information on migrating to version 3, see Changes to the Google Play Developer API.
Investigating the implemented code I found that the sample uses v2 of the google API (check ./subscriptions/play-billing/PlayBilling.ts line 70). So to avoid this situation, you will need to set it to v3, and update googleapis dependency to latest version in package.json.
Additional Notes
After solving this issue, I had a different message in 'OtherError', this time is “The current user has insufficient permissions to perform the requested operation.”. I will note my solution here just someone passed through similar situation:
In google play console, and after clicking on 'Grant access' in 'API Access' tab, you will need to select the user and add some permissions to the user (in my case I set it to admin, but I think it's larger than needed), make sure also to add the app/apps you are listening to.
If the issue is still running, just edit any of your products or just try creating new one, this step will clear the google cash and refresh permissions. (Check this question).

Google Cloud Build can't pull Container Registry images after 1 day

We have CICD enabled, GCP Cloud Build has all the permissions (including Editor, Storage Admin and many many other permissions)
When we follow the steps for getting the image for the first time using instructions here: https://cloud.google.com/cloud-build/docs/deploying-builds/deploy-firebase, cloud build works perfectly.
However, after some time (say 1 day), it starts giving error "unable to pull the image"
Step #0: latest: Pulling from <project name>/firebase
Step #0: 81fc19181915: Pulling fs layer
Step #0: 828510924538: Pulling fs layer
...
Step #0: fe190282039f: Waiting
Step #0: error pulling image configuration: unknown blob
CANCELLED
ERROR: context canceled
ERROR: failed to pull because we ran out of retries.
If we upload the image again, it starts working again only for some time.
Note: We checked and the image is there in Container Registry, but still for some reason Google Cloud Build can't find it.
How can we fix this? Any suggestions on what we need to look at?
Uploading image every single time makes the whole CICD process redundant as we might as well deploy manually.
Thank you,
I had the exact same issue - after pulling images successfully for a period I would start getting the error "unable to pull the image". Permissions were not the issue.
I found my problem. Google GCP Container Registry stores the Docker artefacts in Google GCP Storage in artifacts.<PROJECT_ID>.appspot.com. I set 2 week expiry times on all my Cloud Storage locations to save money. Therefore whenever a Docker artefact was deleted in Cloud Storage all the related Docker images in GCP Container Registry would report an unknown blob when trying to download the deleted slice and the image download would fail. Maybe Google could have explained the link to Cloud Storage better but I suppose should not have set expiry times on storage locations for which I didn't know the exact purpose.
As you mentioned that the Cloud Build only works for one day, you need to re-upload the image to make sure it is working. I think the issue may be caused by the cloud build configuration, maybe be the trigger or tags. Since it is not appropriate to provide your cloud build configuration file here. I recommend you to open a support ticket in the Cloud Console. You can refer to this link to get the instruction of how to File a support case.

Can you give blanket public access to users in a Firebase project?

I have an open-source project that uses two separate Firebase projects for a test environment and the production one.
Ultimately, I want to have other developers be able to pull down the project and actually be able to run it WITHOUT me needing to give each individual developer access.
I see a number of solutions in this question: How to add collaborators to a Firebase app?. Those all seem to require each person's email.
I understand why it maybe isn't a thing, but I am wondering if there is a way to just give access to everyone for only the test project so that contributing is super low-friction. Something similar to Firestore database rules that allow read/write in a public fashion to get started for testing.
I've tried making a new IAM account in the Google Cloud Console, and I think that partially worked for the Firebase Cloud Functions access to Admin SDK, but my collaborators get hung up trying to run firebase use <test-firebase-project> saying that they don't have access.
I see a lot of other config options for IAM, but nothing sticking out to me for this public access scenario.
Can anyone confirm this either is or isn't a thing?
Thanks!
EDIT
To add some more detail to my project...
I am using Authentication, Firestore, and Cloud Functions. The only js package I will use is the Auth one, which will be loaded from a CDN (so I believe that doesn't apply to my question).
I want to give access to people to run the Cloud Functions locally. There is a pre-build step that I have made in vanilla Node that calls a Cloud Function (running locally), which uses the Firebase Admin SDK to call my Firestore database. I then write that response to a JSON file that my front end uses.
When my collaborators pull down the project, and install the Firebase CLI, when they try to serve the Cloud Functions locally, they get hit with a "no access" type of error. I was trying to resolve this by adding a service account into the /functions directory, but apparently that didn't help.
My collaborators don't need access to the console at all. I basically just need them to be able to run the Cloud Function locally (and make sure they can't access my production Firebase project).
I am happy to add more detail, but I kind of feel like I am just rambling. Thanks again.
There is no way to grant everyone contributor access to your Firebase console. You will either have add each individual user, or create your own dashboard that uses the API to show the relevant data.

Firebase back-up

I use Firebase for an Android project and I have some data into a database. I want to know if there is any possibility to save/make a back up to the structure of data. I ask this because somehow, I deleted the project and I had to do all again.
If you just deleted your project, you may still be able to restore it from the Resources pending deletion page in the Google Cloud Platform console with the process shown here.
If that doesn't work, reach out to Firebase support to see if they can help you recover it.
Note that both of these are dependent on the time that has passed since you deleted the project, so time is of the essence.

Resources