It is possible to use OAuth with Cloud Functions. You can check this link for more information, but here is a little summary from it:
First, you would need to configure an OAuth client ID for its use with the Gmail API. After enabling the API and selecting the region, go to the Cloud Console and create the appropriate credential based on the function you are developing. It should include the application type, a name for your client and some authorized JavaScript origins, as shown in the link above. This will provide you a client secret you should store safely.
You would also need to configure some files based on the settings you applied in the Console, such as index.js
and package.json
, as well as renaming the client secret you received with the previous configuration. After adding the proper project and region to your files, it is time for deployment, using the commands included in the link to deploy the functions, initiating the deployment in the same directory where the index.js
file is located.
As for the need to use the refresh token every time to generate new access tokens on every invocation, that would depend on when the access token is set to expire, or when you consider that your current access token is not secure. Refresh tokens can be used any time you see fit, but not for every invocation to the function as long as the access token is valid.
The costs will vary depending on how many invocations you are performing throughout the month, with the first 2 million being free, while the compute time costs may vary depending on how much memory and CPU are being used. Here you can check how Cloud Functions are currently priced. Operations such as using a refresh token to update an access token do not seem to have much effect on the costs, as far as I know.
All of this I explained is more related to Cloud Functions in general rather than Firebase. I am not familiar with the use of Firebase, but I would assume that since the functions samples are meant to be kept as simple as possible, they would include a more simple way of authentication. Anyway, you can add the OAuth option yourself, as you can see in the Firebase documentation.
I hope all of this helps you understand how to use OAuth with Cloud Functions.