firebase-admin.app package

Firebase App and SDK initialization.

Functions

Function Description
applicationDefault(httpAgent) Returns a credential created from the Google Application Default Credentials that grants admin access to Firebase services. This credential can be used in the call to initializeApp().Google Application Default Credentials are available on any Google infrastructure, such as Google App Engine and Google Compute Engine.See Initialize the SDK for more details.
cert(serviceAccountPathOrObject, httpAgent) 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 initializeApp().See Initialize the SDK for more details.
deleteApp(app) Renders this given App unusable and frees the resources of all associated services (though it does *not* clean up any backend resources). When running the SDK locally, this method must be called to ensure graceful termination of the process.
getApp(appName)
getApps()
initializeApp(options, appName)
refreshToken(refreshTokenPathOrObject, httpAgent) Returns a credential created from the provided refresh token that grants admin access to Firebase services. This credential can be used in the call to initializeApp().See Initialize the SDK for more details.

Interfaces

Interface Description
App A Firebase app holds the initialization information for a collection of services.
AppOptions Available options to pass to initializeApp().
Credential Interface that provides Google OAuth2 access tokens used to authenticate with Firebase services.In most cases, you will not need to implement this yourself and can instead use the default implementations provided by the firebase-admin/app module.
FirebaseArrayIndexError Composite type which includes both a FirebaseError object and an index which can be used to get the errored item.
FirebaseError FirebaseError is a subclass of the standard JavaScript Error object. In addition to a message string and stack trace, it contains a string code.
GoogleOAuthAccessToken Interface for Google OAuth 2.0 access tokens.
ServiceAccount

Variables

Variable Description
SDK_VERSION

applicationDefault()

Returns a credential created from the Google Application Default Credentials that grants admin access to Firebase services. This credential can be used in the call to initializeApp().

Google Application Default Credentials are available on any Google infrastructure, such as Google App Engine and Google Compute Engine.

See Initialize the SDK for more details.

Signature:

export declare function applicationDefault(httpAgent?: Agent): Credential;

Parameters

Parameter Type Description
httpAgent Agent Optional HTTP Agent to be used when retrieving access tokens from Google token servers.

Returns:

Credential

A credential authenticated via Google Application Default Credentials that can be used to initialize an app.

Example

initializeApp({
  credential: applicationDefault(),
  databaseURL: "https://<DATABASE_NAME>.firebaseio.com"
});

cert()

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 initializeApp().

See Initialize the SDK for more details.

Signature:

export declare function cert(serviceAccountPathOrObject: string | ServiceAccount, httpAgent?: Agent): Credential;

Parameters

Parameter Type Description
serviceAccountPathOrObject string | ServiceAccount The path to a service account key JSON file or an object representing a service account key.
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 1

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

Example 2

// Providing a service account object inline
initializeApp({
  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"
});

deleteApp()

Renders this given App unusable and frees the resources of all associated services (though it does *not* clean up any backend resources). When running the SDK locally, this method must be called to ensure graceful termination of the process.

Signature:

export declare function deleteApp(app: App): Promise<void>;

Parameters

Parameter Type Description
app App

Returns:

Promise<void>

Example

deleteApp(app)
  .then(function() {
    console.log("App deleted successfully");
  })
  .catch(function(error) {
    console.log("Error deleting app:", error);
  });

getApp()

Signature:

export declare function getApp(appName?: string): App;

Parameters

Parameter Type Description
appName string

Returns:

App

getApps()

Signature:

export declare function getApps(): App[];

Returns:

App[]

initializeApp()

Signature:

export declare function initializeApp(options?: AppOptions, appName?: string): App;

Parameters

Parameter Type Description
options AppOptions
appName string

Returns:

App

refreshToken()

Returns a credential created from the provided refresh token that grants admin access to Firebase services. This credential can be used in the call to initializeApp().

See Initialize the SDK for more details.

Signature:

export declare function refreshToken(refreshTokenPathOrObject: string | object, httpAgent?: Agent): Credential;

Parameters

Parameter Type Description
refreshTokenPathOrObject string | object The path to a Google OAuth2 refresh token JSON file or an object representing a Google OAuth2 refresh token.
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 refresh token JSON file
const refreshToken = require("path/to/refreshToken.json");
initializeApp({
  credential: refreshToken(refreshToken),
  databaseURL: "https://<DATABASE_NAME>.firebaseio.com"
});

SDK_VERSION

Signature:

SDK_VERSION: string