otto
otto

Reputation: 2033

firebase Certificate object must contain a string "private_key" property

I am using firebase cloud messaging with node.js. I just want to connect to firebase cloud messaging I get this error message:

/home/t/ws/js/webserver/blitzer/node_modules/firebase-admin/lib/auth/credential.js:119
            throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_CREDENTIAL, errorMessage);
            ^

Error: Certificate object must contain a string "private_key" property.

this is my code:

import * as admin from 'firebase-admin'
import serviceAccount from  './google-services.json'
const registrationToken = 'fMaw-YgWgwY:APA91bEwv7Z_FHPx0kCuiM6_Ji004_d_K5WQh9PMH1IgshLb_Lqq7zhicKdg6lFO5dl0FY3im5r0jgMZrWNbZIXpPL4k1JC22hT5fUY5h5B3RVXjgRCBQI-l9cNxBRVZP-cnJtyYbqMKqmwvGD8fg3ae8QQjAkRe0w'

var message = {
    data: {
      score: '850',
      time: '2:45'
    },
    token: registrationToken
  };
admin.initializeApp({
    credential: admin.credential.cert(serviceAccount)
});


admin.messaging().send(message)
  .then((response) => {
    // Response is a message ID string.
    console.log('Successfully sent message:', response);
  })
  .catch((error) => {
    console.log('Error sending message:', error);
  });

and here is my google-services.json file. I downloaded it from firebase console. There is no key private_key property that is right, but I have downloaded the correct google-services.json. My Firebase-admin version is 5.13.0

{
  "project_info": {
    "project_number": "x",
    "firebase_url": "x",
    "project_id": "x",
    "storage_bucket": "x"
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "x",
        "android_client_info": {
          "package_name": "x"
        }
      },
      "oauth_client": [
        {
          "client_id": "x",
          "client_type": x
        }
      ],
      "api_key": [
        {
          "current_key": "x"
        }
      ],
      "services": {
        "analytics_service": {
          "status": x
        },
        "appinvite_service": {
          "status": x,
          "other_platform_oauth_client": []
        },
        "ads_service": {
          "status": x
        }
      }
    }
  ],
  "configuration_version": "x"
}

Upvotes: 1

Views: 6207

Answers (2)

According AppOptions interface you need also pass as a param insite initializeApp() method a property named projectId in the same level of credential property with the project id value.

Upvotes: 0

otto
otto

Reputation: 2033

i downloaded the wrong json file. Correct json file is in settings -> serviceaccounts -> and then generate key

Upvotes: 4

Related Questions