googlearchive / firebase-dart

Dart wrapper for Firebase
https://pub.dev/packages/firebase
404 stars 144 forks source link

How do you find or create the 'credential'? #314

Closed aloenobilis closed 4 years ago

aloenobilis commented 4 years ago

Hi,

Firebase allows for service account credentials to be created, which downloads a .json with a private key, client id, client mail etc, but I dont see a single string token/credential. The api provided by firebase-dart is dissimilar from nodejs.

final fbClient = FirebaseClient(credential);

How do you find or create the 'credential'?

EDIT: this is for the Dart VM

EDIT: should import "package:googleapis_auth/auth_io.dart"; be used?

aloenobilis commented 4 years ago

@kevmoo can you maybe help with this?

andrerpena commented 4 years ago

@sashvoncurtis I am also on a quest to get this working. I even mentioned this issue on this Stackoverflow question I posted now https://stackoverflow.com/questions/61835023/how-do-i-access-firebase-firecloud-from-dart-vm-dart-integration-tests

aloenobilis commented 4 years ago

@Ehesp help us! :)

Ehesp commented 4 years ago

Hey, not directly involved here but it does look as through you need to pass in an auth token; it's left open as that can come from anywhere (see https://firebase.google.com/docs/database/rest/auth).

To keep it all in Dart land, you'd want to use https://pub.dev/packages/googleapis along with the auth dep: https://pub.dev/documentation/googleapis_auth/latest/

aloenobilis commented 4 years ago

@Ehesp will give that a try, thanks.

aloenobilis commented 4 years ago

@Ehesp https://pub.dev/packages/googleapis is where its at. Thanks again.

andrerpena commented 4 years ago

@sashvoncurtis , before you close, did you get to make this to work?

I dont know how to transform the credentials from googleapis into the string that FirebaseClient expects. This is the question I ask here:

https://stackoverflow.com/questions/61835023/how-do-i-access-firebase-firestore-from-dart-vm-dart-integration-tests

If you found the answer, it would be amazing if you could share it.

Thank you

aloenobilis commented 4 years ago

@andrerpena no worries.

The googleapis package is the one you want to use, it provides a FirestoreApi object, docs: https://pub.dev/documentation/googleapis/latest/googleapis.firestore.v1/googleapis.firestore.v1-library.html.

You need to specify the import for firestore, import 'package:googleapis/firestore/v1.dart';, the service credentials are passed to clientViaServiceAccount which returns an authenticated http-client which is used to make the requests.

Make sure to install both googleapis and googleapis_auth.

Hope that helps.

andrerpena commented 4 years ago

Thank you @sashvoncurtis ! That worked