0

I'm looking into porting a unity game with a dotnet backend over to firebase firestore / functions, etc. My initial tests look promising, but my biggest hold-up is that I would need to rewrite a lot of the server-side logic in JavaScript.

I know that firebase's functions and firestore both run on google cloud, and the cloud version of functions supports a number of additional languages, including c#. I was able to create a couple of C# test functions and upload them to the same project as my unity test. They show up in the firebase portal and can be called via the HTTP endpoints supplied by google cloud, etc.

I discovered that I can call the function that does not require auth using the FirebaseFunctions callabale API in unity (fun fact, it only seems to work if the response is a JSON object in the form of { "result": [data here] }) I cannot, however, call the version of the same function that does require authentication - it returns an internal error message.

I am wondering there is a way to make these methods callable from the unity firebase API - passing in the user id/auth that I get from logging into firebase? I've seen some examples/answers where people say to call the cloud function directly using the Authorization: bearer token header, but I cannot seem to find a way to get the auth token from the current user in the Unity Firebase API.

I imagine that I am stepping further outside the realm of firebase unity API and more into google cloud/identity platform

1 Answer 1

0

You can retrieve the ID token of the current user by calling TokenAsync() on their profile.

That's the value you need to pass along in the Authorization header of the call to Cloud Functions, where you can then access it in you Callable Cloud Function.

Alternatively you can implement a regular HTTP Cloud Function, pass the same in whatever way you see fit there, and then on the server decode and verify the ID token with the Admin SDK yourself.

1
  • Thanks for info. I had totally missed the token on the user profile. When I was experimenting with the token and the Google Cloud console, I discovered that the auth setting on the js function that I uploaded via the firebase tools didn't have auth required - so, what I was seeing with my C# function was the exact same behaviour. I haven't checked it yet, but I am confident that your suggestion of sending the header and checking with the admin tools would work. Ideally I would be able to block non firebase authorized calls before firing the function, but I'm not sure that it is possible
    – Sevdanski
    Oct 17, 2021 at 7:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.