Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore Server Authentication: Overlapping Documentation

Issue

I'm hosting an app written in Kotlin on AppEngine and have come across overlapping documentation from Google regarding Authenticating a Firestore running on a server. Both implementations run as expected on AppEngine. Does one implementation have advantages, are there separate use cases, or is this purely a duplication?

Firebase's documentation

Initialize on your own server To use the Firebase Admin SDK on your own server, use a service account.

Go to IAM & admin > Service accounts in the Cloud Platform Console. Generate a new private key and save the JSON file. Then use the file to initialize the SDK:

import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.firestore.Firestore;

import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;

// Use a service account
InputStream serviceAccount = new FileInputStream("path/to/serviceAccount.json");
GoogleCredentials credentials = GoogleCredentials.fromStream(serviceAccount);
FirebaseOptions options = new FirebaseOptions.Builder()
    .setCredentials(credentials)
    .build();
FirebaseApp.initializeApp(options);

Firestore db = FirestoreClient.getFirestore();

Google Cloud's documentation

Add the server client library to your app

Using Gradle: compile 'com.google.cloud:google-cloud-firestore:0.58.0-beta'

Initialize Cloud Firestore

import com.google.cloud.firestore.Firestore;
import com.google.cloud.firestore.FirestoreOptions;
FirestoreOptions firestoreOptions =
FirestoreOptions.getDefaultInstance().toBuilder()
    .setProjectId(projectId)
    .build();
Firestore db = firestoreOptions.getService();
like image 912
Adam Hurwitz Avatar asked Mar 22 '26 12:03

Adam Hurwitz


1 Answers

The Firebase Admin SDK (which bundles SDKs for a bunch of different products) is just a wrapper around the Google Cloud Firestore SDK. Pick the one that's most convenient for your situation. - Doug Stevenson, Firebase team

like image 74
Adam Hurwitz Avatar answered Mar 24 '26 02:03

Adam Hurwitz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!