firebase-admin 9.100.0-alpha.0 → 10.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/README.md +7 -3
  2. package/lib/app/core.d.ts +15 -22
  3. package/lib/app/core.js +1 -1
  4. package/lib/app/credential-factory.d.ts +17 -33
  5. package/lib/app/credential-factory.js +17 -33
  6. package/lib/app/credential-internal.d.ts +10 -9
  7. package/lib/app/credential-internal.js +15 -13
  8. package/lib/app/credential.d.ts +3 -9
  9. package/lib/app/credential.js +1 -1
  10. package/lib/app/firebase-app.d.ts +6 -30
  11. package/lib/app/firebase-app.js +72 -216
  12. package/lib/app/firebase-namespace.d.ts +28 -34
  13. package/lib/app/firebase-namespace.js +119 -99
  14. package/lib/app/index.d.ts +6 -1
  15. package/lib/app/index.js +1 -1
  16. package/lib/app/lifecycle.d.ts +24 -3
  17. package/lib/app/lifecycle.js +119 -25
  18. package/lib/app-check/app-check-api-client-internal.d.ts +32 -0
  19. package/lib/app-check/app-check-api-client-internal.js +197 -0
  20. package/lib/app-check/app-check-api.d.ts +95 -0
  21. package/lib/app-check/app-check-api.js +19 -0
  22. package/lib/app-check/app-check-namespace.d.ts +65 -0
  23. package/lib/app-check/app-check-namespace.js +18 -0
  24. package/lib/app-check/app-check.d.ts +49 -0
  25. package/lib/app-check/app-check.js +82 -0
  26. package/lib/app-check/index.d.ts +53 -0
  27. package/lib/app-check/index.js +63 -0
  28. package/lib/app-check/token-generator.d.ts +25 -0
  29. package/lib/app-check/token-generator.js +159 -0
  30. package/lib/app-check/token-verifier.d.ts +17 -0
  31. package/lib/app-check/token-verifier.js +151 -0
  32. package/lib/auth/action-code-settings-builder.d.ts +1 -1
  33. package/lib/auth/action-code-settings-builder.js +2 -2
  34. package/lib/auth/auth-api-request.d.ts +28 -32
  35. package/lib/auth/auth-api-request.js +167 -125
  36. package/lib/auth/auth-config.d.ts +123 -21
  37. package/lib/auth/auth-config.js +85 -34
  38. package/lib/auth/auth-namespace.d.ts +157 -4
  39. package/lib/auth/auth-namespace.js +1 -1
  40. package/lib/auth/auth.d.ts +5 -3
  41. package/lib/auth/auth.js +6 -4
  42. package/lib/auth/base-auth.d.ts +134 -116
  43. package/lib/auth/base-auth.js +213 -143
  44. package/lib/auth/identifier.d.ts +5 -5
  45. package/lib/auth/identifier.js +1 -1
  46. package/lib/auth/index.d.ts +10 -5
  47. package/lib/auth/index.js +9 -4
  48. package/lib/auth/tenant-manager.d.ts +19 -19
  49. package/lib/auth/tenant-manager.js +21 -25
  50. package/lib/auth/tenant.d.ts +14 -5
  51. package/lib/auth/tenant.js +19 -11
  52. package/lib/auth/token-generator.d.ts +7 -108
  53. package/lib/auth/token-generator.js +52 -145
  54. package/lib/auth/token-verifier.d.ts +3 -4
  55. package/lib/auth/token-verifier.js +96 -145
  56. package/lib/auth/user-import-builder.d.ts +11 -11
  57. package/lib/auth/user-import-builder.js +9 -9
  58. package/lib/auth/user-record.d.ts +23 -15
  59. package/lib/auth/user-record.js +30 -20
  60. package/lib/credential/index.d.ts +18 -35
  61. package/lib/credential/index.js +17 -33
  62. package/lib/database/database-namespace.d.ts +39 -10
  63. package/lib/database/database-namespace.js +1 -1
  64. package/lib/database/database.d.ts +16 -6
  65. package/lib/database/database.js +61 -6
  66. package/lib/database/index.d.ts +19 -18
  67. package/lib/database/index.js +21 -23
  68. package/lib/default-namespace.d.ts +7 -1
  69. package/lib/default-namespace.js +4 -4
  70. package/lib/esm/app/index.js +10 -0
  71. package/lib/esm/app-check/index.js +4 -0
  72. package/lib/esm/auth/index.js +14 -0
  73. package/lib/esm/database/index.js +6 -0
  74. package/lib/esm/firestore/index.js +24 -0
  75. package/lib/esm/installations/index.js +4 -0
  76. package/lib/esm/instance-id/index.js +4 -0
  77. package/lib/esm/machine-learning/index.js +5 -0
  78. package/lib/esm/messaging/index.js +4 -0
  79. package/lib/esm/package.json +1 -0
  80. package/lib/esm/project-management/index.js +8 -0
  81. package/lib/esm/remote-config/index.js +4 -0
  82. package/lib/esm/security-rules/index.js +6 -0
  83. package/lib/esm/storage/index.js +4 -0
  84. package/lib/firebase-namespace-api.d.ts +12 -6
  85. package/lib/firebase-namespace-api.js +5 -1
  86. package/lib/firestore/firestore-internal.d.ts +2 -2
  87. package/lib/firestore/firestore-internal.js +2 -2
  88. package/lib/firestore/firestore-namespace.d.ts +6 -1
  89. package/lib/firestore/firestore-namespace.js +2 -1
  90. package/lib/firestore/index.d.ts +36 -4
  91. package/lib/firestore/index.js +29 -1
  92. package/lib/index.d.ts +1 -1
  93. package/lib/index.js +1 -1
  94. package/lib/installations/index.d.ts +52 -0
  95. package/lib/installations/index.js +62 -0
  96. package/lib/installations/installations-namespace.d.ts +55 -0
  97. package/lib/installations/installations-namespace.js +18 -0
  98. package/lib/{instance-id/instance-id-request-internal.d.ts → installations/installations-request-handler.d.ts} +8 -8
  99. package/lib/{instance-id/instance-id-request-internal.js → installations/installations-request-handler.js} +23 -23
  100. package/lib/installations/installations.d.ts +38 -0
  101. package/lib/installations/installations.js +63 -0
  102. package/lib/instance-id/index.d.ts +20 -9
  103. package/lib/instance-id/index.js +20 -9
  104. package/lib/instance-id/instance-id-namespace.d.ts +9 -8
  105. package/lib/instance-id/instance-id-namespace.js +1 -1
  106. package/lib/instance-id/instance-id.d.ts +8 -6
  107. package/lib/instance-id/instance-id.js +20 -11
  108. package/lib/machine-learning/index.d.ts +29 -27
  109. package/lib/machine-learning/index.js +29 -27
  110. package/lib/machine-learning/machine-learning-api-client.d.ts +1 -1
  111. package/lib/machine-learning/machine-learning-api-client.js +4 -4
  112. package/lib/machine-learning/machine-learning-namespace.d.ts +33 -8
  113. package/lib/machine-learning/machine-learning-namespace.js +1 -1
  114. package/lib/machine-learning/machine-learning-utils.d.ts +1 -1
  115. package/lib/machine-learning/machine-learning-utils.js +1 -1
  116. package/lib/machine-learning/machine-learning.d.ts +19 -19
  117. package/lib/machine-learning/machine-learning.js +20 -20
  118. package/lib/messaging/batch-request-internal.d.ts +3 -3
  119. package/lib/messaging/batch-request-internal.js +9 -9
  120. package/lib/messaging/index.d.ts +11 -9
  121. package/lib/messaging/index.js +11 -9
  122. package/lib/messaging/messaging-api-request-internal.d.ts +8 -8
  123. package/lib/messaging/messaging-api-request-internal.js +8 -8
  124. package/lib/messaging/messaging-api.d.ts +79 -75
  125. package/lib/messaging/messaging-api.js +1 -1
  126. package/lib/messaging/messaging-errors-internal.d.ts +5 -5
  127. package/lib/messaging/messaging-errors-internal.js +7 -7
  128. package/lib/messaging/messaging-internal.d.ts +1 -1
  129. package/lib/messaging/messaging-internal.js +6 -31
  130. package/lib/messaging/messaging-namespace.d.ts +105 -8
  131. package/lib/messaging/messaging-namespace.js +1 -1
  132. package/lib/messaging/messaging.d.ts +70 -86
  133. package/lib/messaging/messaging.js +76 -89
  134. package/lib/project-management/android-app.d.ts +11 -12
  135. package/lib/project-management/android-app.js +13 -14
  136. package/lib/project-management/app-metadata.d.ts +1 -1
  137. package/lib/project-management/app-metadata.js +1 -1
  138. package/lib/project-management/index.d.ts +11 -9
  139. package/lib/project-management/index.js +11 -9
  140. package/lib/project-management/ios-app.d.ts +6 -7
  141. package/lib/project-management/ios-app.js +6 -7
  142. package/lib/project-management/project-management-api-request-internal.d.ts +1 -80
  143. package/lib/project-management/project-management-api-request-internal.js +14 -14
  144. package/lib/project-management/project-management-namespace.d.ts +31 -9
  145. package/lib/project-management/project-management-namespace.js +1 -1
  146. package/lib/project-management/project-management.d.ts +18 -21
  147. package/lib/project-management/project-management.js +19 -22
  148. package/lib/remote-config/index.d.ts +12 -10
  149. package/lib/remote-config/index.js +11 -9
  150. package/lib/remote-config/remote-config-api-client-internal.d.ts +1 -1
  151. package/lib/remote-config/remote-config-api-client-internal.js +2 -2
  152. package/lib/remote-config/remote-config-api.d.ts +12 -2
  153. package/lib/remote-config/remote-config-api.js +1 -1
  154. package/lib/remote-config/remote-config-namespace.d.ts +50 -9
  155. package/lib/remote-config/remote-config-namespace.js +1 -1
  156. package/lib/remote-config/remote-config.d.ts +19 -21
  157. package/lib/remote-config/remote-config.js +25 -25
  158. package/lib/security-rules/index.d.ts +12 -10
  159. package/lib/security-rules/index.js +12 -10
  160. package/lib/security-rules/security-rules-api-client-internal.d.ts +1 -1
  161. package/lib/security-rules/security-rules-api-client-internal.js +1 -1
  162. package/lib/security-rules/security-rules-internal.d.ts +1 -1
  163. package/lib/security-rules/security-rules-internal.js +1 -1
  164. package/lib/security-rules/security-rules-namespace.d.ts +43 -28
  165. package/lib/security-rules/security-rules-namespace.js +1 -1
  166. package/lib/security-rules/security-rules.d.ts +39 -42
  167. package/lib/security-rules/security-rules.js +38 -39
  168. package/lib/storage/index.d.ts +9 -7
  169. package/lib/storage/index.js +9 -7
  170. package/lib/storage/storage-namespace.d.ts +7 -6
  171. package/lib/storage/storage-namespace.js +1 -1
  172. package/lib/storage/storage.d.ts +3 -3
  173. package/lib/storage/storage.js +14 -4
  174. package/lib/utils/api-request.d.ts +24 -24
  175. package/lib/utils/api-request.js +25 -25
  176. package/lib/utils/crypto-signer.d.ts +128 -0
  177. package/lib/utils/crypto-signer.js +237 -0
  178. package/lib/utils/deep-copy.d.ts +6 -6
  179. package/lib/utils/deep-copy.js +6 -6
  180. package/lib/utils/error.d.ts +69 -36
  181. package/lib/utils/error.js +98 -43
  182. package/lib/utils/index.d.ts +30 -19
  183. package/lib/utils/index.js +47 -20
  184. package/lib/utils/jwt.d.ts +131 -0
  185. package/lib/utils/jwt.js +355 -0
  186. package/lib/utils/validator.d.ts +37 -37
  187. package/lib/utils/validator.js +37 -37
  188. package/package.json +126 -53
