Interface

Methods

applicationDefault

static

applicationDefault() returns admin.credential.Credential

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

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

The Google Application Default Credential does not grant access to every admin API. Certain methods, such as createCustomToken() and verifyIdToken(), will not work.

See Initialize the SDK for more details.

Returns

non-null admin.credential.Credential A credential authenticated via Google Application Default Credentials that can be used to initialize an app.

Example

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

cert

static

cert(serviceAccountPathOrObject) returns admin.credential.Credential

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

See Initialize the SDK for more details.

Parameter

serviceAccountPathOrObject

(string or non-null Object)

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

Returns

non-null admin.credential.Credential A credential authenticated via the provided service account that can be used to initialize an app.

Examples

// 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"
});
// 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"
});

refreshToken

static

refreshToken(refreshTokenPathOrObject) returns admin.credential.Credential

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

The refresh token credential does not grant access to every admin API. Certain methods, such as createCustomToken() and verifyIdToken(), will not work.

See Initialize the SDK for more details.

Parameter

refreshTokenPathOrObject

(string or non-null Object)

The path to a Google OAuth2 refresh token JSON file or an object representing a Google OAuth2 refresh token.

Returns

non-null admin.credential.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
var refreshToken = require("path/to/refreshToken.json");
admin.initializeApp({
  credential: admin.credential.refreshToken(refreshToken),
  databaseURL: "https://<DATABASE_NAME>.firebaseio.com"
});