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?
Asked
Active
Viewed 1,073 times
0
-
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 Jan 07 '19 at 04:27
-
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. https://firebase.google.com/docs/storage/web/start – John Hanley Jan 07 '19 at 04:37
2 Answers
0
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.

Ronnie Royston
- 16,778
- 6
- 77
- 91
-
Hi Ron, thanks for the info, but I'm not using the firebase admin SDK, nothing privileged. The firebase SDK for node.js works great for client-side end-user login, however it doesn't include GCS. – David Asher Jan 07 '19 at 03:20
0
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.

Frank van Puffelen
- 565,676
- 79
- 828
- 807