0
votes

I have a node.js client that uses firebase authentication. Now I want to access Google Cloud Storage, however the firebase SDK for node.js does not include GCS. Using @google-cloud/storage works but only with anonymous access. How do I apply the firebase credential to @google-cloud/storage so that GCS access is in the context of the logged-in user?

2
This can be done. Post your code where you are authenticating with Google. The key is extracting the access token and then creating credentials for the storage SDK. You will need something like this: firebase.auth().signInWithPopup(provider).then(function(result) { token = result.credential.accessToken; - John Hanley
You can also do this: // Get a non-default Storage bucket var storage = firebase.app().storage("gs://my-custom-bucket"); and then access your bucket using firebase storage apis. firebase.google.com/docs/storage/web/start - John Hanley

2 Answers

0
votes

Node.js is a server that operates in a privileged environment. The Firebase Admin SDK (aka the Node SDK) talks to other services via a service account.

Firebase Authentication enables client-side authentication. The JavaScript SDK is the client-side SDK.

0
votes

There is no Node.js client SDK for Firebase that accesses Cloud Storage. Since both the Firebase Admin SDK and the Google Cloud Platform client for Node.js use administrative privileges to access Cloud Storage, it looks like those won't be an option for you either.

The two options I can think of are:

  • Use the Admin SDK in a Cloud Function, and expose the files from Cloud Storage that way.
  • Use the REST API for Cloud Storage.

I admit that neither is trivial, so I hope somebody knows a better solution.