@deepqai/firebase-admin
Version:
Firebase admin SDK for Node.js
1,570 lines (1,378 loc) • 206 kB
TypeScript
/*! firebase-admin v8.9.0 */
/*!
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Bucket } from '@google-cloud/storage';
import * as _firestore from '@google-cloud/firestore';
import { Agent } from 'http';
/**
* `admin` is a global namespace from which all Firebase Admin
* services are accessed.
*/
declare namespace admin {
/**
* `FirebaseError` is a subclass of the standard JavaScript `Error` object. In
* addition to a message string and stack trace, it contains a string code.
*/
interface FirebaseError {
/**
* Error codes are strings using the following format: `"service/string-code"`.
* Some examples include `"auth/invalid-uid"` and
* `"messaging/invalid-recipient"`.
*
* While the message for a given error can change, the code will remain the same
* between backward-compatible versions of the Firebase SDK.
*/
code: string;
/**
* An explanatory message for the error that just occurred.
*
* This message is designed to be helpful to you, the developer. Because
* it generally does not convey meaningful information to end users,
* this message should not be displayed in your application.
*/
message: string;
/**
* A string value containing the execution backtrace when the error originally
* occurred.
*
* This information can be useful to you and can be sent to
* {@link https://firebase.google.com/support/ Firebase Support} to help
* explain the cause of an error.
*/
stack: string;
/**
* @return A JSON-serializable representation of this object.
*/
toJSON(): Object;
}
/**
* Composite type which includes both a `FirebaseError` object and an index
* which can be used to get the errored item.
*
* @example
* ```javascript
* var registrationTokens = [token1, token2, token3];
* admin.messaging().subscribeToTopic(registrationTokens, 'topic-name')
* .then(function(response) {
* if (response.failureCount > 0) {
* console.log("Following devices unsucessfully subscribed to topic:");
* response.errors.forEach(function(error) {
* var invalidToken = registrationTokens[error.index];
* console.log(invalidToken, error.error);
* });
* } else {
* console.log("All devices successfully subscribed to topic:", response);
* }
* })
* .catch(function(error) {
* console.log("Error subscribing to topic:", error);
* });
*```
*/
interface FirebaseArrayIndexError {
/**
* The index of the errored item within the original array passed as part of the
* called API method.
*/
index: number;
/**
* The error object.
*/
error: FirebaseError;
}
interface ServiceAccount {
projectId?: string;
clientEmail?: string;
privateKey?: string;
}
interface GoogleOAuthAccessToken {
access_token: string;
expires_in: number;
}
/**
* Available options to pass to [`initializeApp()`](admin#.initializeApp).
*/
interface AppOptions {
/**
* A {@link admin.credential.Credential `Credential`} object used to
* authenticate the Admin SDK.
*
* See [Initialize the SDK](/docs/admin/setup#initialize_the_sdk) for detailed
* documentation and code samples.
*/
credential?: admin.credential.Credential;
/**
* The object to use as the [`auth`](/docs/reference/security/database/#auth)
* variable in your Realtime Database Rules when the Admin SDK reads from or
* writes to the Realtime Database. This allows you to downscope the Admin SDK
* from its default full read and write privileges.
*
* You can pass `null` to act as an unauthenticated client.
*
* See
* [Authenticate with limited privileges](/docs/database/admin/start#authenticate-with-limited-privileges)
* for detailed documentation and code samples.
*/
databaseAuthVariableOverride?: Object | null;
/**
* The URL of the Realtime Database from which to read and write data.
*/
databaseURL?: string;
/**
* The ID of the service account to be used for signing custom tokens. This
* can be found in the `client_email` field of a service account JSON file.
*/
serviceAccountId?: string;
/**
* The ID of the service account to be used for signing custom tokens. This
* can be found in the `client_email` field of a service account JSON file.
*/
storageBucket?: string;
/**
* The ID of the Google Cloud project associated with the App.
*/
projectId?: string;
/**
* An [HTTP Agent](https://nodejs.org/api/http.html#http_class_http_agent)
* to be used when making outgoing HTTP calls. This Agent instance is used
* by all services that make REST calls (e.g. `auth`, `messaging`,
* `projectManagement`).
*
* Realtime Database and Firestore use other means of communicating with
* the backend servers, so they do not use this HTTP Agent. `Credential`
* instances also do not use this HTTP Agent, but instead support
* specifying an HTTP Agent in the corresponding factory methods.
*/
httpAgent?: Agent;
}
var SDK_VERSION: string;
var apps: (admin.app.App | null)[];
function app(name?: string): admin.app.App;
/**
* Gets the {@link admin.auth.Auth `Auth`} service for the default app or a
* given app.
*
* `admin.auth()` can be called with no arguments to access the default app's
* {@link admin.auth.Auth `Auth`} service or as `admin.auth(app)` to access the
* {@link admin.auth.Auth `Auth`} service associated with a specific app.
*
* @example
* ```javascript
* // Get the Auth service for the default app
* var defaultAuth = admin.auth();
* ```
*
* @example
* ```javascript
* // Get the Auth service for a given app
* var otherAuth = admin.auth(otherApp);
* ```
*
*/
function auth(app?: admin.app.App): admin.auth.Auth;
/**
* Gets the {@link admin.database.Database `Database`} service for the default
* app or a given app.
*
* `admin.database()` can be called with no arguments to access the default
* app's {@link admin.database.Database `Database`} service or as
* `admin.database(app)` to access the
* {@link admin.database.Database `Database`} service associated with a specific
* app.
*
* `admin.database` is also a namespace that can be used to access global
* constants and methods associated with the `Database` service.
*
* @example
* ```javascript
* // Get the Database service for the default app
* var defaultDatabase = admin.database();
* ```
*
* @example
* ```javascript
* // Get the Database service for a specific app
* var otherDatabase = admin.database(app);
* ```
*
* @param App whose `Database` service to
* return. If not provided, the default `Database` service will be returned.
*
* @return The default `Database` service if no app
* is provided or the `Database` service associated with the provided app.
*/
function database(app?: admin.app.App): admin.database.Database;
/**
* Gets the {@link admin.messaging.Messaging `Messaging`} service for the
* default app or a given app.
*
* `admin.messaging()` can be called with no arguments to access the default
* app's {@link admin.messaging.Messaging `Messaging`} service or as
* `admin.messaging(app)` to access the
* {@link admin.messaging.Messaging `Messaging`} service associated with a
* specific app.
*
* @example
* ```javascript
* // Get the Messaging service for the default app
* var defaultMessaging = admin.messaging();
* ```
*
* @example
* ```javascript
* // Get the Messaging service for a given app
* var otherMessaging = admin.messaging(otherApp);
* ```
*
* @param app Optional app whose `Messaging` service to
* return. If not provided, the default `Messaging` service will be returned.
*
* @return The default `Messaging` service if no
* app is provided or the `Messaging` service associated with the provided
* app.
*/
function messaging(app?: admin.app.App): admin.messaging.Messaging;
/**
* Gets the {@link admin.storage.Storage `Storage`} service for the
* default app or a given app.
*
* `admin.storage()` can be called with no arguments to access the default
* app's {@link admin.storage.Storage `Storage`} service or as
* `admin.storage(app)` to access the
* {@link admin.storage.Storage `Storage`} service associated with a
* specific app.
*
* @example
* ```javascript
* // Get the Storage service for the default app
* var defaultStorage = admin.storage();
* ```
*
* @example
* ```javascript
* // Get the Storage service for a given app
* var otherStorage = admin.storage(otherApp);
* ```
*/
function storage(app?: admin.app.App): admin.storage.Storage;
/**
*
* @param app A Firebase App instance
* @returns A [Firestore](https://cloud.google.com/nodejs/docs/reference/firestore/latest/Firestore)
* instance as defined in the `@google-cloud/firestore` package.
*/
function firestore(app?: admin.app.App): admin.firestore.Firestore;
/**
* Gets the {@link admin.instanceId.InstanceId `InstanceId`} service for the
* default app or a given app.
*
* `admin.instanceId()` can be called with no arguments to access the default
* app's {@link admin.instanceId.InstanceId `InstanceId`} service or as
* `admin.instanceId(app)` to access the
* {@link admin.instanceId.InstanceId `InstanceId`} service associated with a
* specific app.
*
* @example
* ```javascript
* // Get the Instance ID service for the default app
* var defaultInstanceId = admin.instanceId();
* ```
*
* @example
* ```javascript
* // Get the Instance ID service for a given app
* var otherInstanceId = admin.instanceId(otherApp);
*```
*
* @param app Optional app whose `InstanceId` service to
* return. If not provided, the default `InstanceId` service will be
* returned.
*
* @return The default `InstanceId` service if
* no app is provided or the `InstanceId` service associated with the
* provided app.
*/
function instanceId(app?: admin.app.App): admin.instanceId.InstanceId;
/**
* Gets the {@link admin.projectManagement.ProjectManagement
* `ProjectManagement`} service for the default app or a given app.
*
* `admin.projectManagement()` can be called with no arguments to access the
* default app's {@link admin.projectManagement.ProjectManagement
* `ProjectManagement`} service, or as `admin.projectManagement(app)` to access
* the {@link admin.projectManagement.ProjectManagement `ProjectManagement`}
* service associated with a specific app.
*
* @example
* ```javascript
* // Get the ProjectManagement service for the default app
* var defaultProjectManagement = admin.projectManagement();
* ```
*
* @example
* ```javascript
* // Get the ProjectManagement service for a given app
* var otherProjectManagement = admin.projectManagement(otherApp);
* ```
*
* @param app Optional app whose `ProjectManagement` service
* to return. If not provided, the default `ProjectManagement` service will
* be returned. *
* @return The default `ProjectManagement` service if no app is provided or the
* `ProjectManagement` service associated with the provided app.
*/
function projectManagement(app?: admin.app.App): admin.projectManagement.ProjectManagement;
/**
* Gets the {@link admin.securityRules.SecurityRules
* `SecurityRules`} service for the default app or a given app.
*
* `admin.securityRules()` can be called with no arguments to access the
* default app's {@link admin.securityRules.SecurityRules
* `SecurityRules`} service, or as `admin.securityRules(app)` to access
* the {@link admin.securityRules.SecurityRules `SecurityRules`}
* service associated with a specific app.
*
* @example
* ```javascript
* // Get the SecurityRules service for the default app
* var defaultSecurityRules = admin.securityRules();
* ```
*
* @example
* ```javascript
* // Get the SecurityRules service for a given app
* var otherSecurityRules = admin.securityRules(otherApp);
* ```
*
* @param app Optional app to return the `SecurityRules` service
* for. If not provided, the default `SecurityRules` service
* is returned.
* @return The default `SecurityRules` service if no app is provided, or the
* `SecurityRules` service associated with the provided app.
*/
function securityRules(app?: admin.app.App): admin.securityRules.SecurityRules;
function initializeApp(options?: admin.AppOptions, name?: string): admin.app.App;
}
declare namespace admin.app {
/**
* A Firebase app holds the initialization information for a collection of
* services.
*
* Do not call this constructor directly. Instead, use
* {@link
* https://firebase.google.com/docs/reference/admin/node/admin#.initializeApp
* `admin.initializeApp()`}
* to create an app.
*/
interface App {
/**
* The (read-only) name for this app.
*
* The default app's name is `"[DEFAULT]"`.
*
* @example
* ```javascript
* // The default app's name is "[DEFAULT]"
* admin.initializeApp(defaultAppConfig);
* console.log(admin.app().name); // "[DEFAULT]"
* ```
*
* @example
* ```javascript
* // A named app's name is what you provide to initializeApp()
* var otherApp = admin.initializeApp(otherAppConfig, "other");
* console.log(otherApp.name); // "other"
* ```
*/
name: string;
/**
* The (read-only) configuration options for this app. These are the original
* parameters given in
* {@link
* https://firebase.google.com/docs/reference/admin/node/admin#.initializeApp
* `admin.initializeApp()`}.
*
* @example
* ```javascript
* var app = admin.initializeApp(config);
* console.log(app.options.credential === config.credential); // true
* console.log(app.options.databaseURL === config.databaseURL); // true
* ```
*/
options: admin.AppOptions;
auth(): admin.auth.Auth;
database(url?: string): admin.database.Database;
firestore(): admin.firestore.Firestore;
instanceId(): admin.instanceId.InstanceId;
messaging(): admin.messaging.Messaging;
projectManagement(): admin.projectManagement.ProjectManagement;
securityRules(): admin.securityRules.SecurityRules;
storage(): admin.storage.Storage;
/**
* Renders this local `FirebaseApp` 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.
*
* @example
* ```javascript
* app.delete()
* .then(function() {
* console.log("App deleted successfully");
* })
* .catch(function(error) {
* console.log("Error deleting app:", error);
* });
* ```
*/
delete(): Promise<void>;
}
}
declare namespace admin.auth {
/**
* Interface representing a user's metadata.
*/
interface UserMetadata {
/**
* The date the user last signed in, formatted as a UTC string.
*/
lastSignInTime: string;
/**
* The date the user was created, formatted as a UTC string.
*
*/
creationTime: string;
/**
* @return A JSON-serializable representation of this object.
*/
toJSON(): Object;
}
/**
* Interface representing a user's info from a third-party identity provider
* such as Google or Facebook.
*/
interface UserInfo {
/**
* The user identifier for the linked provider.
*/
uid: string;
/**
* The display name for the linked provider.
*/
displayName: string;
/**
* The email for the linked provider.
*/
email: string;
/**
* The phone number for the linked provider.
*/
phoneNumber: string;
/**
* The photo URL for the linked provider.
*/
photoURL: string;
/**
* The linked provider ID (for example, "google.com" for the Google provider).
*/
providerId: string;
/**
* @return A JSON-serializable representation of this object.
*/
toJSON(): Object;
}
/**
* Interface representing a user.
*/
interface UserRecord {
/**
* The user's `uid`.
*/
uid: string;
/**
* The user's primary email, if set.
*/
email?: string;
/**
* Whether or not the user's primary email is verified.
*/
emailVerified: boolean;
/**
* The user's display name.
*/
displayName?: string;
/**
* The user's primary phone number, if set.
*/
phoneNumber?: string;
/**
* The user's photo URL.
*/
photoURL?: string;
/**
* Whether or not the user is disabled: `true` for disabled; `false` for
* enabled.
*/
disabled: boolean;
/**
* Additional metadata about the user.
*/
metadata: admin.auth.UserMetadata;
/**
* An array of providers (for example, Google, Facebook) linked to the user.
*/
providerData: admin.auth.UserInfo[];
/**
* The user's hashed password (base64-encoded), only if Firebase Auth hashing
* algorithm (SCRYPT) is used. If a different hashing algorithm had been used
* when uploading this user, as is typical when migrating from another Auth
* system, this will be an empty string. If no password is set, this is
* null. This is only available when the user is obtained from
* {@link https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#listUsers `listUsers()`}.
*
*/
passwordHash?: string;
/**
* The user's password salt (base64-encoded), only if Firebase Auth hashing
* algorithm (SCRYPT) is used. If a different hashing algorithm had been used to
* upload this user, typical when migrating from another Auth system, this will
* be an empty string. If no password is set, this is null. This is only
* available when the user is obtained from
* {@link https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#listUsers `listUsers()`}.
*
*/
passwordSalt?: string;
/**
* The user's custom claims object if available, typically used to define
* user roles and propagated to an authenticated user's ID token.
* This is set via
* {@link https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#setCustomUserClaims `setCustomUserClaims()`}
*/
customClaims?: Object;
/**
* The date the user's tokens are valid after, formatted as a UTC string.
* This is updated every time the user's refresh token are revoked either
* from the {@link https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#revokeRefreshTokens `revokeRefreshTokens()`}
* API or from the Firebase Auth backend on big account changes (password
* resets, password or email updates, etc).
*/
tokensValidAfterTime?: string;
/**
* The ID of the tenant the user belongs to, if available.
*/
tenantId?: string | null;
/**
* @return A JSON-serializable representation of this object.
*/
toJSON(): Object;
}
/**
* Interface representing the properties to update on the provided user.
*/
interface UpdateRequest {
/**
* Whether or not the user is disabled: `true` for disabled;
* `false` for enabled.
*/
disabled?: boolean;
/**
* The user's display name.
*/
displayName?: string | null;
/**
* The user's primary email.
*/
email?: string;
/**
* Whether or not the user's primary email is verified.
*/
emailVerified?: boolean;
/**
* The user's unhashed password.
*/
password?: string;
/**
* The user's primary phone number.
*/
phoneNumber?: string | null;
/**
* The user's photo URL.
*/
photoURL?: string | null;
}
/**
* Interface representing the properties to set on a new user record to be
* created.
*/
interface CreateRequest extends UpdateRequest {
/**
* The user's `uid`.
*/
uid?: string;
}
/**
* Interface representing a decoded Firebase ID token, returned from the
* {@link https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#verifyIdToken `verifyIdToken()`} method.
*
* Firebase ID tokens are OpenID Connect spec-compliant JSON Web Tokens (JWTs).
* See the
* [ID Token section of the OpenID Connect spec](http://openid.net/specs/openid-connect-core-1_0.html#IDToken)
* for more information about the specific properties below.
*/
interface DecodedIdToken {
/**
* The audience for which this token is intended.
*
* This value is a string equal to your Firebase project ID, the unique
* identifier for your Firebase project, which can be found in [your project's
* settings](https://console.firebase.google.com/project/_/settings/general/android:com.random.android).
*/
aud: string;
/**
* Time, in seconds since the Unix epoch, when the end-user authentication
* occurred.
*
* This value is not set when this particular ID token was created, but when the
* user initially logged in to this session. In a single session, the Firebase
* SDKs will refresh a user's ID tokens every hour. Each ID token will have a
* different [`iat`](#iat) value, but the same `auth_time` value.
*/
auth_time: number;
/**
* The ID token's expiration time, in seconds since the Unix epoch. That is, the
* time at which this ID token expires and should no longer be considered valid.
*
* The Firebase SDKs transparently refresh ID tokens every hour, issuing a new
* ID token with up to a one hour expiration.
*/
exp: number;
/**
* Information about the sign in event, including which sign in provider was
* used and provider-specific identity details.
*
* This data is provided by the Firebase Authentication service and is a
* reserved claim in the ID token.
*/
firebase: {
/**
* Provider-specific identity details corresponding
* to the provider used to sign in the user.
*/
identities: {
[key: string]: any;
};
/**
* The ID of the provider used to sign in the user.
* One of `"anonymous"`, `"password"`, `"facebook.com"`, `"github.com"`,
* `"google.com"`, `"twitter.com"`, or `"custom"`.
*/
sign_in_provider: string;
/**
* The ID of the tenant the user belongs to, if available.
*/
tenant?: string;
[key: string]: any;
};
/**
* The ID token's issued-at time, in seconds since the Unix epoch. That is, the
* time at which this ID token was issued and should start to be considered
* valid.
*
* The Firebase SDKs transparently refresh ID tokens every hour, issuing a new
* ID token with a new issued-at time. If you want to get the time at which the
* user session corresponding to the ID token initially occurred, see the
* [`auth_time`](#auth_time) property.
*/
iat: number;
/**
* The issuer identifier for the issuer of the response.
*
* This value is a URL with the format
* `https://securetoken.google.com/<PROJECT_ID>`, where `<PROJECT_ID>` is the
* same project ID specified in the [`aud`](#aud) property.
*/
iss: string;
/**
* The `uid` corresponding to the user who the ID token belonged to.
*
* As a convenience, this value is copied over to the [`uid`](#uid) property.
*/
sub: string;
/**
* The `uid` corresponding to the user who the ID token belonged to.
*
* This value is not actually in the JWT token claims itself. It is added as a
* convenience, and is set as the value of the [`sub`](#sub) property.
*/
uid: string;
[key: string]: any;
}
/**
* Interface representing the object returned from a
* {@link https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#listUsers `listUsers()`} operation. Contains the list
* of users for the current batch and the next page token if available.
*/
interface ListUsersResult {
/**
* The list of {@link admin.auth.UserRecord `UserRecord`} objects for the
* current downloaded batch.
*/
users: admin.auth.UserRecord[];
/**
* The next page token if available. This is needed for the next batch download.
*/
pageToken?: string;
}
type HashAlgorithmType = 'SCRYPT' | 'STANDARD_SCRYPT' | 'HMAC_SHA512' |
'HMAC_SHA256' | 'HMAC_SHA1' | 'HMAC_MD5' | 'MD5' | 'PBKDF_SHA1' | 'BCRYPT' |
'PBKDF2_SHA256' | 'SHA512' | 'SHA256' | 'SHA1';
/**
* Interface representing the user import options needed for
* {@link https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#importUsers `importUsers()`} method. This is used to
* provide the password hashing algorithm information.
*/
interface UserImportOptions {
/**
* The password hashing information.
*/
hash: {
/**
* The password hashing algorithm identifier. The following algorithm
* identifiers are supported:
* `SCRYPT`, `STANDARD_SCRYPT`, `HMAC_SHA512`, `HMAC_SHA256`, `HMAC_SHA1`,
* `HMAC_MD5`, `MD5`, `PBKDF_SHA1`, `BCRYPT`, `PBKDF2_SHA256`, `SHA512`,
* `SHA256` and `SHA1`.
*/
algorithm: HashAlgorithmType;
/**
* The signing key used in the hash algorithm in buffer bytes.
* Required by hashing algorithms `SCRYPT`, `HMAC_SHA512`, `HMAC_SHA256`,
* `HAMC_SHA1` and `HMAC_MD5`.
*/
key?: Buffer;
/**
* The salt separator in buffer bytes which is appended to salt when
* verifying a password. This is only used by the `SCRYPT` algorithm.
*/
saltSeparator?: Buffer;
/**
* The number of rounds for hashing calculation.
* Required for `SCRYPT`, `MD5`, `SHA512`, `SHA256`, `SHA1`, `PBKDF_SHA1` and
* `PBKDF2_SHA256`.
*/
rounds?: number;
/**
* The memory cost required for `SCRYPT` algorithm, or the CPU/memory cost.
* Required for `STANDARD_SCRYPT` algorithm.
*/
memoryCost?: number;
/**
* The parallelization of the hashing algorithm. Required for the
* `STANDARD_SCRYPT` algorithm.
*/
parallelization?: number;
/**
* The block size (normally 8) of the hashing algorithm. Required for the
* `STANDARD_SCRYPT` algorithm.
*/
blockSize?: number;
/**
* The derived key length of the hashing algorithm. Required for the
* `STANDARD_SCRYPT` algorithm.
*/
derivedKeyLength?: number;
};
}
/**
* Interface representing the response from the
* {@link https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#importUsers `importUsers()`} method for batch
* importing users to Firebase Auth.
*/
interface UserImportResult {
/**
* The number of user records that failed to import to Firebase Auth.
*/
failureCount: number;
/**
* The number of user records that successfully imported to Firebase Auth.
*/
successCount: number;
/**
* An array of errors corresponding to the provided users to import. The
* length of this array is equal to [`failureCount`](#failureCount).
*/
errors: admin.FirebaseArrayIndexError[];
}
/**
* Interface representing a user to import to Firebase Auth via the
* {@link https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#importUsers `importUsers()`} method.
*/
interface UserImportRecord {
/**
* The user's `uid`.
*/
uid: string;
/**
* The user's primary email, if set.
*/
email?: string;
/**
* Whether or not the user's primary email is verified.
*/
emailVerified: boolean;
/**
* The user's display name.
*/
displayName?: string;
/**
* The user's primary phone number, if set.
*/
phoneNumber?: string;
/**
* The user's photo URL.
*/
photoURL?: string;
/**
* Whether or not the user is disabled: `true` for disabled; `false` for
* enabled.
*/
disabled: boolean;
/**
* Additional metadata about the user.
*/
metadata: admin.auth.UserMetadata;
/**
* An array of providers (for example, Google, Facebook) linked to the user.
*/
providerData?: admin.auth.UserInfo[];
/**
* The user's custom claims object if available, typically used to define
* user roles and propagated to an authenticated user's ID token.
*/
customClaims?: Object;
/**
* The buffer of bytes representing the user's hashed password.
* When a user is to be imported with a password hash,
* {@link admin.auth.UserImportOptions `UserImportOptions`} are required to be
* specified to identify the hashing algorithm used to generate this hash.
*/
passwordHash?: Buffer;
/**
* The buffer of bytes representing the user's password salt.
*/
passwordSalt?: Buffer;
/**
* The identifier of the tenant where user is to be imported to.
* When not provided in an `admin.auth.Auth` context, the user is uploaded to
* the default parent project.
* When not provided in an `admin.auth.TenantAwareAuth` context, the user is uploaded
* to the tenant corresponding to that `TenantAwareAuth` instance's tenant ID.
*/
tenantId?: string | null;
}
/**
* Interface representing the session cookie options needed for the
* {@link https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#createSessionCookie `createSessionCookie()`} method.
*/
interface SessionCookieOptions {
/**
* The session cookie custom expiration in milliseconds. The minimum allowed is
* 5 minutes and the maxium allowed is 2 weeks.
*/
expiresIn: number;
}
/**
* This is the interface that defines the required continue/state URL with
* optional Android and iOS bundle identifiers.
*/
interface ActionCodeSettings {
/**
* Defines the link continue/state URL, which has different meanings in
* different contexts:
* <ul>
* <li>When the link is handled in the web action widgets, this is the deep
* link in the `continueUrl` query parameter.</li>
* <li>When the link is handled in the app directly, this is the `continueUrl`
* query parameter in the deep link of the Dynamic Link.</li>
* </ul>
*/
url: string;
/**
* Whether to open the link via a mobile app or a browser.
* The default is false. When set to true, the action code link is sent
* as a Universal Link or Android App Link and is opened by the app if
* installed. In the false case, the code is sent to the web widget first
* and then redirects to the app if installed.
*/
handleCodeInApp?: boolean;
/**
* Defines the iOS bundle ID. This will try to open the link in an iOS app if it
* is installed.
*/
iOS?: {
/**
* Defines the required iOS bundle ID of the app where the link should be
* handled if the application is already installed on the device.
*/
bundleId: string;
};
/**
* Defines the Android package name. This will try to open the link in an
* android app if it is installed. If `installApp` is passed, it specifies
* whether to install the Android app if the device supports it and the app is
* not already installed. If this field is provided without a `packageName`, an
* error is thrown explaining that the `packageName` must be provided in
* conjunction with this field. If `minimumVersion` is specified, and an older
* version of the app is installed, the user is taken to the Play Store to
* upgrade the app.
*/
android?: {
/**
* Defines the required Android package name of the app where the link should be
* handled if the Android app is installed.
*/
packageName: string;
/**
* Whether to install the Android app if the device supports it and the app is
* not already installed.
*/
installApp?: boolean;
/**
* The Android minimum version if available. If the installed app is an older
* version, the user is taken to the GOogle Play Store to upgrade the app.
*/
minimumVersion?: string;
};
/**
* Defines the dynamic link domain to use for the current link if it is to be
* opened using Firebase Dynamic Links, as multiple dynamic link domains can be
* configured per project. This field provides the ability to explicitly choose
* configured per project. This fields provides the ability explicitly choose
* one. If none is provided, the oldest domain is used by default.
*/
dynamicLinkDomain?: string;
}
/**
* Interface representing a tenant configuration.
*
* Multi-tenancy support requires Google Cloud's Identity Platform
* (GCIP). To learn more about GCIP, including pricing and features,
* see the [GCIP documentation](https://cloud.google.com/identity-platform)
*
* Before multi-tenancy can be used on a Google Cloud Identity Platform project,
* tenants must be allowed on that project via the Cloud Console UI.
*
* A tenant configuration provides information such as the display name, tenant
* identifier and email authentication configuration.
* For OIDC/SAML provider configuration management, `TenantAwareAuth` instances should
* be used instead of a `Tenant` to retrieve the list of configured IdPs on a tenant.
* When configuring these providers, note that tenants will inherit
* whitelisted domains and authenticated redirect URIs of their parent project.
*
* All other settings of a tenant will also be inherited. These will need to be managed
* from the Cloud Console UI.
*/
interface Tenant {
/**
* The tenant identifier.
*/
tenantId: string;
/**
* The tenant display name.
*/
displayName?: string;
/**
* The email sign in provider configuration.
*/
emailSignInConfig?: {
/**
* Whether email provider is enabled.
*/
enabled: boolean;
/**
* Whether password is required for email sign-in. When not required,
* email sign-in can be performed with password or via email link sign-in.
*/
passwordRequired?: boolean
};
/**
* @return A JSON-serializable representation of this object.
*/
toJSON(): Object;
}
/**
* Interface representing the properties to update on the provided tenant.
*/
interface UpdateTenantRequest {
/**
* The tenant display name.
*/
displayName?: string;
/**
* The email sign in configuration.
*/
emailSignInConfig?: {
/**
* Whether email provider is enabled.
*/
enabled: boolean;
/**
* Whether password is required for email sign-in. When not required,
* email sign-in can be performed with password or via email link sign-in.
*/
passwordRequired?: boolean;
};
}
/**
* Interface representing the properties to set on a new tenant.
*/
interface CreateTenantRequest extends UpdateTenantRequest {
}
/**
* Interface representing the object returned from a
* {@link https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#listTenants `listTenants()`}
* operation.
* Contains the list of tenants for the current batch and the next page token if available.
*/
interface ListTenantsResult {
/**
* The list of {@link admin.auth.Tenant `Tenant`} objects for the downloaded batch.
*/
tenants: admin.auth.Tenant[];
/**
* The next page token if available. This is needed for the next batch download.
*/
pageToken?: string;
}
/**
* The filter interface used for listing provider configurations. This is used
* when specifying how to list configured identity providers via
* {@link https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#listProviderConfigs `listProviderConfigs()`}.
*/
interface AuthProviderConfigFilter {
/**
* The Auth provider configuration filter. This can be either `saml` or `oidc`.
* The former is used to look up SAML providers only, while the latter is used
* for OIDC providers.
*/
type: 'saml' | 'oidc';
/**
* The maximum number of results to return per page. The default and maximum is
* 100.
*/
maxResults?: number;
/**
* The next page token. When not specified, the lookup starts from the beginning
* of the list.
*/
pageToken?: string;
}
/**
* The base Auth provider configuration interface.
*/
interface AuthProviderConfig {
/**
* The provider ID defined by the developer.
* For a SAML provider, this is always prefixed by `saml.`.
* For an OIDC provider, this is always prefixed by `oidc.`.
*/
providerId: string;
/**
* The user-friendly display name to the current configuration. This name is
* also used as the provider label in the Cloud Console.
*/
displayName: string;
/**
* Whether the provider configuration is enabled or disabled. A user
* cannot sign in using a disabled provider.
*/
enabled: boolean;
}
/**
* The
* [SAML](http://docs.oasis-open.org/security/saml/Post2.0/sstc-saml-tech-overview-2.0.html)
* Auth provider configuration interface. A SAML provider can be created via
* {@link https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#createProviderConfig `createProviderConfig()`}.
*/
interface SAMLAuthProviderConfig extends admin.auth.AuthProviderConfig {
/**
* The SAML IdP entity identifier.
*/
idpEntityId: string;
/**
* The SAML IdP SSO URL. This must be a valid URL.
*/
ssoURL: string;
/**
* The list of SAML IdP X.509 certificates issued by CA for this provider.
* Multiple certificates are accepted to prevent outages during
* IdP key rotation (for example ADFS rotates every 10 days). When the Auth
* server receives a SAML response, it will match the SAML response with the
* certificate on record. Otherwise the response is rejected.
* Developers are expected to manage the certificate updates as keys are
* rotated.
*/
x509Certificates: string[];
/**
* The SAML relying party (service provider) entity ID.
* This is defined by the developer but needs to be provided to the SAML IdP.
*/
rpEntityId: string;
/**
* This is fixed and must always be the same as the OAuth redirect URL
* provisioned by Firebase Auth,
* `https://project-id.firebaseapp.com/__/auth/handler` unless a custom
* `authDomain` is used.
* The callback URL should also be provided to the SAML IdP during
* configuration.
*/
callbackURL?: string;
}
/**
* The [OIDC](https://openid.net/specs/openid-connect-core-1_0-final.html) Auth
* provider configuration interface. An OIDC provider can be created via
* {@link https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#createProviderConfig `createProviderConfig()`}.
*/
interface OIDCAuthProviderConfig extends admin.auth.AuthProviderConfig {
/**
* This is the required client ID used to confirm the audience of an OIDC
* provider's
* [ID token](https://openid.net/specs/openid-connect-core-1_0-final.html#IDToken).
*/
clientId: string;
/**
* This is the required provider issuer used to match the provider issuer of
* the ID token and to determine the corresponding OIDC discovery document, eg.
* [`/.well-known/openid-configuration`](https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfig).
* This is needed for the following:
* <ul>
* <li>To verify the provided issuer.</li>
* <li>Determine the authentication/authorization endpoint during the OAuth
* `id_token` authentication flow.</li>
* <li>To retrieve the public signing keys via `jwks_uri` to verify the OIDC
* provider's ID token's signature.</li>
* <li>To determine the claims_supported to construct the user attributes to be
* returned in the additional user info response.</li>
* </ul>
* ID token validation will be performed as defined in the
* [spec](https://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation).
*/
issuer: string;
}
/**
* The request interface for updating a SAML Auth provider. This is used
* when updating a SAML provider's configuration via
* {@link https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#updateProviderConfig `updateProviderConfig()`}.
*/
interface SAMLUpdateAuthProviderRequest {
/**
* The SAML provider's updated display name. If not provided, the existing
* configuration's value is not modified.
*/
displayName?: string;
/**
* Whether the SAML provider is enabled or not. If not provided, the existing
* configuration's setting is not modified.
*/
enabled?: boolean;
/**
* The SAML provider's updated IdP entity ID. If not provided, the existing
* configuration's value is not modified.
*/
idpEntityId?: string;
/**
* The SAML provider's updated SSO URL. If not provided, the existing
* configuration's value is not modified.
*/
ssoURL?: string;
/**
* The SAML provider's updated list of X.509 certificated. If not provided, the
* existing configuration list is not modified.
*/
x509Certificates?: string[];
/**
* The SAML provider's updated RP entity ID. If not provided, the existing
* configuration's value is not modified.
*/
rpEntityId?: string;
/**
* The SAML provider's callback URL. If not provided, the existing
* configuration's value is not modified.
*/
callbackURL?: string;
}
/**
* The request interface for updating an OIDC Auth provider. This is used
* when updating an OIDC provider's configuration via
* {@link https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#updateProviderConfig `updateProviderConfig()`}.
*/
interface OIDCUpdateAuthProviderRequest {
/**
* The OIDC provider's updated display name. If not provided, the existing
* configuration's value is not modified.
*/
displayName?: string;
/**
* Whether the OIDC provider is enabled or not. If not provided, the existing
* configuration's setting is not modified.
*/
enabled?: boolean;
/**
* The OIDC provider's updated client ID. If not provided, the existing
* configuration's value is not modified.
*/
clientId?: string;
/**
* The OIDC provider's updated issuer. If not provided, the existing
* configuration's value is not modified.
*/
issuer?: string;
}
/**
* The response interface for listing provider configs. This is only available
* when listing all identity providers' configurations via
* {@link https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#listProviderConfigs `listProviderConfigs()`}.
*/
interface ListProviderConfigResults {
/**
* The list of providers for the specified type in the current page.
*/
providerConfigs: admin.auth.AuthProviderConfig[];
/**
* The next page token, if available.
*/
pageToken?: string;
}
type UpdateAuthProviderRequest =
admin.auth.SAMLUpdateAuthProviderRequest | admin.auth.OIDCUpdateAuthProviderRequest;
interface BaseAuth {
/**
* Creates a new Firebase custom token (JWT) that can be sent back to a client
* device to use to sign in with the client SDKs' `signInWithCustomToken()`
* methods. (Tenant-aware instances will also embed the tenant ID in the
* token.)
*
* See [Create Custom Tokens](/docs/auth/admin/create-custom-tokens) for code
* samples and detailed documentation.
*
* @param uid The `uid` to use as the custom token's subject.
* @param developerClaims Optional additional claims to include
* in the custom token's payload.
*
* @return A promise fulfilled with a custom token for the
* provided `uid` and payload.
*/
createCustomToken(uid: string, developerClaims?: Object): Promise<string>;
/**
* Creates a new user.
*
* See [Create a user](/docs/auth/admin/manage-users#create_a_user) for code
* samples and detailed documentation.
*
* @param properties The properties to set on the
* new user record to be created.
*
* @return A promise fulfilled with the user
* data corresponding to the newly created user.
*/
createUser(properties: admin.auth.CreateRequest): Promise<admin.auth.UserRecord>;
/**
* Deletes an existing user.
*
* See [Delete a user](/docs/auth/admin/manage-users#delete_a_user) for code
* samples and detailed documentation.
*
* @param uid The `uid` corresponding to the user to delete.
*
* @return An empty promise fulfilled once the user has been
* deleted.
*/
deleteUser(uid: string): Promise<void>;
/**
* Gets the user data for the user corresponding to a given `uid`.
*
* See [Retrieve user data](/docs/auth/admin/manage-users#retrieve_user_data)
* for code samples and detailed documentation.
*
* @param uid The `uid` corresponding to the user whose data to fetch.
*
* @return A promise fulfilled with the user
* data corresponding to the provided `uid`.
*/
getUser(uid: string): Promise<admin.auth.UserRecord>;
/**
* Gets the user data for the user corresponding to a given email.
*
* See [Retrieve user data](/docs/auth/admin/manage-users#retrieve_user_data)
* for code samples and detailed documentation.
*
* @param email The email corresponding to the user whose data to
* fetch.
*
* @return A promise fulfilled with the user
* data corresponding to the provided email.
*/
getUserByEmail(email: string): Promise<admin.auth.UserRecord>;
/**
* Gets the user data for the user corresponding to a given phone number. The
* phone number has to conform to the E.164 specification.
*
* See [Retrieve user data](/docs/auth/admin/manage-users#retrieve_user_data)
* for code samples and detailed documentation.
*
* @param phoneNumber The phone number corresponding to the user whose
* data to fetch.
*
* @return A promise fulfilled with the user
* data corresponding to the provided phone number.
*/
getUserByPhoneNumber(phoneNumber: string): Promise<admin.auth.UserRecord>;
/**
* Retrieves a list of users (single batch only) with a size of `maxResults`
* starting from the offset as specified by `pageToken`. This is used to
* retrieve all the users of a specified project in batches.
*
* See [List all users](/docs/auth/admin/manage-users#list_all_users)
* for code samples and detailed documentation.
*
* @param maxResults The page size, 1000 if undefined. This is also
* the maximum allowed limit.
* @param pageToken The next page token. If not specified, returns
* users starting without any offset.
* @return A promise that resolves with
* the current batch of downloaded users and the next page token.
*/
listUsers(maxResults?: number, pageToken?: string): Promise<admin.auth.ListUsersResult>;
/**
* Updates an existing user.
*
* See [Update a user](/docs/auth/admin/manage-users#update_a_user) for code
* samples and detailed documentation.
*
* @param uid The `uid` corresponding to the user to delete.
* @param properties The properties to update on
* the provided user.
*
* @return A promise fulfilled with the
* updated user data.
*/
updateUser(uid: string, properties: admin.auth.UpdateRequest): Promise<admin.auth.UserRecord>;
/**
* Verifies a Firebase ID token (JWT). If the token is valid, the promise is
* fulfilled with the token's decoded claims; otherwise, the promise is
* rejected.
* An optional flag can be passed to additionally check whether the ID token
* was rev