The Captain of the Ferris Wheel

I went to college in Southern California but never went to Coachella during those four years. To be honest, I didn’t even know what Coachella was, and I could count the number of concerns and musical…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Firebase Functions cross projects invocation

Firebase is a subset of Google Cloud Platform’s products

Our team is developing an appraisal feature that allow a property’s owner to be able to appraise their premise base on some of the property’s characteristic. We have already had a system that will preprocess this information, like geocoding, tagging near by landmarks, etc., which was written in NodeJS. But our new appraisal component is a regression model that was written in Python, and we’ve decided to separate the new component into a different Firebase project so that maybe in the future we can publish this API as a standalone product. With that said, for now, we need a quick and easy way for our internal functions to be able to call each other and still does not allow public access.

From now on, I will refer to the Firebase Functions that being called as receiving function, the Firebase Functions that is calling as calling function, and the original Google document as the document.

This step is quite straight forward, you should be able to follow the document’s instruction easily. In short, you need to grant the role Cloud Functions Invoker (roles/cloudfunctions.invoker) of the receiving function to the calling function’s service account email.
How to find the calling function’s service account email:

Another note is that if you’re running Firebase Functions’ shell or emulator, you will also need to add the service account that you’re using to authenticate to the receiving function’s Cloud Functions Invoker role. For example, if you’re running the shell locally like this:

Please pay attention to the const targetAudience = url (line 15). According to the document and the example source code, it seems that targetAudience should be the origin of the URL (?), meaning “https://region-project-id.cloudfunctions.net” in this example. I don’t know if it’s a mistake but as I tried the document’s example code, it simply does not work, and Google cloud does not give us any log of what’s the problem. After several trial and error, audience needs to be full URL.

Also, on line 24, if you don’t add this line, the default Content-Type is text/plain, it would not be any problem if your deployment can support this content type. However, Firebase Functions requires the application/json content type and will give you the incorrect content type error if you skip this line.

As you know Firebase Functions allow https.onRequest and https.onCall helpers to deploy. The former https.onRequest is plain Google Cloud function, and https.onCall is basically https.onRequest with a special protocol to easily authenticate your request with Firebase Authentication. However, as you notice above, we’re not using Firebase Authentication to authenticate the request, so if we’re use https.onCall in this case, it would not work, it would simply show this error for wrong audience.

What you should do is using https.onRequest protocol that does not include a Firebase Authentication step. For example:

That’s it. You should be able to call Firebase Functions across projects with ease.

Add a comment

Related posts:

101 Daily Positive Affirmations For Kids

Affirmations. We all need it. I use them personally, and I use it with my family on a daily basis. Positive affirmations can be a powerful tool for kids as well. By using the right sentences we can…

Skipping Memories

I am getting close to turning 55 years old. My memory is skipping out on me much like a rock thrown upon a pond. I know as the rock stays solid and whole so will my mind for now. But, my recall of…

What is JSX? Find out about the syntax used to write code in ReactJS

As a student learning front-end development, your first choice after HTML, CSS, and Javascript is a framework that will make it easy to create the first project. And as most beginners start with…