• Returns a credential created from the provided service account that grants admin access to Firebase services. This credential can be used in the call to firebase-admin.app#initializeApp.

    See Initialize the SDK for more details.

    Parameters

    • serviceAccountPathOrObject: string | ServiceAccount

      The path to a service account key JSON file or an object representing a service account key.

    • Optional httpAgent: Agent

      Optional HTTP Agent to be used when retrieving access tokens from Google token servers.

    Returns Credential

    A credential authenticated via the provided service account that can be used to initialize an app.

    Example

    // Providing a path to a service account key JSON file
    var serviceAccount = require("path/to/serviceAccountKey.json");
    admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://<DATABASE_NAME>.firebaseio.com"
    });

    Example

    // Providing a service account object inline
    admin.initializeApp({
    credential: admin.credential.cert({
    projectId: "<PROJECT_ID>",
    clientEmail: "foo@<PROJECT_ID>.iam.gserviceaccount.com",
    privateKey: "-----BEGIN PRIVATE KEY-----<KEY>-----END PRIVATE KEY-----\n"
    }),
    databaseURL: "https://<DATABASE_NAME>.firebaseio.com"
    });