On my Firebase app, I'd like to know the recommended way to make a server-side request to Cloud Storage for Firebase on behalf of a signed-in user (authenticated via ID token), with security rules applied to the request (i.e. not with the Admin SDK).
The overall app flow currently looks like this:
- User signs in on the client and makes a request to a Google Cloud API gateway, sending their ID token in the request header
- API gateway authenticates user and forwards request to different endpoints in the backend API:
- If it's a request for Firebase Authentication, the API uses Auth Admin SDK to handle it directly
- If it's for Firestore, the API uses the
x-forwarded-authorization
request header (which contains the ID token originally provided by the client) forwarded by API gateway to then make a request to Firestore's REST API, so that the request can be evaluated by security rules.
For Cloud Storage, I'd like to do something similar to the Firestore case above, but there isn't a Firebase-specific REST API available in the docs. It's possible to just let the client make requests directly to Firebase (as suggested in this answer), but would prefer to keep the logic in the backend.
Are there alternatives to doing this for Storage? Please feel free to also point out if there are better ways of handling the Firebase Auth and Firestore cases mentioned above. Thanks!
EDIT: Adding more possible solutions as I find them
- Doug's answer here and Frank's answer here suggest using the Cloud Storage REST API, where the app generates an OAuth token for the user and makes the request
- This answer here mentions it's possible to pass an
auth=IDTOKEN
query parameter to the Firebase REST API:
Once you have an ID token, you can pass that to the REST API via the auth query parameter to authenticate a request. The request respects Firebase Security Rules as if the end user logged into the client was making the request.