firebase-admin 10.2.0 → 11.0.1
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.
- package/README.md +1 -1
- package/lib/app/core.d.ts +1 -1
- package/lib/app/core.js +1 -1
- package/lib/app/credential-factory.d.ts +1 -1
- package/lib/app/credential-factory.js +8 -8
- package/lib/app/credential-internal.d.ts +7 -1
- package/lib/app/credential-internal.js +120 -106
- package/lib/app/credential.d.ts +1 -1
- package/lib/app/credential.js +1 -1
- package/lib/app/firebase-app.d.ts +1 -1
- package/lib/app/firebase-app.js +76 -91
- package/lib/app/firebase-namespace.d.ts +1 -1
- package/lib/app/firebase-namespace.js +209 -279
- package/lib/app/index.d.ts +1 -1
- package/lib/app/index.js +4 -4
- package/lib/app/lifecycle.d.ts +1 -1
- package/lib/app/lifecycle.js +37 -43
- package/lib/app-check/app-check-api-client-internal.d.ts +1 -1
- package/lib/app-check/app-check-api-client-internal.js +54 -73
- package/lib/app-check/app-check-api.d.ts +1 -1
- package/lib/app-check/app-check-api.js +1 -1
- package/lib/app-check/app-check-namespace.d.ts +1 -1
- package/lib/app-check/app-check-namespace.js +1 -1
- package/lib/app-check/app-check.d.ts +1 -1
- package/lib/app-check/app-check.js +17 -19
- package/lib/app-check/index.d.ts +1 -1
- package/lib/app-check/index.js +7 -7
- package/lib/app-check/token-generator.d.ts +1 -1
- package/lib/app-check/token-generator.js +47 -52
- package/lib/app-check/token-verifier.d.ts +1 -1
- package/lib/app-check/token-verifier.js +46 -50
- package/lib/auth/action-code-settings-builder.d.ts +1 -1
- package/lib/auth/action-code-settings-builder.js +10 -11
- package/lib/auth/auth-api-request.d.ts +1 -1
- package/lib/auth/auth-api-request.js +346 -393
- package/lib/auth/auth-config.d.ts +1 -1
- package/lib/auth/auth-config.js +95 -106
- package/lib/auth/auth-namespace.d.ts +1 -1
- package/lib/auth/auth-namespace.js +1 -1
- package/lib/auth/auth.d.ts +1 -1
- package/lib/auth/auth.js +20 -40
- package/lib/auth/base-auth.d.ts +1 -1
- package/lib/auth/base-auth.js +137 -144
- package/lib/auth/identifier.d.ts +1 -1
- package/lib/auth/identifier.js +2 -2
- package/lib/auth/index.d.ts +1 -1
- package/lib/auth/index.js +7 -7
- package/lib/auth/tenant-manager.d.ts +1 -1
- package/lib/auth/tenant-manager.js +49 -71
- package/lib/auth/tenant.d.ts +1 -1
- package/lib/auth/tenant.js +44 -55
- package/lib/auth/token-generator.d.ts +1 -1
- package/lib/auth/token-generator.js +49 -53
- package/lib/auth/token-verifier.d.ts +1 -1
- package/lib/auth/token-verifier.js +83 -91
- package/lib/auth/user-import-builder.d.ts +1 -1
- package/lib/auth/user-import-builder.js +70 -73
- package/lib/auth/user-record.d.ts +1 -1
- package/lib/auth/user-record.js +62 -84
- package/lib/credential/index.d.ts +1 -1
- package/lib/credential/index.js +2 -2
- package/lib/database/database-namespace.d.ts +1 -1
- package/lib/database/database-namespace.js +1 -1
- package/lib/database/database.d.ts +1 -1
- package/lib/database/database.js +92 -108
- package/lib/database/index.d.ts +1 -1
- package/lib/database/index.js +10 -10
- package/lib/default-namespace.d.ts +1 -1
- package/lib/default-namespace.js +2 -2
- package/lib/eventarc/cloudevent.d.ts +1 -1
- package/lib/eventarc/cloudevent.js +1 -1
- package/lib/eventarc/eventarc-client-internal.d.ts +1 -1
- package/lib/eventarc/eventarc-client-internal.js +63 -129
- package/lib/eventarc/eventarc-utils.d.ts +1 -1
- package/lib/eventarc/eventarc-utils.js +16 -32
- package/lib/eventarc/eventarc.d.ts +1 -1
- package/lib/eventarc/eventarc.js +51 -65
- package/lib/eventarc/index.d.ts +1 -1
- package/lib/eventarc/index.js +7 -7
- package/lib/firebase-namespace-api.d.ts +1 -1
- package/lib/firebase-namespace-api.js +8 -3
- package/lib/firestore/firestore-internal.d.ts +1 -1
- package/lib/firestore/firestore-internal.js +28 -37
- package/lib/firestore/firestore-namespace.d.ts +9 -1
- package/lib/firestore/firestore-namespace.js +2 -2
- package/lib/firestore/index.d.ts +2 -2
- package/lib/firestore/index.js +7 -7
- package/lib/functions/functions-api-client-internal.d.ts +19 -1
- package/lib/functions/functions-api-client-internal.js +83 -103
- package/lib/functions/functions-api.d.ts +1 -1
- package/lib/functions/functions-api.js +1 -1
- package/lib/functions/functions.d.ts +1 -1
- package/lib/functions/functions.js +13 -15
- package/lib/functions/index.d.ts +1 -1
- package/lib/functions/index.js +7 -7
- package/lib/index.d.ts +1 -1
- package/lib/index.js +14 -4
- package/lib/installations/index.d.ts +1 -1
- package/lib/installations/index.js +6 -6
- package/lib/installations/installations-namespace.d.ts +1 -1
- package/lib/installations/installations-namespace.js +1 -1
- package/lib/installations/installations-request-handler.d.ts +1 -1
- package/lib/installations/installations-request-handler.js +33 -36
- package/lib/installations/installations.d.ts +1 -1
- package/lib/installations/installations.js +17 -22
- package/lib/instance-id/index.d.ts +1 -1
- package/lib/instance-id/index.js +6 -6
- package/lib/instance-id/instance-id-namespace.d.ts +1 -1
- package/lib/instance-id/instance-id-namespace.js +1 -1
- package/lib/instance-id/instance-id.d.ts +1 -1
- package/lib/instance-id/instance-id.js +21 -26
- package/lib/machine-learning/index.d.ts +1 -1
- package/lib/machine-learning/index.js +7 -7
- package/lib/machine-learning/machine-learning-api-client.d.ts +1 -1
- package/lib/machine-learning/machine-learning-api-client.js +110 -124
- package/lib/machine-learning/machine-learning-namespace.d.ts +1 -1
- package/lib/machine-learning/machine-learning-namespace.js +1 -1
- package/lib/machine-learning/machine-learning-utils.d.ts +1 -1
- package/lib/machine-learning/machine-learning-utils.js +9 -24
- package/lib/machine-learning/machine-learning.d.ts +1 -1
- package/lib/machine-learning/machine-learning.js +146 -207
- package/lib/messaging/batch-request-internal.d.ts +1 -1
- package/lib/messaging/batch-request-internal.js +33 -35
- package/lib/messaging/index.d.ts +1 -1
- package/lib/messaging/index.js +7 -7
- package/lib/messaging/messaging-api-request-internal.d.ts +1 -1
- package/lib/messaging/messaging-api-request-internal.js +38 -40
- package/lib/messaging/messaging-api.d.ts +1 -1
- package/lib/messaging/messaging-api.js +1 -1
- package/lib/messaging/messaging-errors-internal.d.ts +1 -1
- package/lib/messaging/messaging-errors-internal.js +12 -13
- package/lib/messaging/messaging-internal.d.ts +1 -1
- package/lib/messaging/messaging-internal.js +51 -51
- package/lib/messaging/messaging-namespace.d.ts +1 -1
- package/lib/messaging/messaging-namespace.js +1 -1
- package/lib/messaging/messaging.d.ts +1 -1
- package/lib/messaging/messaging.js +184 -208
- package/lib/project-management/android-app.d.ts +1 -1
- package/lib/project-management/android-app.js +41 -43
- package/lib/project-management/app-metadata.d.ts +1 -1
- package/lib/project-management/app-metadata.js +1 -1
- package/lib/project-management/index.d.ts +1 -1
- package/lib/project-management/index.js +7 -7
- package/lib/project-management/ios-app.d.ts +1 -1
- package/lib/project-management/ios-app.js +25 -26
- package/lib/project-management/project-management-api-request-internal.d.ts +1 -1
- package/lib/project-management/project-management-api-request-internal.js +84 -89
- package/lib/project-management/project-management-namespace.d.ts +1 -1
- package/lib/project-management/project-management-namespace.js +1 -1
- package/lib/project-management/project-management.d.ts +1 -1
- package/lib/project-management/project-management.js +80 -87
- package/lib/remote-config/index.d.ts +1 -1
- package/lib/remote-config/index.js +7 -7
- package/lib/remote-config/remote-config-api-client-internal.d.ts +1 -1
- package/lib/remote-config/remote-config-api-client-internal.js +116 -154
- package/lib/remote-config/remote-config-api.d.ts +1 -1
- package/lib/remote-config/remote-config-api.js +1 -1
- package/lib/remote-config/remote-config-namespace.d.ts +1 -1
- package/lib/remote-config/remote-config-namespace.js +1 -1
- package/lib/remote-config/remote-config.d.ts +1 -1
- package/lib/remote-config/remote-config.js +51 -59
- package/lib/security-rules/index.d.ts +1 -1
- package/lib/security-rules/index.js +7 -7
- package/lib/security-rules/security-rules-api-client-internal.d.ts +3 -1
- package/lib/security-rules/security-rules-api-client-internal.js +118 -107
- package/lib/security-rules/security-rules-internal.d.ts +1 -1
- package/lib/security-rules/security-rules-internal.js +6 -21
- package/lib/security-rules/security-rules-namespace.d.ts +1 -1
- package/lib/security-rules/security-rules-namespace.js +1 -1
- package/lib/security-rules/security-rules.d.ts +1 -1
- package/lib/security-rules/security-rules.js +83 -92
- package/lib/storage/index.d.ts +1 -1
- package/lib/storage/index.js +7 -7
- package/lib/storage/storage-namespace.d.ts +1 -1
- package/lib/storage/storage-namespace.js +1 -1
- package/lib/storage/storage.d.ts +1 -1
- package/lib/storage/storage.js +25 -30
- package/lib/utils/api-request.d.ts +3 -1
- package/lib/utils/api-request.js +278 -356
- package/lib/utils/crypto-signer.d.ts +1 -1
- package/lib/utils/crypto-signer.js +58 -93
- package/lib/utils/deep-copy.d.ts +1 -1
- package/lib/utils/deep-copy.js +3 -3
- package/lib/utils/error.d.ts +1 -1
- package/lib/utils/error.js +611 -681
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +38 -43
- package/lib/utils/jwt.d.ts +1 -1
- package/lib/utils/jwt.js +97 -123
- package/lib/utils/validator.d.ts +1 -1
- package/lib/utils/validator.js +13 -13
- package/package.json +25 -10
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.1 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* @license
|
|
@@ -16,41 +16,30 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
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
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
20
|
exports.appCheckErrorFromCryptoSignerError = exports.AppCheckTokenGenerator = void 0;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
21
|
+
const validator = require("../utils/validator");
|
|
22
|
+
const utils_1 = require("../utils");
|
|
23
|
+
const crypto_signer_1 = require("../utils/crypto-signer");
|
|
24
|
+
const app_check_api_client_internal_1 = require("./app-check-api-client-internal");
|
|
25
|
+
const ONE_MINUTE_IN_SECONDS = 60;
|
|
26
|
+
const ONE_MINUTE_IN_MILLIS = ONE_MINUTE_IN_SECONDS * 1000;
|
|
27
|
+
const ONE_DAY_IN_MILLIS = 24 * 60 * 60 * 1000;
|
|
39
28
|
// Audience to use for Firebase App Check Custom tokens
|
|
40
|
-
|
|
29
|
+
const FIREBASE_APP_CHECK_AUDIENCE = 'https://firebaseappcheck.googleapis.com/google.firebase.appcheck.v1.TokenExchangeService';
|
|
41
30
|
/**
|
|
42
31
|
* Class for generating Firebase App Check tokens.
|
|
43
32
|
*
|
|
44
33
|
* @internal
|
|
45
34
|
*/
|
|
46
|
-
|
|
35
|
+
class AppCheckTokenGenerator {
|
|
47
36
|
/**
|
|
48
37
|
* The AppCheckTokenGenerator class constructor.
|
|
49
38
|
*
|
|
50
39
|
* @param signer - The CryptoSigner instance for this token generator.
|
|
51
40
|
* @constructor
|
|
52
41
|
*/
|
|
53
|
-
|
|
42
|
+
constructor(signer) {
|
|
54
43
|
if (!validator.isNonNullObject(signer)) {
|
|
55
44
|
throw new app_check_api_client_internal_1.FirebaseAppCheckError('invalid-argument', 'INTERNAL ASSERT: Must provide a CryptoSigner to use AppCheckTokenGenerator.');
|
|
56
45
|
}
|
|
@@ -64,35 +53,42 @@ var AppCheckTokenGenerator = /** @class */ (function () {
|
|
|
64
53
|
* @returns A Promise fulfilled with a custom token signed with a service account key
|
|
65
54
|
* that can be exchanged to an App Check token.
|
|
66
55
|
*/
|
|
67
|
-
|
|
68
|
-
var _this = this;
|
|
56
|
+
createCustomToken(appId, options) {
|
|
69
57
|
if (!validator.isNonEmptyString(appId)) {
|
|
70
58
|
throw new app_check_api_client_internal_1.FirebaseAppCheckError('invalid-argument', '`appId` must be a non-empty string.');
|
|
71
59
|
}
|
|
72
|
-
|
|
60
|
+
let customOptions = {};
|
|
73
61
|
if (typeof options !== 'undefined') {
|
|
74
62
|
customOptions = this.validateTokenOptions(options);
|
|
75
63
|
}
|
|
76
|
-
return this.signer.getAccountId().then(
|
|
77
|
-
|
|
78
|
-
alg:
|
|
64
|
+
return this.signer.getAccountId().then((account) => {
|
|
65
|
+
const header = {
|
|
66
|
+
alg: this.signer.algorithm,
|
|
79
67
|
typ: 'JWT',
|
|
80
68
|
};
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
69
|
+
const iat = Math.floor(Date.now() / 1000);
|
|
70
|
+
const body = {
|
|
71
|
+
iss: account,
|
|
72
|
+
sub: account,
|
|
73
|
+
app_id: appId,
|
|
74
|
+
aud: FIREBASE_APP_CHECK_AUDIENCE,
|
|
75
|
+
exp: iat + (ONE_MINUTE_IN_SECONDS * 5),
|
|
76
|
+
iat,
|
|
77
|
+
...customOptions,
|
|
78
|
+
};
|
|
79
|
+
const token = `${this.encodeSegment(header)}.${this.encodeSegment(body)}`;
|
|
80
|
+
return this.signer.sign(Buffer.from(token))
|
|
81
|
+
.then((signature) => {
|
|
82
|
+
return `${token}.${this.encodeSegment(signature)}`;
|
|
87
83
|
});
|
|
88
|
-
}).catch(
|
|
84
|
+
}).catch((err) => {
|
|
89
85
|
throw appCheckErrorFromCryptoSignerError(err);
|
|
90
86
|
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return utils_1.toWebSafeBase64(buffer).replace(/=+$/, '');
|
|
95
|
-
}
|
|
87
|
+
}
|
|
88
|
+
encodeSegment(segment) {
|
|
89
|
+
const buffer = (segment instanceof Buffer) ? segment : Buffer.from(JSON.stringify(segment));
|
|
90
|
+
return (0, utils_1.toWebSafeBase64)(buffer).replace(/=+$/, '');
|
|
91
|
+
}
|
|
96
92
|
/**
|
|
97
93
|
* Checks if a given `AppCheckTokenOptions` object is valid. If successful, returns an object with
|
|
98
94
|
* custom properties.
|
|
@@ -100,7 +96,7 @@ var AppCheckTokenGenerator = /** @class */ (function () {
|
|
|
100
96
|
* @param options - An options object to be validated.
|
|
101
97
|
* @returns A custom object with ttl converted to protobuf Duration string format.
|
|
102
98
|
*/
|
|
103
|
-
|
|
99
|
+
validateTokenOptions(options) {
|
|
104
100
|
if (!validator.isNonNullObject(options)) {
|
|
105
101
|
throw new app_check_api_client_internal_1.FirebaseAppCheckError('invalid-argument', 'AppCheckTokenOptions must be a non-null object.');
|
|
106
102
|
}
|
|
@@ -112,12 +108,11 @@ var AppCheckTokenGenerator = /** @class */ (function () {
|
|
|
112
108
|
if (options.ttlMillis < (ONE_MINUTE_IN_MILLIS * 30) || options.ttlMillis > (ONE_DAY_IN_MILLIS * 7)) {
|
|
113
109
|
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
110
|
}
|
|
115
|
-
return { ttl: utils_1.transformMillisecondsToSecondsString(options.ttlMillis) };
|
|
111
|
+
return { ttl: (0, utils_1.transformMillisecondsToSecondsString)(options.ttlMillis) };
|
|
116
112
|
}
|
|
117
113
|
return {};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
}());
|
|
114
|
+
}
|
|
115
|
+
}
|
|
121
116
|
exports.AppCheckTokenGenerator = AppCheckTokenGenerator;
|
|
122
117
|
/**
|
|
123
118
|
* Creates a new `FirebaseAppCheckError` by extracting the error code, message and other relevant
|
|
@@ -131,16 +126,16 @@ function appCheckErrorFromCryptoSignerError(err) {
|
|
|
131
126
|
return err;
|
|
132
127
|
}
|
|
133
128
|
if (err.code === crypto_signer_1.CryptoSignerErrorCode.SERVER_ERROR && validator.isNonNullObject(err.cause)) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (errorResponse
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
129
|
+
const httpError = err.cause;
|
|
130
|
+
const errorResponse = httpError.response.data;
|
|
131
|
+
if (errorResponse?.error) {
|
|
132
|
+
const status = errorResponse.error.status;
|
|
133
|
+
const description = errorResponse.error.message || JSON.stringify(httpError.response);
|
|
134
|
+
let code = 'unknown-error';
|
|
140
135
|
if (status && status in app_check_api_client_internal_1.APP_CHECK_ERROR_CODE_MAPPING) {
|
|
141
136
|
code = app_check_api_client_internal_1.APP_CHECK_ERROR_CODE_MAPPING[status];
|
|
142
137
|
}
|
|
143
|
-
return new app_check_api_client_internal_1.FirebaseAppCheckError(code,
|
|
138
|
+
return new app_check_api_client_internal_1.FirebaseAppCheckError(code, `Error returned from server while signing a custom token: ${description}`);
|
|
144
139
|
}
|
|
145
140
|
return new app_check_api_client_internal_1.FirebaseAppCheckError('internal-error', 'Error returned from server: ' + JSON.stringify(errorResponse) + '.');
|
|
146
141
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.1 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* Copyright 2021 Google Inc.
|
|
@@ -17,19 +17,19 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.AppCheckTokenVerifier = void 0;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
const validator = require("../utils/validator");
|
|
21
|
+
const util = require("../utils/index");
|
|
22
|
+
const app_check_api_client_internal_1 = require("./app-check-api-client-internal");
|
|
23
|
+
const jwt_1 = require("../utils/jwt");
|
|
24
|
+
const APP_CHECK_ISSUER = 'https://firebaseappcheck.googleapis.com/';
|
|
25
|
+
const JWKS_URL = 'https://firebaseappcheck.googleapis.com/v1/jwks';
|
|
26
26
|
/**
|
|
27
27
|
* Class for verifying Firebase App Check tokens.
|
|
28
28
|
*
|
|
29
29
|
* @internal
|
|
30
30
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
class AppCheckTokenVerifier {
|
|
32
|
+
constructor(app) {
|
|
33
33
|
this.app = app;
|
|
34
34
|
this.signatureVerifier = jwt_1.PublicKeySignatureVerifier.withJwksUrl(JWKS_URL);
|
|
35
35
|
}
|
|
@@ -39,61 +39,59 @@ var AppCheckTokenVerifier = /** @class */ (function () {
|
|
|
39
39
|
* @param token - The Firebase Auth JWT token to verify.
|
|
40
40
|
* @returns A promise fulfilled with the decoded claims of the Firebase App Check token.
|
|
41
41
|
*/
|
|
42
|
-
|
|
43
|
-
var _this = this;
|
|
42
|
+
verifyToken(token) {
|
|
44
43
|
if (!validator.isString(token)) {
|
|
45
44
|
throw new app_check_api_client_internal_1.FirebaseAppCheckError('invalid-argument', 'App check token must be a non-null string.');
|
|
46
45
|
}
|
|
47
46
|
return this.ensureProjectId()
|
|
48
|
-
.then(
|
|
49
|
-
return
|
|
47
|
+
.then((projectId) => {
|
|
48
|
+
return this.decodeAndVerify(token, projectId);
|
|
50
49
|
})
|
|
51
|
-
.then(
|
|
52
|
-
|
|
50
|
+
.then((decoded) => {
|
|
51
|
+
const decodedAppCheckToken = decoded.payload;
|
|
53
52
|
decodedAppCheckToken.app_id = decodedAppCheckToken.sub;
|
|
54
53
|
return decodedAppCheckToken;
|
|
55
54
|
});
|
|
56
|
-
}
|
|
57
|
-
|
|
55
|
+
}
|
|
56
|
+
ensureProjectId() {
|
|
58
57
|
return util.findProjectId(this.app)
|
|
59
|
-
.then(
|
|
58
|
+
.then((projectId) => {
|
|
60
59
|
if (!validator.isNonEmptyString(projectId)) {
|
|
61
60
|
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
61
|
'GOOGLE_CLOUD_PROJECT environment variable to verify an App Check token.');
|
|
63
62
|
}
|
|
64
63
|
return projectId;
|
|
65
64
|
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
var _this = this;
|
|
65
|
+
}
|
|
66
|
+
decodeAndVerify(token, projectId) {
|
|
69
67
|
return this.safeDecode(token)
|
|
70
|
-
.then(
|
|
71
|
-
|
|
72
|
-
return
|
|
73
|
-
.then(
|
|
68
|
+
.then((decodedToken) => {
|
|
69
|
+
this.verifyContent(decodedToken, projectId);
|
|
70
|
+
return this.verifySignature(token)
|
|
71
|
+
.then(() => decodedToken);
|
|
74
72
|
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return jwt_1.decodeJwt(jwtToken)
|
|
78
|
-
.catch(
|
|
79
|
-
|
|
73
|
+
}
|
|
74
|
+
safeDecode(jwtToken) {
|
|
75
|
+
return (0, jwt_1.decodeJwt)(jwtToken)
|
|
76
|
+
.catch(() => {
|
|
77
|
+
const errorMessage = 'Decoding App Check token failed. Make sure you passed ' +
|
|
80
78
|
'the entire string JWT which represents the Firebase App Check token.';
|
|
81
79
|
throw new app_check_api_client_internal_1.FirebaseAppCheckError('invalid-argument', errorMessage);
|
|
82
80
|
});
|
|
83
|
-
}
|
|
81
|
+
}
|
|
84
82
|
/**
|
|
85
83
|
* Verifies the content of a Firebase App Check JWT.
|
|
86
84
|
*
|
|
87
85
|
* @param fullDecodedToken - The decoded JWT.
|
|
88
86
|
* @param projectId - The Firebase Project Id.
|
|
89
87
|
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
verifyContent(fullDecodedToken, projectId) {
|
|
89
|
+
const header = fullDecodedToken.header;
|
|
90
|
+
const payload = fullDecodedToken.payload;
|
|
91
|
+
const projectIdMatchMessage = ' Make sure the App Check token comes from the same ' +
|
|
94
92
|
'Firebase project as the service account used to authenticate this SDK.';
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
const scopedProjectId = `projects/${projectId}`;
|
|
94
|
+
let errorMessage;
|
|
97
95
|
if (header.alg !== jwt_1.ALGORITHM_RS256) {
|
|
98
96
|
errorMessage = 'The provided App Check token has incorrect algorithm. Expected "' +
|
|
99
97
|
jwt_1.ALGORITHM_RS256 + '" but got ' + '"' + header.alg + '".';
|
|
@@ -114,38 +112,36 @@ var AppCheckTokenVerifier = /** @class */ (function () {
|
|
|
114
112
|
if (errorMessage) {
|
|
115
113
|
throw new app_check_api_client_internal_1.FirebaseAppCheckError('invalid-argument', errorMessage);
|
|
116
114
|
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
var _this = this;
|
|
115
|
+
}
|
|
116
|
+
verifySignature(jwtToken) {
|
|
120
117
|
return this.signatureVerifier.verify(jwtToken)
|
|
121
|
-
.catch(
|
|
122
|
-
throw
|
|
118
|
+
.catch((error) => {
|
|
119
|
+
throw this.mapJwtErrorToAppCheckError(error);
|
|
123
120
|
});
|
|
124
|
-
}
|
|
121
|
+
}
|
|
125
122
|
/**
|
|
126
123
|
* Maps JwtError to FirebaseAppCheckError
|
|
127
124
|
*
|
|
128
125
|
* @param error - JwtError to be mapped.
|
|
129
126
|
* @returns FirebaseAppCheckError instance.
|
|
130
127
|
*/
|
|
131
|
-
|
|
128
|
+
mapJwtErrorToAppCheckError(error) {
|
|
132
129
|
if (error.code === jwt_1.JwtErrorCode.TOKEN_EXPIRED) {
|
|
133
|
-
|
|
130
|
+
const errorMessage = 'The provided App Check token has expired. Get a fresh App Check token' +
|
|
134
131
|
' from your client app and try again.';
|
|
135
132
|
return new app_check_api_client_internal_1.FirebaseAppCheckError('app-check-token-expired', errorMessage);
|
|
136
133
|
}
|
|
137
134
|
else if (error.code === jwt_1.JwtErrorCode.INVALID_SIGNATURE) {
|
|
138
|
-
|
|
135
|
+
const errorMessage = 'The provided App Check token has invalid signature.';
|
|
139
136
|
return new app_check_api_client_internal_1.FirebaseAppCheckError('invalid-argument', errorMessage);
|
|
140
137
|
}
|
|
141
138
|
else if (error.code === jwt_1.JwtErrorCode.NO_MATCHING_KID) {
|
|
142
|
-
|
|
139
|
+
const errorMessage = 'The provided App Check token has "kid" claim which does not ' +
|
|
143
140
|
'correspond to a known public key. Most likely the provided App Check token ' +
|
|
144
141
|
'is expired, so get a fresh token from your client app and try again.';
|
|
145
142
|
return new app_check_api_client_internal_1.FirebaseAppCheckError('invalid-argument', errorMessage);
|
|
146
143
|
}
|
|
147
144
|
return new app_check_api_client_internal_1.FirebaseAppCheckError('invalid-argument', error.message);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
}());
|
|
145
|
+
}
|
|
146
|
+
}
|
|
151
147
|
exports.AppCheckTokenVerifier = AppCheckTokenVerifier;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.1 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* Copyright 2018 Google Inc.
|
|
@@ -17,15 +17,15 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.ActionCodeSettingsBuilder = void 0;
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const validator = require("../utils/validator");
|
|
21
|
+
const error_1 = require("../utils/error");
|
|
22
22
|
/**
|
|
23
23
|
* Defines the ActionCodeSettings builder class used to convert the
|
|
24
24
|
* ActionCodeSettings object to its corresponding server request.
|
|
25
25
|
*
|
|
26
26
|
* @internal
|
|
27
27
|
*/
|
|
28
|
-
|
|
28
|
+
class ActionCodeSettingsBuilder {
|
|
29
29
|
/**
|
|
30
30
|
* ActionCodeSettingsBuilder constructor.
|
|
31
31
|
*
|
|
@@ -33,7 +33,7 @@ var ActionCodeSettingsBuilder = /** @class */ (function () {
|
|
|
33
33
|
* object used to initiliaze this server request builder.
|
|
34
34
|
* @constructor
|
|
35
35
|
*/
|
|
36
|
-
|
|
36
|
+
constructor(actionCodeSettings) {
|
|
37
37
|
if (!validator.isNonNullObject(actionCodeSettings)) {
|
|
38
38
|
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, '"ActionCodeSettings" must be a non-null object.');
|
|
39
39
|
}
|
|
@@ -95,8 +95,8 @@ var ActionCodeSettingsBuilder = /** @class */ (function () {
|
|
|
95
95
|
*
|
|
96
96
|
* @returns The constructed EmailActionCodeRequest request.
|
|
97
97
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
buildRequest() {
|
|
99
|
+
const request = {
|
|
100
100
|
continueUrl: this.continueUrl,
|
|
101
101
|
canHandleCodeInApp: this.canHandleCodeInApp,
|
|
102
102
|
dynamicLinkDomain: this.dynamicLinkDomain,
|
|
@@ -106,7 +106,7 @@ var ActionCodeSettingsBuilder = /** @class */ (function () {
|
|
|
106
106
|
iOSBundleId: this.ibi,
|
|
107
107
|
};
|
|
108
108
|
// Remove all null and undefined fields from request.
|
|
109
|
-
for (
|
|
109
|
+
for (const key in request) {
|
|
110
110
|
if (Object.prototype.hasOwnProperty.call(request, key)) {
|
|
111
111
|
if (typeof request[key] === 'undefined' || request[key] === null) {
|
|
112
112
|
delete request[key];
|
|
@@ -114,7 +114,6 @@ var ActionCodeSettingsBuilder = /** @class */ (function () {
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
return request;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
}());
|
|
117
|
+
}
|
|
118
|
+
}
|
|
120
119
|
exports.ActionCodeSettingsBuilder = ActionCodeSettingsBuilder;
|