Reputation: 1108
I am trying to add some custom headers to a Firebase HttpsCallable function when calling from client side. But the firebase.functions.HttpsCallable does not provide any way to customize headers. The second param "options" only support "timeout".
Is there any workaround or alternative solution to add headers to a Firebase function?
Upvotes: 1
Views: 4990
Reputation: 83113
As explained in the protocol specification for https.onCall
, you can only have the following headers when calling a Callable Cloud Function:
Required:
Content-Type: application/json
An optional ;charset=utf-8
is allowed.Optional:
Authorization: Bearer <token>
A Firebase Authentication user ID token for the logged-in user making the request. The backend automatically verifies this token and makes it available in the handler'scontext
. If the token is not valid, the request is rejected.Optional:
Firebase-Instance-ID-Token: <iid>
The Instance ID token from the Firebase client SDK. This must be a string. This is available in the handler'scontext
. It is particularly useful for sending push notifications.
And the doc adds that:
If any other headers are included, the request is rejected
On the other hand, with HTTP Cloud Functions you can add any custom header that you want. However, by using an HTTP Cloud Function, you'll loose the advantages of a Callable Cloud Function (i.e. Firebase Authentication and FCM tokens are automatically included in requests and the functions.https.onCall trigger automatically deserializes the request body and validates auth tokens).
Upvotes: 5