@@ -0,0 +1,159 @@
1
+ /*! firebase-admin v10.0.2 */
2
+ "use strict";
3
+ /*!
4
+ * @license
5
+ * Copyright 2021 Google Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ var __assign = (this && this.__assign) || function () {
20
+ __assign = Object.assign || function(t) {
21
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
22
+ s = arguments[i];
23
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
24
+ t[p] = s[p];
25
+ }
26
+ return t;
27
+ };
28
+ return __assign.apply(this, arguments);
29
+ };
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ exports.appCheckErrorFromCryptoSignerError = exports.AppCheckTokenGenerator = void 0;
32
+ var validator = require("../utils/validator");
33
+ var utils_1 = require("../utils");
34
+ var crypto_signer_1 = require("../utils/crypto-signer");
35
+ var app_check_api_client_internal_1 = require("./app-check-api-client-internal");
36
+ var ONE_MINUTE_IN_SECONDS = 60;
37
+ var ONE_MINUTE_IN_MILLIS = ONE_MINUTE_IN_SECONDS * 1000;
38
+ var ONE_DAY_IN_MILLIS = 24 * 60 * 60 * 1000;
39
+ // Audience to use for Firebase App Check Custom tokens
40
+ var FIREBASE_APP_CHECK_AUDIENCE = 'https://firebaseappcheck.googleapis.com/google.firebase.appcheck.v1beta.TokenExchangeService';
41
+ /**
42
+ * Class for generating Firebase App Check tokens.
43
+ *
44
+ * @internal
45
+ */
46
+ var AppCheckTokenGenerator = /** @class */ (function () {
47
+ /**
48
+ * The AppCheckTokenGenerator class constructor.
49
+ *
50
+ * @param signer - The CryptoSigner instance for this token generator.
51
+ * @constructor
52
+ */
53
+ function AppCheckTokenGenerator(signer) {
54
+ if (!validator.isNonNullObject(signer)) {
55
+ throw new app_check_api_client_internal_1.FirebaseAppCheckError('invalid-argument', 'INTERNAL ASSERT: Must provide a CryptoSigner to use AppCheckTokenGenerator.');
56
+ }
57
+ this.signer = signer;
58
+ }
59
+ /**
60
+ * Creates a new custom token that can be exchanged to an App Check token.
61
+ *
62
+ * @param appId - The Application ID to use for the generated token.
63
+ *
64
+ * @returns A Promise fulfilled with a custom token signed with a service account key
65
+ * that can be exchanged to an App Check token.
66
+ */
67
+ AppCheckTokenGenerator.prototype.createCustomToken = function (appId, options) {
68
+ var _this = this;
69
+ if (!validator.isNonEmptyString(appId)) {
70
+ throw new app_check_api_client_internal_1.FirebaseAppCheckError('invalid-argument', '`appId` must be a non-empty string.');
71
+ }
72
+ var customOptions = {};
73
+ if (typeof options !== 'undefined') {
74
+ customOptions = this.validateTokenOptions(options);
75
+ }
76
+ return this.signer.getAccountId().then(function (account) {
77
+ var header = {
78
+ alg: _this.signer.algorithm,
79
+ typ: 'JWT',
80
+ };
81
+ var iat = Math.floor(Date.now() / 1000);
82
+ var body = __assign({ iss: account, sub: account, app_id: appId, aud: FIREBASE_APP_CHECK_AUDIENCE, exp: iat + (ONE_MINUTE_IN_SECONDS * 5), iat: iat }, customOptions);
83
+ var token = _this.encodeSegment(header) + "." + _this.encodeSegment(body);
84
+ return _this.signer.sign(Buffer.from(token))
85
+ .then(function (signature) {
86
+ return token + "." + _this.encodeSegment(signature);
87
+ });
88
+ }).catch(function (err) {
89
+ throw appCheckErrorFromCryptoSignerError(err);
90
+ });
91
+ };
92
+ AppCheckTokenGenerator.prototype.encodeSegment = function (segment) {
93
+ var buffer = (segment instanceof Buffer) ? segment : Buffer.from(JSON.stringify(segment));
94
+ return utils_1.toWebSafeBase64(buffer).replace(/=+$/, '');
95
+ };
96
+ /**
97
+ * Checks if a given `AppCheckTokenOptions` object is valid. If successful, returns an object with
98
+ * custom properties.
99
+ *
100
+ * @param options - An options object to be validated.
101
+ * @returns A custom object with ttl converted to protobuf Duration string format.
102
+ */
103
+ AppCheckTokenGenerator.prototype.validateTokenOptions = function (options) {
104
+ if (!validator.isNonNullObject(options)) {
105
+ throw new app_check_api_client_internal_1.FirebaseAppCheckError('invalid-argument', 'AppCheckTokenOptions must be a non-null object.');
106
+ }
107
+ if (typeof options.ttlMillis !== 'undefined') {
108
+ if (!validator.isNumber(options.ttlMillis)) {
109
+ throw new app_check_api_client_internal_1.FirebaseAppCheckError('invalid-argument', 'ttlMillis must be a duration in milliseconds.');
110
+ }
111
+ // ttlMillis must be between 30 minutes and 7 days (inclusive)
112
+ if (options.ttlMillis < (ONE_MINUTE_IN_MILLIS * 30) || options.ttlMillis > (ONE_DAY_IN_MILLIS * 7)) {
113
+ throw new app_check_api_client_internal_1.FirebaseAppCheckError('invalid-argument', 'ttlMillis must be a duration in milliseconds between 30 minutes and 7 days (inclusive).');
114
+ }
115
+ return { ttl: utils_1.transformMillisecondsToSecondsString(options.ttlMillis) };
116
+ }
117
+ return {};
118
+ };
119
+ return AppCheckTokenGenerator;
120
+ }());
121
+ exports.AppCheckTokenGenerator = AppCheckTokenGenerator;
122
+ /**
123
+ * Creates a new `FirebaseAppCheckError` by extracting the error code, message and other relevant
124
+ * details from a `CryptoSignerError`.
125
+ *
126
+ * @param err - The Error to convert into a `FirebaseAppCheckError` error
127
+ * @returns A Firebase App Check error that can be returned to the user.
128
+ */
129
+ function appCheckErrorFromCryptoSignerError(err) {
130
+ if (!(err instanceof crypto_signer_1.CryptoSignerError)) {
131
+ return err;
132
+ }
133
+ if (err.code === crypto_signer_1.CryptoSignerErrorCode.SERVER_ERROR && validator.isNonNullObject(err.cause)) {
134
+ var httpError = err.cause;
135
+ var errorResponse = httpError.response.data;
136
+ if (errorResponse === null || errorResponse === void 0 ? void 0 : errorResponse.error) {
137
+ var status = errorResponse.error.status;
138
+ var description = errorResponse.error.message || JSON.stringify(httpError.response);
139
+ var code = 'unknown-error';
140
+ if (status && status in app_check_api_client_internal_1.APP_CHECK_ERROR_CODE_MAPPING) {
141
+ code = app_check_api_client_internal_1.APP_CHECK_ERROR_CODE_MAPPING[status];
142
+ }
143
+ return new app_check_api_client_internal_1.FirebaseAppCheckError(code, "Error returned from server while signing a custom token: " + description);
144
+ }
145
+ return new app_check_api_client_internal_1.FirebaseAppCheckError('internal-error', 'Error returned from server: ' + JSON.stringify(errorResponse) + '.');
146
+ }
147
+ return new app_check_api_client_internal_1.FirebaseAppCheckError(mapToAppCheckErrorCode(err.code), err.message);
148
+ }
149
+ exports.appCheckErrorFromCryptoSignerError = appCheckErrorFromCryptoSignerError;
150
+ function mapToAppCheckErrorCode(code) {
151
+ switch (code) {
152
+ case crypto_signer_1.CryptoSignerErrorCode.INVALID_CREDENTIAL:
153
+ return 'invalid-credential';
154
+ case crypto_signer_1.CryptoSignerErrorCode.INVALID_ARGUMENT:
155
+ return 'invalid-argument';
156
+ default:
157
+ return 'internal-error';
158
+ }
159
+ }
@@ -0,0 +1,17 @@
1
+ /*! firebase-admin v10.0.2 */
2
+ /*!
3
+ * Copyright 2021 Google Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export {};
@@ -0,0 +1,151 @@
1
+ /*! firebase-admin v10.0.2 */
2
+ "use strict";
3
+ /*!
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
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.AppCheckTokenVerifier = void 0;
20
+ var validator = require("../utils/validator");
21
+ var util = require("../utils/index");
22
+ var app_check_api_client_internal_1 = require("./app-check-api-client-internal");
23
+ var jwt_1 = require("../utils/jwt");
24
+ var APP_CHECK_ISSUER = 'https://firebaseappcheck.googleapis.com/';
25
+ var JWKS_URL = 'https://firebaseappcheck.googleapis.com/v1beta/jwks';
26
+ /**
27
+ * Class for verifying Firebase App Check tokens.
28
+ *
29
+ * @internal
30
+ */
31
+ var AppCheckTokenVerifier = /** @class */ (function () {
32
+ function AppCheckTokenVerifier(app) {
33
+ this.app = app;
34
+ this.signatureVerifier = jwt_1.PublicKeySignatureVerifier.withJwksUrl(JWKS_URL);
35
+ }
36
+ /**
37
+ * Verifies the format and signature of a Firebase App Check token.
38
+ *
39
+ * @param token - The Firebase Auth JWT token to verify.
40
+ * @returns A promise fulfilled with the decoded claims of the Firebase App Check token.
41
+ */
42
+ AppCheckTokenVerifier.prototype.verifyToken = function (token) {
43
+ var _this = this;
44
+ if (!validator.isString(token)) {
45
+ throw new app_check_api_client_internal_1.FirebaseAppCheckError('invalid-argument', 'App check token must be a non-null string.');
46
+ }
47
+ return this.ensureProjectId()
48
+ .then(function (projectId) {
49
+ return _this.decodeAndVerify(token, projectId);
50
+ })
51
+ .then(function (decoded) {
52
+ var decodedAppCheckToken = decoded.payload;
53
+ decodedAppCheckToken.app_id = decodedAppCheckToken.sub;
54
+ return decodedAppCheckToken;
55
+ });
56
+ };
57
+ AppCheckTokenVerifier.prototype.ensureProjectId = function () {
58
+ return util.findProjectId(this.app)
59
+ .then(function (projectId) {
60
+ if (!validator.isNonEmptyString(projectId)) {
61
+ throw new app_check_api_client_internal_1.FirebaseAppCheckError('invalid-credential', 'Must initialize app with a cert credential or set your Firebase project ID as the ' +
62
+ 'GOOGLE_CLOUD_PROJECT environment variable to verify an App Check token.');
63
+ }
64
+ return projectId;
65
+ });
66
+ };
67
+ AppCheckTokenVerifier.prototype.decodeAndVerify = function (token, projectId) {
68
+ var _this = this;
69
+ return this.safeDecode(token)
70
+ .then(function (decodedToken) {
71
+ _this.verifyContent(decodedToken, projectId);
72
+ return _this.verifySignature(token)
73
+ .then(function () { return decodedToken; });
74
+ });
75
+ };
76
+ AppCheckTokenVerifier.prototype.safeDecode = function (jwtToken) {
77
+ return jwt_1.decodeJwt(jwtToken)
78
+ .catch(function () {
79
+ var errorMessage = 'Decoding App Check token failed. Make sure you passed ' +
80
+ 'the entire string JWT which represents the Firebase App Check token.';
81
+ throw new app_check_api_client_internal_1.FirebaseAppCheckError('invalid-argument', errorMessage);
82
+ });
83
+ };
84
+ /**
85
+ * Verifies the content of a Firebase App Check JWT.
86
+ *
87
+ * @param fullDecodedToken - The decoded JWT.
88
+ * @param projectId - The Firebase Project Id.
89
+ */
90
+ AppCheckTokenVerifier.prototype.verifyContent = function (fullDecodedToken, projectId) {
91
+ var header = fullDecodedToken.header;
92
+ var payload = fullDecodedToken.payload;
93
+ var projectIdMatchMessage = ' Make sure the App Check token comes from the same ' +
94
+ 'Firebase project as the service account used to authenticate this SDK.';
95
+ var scopedProjectId = "projects/" + projectId;
96
+ var errorMessage;
97
+ if (header.alg !== jwt_1.ALGORITHM_RS256) {
98
+ errorMessage = 'The provided App Check token has incorrect algorithm. Expected "' +
99
+ jwt_1.ALGORITHM_RS256 + '" but got ' + '"' + header.alg + '".';
100
+ }
101
+ else if (!validator.isNonEmptyArray(payload.aud) || !payload.aud.includes(scopedProjectId)) {
102
+ errorMessage = 'The provided App Check token has incorrect "aud" (audience) claim. Expected "' +
103
+ scopedProjectId + '" but got "' + payload.aud + '".' + projectIdMatchMessage;
104
+ }
105
+ else if (typeof payload.iss !== 'string' || !payload.iss.startsWith(APP_CHECK_ISSUER)) {
106
+ errorMessage = 'The provided App Check token has incorrect "iss" (issuer) claim.';
107
+ }
108
+ else if (typeof payload.sub !== 'string') {
109
+ errorMessage = 'The provided App Check token has no "sub" (subject) claim.';
110
+ }
111
+ else if (payload.sub === '') {
112
+ errorMessage = 'The provided App Check token has an empty string "sub" (subject) claim.';
113
+ }
114
+ if (errorMessage) {
115
+ throw new app_check_api_client_internal_1.FirebaseAppCheckError('invalid-argument', errorMessage);
116
+ }
117
+ };
118
+ AppCheckTokenVerifier.prototype.verifySignature = function (jwtToken) {
119
+ var _this = this;
120
+ return this.signatureVerifier.verify(jwtToken)
121
+ .catch(function (error) {
122
+ throw _this.mapJwtErrorToAppCheckError(error);
123
+ });
124
+ };
125
+ /**
126
+ * Maps JwtError to FirebaseAppCheckError
127
+ *
128
+ * @param error - JwtError to be mapped.
129
+ * @returns FirebaseAppCheckError instance.
130
+ */
131
+ AppCheckTokenVerifier.prototype.mapJwtErrorToAppCheckError = function (error) {
132
+ if (error.code === jwt_1.JwtErrorCode.TOKEN_EXPIRED) {
133
+ var errorMessage = 'The provided App Check token has expired. Get a fresh App Check token' +
134
+ ' from your client app and try again.';
135
+ return new app_check_api_client_internal_1.FirebaseAppCheckError('app-check-token-expired', errorMessage);
136
+ }
137
+ else if (error.code === jwt_1.JwtErrorCode.INVALID_SIGNATURE) {
138
+ var errorMessage = 'The provided App Check token has invalid signature.';
139
+ return new app_check_api_client_internal_1.FirebaseAppCheckError('invalid-argument', errorMessage);
140
+ }
141
+ else if (error.code === jwt_1.JwtErrorCode.NO_MATCHING_KID) {
142
+ var errorMessage = 'The provided App Check token has "kid" claim which does not ' +
143
+ 'correspond to a known public key. Most likely the provided App Check token ' +
144
+ 'is expired, so get a fresh token from your client app and try again.';
145
+ return new app_check_api_client_internal_1.FirebaseAppCheckError('invalid-argument', errorMessage);
146
+ }
147
+ return new app_check_api_client_internal_1.FirebaseAppCheckError('invalid-argument', error.message);
148
+ };
149
+ return AppCheckTokenVerifier;
150
+ }());
151
+ exports.AppCheckTokenVerifier = AppCheckTokenVerifier;
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v9.100.0-alpha.0 */
1
+ /*! firebase-admin v10.0.2 */
2
2
  /*!
3
3
  * Copyright 2018 Google Inc.
4
4
  *
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v9.100.0-alpha.0 */
1
+ /*! firebase-admin v10.0.2 */
2
2
  "use strict";
