UNPKG

4.78 kBTypeScriptView Raw
1/*! firebase-admin v12.0.0 */
2/*!
3 * @license
4 * Copyright 2021 Google Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18/// <reference types="node" />
19import { Agent } from 'http';
20import { Credential, ServiceAccount } from './credential';
21/**
22 * Returns a credential created from the
23 * {@link https://developers.google.com/identity/protocols/application-default-credentials |
24 * Google Application Default Credentials}
25 * that grants admin access to Firebase services. This credential can be used
26 * in the call to {@link firebase-admin.app#initializeApp}.
27 *
28 * Google Application Default Credentials are available on any Google
29 * infrastructure, such as Google App Engine and Google Compute Engine.
30 *
31 * See
32 * {@link https://firebase.google.com/docs/admin/setup#initialize_the_sdk | Initialize the SDK}
33 * for more details.
34 *
35 * @example
36 * ```javascript
37 * initializeApp({
38 * credential: applicationDefault(),
39 * databaseURL: "https://<DATABASE_NAME>.firebaseio.com"
40 * });
41 * ```
42 *
43 * @param httpAgent - Optional {@link https://nodejs.org/api/http.html#http_class_http_agent | HTTP Agent}
44 * to be used when retrieving access tokens from Google token servers.
45 *
46 * @returns A credential authenticated via Google
47 * Application Default Credentials that can be used to initialize an app.
48 */
49export declare function applicationDefault(httpAgent?: Agent): Credential;
50/**
51 * Returns a credential created from the provided service account that grants
52 * admin access to Firebase services. This credential can be used in the call
53 * to {@link firebase-admin.app#initializeApp}.
54 *
55 * See
56 * {@link https://firebase.google.com/docs/admin/setup#initialize_the_sdk | Initialize the SDK}
57 * for more details.
58 *
59 * @example
60 * ```javascript
61 * // Providing a path to a service account key JSON file
62 * const serviceAccount = require("path/to/serviceAccountKey.json");
63 * initializeApp({
64 * credential: cert(serviceAccount),
65 * databaseURL: "https://<DATABASE_NAME>.firebaseio.com"
66 * });
67 * ```
68 *
69 * @example
70 * ```javascript
71 * // Providing a service account object inline
72 * initializeApp({
73 * credential: cert({
74 * projectId: "<PROJECT_ID>",
75 * clientEmail: "foo@<PROJECT_ID>.iam.gserviceaccount.com",
76 * privateKey: "-----BEGIN PRIVATE KEY-----<KEY>-----END PRIVATE KEY-----\n"
77 * }),
78 * databaseURL: "https://<DATABASE_NAME>.firebaseio.com"
79 * });
80 * ```
81 *
82 * @param serviceAccountPathOrObject - The path to a service
83 * account key JSON file or an object representing a service account key.
84 * @param httpAgent - Optional {@link https://nodejs.org/api/http.html#http_class_http_agent | HTTP Agent}
85 * to be used when retrieving access tokens from Google token servers.
86 *
87 * @returns A credential authenticated via the
88 * provided service account that can be used to initialize an app.
89 */
90export declare function cert(serviceAccountPathOrObject: string | ServiceAccount, httpAgent?: Agent): Credential;
91/**
92 * Returns a credential created from the provided refresh token that grants
93 * admin access to Firebase services. This credential can be used in the call
94 * to {@link firebase-admin.app#initializeApp}.
95 *
96 * See
97 * {@link https://firebase.google.com/docs/admin/setup#initialize_the_sdk | Initialize the SDK}
98 * for more details.
99 *
100 * @example
101 * ```javascript
102 * // Providing a path to a refresh token JSON file
103 * const refreshToken = require("path/to/refreshToken.json");
104 * initializeApp({
105 * credential: refreshToken(refreshToken),
106 * databaseURL: "https://<DATABASE_NAME>.firebaseio.com"
107 * });
108 * ```
109 *
110 * @param refreshTokenPathOrObject - The path to a Google
111 * OAuth2 refresh token JSON file or an object representing a Google OAuth2
112 * refresh token.
113 * @param httpAgent - Optional {@link https://nodejs.org/api/http.html#http_class_http_agent | HTTP Agent}
114 * to be used when retrieving access tokens from Google token servers.
115 *
116 * @returns A credential authenticated via the
117 * provided service account that can be used to initialize an app.
118 */
119export declare function refreshToken(refreshTokenPathOrObject: string | object, httpAgent?: Agent): Credential;
120/**
121 * Clears the global ADC cache. Exported for testing.
122 */
123export declare function clearGlobalAppDefaultCred(): void;