Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I get "serviceAccountCredentials.json" for Firebase Admin?

Here is said what I need to setup Firebase on java:

FirebaseOptions options = new FirebaseOptions.Builder()
    .setDatabaseUrl("https://databaseName.firebaseio.com")
    .setServiceAccount(new FileInputStream("path/to/serviceAccountCredentials.json"))
    .build();
FirebaseApp.initializeApp(options);

But where can I get serviceAccountCredentials.json ?

UPDATED: I found that this file seems should have this fields, but where get this values?

{
  "type": "",
  "project_id": "",
  "private_key_id": "",
  "private_key": "",
  "client_email": "",
  "client_id": "",
  "auth_uri": "",
  "token_uri": "",
  "auth_provider_x509_cert_url": "",
  "client_x509_cert_url": ""
}
like image 213
NickUnuchek Avatar asked Nov 25 '16 06:11

NickUnuchek


People also ask

How do I get Firebase Admin JSON?

In the Firebase console, open Settings > Service Accounts. Click Generate New Private Key, then confirm by clicking Generate Key. Securely store the JSON file containing the key.

Where is JSON file in Firebase?

Open your browser, go to your Firebase console->Three Dots on the right->Import JSON. Important to note that when importing, whichever node you have selected in your Firebase database will be overwritten, so make sure you don't have your root node selected - create a child node and then do your import.

What is serviceAccountKey JSON?

serviceAccountKey.json is not the actual file name However, it's just a place-holder name. The file is generated with a unique name from the Google Web UI, and that is the file to apply where the place-holder is referenced.

What is JSON file in Firebase?

All Firebase Realtime Database data is stored as JSON objects. You can think of the database as a cloud-hosted JSON tree. Unlike a SQL database, there are no tables or records. When you add data to the JSON tree, it becomes a node in the existing JSON structure with an associated key.


2 Answers

Found details about this in this link

[UPDATED 30.11.2021]

To generate a private key file for your service account:

In the Firebase console, open Settings > Service Accounts.

Click Generate New Private Key, then confirm by clicking Generate Key.

Securely store the JSON file containing the key.

When authorizing via a service account, you have two choices for providing the credentials to your application. You can either set the GOOGLE_APPLICATION_CREDENTIALS environment variable, or you can explicitly pass the path to the service account key in code. The first option is more secure and is strongly recommended.

NB: When you generate a new private key, the old key will stop working immediately

To create the a new private key file you need to go to this link

https://console.firebase.google.com/project/**YOUR_PROJECT**/settings/serviceaccounts/adminsdk

[OLD]

Quote from firebase docs:

  1. Navigate to the Service Accounts tab in your project's settings page.
  2. Click the Generate New Private Key button at the bottom of the Firebase Admin SDK section of the Service Accounts tab.

After you click the button, a JSON file containing your service account's credentials will be downloaded. You'll need this to initialize the SDK in the next step.

Warning: Use extra caution when handling service account credentials in your code. Do not commit them to a public repository, deploy them in a client app, or expose them in any way that could compromise the security of your Firebase project.

This file is only generated once. If you lose or leak the key, you can repeat the instructions above to create a new JSON key for the service account.

like image 60
NickUnuchek Avatar answered Oct 10 '22 17:10

NickUnuchek


You can directly go to your Firebase portal --> Project Settings then Service accounts. I made a tutorial that explain all the details : How to get my Firebase Service Account Key file

like image 32
Clement Avatar answered Oct 10 '22 15:10

Clement