Where can I get “serviceAccountCredentials.json” for Firebase Admin?

自作多情 提交于 2021-01-20 15:46:27

问题


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": ""
}

回答1:


Found details about this in this link

To create the file you need to go to this link

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

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.




回答2:


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



来源:https://stackoverflow.com/questions/40799258/where-can-i-get-serviceaccountcredentials-json-for-firebase-admin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!