Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Cloud Functions Secure HTTPS Endpoints with API key

I've looked at a few places, Including this post and the firebase panel

enter image description here

Is there no way to use these api's to secure these endpoints using an api key you create per client who uses your cloud functions?

I'm able to block every one putting a restriction on the Browser key, but I would like to create a new api key, and use that as a way to authenticate my endpoint for various clients.

Creating a new api key, and using that as a parameter in my query doesn't work (don't now if I'm doing anything wrong)

enter image description here

Is there a way to do this?

like image 667
Ruan Avatar asked Oct 20 '18 18:10

Ruan


People also ask

How to secure Firebase Cloud Functions for authenticated users?

Secure Firebase Cloud Functions for Authenticated Users 1 Method 1 - Database Trigger with Backend Rules#N#database.rules.json#N#Cloud Function index.js 2 Method 2 - HTTP Trigger with CORs and Token Decoding#N#HTTP Cloud Function that Validates Auth Data#N#Make the HTTP Call in... More ...

What happens if someone gets my Firebase API key?

If you use password-based Firebase Authentication and someone gets hold of your API key, they will not be able to access any of your Firebase project's database or Cloud Storage data as long as this data is protected by Firebase Security Rules.

How do I enable Firebase authentication in OpenAPI?

To support Firebase authentication: Add the following to the security definition in your OpenAPI document: Add a security section at either the API level to apply to the entire API, or at the method level to apply to a specific method.

How do I restrict access to the firebase Super Service API?

Return to the Credentials page. Be sure your Firebase project is still selected. Click Create credentials > API key. Take note of the new API key, then click Restrict key. In the API restrictions section, select Restrict key, then add to the list only the Super Service API. This new API key grants access only to the Super Service API.


1 Answers

Option 1: handle authentication within the function

https://github.com/firebase/functions-samples/tree/master/authorized-https-endpoint

Adapt above to use clients/keys stored in firestore


Option 2: Use an an API Gateway

  • Google Cloud Endpoints (no direct support for functions yet, need to implement a proxy)
  • Apigee (higher cost, perhaps more than you need)
  • Azure API Management (lower entry cost + easy to implement as a facade for services hosted outside Azure)
  • there are more..

The above gateways are probably best for your use case in that the first two would let you keep everything within Google, albeit with more complexity/cost -- hopefully Endpoints will get support for functions soon. Azure would mean having part of your architecture outside Google, but looks like an easy way to achieve what your after (api key per client for your google cloud / firebase functions)

Here's a good walkthrough of implementing Azure API Management:

https://koukia.ca/a-microservices-implementation-journey-part-4-9c19a16385e9

like image 71
Ville Avatar answered Sep 30 '22 06:09

Ville