GooglePlayServicesComponents icon indicating copy to clipboard operation
GooglePlayServicesComponents copied to clipboard

Xamarin.Firebase.Functions can't determine region on client

Open jawa-gh opened this issue 5 years ago • 10 comments

According to the docs for Firebase Functions: regarding the callable function, client callable setups should follow the same guidelines as HTTP functions. The client can also specify a region, and must do so if the function runs in any region other than us-central1. -> https://firebase.google.com/docs/functions/locations

In this nuget package there is no possibility to set the region on client. Please does somebody know how to solve this? Help is appreciated. Thx.

Update: I want to use Firebase Functions in my Xamarin Android Project. Therefore I have set up callable function which can be called directly from the App(https://firebase.google.com/docs/functions/callable). I also set up a specific region in the function like this: exports.testfunc = functions.region('europe-west1').https.onCall(async data =>{ // code })

So in the firebase functions documentation the following is mentioned:

Regarding the callable function, client callable setups should follow the same guidelines as HTTP functions. The client can also specify a region, and must do so if the function runs in any region other than us-central1.

There are also examples given how to set it up fore the client: Android: private FirebaseFunctions mFunctions; mFunctions = FirebaseFunctions.getInstance("us-central1");

Unity: firebase.Functions.FirebaseFunctions functions; functions = Firebase.Functions.FirebaseFunctions.GetInstance("us-central1");

C++: firebase::functions::Functions* functions; functions = firebase::functions::Functions::GetInstance("us-central1");

I wanted to achieve the same with C# using the Xamarin.Firebase.Functions Nuget Package: private void InitFirebase() { //firebaseFunctions = FirebaseFunctions.Instance; FireabseApp app = FirebaseApp.InitializeApp(this); FirebaseFunctions firebaseFunctions = FirebaseFunctions.GetInstance(app); } But I can't specify the region. FirebaseFunctions.GetInstance just accepts an instance of FirebaseApp as parameter. When initializin the FirebaseApp I also can't find an option to define the region.

jawa-gh avatar Oct 15 '19 17:10 jawa-gh

@jagnarock Would it be possible to provide minimal repro sample? This would help me speed investigation up.

moljac avatar Oct 16 '19 09:10 moljac

@jagnarock

Decompiled classes.jar from firebase-functions aar artifact:

    public static FirebaseFunctions getInstance(final FirebaseApp app) {
        return a(app, "us-central1");
    }
    
    public static FirebaseFunctions getInstance() {
        return a(FirebaseApp.getInstance(), "us-central1");
    }

There is no, getInstance(string). Perhasps API changed?

Could you be so kind and check the docs for newer versions, please?

According to this doc you are right, but decompiled artifact does not have that API.

https://firebase.google.com/docs/reference/android/com/google/firebase/functions/FirebaseFunctions.html#getInstance(java.lang.String)

There is ctor accepting string for region. Could that be the new API?

moljac avatar Nov 04 '19 13:11 moljac

@moljac Thx for the info. I will chek it and let you know then.

jawa-gh avatar Nov 13 '19 09:11 jawa-gh

HI @moljac Thx again for checking. Had again a look on this issue. I'm still not quite sure how this should work for C# and the given nuget package. https://firebase.google.com/docs/reference/android/com/google/firebase/functions/FirebaseFunctions.html#public-static-firebasefunctions-getinstance-string-region In Java (and also for other languages) there is a GetInstance(string region) method. This one is not provided in C# and also can't find anywhere to set the region on client side - and the region has to set on client side otherwise I would have to set up the functions in us region (=default). Also var app = FirebaseApp.InitializeApp() takes just the Context and no region.

For the time being I found a workaround/solution: I set up cloud functions which can be called via https and in the Xamarin project i instantiate a HttpClient where I can privide the functions url (with the region) and call the functions directly and not via the nuget package. Technically I think it's the same.

jawa-gh avatar Nov 20 '19 17:11 jawa-gh

@jagnarock OK. i will decompile the aar (jar) and see.

moljac avatar Nov 22 '19 15:11 moljac

Any update??? I've just run in to this now and it's a bit of a problem :/

jmkyarrow avatar Jul 23 '20 12:07 jmkyarrow

I also still could not figure out how to solve this issue (meanwhile switched technology); One idea would be to implement an own httpclient in C# without using the callable funcitons package.

jawa-gh avatar Jul 29 '20 08:07 jawa-gh

I've just switched to using standard https functions with authorisation header which wasn't much work to sort out (the admin SDK couldn't make that easier tbh) plus it means it means here I can just JSON serialise my data in my XF project rather than have to bespoke build my objects every time on each platform so it's for the better tbh.

jmkyarrow avatar Jul 29 '20 10:07 jmkyarrow

I've just found a solution. Instead of calling "DefaultInstance", you make it "From":

Firebase.CloudFunctions.HttpsCallable call = Firebase.CloudFunctions.CloudFunctions.From("southamerica-east1").HttpsCallable("addMessage");

movisis avatar Jun 03 '21 00:06 movisis

I've just found a solution. Instead of calling "DefaultInstance", you make it "From":

Firebase.CloudFunctions.HttpsCallable call = Firebase.CloudFunctions.CloudFunctions.From("southamerica-east1").HttpsCallable("addMessage");

thx for the hint, will have a look at it

jawa-gh avatar Jun 04 '21 10:06 jawa-gh