3
3
  /*!
4
4
  * Copyright 2018 Google Inc.
@@ -93,7 +93,7 @@ var ActionCodeSettingsBuilder = /** @class */ (function () {
93
93
  * Returns the corresponding constructed server request corresponding to the
94
94
  * current ActionCodeSettings.
95
95
  *
96
- * @return {EmailActionCodeRequest} The constructed EmailActionCodeRequest request.
96
+ * @returns The constructed EmailActionCodeRequest request.
97
97
  */
98
98
  ActionCodeSettingsBuilder.prototype.buildRequest = function () {
99
99
  var request = {
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v9.100.0-alpha.0 */
1
+ /*! firebase-admin v10.0.2 */
2
2
  /*!
3
3
  * @license
4
4
  * Copyright 2017 Google Inc.
@@ -31,18 +31,18 @@ declare class AuthResourceUrlBuilder {
31
31
  /**
32
32
  * The resource URL builder constructor.
33
33
  *
34
- * @param {string} projectId The resource project ID.
35
- * @param {string} version The endpoint API version.
34
+ * @param projectId - The resource project ID.
35
+ * @param version - The endpoint API version.
36
36
  * @constructor
37
37
  */
38
38
  constructor(app: App, version?: string);
39
39
  /**
40
40
  * Returns the resource URL corresponding to the provided parameters.
41
41
  *
42
- * @param {string=} api The backend API name.
43
- * @param {object=} params The optional additional parameters to substitute in the
42
+ * @param api - The backend API name.
43
+ * @param params - The optional additional parameters to substitute in the
44
44
  * URL path.
45
- * @return {Promise<string>} The corresponding resource URL.
45
+ * @returns The corresponding resource URL.
46
46
  */
47
47
  getUrl(api?: string, params?: object): Promise<string>;
48
48
  private getProjectId;
@@ -65,35 +65,35 @@ export declare class AuthRequestHandler extends AbstractAuthRequestHandler {
65
65
  /**
66
66
  * The FirebaseAuthRequestHandler constructor used to initialize an instance using a FirebaseApp.
67
67
  *
68
- * @param {FirebaseApp} app The app used to fetch access tokens to sign API requests.
68
+ * @param app - The app used to fetch access tokens to sign API requests.
69
69
  * @constructor.
70
70
  */
71
71
  constructor(app: App);
72
72
  /**
73
- * @return {AuthResourceUrlBuilder} A new Auth user management resource URL builder instance.
73
+ * @returns A new Auth user management resource URL builder instance.
74
74
  */
75
75
  protected newAuthUrlBuilder(): AuthResourceUrlBuilder;
76
76
  /**
77
- * @return {AuthResourceUrlBuilder} A new project config resource URL builder instance.
77
+ * @returns A new project config resource URL builder instance.
78
78
  */
79
79
  protected newProjectConfigUrlBuilder(): AuthResourceUrlBuilder;
80
80
  /**
81
81
  * Looks up a tenant by tenant ID.
82
82
  *
83
- * @param {string} tenantId The tenant identifier of the tenant to lookup.
84
- * @return {Promise<TenantServerResponse>} A promise that resolves with the tenant information.
83
+ * @param tenantId - The tenant identifier of the tenant to lookup.
84
+ * @returns A promise that resolves with the tenant information.
85
85
  */
86
86
  getTenant(tenantId: string): Promise<TenantServerResponse>;
87
87
  /**
88
88
  * Exports the tenants (single batch only) with a size of maxResults and starting from
89
89
  * the offset as specified by pageToken.
90
90
  *
91
- * @param {number=} maxResults The page size, 1000 if undefined. This is also the maximum
91
+ * @param maxResults - The page size, 1000 if undefined. This is also the maximum
92
92
  * allowed limit.
93
- * @param {string=} pageToken The next page token. If not specified, returns tenants starting
93
+ * @param pageToken - The next page token. If not specified, returns tenants starting
94
94
  * without any offset. Tenants are returned in the order they were created from oldest to
95
95
  * newest, relative to the page token offset.
96
- * @return {Promise<object>} A promise that resolves with the current batch of downloaded
96
+ * @returns A promise that resolves with the current batch of downloaded
97
97
  * tenants and the next page token if available. For the last page, an empty list of tenants
98
98
  * and no page token are returned.
99
99
  */
@@ -104,23 +104,23 @@ export declare class AuthRequestHandler extends AbstractAuthRequestHandler {
104
104
  /**
105
105
  * Deletes a tenant identified by a tenantId.
106
106
  *
107
- * @param {string} tenantId The identifier of the tenant to delete.
108
- * @return {Promise<void>} A promise that resolves when the tenant is deleted.
107
+ * @param tenantId - The identifier of the tenant to delete.
108
+ * @returns A promise that resolves when the tenant is deleted.
109
109
  */
110
110
  deleteTenant(tenantId: string): Promise<void>;
111
111
  /**
112
112
  * Creates a new tenant with the properties provided.
113
113
  *
114
- * @param {TenantOptions} tenantOptions The properties to set on the new tenant to be created.
115
- * @return {Promise<TenantServerResponse>} A promise that resolves with the newly created tenant object.
114
+ * @param tenantOptions - The properties to set on the new tenant to be created.
115
+ * @returns A promise that resolves with the newly created tenant object.
116
116
  */
117
117
  createTenant(tenantOptions: CreateTenantRequest): Promise<TenantServerResponse>;
118
118
  /**
119
119
  * Updates an existing tenant with the properties provided.
120
120
  *
121
- * @param {string} tenantId The tenant identifier of the tenant to update.
122
- * @param {TenantOptions} tenantOptions The properties to update on the existing tenant.
123
- * @return {Promise<TenantServerResponse>} A promise that resolves with the modified tenant object.
121
+ * @param tenantId - The tenant identifier of the tenant to update.
122
+ * @param tenantOptions - The properties to update on the existing tenant.
123
+ * @returns A promise that resolves with the modified tenant object.
124
124
  */
125
125
  updateTenant(tenantId: string, tenantOptions: UpdateTenantRequest): Promise<TenantServerResponse>;
126
126
  }
@@ -135,17 +135,17 @@ export declare class TenantAwareAuthRequestHandler extends AbstractAuthRequestHa
135
135
  * The FirebaseTenantRequestHandler constructor used to initialize an instance using a
136
136
  * FirebaseApp and a tenant ID.
137
137
  *
138
- * @param {FirebaseApp} app The app used to fetch access tokens to sign API requests.
139
- * @param {string} tenantId The request handler's tenant ID.
138
+ * @param app - The app used to fetch access tokens to sign API requests.
139
+ * @param tenantId - The request handler's tenant ID.
140
140
  * @constructor
141
141
  */
142
142
  constructor(app: App, tenantId: string);
143
143
  /**
144
- * @return {AuthResourceUrlBuilder} A new Auth user management resource URL builder instance.
144
+ * @returns A new Auth user management resource URL builder instance.
145
145
  */
146
146
  protected newAuthUrlBuilder(): AuthResourceUrlBuilder;
147
147
  /**
148
- * @return {AuthResourceUrlBuilder} A new project config resource URL builder instance.
148
+ * @returns A new project config resource URL builder instance.
149
149
  */
150
150
  protected newProjectConfigUrlBuilder(): AuthResourceUrlBuilder;
151
151
  /**
@@ -157,10 +157,10 @@ export declare class TenantAwareAuthRequestHandler extends AbstractAuthRequestHa
157
157
  * Overrides the superclass methods by adding an additional check to match tenant IDs of
158
158
  * imported user records if present.
159
159
  *
160
- * @param {UserImportRecord[]} users The list of user records to import to Firebase Auth.
161
- * @param {UserImportOptions=} options The user import options, required when the users provided
160
+ * @param users - The list of user records to import to Firebase Auth.
161
+ * @param options - The user import options, required when the users provided
162
162
  * include password credentials.
163
- * @return {Promise<UserImportResult>} A promise that resolves when the operation completes
163
+ * @returns A promise that resolves when the operation completes
164
164
  * with the result of the import. This includes the number of successful imports, the number
165
165
  * of failed uploads and their corresponding errors.
166
166
  */
@@ -169,10 +169,6 @@ export declare class TenantAwareAuthRequestHandler extends AbstractAuthRequestHa
169
169
  /**
170
170
  * When true the SDK should communicate with the Auth Emulator for all API
171
171
  * calls and also produce unsigned tokens.
172
- *
173
- * This alone does <b>NOT<b> short-circuit ID Token verification.
174
- * For security reasons that must be explicitly disabled through
175
- * setJwtVerificationEnabled(false);
176
172
  */
177
173
  export declare function useEmulator(): boolean;
178
174
  export {};