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.
- package/README.md +7 -3
- package/lib/app/core.d.ts +15 -22
- package/lib/app/core.js +1 -1
- package/lib/app/credential-factory.d.ts +17 -33
- package/lib/app/credential-factory.js +17 -33
- package/lib/app/credential-internal.d.ts +10 -9
- package/lib/app/credential-internal.js +15 -13
- package/lib/app/credential.d.ts +3 -9
- package/lib/app/credential.js +1 -1
- package/lib/app/firebase-app.d.ts +6 -30
- package/lib/app/firebase-app.js +72 -216
- package/lib/app/firebase-namespace.d.ts +28 -34
- package/lib/app/firebase-namespace.js +119 -99
- package/lib/app/index.d.ts +6 -1
- package/lib/app/index.js +1 -1
- package/lib/app/lifecycle.d.ts +24 -3
- package/lib/app/lifecycle.js +119 -25
- package/lib/app-check/app-check-api-client-internal.d.ts +32 -0
- package/lib/app-check/app-check-api-client-internal.js +197 -0
- package/lib/app-check/app-check-api.d.ts +95 -0
- package/lib/app-check/app-check-api.js +19 -0
- package/lib/app-check/app-check-namespace.d.ts +65 -0
- package/lib/app-check/app-check-namespace.js +18 -0
- package/lib/app-check/app-check.d.ts +49 -0
- package/lib/app-check/app-check.js +82 -0
- package/lib/app-check/index.d.ts +53 -0
- package/lib/app-check/index.js +63 -0
- package/lib/app-check/token-generator.d.ts +25 -0
- package/lib/app-check/token-generator.js +159 -0
- package/lib/app-check/token-verifier.d.ts +17 -0
- package/lib/app-check/token-verifier.js +151 -0
- package/lib/auth/action-code-settings-builder.d.ts +1 -1
- package/lib/auth/action-code-settings-builder.js +2 -2
- package/lib/auth/auth-api-request.d.ts +28 -32
- package/lib/auth/auth-api-request.js +167 -125
- package/lib/auth/auth-config.d.ts +123 -21
- package/lib/auth/auth-config.js +85 -34
- package/lib/auth/auth-namespace.d.ts +157 -4
- package/lib/auth/auth-namespace.js +1 -1
- package/lib/auth/auth.d.ts +5 -3
- package/lib/auth/auth.js +6 -4
- package/lib/auth/base-auth.d.ts +134 -116
- package/lib/auth/base-auth.js +213 -143
- package/lib/auth/identifier.d.ts +5 -5
- package/lib/auth/identifier.js +1 -1
- package/lib/auth/index.d.ts +10 -5
- package/lib/auth/index.js +9 -4
- package/lib/auth/tenant-manager.d.ts +19 -19
- package/lib/auth/tenant-manager.js +21 -25
- package/lib/auth/tenant.d.ts +14 -5
- package/lib/auth/tenant.js +19 -11
- package/lib/auth/token-generator.d.ts +7 -108
- package/lib/auth/token-generator.js +52 -145
- package/lib/auth/token-verifier.d.ts +3 -4
- package/lib/auth/token-verifier.js +96 -145
- package/lib/auth/user-import-builder.d.ts +11 -11
- package/lib/auth/user-import-builder.js +9 -9
- package/lib/auth/user-record.d.ts +23 -15
- package/lib/auth/user-record.js +30 -20
- package/lib/credential/index.d.ts +18 -35
- package/lib/credential/index.js +17 -33
- package/lib/database/database-namespace.d.ts +39 -10
- package/lib/database/database-namespace.js +1 -1
- package/lib/database/database.d.ts +16 -6
- package/lib/database/database.js +61 -6
- package/lib/database/index.d.ts +19 -18
- package/lib/database/index.js +21 -23
- package/lib/default-namespace.d.ts +7 -1
- package/lib/default-namespace.js +4 -4
- package/lib/esm/app/index.js +10 -0
- package/lib/esm/app-check/index.js +4 -0
- package/lib/esm/auth/index.js +14 -0
- package/lib/esm/database/index.js +6 -0
- package/lib/esm/firestore/index.js +24 -0
- package/lib/esm/installations/index.js +4 -0
- package/lib/esm/instance-id/index.js +4 -0
- package/lib/esm/machine-learning/index.js +5 -0
- package/lib/esm/messaging/index.js +4 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/project-management/index.js +8 -0
- package/lib/esm/remote-config/index.js +4 -0
- package/lib/esm/security-rules/index.js +6 -0
- package/lib/esm/storage/index.js +4 -0
- package/lib/firebase-namespace-api.d.ts +12 -6
- package/lib/firebase-namespace-api.js +5 -1
- package/lib/firestore/firestore-internal.d.ts +2 -2
- package/lib/firestore/firestore-internal.js +2 -2
- package/lib/firestore/firestore-namespace.d.ts +6 -1
- package/lib/firestore/firestore-namespace.js +2 -1
- package/lib/firestore/index.d.ts +36 -4
- package/lib/firestore/index.js +29 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/installations/index.d.ts +52 -0
- package/lib/installations/index.js +62 -0
- package/lib/installations/installations-namespace.d.ts +55 -0
- package/lib/installations/installations-namespace.js +18 -0
- package/lib/{instance-id/instance-id-request-internal.d.ts → installations/installations-request-handler.d.ts} +8 -8
- package/lib/{instance-id/instance-id-request-internal.js → installations/installations-request-handler.js} +23 -23
- package/lib/installations/installations.d.ts +38 -0
- package/lib/installations/installations.js +63 -0
- package/lib/instance-id/index.d.ts +20 -9
- package/lib/instance-id/index.js +20 -9
- package/lib/instance-id/instance-id-namespace.d.ts +9 -8
- package/lib/instance-id/instance-id-namespace.js +1 -1
- package/lib/instance-id/instance-id.d.ts +8 -6
- package/lib/instance-id/instance-id.js +20 -11
- package/lib/machine-learning/index.d.ts +29 -27
- package/lib/machine-learning/index.js +29 -27
- package/lib/machine-learning/machine-learning-api-client.d.ts +1 -1
- package/lib/machine-learning/machine-learning-api-client.js +4 -4
- package/lib/machine-learning/machine-learning-namespace.d.ts +33 -8
- 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 +1 -1
- package/lib/machine-learning/machine-learning.d.ts +19 -19
- package/lib/machine-learning/machine-learning.js +20 -20
- package/lib/messaging/batch-request-internal.d.ts +3 -3
- package/lib/messaging/batch-request-internal.js +9 -9
- package/lib/messaging/index.d.ts +11 -9
- package/lib/messaging/index.js +11 -9
- package/lib/messaging/messaging-api-request-internal.d.ts +8 -8
- package/lib/messaging/messaging-api-request-internal.js +8 -8
- package/lib/messaging/messaging-api.d.ts +79 -75
- package/lib/messaging/messaging-api.js +1 -1
- package/lib/messaging/messaging-errors-internal.d.ts +5 -5
- package/lib/messaging/messaging-errors-internal.js +7 -7
- package/lib/messaging/messaging-internal.d.ts +1 -1
- package/lib/messaging/messaging-internal.js +6 -31
- package/lib/messaging/messaging-namespace.d.ts +105 -8
- package/lib/messaging/messaging-namespace.js +1 -1
- package/lib/messaging/messaging.d.ts +70 -86
- package/lib/messaging/messaging.js +76 -89
- package/lib/project-management/android-app.d.ts +11 -12
- package/lib/project-management/android-app.js +13 -14
- 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 +11 -9
- package/lib/project-management/index.js +11 -9
- package/lib/project-management/ios-app.d.ts +6 -7
- package/lib/project-management/ios-app.js +6 -7
- package/lib/project-management/project-management-api-request-internal.d.ts +1 -80
- package/lib/project-management/project-management-api-request-internal.js +14 -14
- package/lib/project-management/project-management-namespace.d.ts +31 -9
- package/lib/project-management/project-management-namespace.js +1 -1
- package/lib/project-management/project-management.d.ts +18 -21
- package/lib/project-management/project-management.js +19 -22
- package/lib/remote-config/index.d.ts +12 -10
- package/lib/remote-config/index.js +11 -9
- package/lib/remote-config/remote-config-api-client-internal.d.ts +1 -1
- package/lib/remote-config/remote-config-api-client-internal.js +2 -2
- package/lib/remote-config/remote-config-api.d.ts +12 -2
- package/lib/remote-config/remote-config-api.js +1 -1
- package/lib/remote-config/remote-config-namespace.d.ts +50 -9
- package/lib/remote-config/remote-config-namespace.js +1 -1
- package/lib/remote-config/remote-config.d.ts +19 -21
- package/lib/remote-config/remote-config.js +25 -25
- package/lib/security-rules/index.d.ts +12 -10
- package/lib/security-rules/index.js +12 -10
- package/lib/security-rules/security-rules-api-client-internal.d.ts +1 -1
- package/lib/security-rules/security-rules-api-client-internal.js +1 -1
- package/lib/security-rules/security-rules-internal.d.ts +1 -1
- package/lib/security-rules/security-rules-internal.js +1 -1
- package/lib/security-rules/security-rules-namespace.d.ts +43 -28
- package/lib/security-rules/security-rules-namespace.js +1 -1
- package/lib/security-rules/security-rules.d.ts +39 -42
- package/lib/security-rules/security-rules.js +38 -39
- package/lib/storage/index.d.ts +9 -7
- package/lib/storage/index.js +9 -7
- package/lib/storage/storage-namespace.d.ts +7 -6
- package/lib/storage/storage-namespace.js +1 -1
- package/lib/storage/storage.d.ts +3 -3
- package/lib/storage/storage.js +14 -4
- package/lib/utils/api-request.d.ts +24 -24
- package/lib/utils/api-request.js +25 -25
- package/lib/utils/crypto-signer.d.ts +128 -0
- package/lib/utils/crypto-signer.js +237 -0
- package/lib/utils/deep-copy.d.ts +6 -6
- package/lib/utils/deep-copy.js +6 -6
- package/lib/utils/error.d.ts +69 -36
- package/lib/utils/error.js +98 -43
- package/lib/utils/index.d.ts +30 -19
- package/lib/utils/index.js +47 -20
- package/lib/utils/jwt.d.ts +131 -0
- package/lib/utils/jwt.js +355 -0
- package/lib/utils/validator.d.ts +37 -37
- package/lib/utils/validator.js +37 -37
- package/package.json +126 -53
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v10.0.2 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* @license
|
|
@@ -17,13 +17,11 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
21
|
-
var credential_internal_1 = require("../app/credential-internal");
|
|
20
|
+
exports.handleCryptoSignerError = exports.FirebaseTokenGenerator = exports.EmulatedSigner = exports.BLACKLISTED_CLAIMS = void 0;
|
|
22
21
|
var error_1 = require("../utils/error");
|
|
23
|
-
var
|
|
22
|
+
var crypto_signer_1 = require("../utils/crypto-signer");
|
|
24
23
|
var validator = require("../utils/validator");
|
|
25
24
|
var utils_1 = require("../utils");
|
|
26
|
-
var ALGORITHM_RS256 = 'RS256';
|
|
27
25
|
var ALGORITHM_NONE = 'none';
|
|
28
26
|
var ONE_HOUR_IN_SECONDS = 60 * 60;
|
|
29
27
|
// List of blacklisted claims which cannot be provided when creating a custom token
|
|
@@ -33,124 +31,6 @@ exports.BLACKLISTED_CLAIMS = [
|
|
|
33
31
|
];
|
|
34
32
|
// Audience to use for Firebase Auth Custom tokens
|
|
35
33
|
var FIREBASE_AUDIENCE = 'https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit';
|
|
36
|
-
/**
|
|
37
|
-
* A CryptoSigner implementation that uses an explicitly specified service account private key to
|
|
38
|
-
* sign data. Performs all operations locally, and does not make any RPC calls.
|
|
39
|
-
*/
|
|
40
|
-
var ServiceAccountSigner = /** @class */ (function () {
|
|
41
|
-
/**
|
|
42
|
-
* Creates a new CryptoSigner instance from the given service account credential.
|
|
43
|
-
*
|
|
44
|
-
* @param {ServiceAccountCredential} credential A service account credential.
|
|
45
|
-
*/
|
|
46
|
-
function ServiceAccountSigner(credential) {
|
|
47
|
-
this.credential = credential;
|
|
48
|
-
this.algorithm = ALGORITHM_RS256;
|
|
49
|
-
if (!credential) {
|
|
50
|
-
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_CREDENTIAL, 'INTERNAL ASSERT: Must provide a service account credential to initialize ServiceAccountSigner.');
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* @inheritDoc
|
|
55
|
-
*/
|
|
56
|
-
ServiceAccountSigner.prototype.sign = function (buffer) {
|
|
57
|
-
var crypto = require('crypto'); // eslint-disable-line @typescript-eslint/no-var-requires
|
|
58
|
-
var sign = crypto.createSign('RSA-SHA256');
|
|
59
|
-
sign.update(buffer);
|
|
60
|
-
return Promise.resolve(sign.sign(this.credential.privateKey));
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* @inheritDoc
|
|
64
|
-
*/
|
|
65
|
-
ServiceAccountSigner.prototype.getAccountId = function () {
|
|
66
|
-
return Promise.resolve(this.credential.clientEmail);
|
|
67
|
-
};
|
|
68
|
-
return ServiceAccountSigner;
|
|
69
|
-
}());
|
|
70
|
-
exports.ServiceAccountSigner = ServiceAccountSigner;
|
|
71
|
-
/**
|
|
72
|
-
* A CryptoSigner implementation that uses the remote IAM service to sign data. If initialized without
|
|
73
|
-
* a service account ID, attempts to discover a service account ID by consulting the local Metadata
|
|
74
|
-
* service. This will succeed in managed environments like Google Cloud Functions and App Engine.
|
|
75
|
-
*
|
|
76
|
-
* @see https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts/signBlob
|
|
77
|
-
* @see https://cloud.google.com/compute/docs/storing-retrieving-metadata
|
|
78
|
-
*/
|
|
79
|
-
var IAMSigner = /** @class */ (function () {
|
|
80
|
-
function IAMSigner(httpClient, serviceAccountId) {
|
|
81
|
-
this.algorithm = ALGORITHM_RS256;
|
|
82
|
-
if (!httpClient) {
|
|
83
|
-
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, 'INTERNAL ASSERT: Must provide a HTTP client to initialize IAMSigner.');
|
|
84
|
-
}
|
|
85
|
-
if (typeof serviceAccountId !== 'undefined' && !validator.isNonEmptyString(serviceAccountId)) {
|
|
86
|
-
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, 'INTERNAL ASSERT: Service account ID must be undefined or a non-empty string.');
|
|
87
|
-
}
|
|
88
|
-
this.httpClient = httpClient;
|
|
89
|
-
this.serviceAccountId = serviceAccountId;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* @inheritDoc
|
|
93
|
-
*/
|
|
94
|
-
IAMSigner.prototype.sign = function (buffer) {
|
|
95
|
-
var _this = this;
|
|
96
|
-
return this.getAccountId().then(function (serviceAccount) {
|
|
97
|
-
var request = {
|
|
98
|
-
method: 'POST',
|
|
99
|
-
url: "https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/" + serviceAccount + ":signBlob",
|
|
100
|
-
data: { payload: buffer.toString('base64') },
|
|
101
|
-
};
|
|
102
|
-
return _this.httpClient.send(request);
|
|
103
|
-
}).then(function (response) {
|
|
104
|
-
// Response from IAM is base64 encoded. Decode it into a buffer and return.
|
|
105
|
-
return Buffer.from(response.data.signedBlob, 'base64');
|
|
106
|
-
}).catch(function (err) {
|
|
107
|
-
if (err instanceof api_request_1.HttpError) {
|
|
108
|
-
var error = err.response.data;
|
|
109
|
-
if (validator.isNonNullObject(error) && error.error) {
|
|
110
|
-
var errorCode = error.error.status;
|
|
111
|
-
var description = 'Please refer to https://firebase.google.com/docs/auth/admin/create-custom-tokens ' +
|
|
112
|
-
'for more details on how to use and troubleshoot this feature.';
|
|
113
|
-
var errorMsg = error.error.message + "; " + description;
|
|
114
|
-
throw error_1.FirebaseAuthError.fromServerError(errorCode, errorMsg, error);
|
|
115
|
-
}
|
|
116
|
-
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INTERNAL_ERROR, 'Error returned from server: ' + error + '. Additionally, an ' +
|
|
117
|
-
'internal error occurred while attempting to extract the ' +
|
|
118
|
-
'errorcode from the error.');
|
|
119
|
-
}
|
|
120
|
-
throw err;
|
|
121
|
-
});
|
|
122
|
-
};
|
|
123
|
-
/**
|
|
124
|
-
* @inheritDoc
|
|
125
|
-
*/
|
|
126
|
-
IAMSigner.prototype.getAccountId = function () {
|
|
127
|
-
var _this = this;
|
|
128
|
-
if (validator.isNonEmptyString(this.serviceAccountId)) {
|
|
129
|
-
return Promise.resolve(this.serviceAccountId);
|
|
130
|
-
}
|
|
131
|
-
var request = {
|
|
132
|
-
method: 'GET',
|
|
133
|
-
url: 'http://metadata/computeMetadata/v1/instance/service-accounts/default/email',
|
|
134
|
-
headers: {
|
|
135
|
-
'Metadata-Flavor': 'Google',
|
|
136
|
-
},
|
|
137
|
-
};
|
|
138
|
-
var client = new api_request_1.HttpClient();
|
|
139
|
-
return client.send(request).then(function (response) {
|
|
140
|
-
if (!response.text) {
|
|
141
|
-
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INTERNAL_ERROR, 'HTTP Response missing payload');
|
|
142
|
-
}
|
|
143
|
-
_this.serviceAccountId = response.text;
|
|
144
|
-
return response.text;
|
|
145
|
-
}).catch(function (err) {
|
|
146
|
-
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_CREDENTIAL, 'Failed to determine service account. Make sure to initialize ' +
|
|
147
|
-
'the SDK with a service account credential. Alternatively specify a service ' +
|
|
148
|
-
("account with iam.serviceAccounts.signBlob permission. Original error: " + err));
|
|
149
|
-
});
|
|
150
|
-
};
|
|
151
|
-
return IAMSigner;
|
|
152
|
-
}());
|
|
153
|
-
exports.IAMSigner = IAMSigner;
|
|
154
34
|
/**
|
|
155
35
|
* A CryptoSigner implementation that is used when communicating with the Auth emulator.
|
|
156
36
|
* It produces unsigned tokens.
|
|
@@ -175,27 +55,14 @@ var EmulatedSigner = /** @class */ (function () {
|
|
|
175
55
|
return EmulatedSigner;
|
|
176
56
|
}());
|
|
177
57
|
exports.EmulatedSigner = EmulatedSigner;
|
|
178
|
-
/**
|
|
179
|
-
* Create a new CryptoSigner instance for the given app. If the app has been initialized with a service
|
|
180
|
-
* account credential, creates a ServiceAccountSigner. Otherwise creates an IAMSigner.
|
|
181
|
-
*
|
|
182
|
-
* @param {FirebaseApp} app A FirebaseApp instance.
|
|
183
|
-
* @return {CryptoSigner} A CryptoSigner instance.
|
|
184
|
-
*/
|
|
185
|
-
function cryptoSignerFromApp(app) {
|
|
186
|
-
var credential = app.options.credential;
|
|
187
|
-
if (credential instanceof credential_internal_1.ServiceAccountCredential) {
|
|
188
|
-
return new ServiceAccountSigner(credential);
|
|
189
|
-
}
|
|
190
|
-
return new IAMSigner(new api_request_1.AuthorizedHttpClient(app), app.options.serviceAccountId);
|
|
191
|
-
}
|
|
192
|
-
exports.cryptoSignerFromApp = cryptoSignerFromApp;
|
|
193
58
|
/**
|
|
194
59
|
* Class for generating different types of Firebase Auth tokens (JWTs).
|
|
60
|
+
*
|
|
61
|
+
* @internal
|
|
195
62
|
*/
|
|
196
63
|
var FirebaseTokenGenerator = /** @class */ (function () {
|
|
197
64
|
/**
|
|
198
|
-
* @param tenantId The tenant ID to use for the generated Firebase Auth
|
|
65
|
+
* @param tenantId - The tenant ID to use for the generated Firebase Auth
|
|
199
66
|
* Custom token. If absent, then no tenant ID claim will be set in the
|
|
200
67
|
* resulting JWT.
|
|
201
68
|
*/
|
|
@@ -212,10 +79,10 @@ var FirebaseTokenGenerator = /** @class */ (function () {
|
|
|
212
79
|
/**
|
|
213
80
|
* Creates a new Firebase Auth Custom token.
|
|
214
81
|
*
|
|
215
|
-
* @param uid The user ID to use for the generated Firebase Auth Custom token.
|
|
216
|
-
* @param developerClaims Optional developer claims to include in the generated Firebase
|
|
82
|
+
* @param uid - The user ID to use for the generated Firebase Auth Custom token.
|
|
83
|
+
* @param developerClaims - Optional developer claims to include in the generated Firebase
|
|
217
84
|
* Auth Custom token.
|
|
218
|
-
* @
|
|
85
|
+
* @returns A Promise fulfilled with a Firebase Auth Custom token signed with a
|
|
219
86
|
* service account key and containing the provided payload.
|
|
220
87
|
*/
|
|
221
88
|
FirebaseTokenGenerator.prototype.createCustomToken = function (uid, developerClaims) {
|
|
@@ -260,7 +127,6 @@ var FirebaseTokenGenerator = /** @class */ (function () {
|
|
|
260
127
|
uid: uid,
|
|
261
128
|
};
|
|
262
129
|
if (_this.tenantId) {
|
|
263
|
-
// eslint-disable-next-line @typescript-eslint/camelcase
|
|
264
130
|
body.tenant_id = _this.tenantId;
|
|
265
131
|
}
|
|
266
132
|
if (Object.keys(claims).length > 0) {
|
|
@@ -272,6 +138,8 @@ var FirebaseTokenGenerator = /** @class */ (function () {
|
|
|
272
138
|
}).then(function (_a) {
|
|
273
139
|
var token = _a[0], signature = _a[1];
|
|
274
140
|
return token + "." + _this.encodeSegment(signature);
|
|
141
|
+
}).catch(function (err) {
|
|
142
|
+
throw handleCryptoSignerError(err);
|
|
275
143
|
});
|
|
276
144
|
};
|
|
277
145
|
FirebaseTokenGenerator.prototype.encodeSegment = function (segment) {
|
|
@@ -281,9 +149,10 @@ var FirebaseTokenGenerator = /** @class */ (function () {
|
|
|
281
149
|
/**
|
|
282
150
|
* Returns whether or not the provided developer claims are valid.
|
|
283
151
|
*
|
|
284
|
-
* @param
|
|
285
|
-
* @
|
|
152
|
+
* @param developerClaims - Optional developer claims to validate.
|
|
153
|
+
* @returns True if the provided claims are valid; otherwise, false.
|
|
286
154
|
*/
|
|
155
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
287
156
|
FirebaseTokenGenerator.prototype.isDeveloperClaimsValid_ = function (developerClaims) {
|
|
288
157
|
if (typeof developerClaims === 'undefined') {
|
|
289
158
|
return true;
|
|
@@ -293,3 +162,41 @@ var FirebaseTokenGenerator = /** @class */ (function () {
|
|
|
293
162
|
return FirebaseTokenGenerator;
|
|
294
163
|
}());
|
|
295
164
|
exports.FirebaseTokenGenerator = FirebaseTokenGenerator;
|
|
165
|
+
/**
|
|
166
|
+
* Creates a new FirebaseAuthError by extracting the error code, message and other relevant
|
|
167
|
+
* details from a CryptoSignerError.
|
|
168
|
+
*
|
|
169
|
+
* @param err - The Error to convert into a FirebaseAuthError error
|
|
170
|
+
* @returns A Firebase Auth error that can be returned to the user.
|
|
171
|
+
*/
|
|
172
|
+
function handleCryptoSignerError(err) {
|
|
173
|
+
if (!(err instanceof crypto_signer_1.CryptoSignerError)) {
|
|
174
|
+
return err;
|
|
175
|
+
}
|
|
176
|
+
if (err.code === crypto_signer_1.CryptoSignerErrorCode.SERVER_ERROR && validator.isNonNullObject(err.cause)) {
|
|
177
|
+
var httpError = err.cause;
|
|
178
|
+
var errorResponse = httpError.response.data;
|
|
179
|
+
if (validator.isNonNullObject(errorResponse) && errorResponse.error) {
|
|
180
|
+
var errorCode = errorResponse.error.status;
|
|
181
|
+
var description = 'Please refer to https://firebase.google.com/docs/auth/admin/create-custom-tokens ' +
|
|
182
|
+
'for more details on how to use and troubleshoot this feature.';
|
|
183
|
+
var errorMsg = errorResponse.error.message + "; " + description;
|
|
184
|
+
return error_1.FirebaseAuthError.fromServerError(errorCode, errorMsg, errorResponse);
|
|
185
|
+
}
|
|
186
|
+
return new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INTERNAL_ERROR, 'Error returned from server: ' + errorResponse + '. Additionally, an ' +
|
|
187
|
+
'internal error occurred while attempting to extract the ' +
|
|
188
|
+
'errorcode from the error.');
|
|
189
|
+
}
|
|
190
|
+
return new error_1.FirebaseAuthError(mapToAuthClientErrorCode(err.code), err.message);
|
|
191
|
+
}
|
|
192
|
+
exports.handleCryptoSignerError = handleCryptoSignerError;
|
|
193
|
+
function mapToAuthClientErrorCode(code) {
|
|
194
|
+
switch (code) {
|
|
195
|
+
case crypto_signer_1.CryptoSignerErrorCode.INVALID_CREDENTIAL:
|
|
196
|
+
return error_1.AuthClientErrorCode.INVALID_CREDENTIAL;
|
|
197
|
+
case crypto_signer_1.CryptoSignerErrorCode.INVALID_ARGUMENT:
|
|
198
|
+
return error_1.AuthClientErrorCode.INVALID_ARGUMENT;
|
|
199
|
+
default:
|
|
200
|
+
return error_1.AuthClientErrorCode.INTERNAL_ERROR;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v10.0.2 */
|
|
2
2
|
/*!
|
|
3
3
|
* Copyright 2018 Google Inc.
|
|
4
4
|
*
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
/**
|
|
18
18
|
* Interface representing a decoded Firebase ID token, returned from the
|
|
19
|
-
* {@link
|
|
19
|
+
* {@link BaseAuth.verifyIdToken} method.
|
|
20
20
|
*
|
|
21
21
|
* Firebase ID tokens are OpenID Connect spec-compliant JSON Web Tokens (JWTs).
|
|
22
22
|
* See the
|
|
@@ -78,7 +78,7 @@ export interface DecodedIdToken {
|
|
|
78
78
|
* The ID of the provider used to sign in the user.
|
|
79
79
|
* One of `"anonymous"`, `"password"`, `"facebook.com"`, `"github.com"`,
|
|
80
80
|
* `"google.com"`, `"twitter.com"`, `"apple.com"`, `"microsoft.com"`,
|
|
81
|
-
* "yahoo.com"`, `"phone"`, `"playgames.google.com"`, `"gc.apple.com"`,
|
|
81
|
+
* `"yahoo.com"`, `"phone"`, `"playgames.google.com"`, `"gc.apple.com"`,
|
|
82
82
|
* or `"custom"`.
|
|
83
83
|
*
|
|
84
84
|
* Additional Identity Platform provider IDs include `"linkedin.com"`,
|
|
@@ -148,4 +148,3 @@ export interface DecodedIdToken {
|
|
|
148
148
|
*/
|
|
149
149
|
[key: string]: any;
|
|
150
150
|
}
|
|
151
|
-
export declare const ALGORITHM_RS256 = "RS256";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v10.0.2 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* Copyright 2018 Google Inc.
|
|
@@ -16,20 +16,19 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.createSessionCookieVerifier = exports.createIdTokenVerifier = exports.FirebaseTokenVerifier = exports.SESSION_COOKIE_INFO = exports.ID_TOKEN_INFO =
|
|
19
|
+
exports.createSessionCookieVerifier = exports.createIdTokenVerifier = exports.FirebaseTokenVerifier = exports.SESSION_COOKIE_INFO = exports.ID_TOKEN_INFO = void 0;
|
|
20
20
|
var error_1 = require("../utils/error");
|
|
21
21
|
var util = require("../utils/index");
|
|
22
22
|
var validator = require("../utils/validator");
|
|
23
|
-
var
|
|
24
|
-
var api_request_1 = require("../utils/api-request");
|
|
23
|
+
var jwt_1 = require("../utils/jwt");
|
|
25
24
|
// Audience to use for Firebase Auth Custom tokens
|
|
26
25
|
var FIREBASE_AUDIENCE = 'https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit';
|
|
27
|
-
exports.ALGORITHM_RS256 = 'RS256';
|
|
28
26
|
// URL containing the public keys for the Google certs (whose private keys are used to sign Firebase
|
|
29
27
|
// Auth ID tokens)
|
|
30
28
|
var CLIENT_CERT_URL = 'https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com';
|
|
31
29
|
// URL containing the public keys for Firebase session cookies. This will be updated to a different URL soon.
|
|
32
30
|
var SESSION_COOKIE_CERT_URL = 'https://www.googleapis.com/identitytoolkit/v3/relyingparty/publicKeys';
|
|
31
|
+
var EMULATOR_VERIFIER = new jwt_1.EmulatorSignatureVerifier();
|
|
33
32
|
/**
|
|
34
33
|
* User facing token information related to the Firebase ID token.
|
|
35
34
|
*
|
|
@@ -60,18 +59,13 @@ exports.SESSION_COOKIE_INFO = {
|
|
|
60
59
|
* @internal
|
|
61
60
|
*/
|
|
62
61
|
var FirebaseTokenVerifier = /** @class */ (function () {
|
|
63
|
-
function FirebaseTokenVerifier(clientCertUrl,
|
|
64
|
-
this.clientCertUrl = clientCertUrl;
|
|
65
|
-
this.algorithm = algorithm;
|
|
62
|
+
function FirebaseTokenVerifier(clientCertUrl, issuer, tokenInfo, app) {
|
|
66
63
|
this.issuer = issuer;
|
|
67
64
|
this.tokenInfo = tokenInfo;
|
|
68
65
|
this.app = app;
|
|
69
66
|
if (!validator.isURL(clientCertUrl)) {
|
|
70
67
|
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, 'The provided public client certificate URL is an invalid URL.');
|
|
71
68
|
}
|
|
72
|
-
else if (!validator.isNonEmptyString(algorithm)) {
|
|
73
|
-
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, 'The provided JWT algorithm is an empty string.');
|
|
74
|
-
}
|
|
75
69
|
else if (!validator.isURL(issuer)) {
|
|
76
70
|
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, 'The provided JWT issuer is an invalid URL.');
|
|
77
71
|
}
|
|
@@ -94,41 +88,76 @@ var FirebaseTokenVerifier = /** @class */ (function () {
|
|
|
94
88
|
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, 'The JWT expiration error code must be a non-null ErrorInfo object.');
|
|
95
89
|
}
|
|
96
90
|
this.shortNameArticle = tokenInfo.shortName.charAt(0).match(/[aeiou]/i) ? 'an' : 'a';
|
|
91
|
+
this.signatureVerifier =
|
|
92
|
+
jwt_1.PublicKeySignatureVerifier.withCertificateUrl(clientCertUrl, app.options.httpAgent);
|
|
97
93
|
// For backward compatibility, the project ID is validated in the verification call.
|
|
98
94
|
}
|
|
99
95
|
/**
|
|
100
96
|
* Verifies the format and signature of a Firebase Auth JWT token.
|
|
101
97
|
*
|
|
102
|
-
* @param
|
|
103
|
-
* @
|
|
104
|
-
*
|
|
98
|
+
* @param jwtToken - The Firebase Auth JWT token to verify.
|
|
99
|
+
* @param isEmulator - Whether to accept Auth Emulator tokens.
|
|
100
|
+
* @returns A promise fulfilled with the decoded claims of the Firebase Auth ID token.
|
|
105
101
|
*/
|
|
106
|
-
FirebaseTokenVerifier.prototype.verifyJWT = function (jwtToken) {
|
|
102
|
+
FirebaseTokenVerifier.prototype.verifyJWT = function (jwtToken, isEmulator) {
|
|
107
103
|
var _this = this;
|
|
104
|
+
if (isEmulator === void 0) { isEmulator = false; }
|
|
108
105
|
if (!validator.isString(jwtToken)) {
|
|
109
106
|
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, "First argument to " + this.tokenInfo.verifyApiName + " must be a " + this.tokenInfo.jwtName + " string.");
|
|
110
107
|
}
|
|
108
|
+
return this.ensureProjectId()
|
|
109
|
+
.then(function (projectId) {
|
|
110
|
+
return _this.decodeAndVerify(jwtToken, projectId, isEmulator);
|
|
111
|
+
})
|
|
112
|
+
.then(function (decoded) {
|
|
113
|
+
var decodedIdToken = decoded.payload;
|
|
114
|
+
decodedIdToken.uid = decodedIdToken.sub;
|
|
115
|
+
return decodedIdToken;
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
FirebaseTokenVerifier.prototype.ensureProjectId = function () {
|
|
119
|
+
var _this = this;
|
|
111
120
|
return util.findProjectId(this.app)
|
|
112
121
|
.then(function (projectId) {
|
|
113
|
-
|
|
122
|
+
if (!validator.isNonEmptyString(projectId)) {
|
|
123
|
+
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_CREDENTIAL, 'Must initialize app with a cert credential or set your Firebase project ID as the ' +
|
|
124
|
+
("GOOGLE_CLOUD_PROJECT environment variable to call " + _this.tokenInfo.verifyApiName + "."));
|
|
125
|
+
}
|
|
126
|
+
return Promise.resolve(projectId);
|
|
114
127
|
});
|
|
115
128
|
};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
129
|
+
FirebaseTokenVerifier.prototype.decodeAndVerify = function (token, projectId, isEmulator) {
|
|
130
|
+
var _this = this;
|
|
131
|
+
return this.safeDecode(token)
|
|
132
|
+
.then(function (decodedToken) {
|
|
133
|
+
_this.verifyContent(decodedToken, projectId, isEmulator);
|
|
134
|
+
return _this.verifySignature(token, isEmulator)
|
|
135
|
+
.then(function () { return decodedToken; });
|
|
136
|
+
});
|
|
122
137
|
};
|
|
123
|
-
FirebaseTokenVerifier.prototype.
|
|
138
|
+
FirebaseTokenVerifier.prototype.safeDecode = function (jwtToken) {
|
|
124
139
|
var _this = this;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
140
|
+
return jwt_1.decodeJwt(jwtToken)
|
|
141
|
+
.catch(function (err) {
|
|
142
|
+
if (err.code == jwt_1.JwtErrorCode.INVALID_ARGUMENT) {
|
|
143
|
+
var verifyJwtTokenDocsMessage = " See " + _this.tokenInfo.url + " " +
|
|
144
|
+
("for details on how to retrieve " + _this.shortNameArticle + " " + _this.tokenInfo.shortName + ".");
|
|
145
|
+
var errorMessage = "Decoding " + _this.tokenInfo.jwtName + " failed. Make sure you passed " +
|
|
146
|
+
("the entire string JWT which represents " + _this.shortNameArticle + " ") +
|
|
147
|
+
(_this.tokenInfo.shortName + ".") + verifyJwtTokenDocsMessage;
|
|
148
|
+
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, errorMessage);
|
|
149
|
+
}
|
|
150
|
+
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INTERNAL_ERROR, err.message);
|
|
131
151
|
});
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Verifies the content of a Firebase Auth JWT.
|
|
155
|
+
*
|
|
156
|
+
* @param fullDecodedToken - The decoded JWT.
|
|
157
|
+
* @param projectId - The Firebase Project Id.
|
|
158
|
+
* @param isEmulator - Whether the token is an Emulator token.
|
|
159
|
+
*/
|
|
160
|
+
FirebaseTokenVerifier.prototype.verifyContent = function (fullDecodedToken, projectId, isEmulator) {
|
|
132
161
|
var header = fullDecodedToken && fullDecodedToken.header;
|
|
133
162
|
var payload = fullDecodedToken && fullDecodedToken.payload;
|
|
134
163
|
var projectIdMatchMessage = " Make sure the " + this.tokenInfo.shortName + " comes from the same " +
|
|
@@ -136,11 +165,7 @@ var FirebaseTokenVerifier = /** @class */ (function () {
|
|
|
136
165
|
var verifyJwtTokenDocsMessage = " See " + this.tokenInfo.url + " " +
|
|
137
166
|
("for details on how to retrieve " + this.shortNameArticle + " " + this.tokenInfo.shortName + ".");
|
|
138
167
|
var errorMessage;
|
|
139
|
-
if (!
|
|
140
|
-
errorMessage = "Decoding " + this.tokenInfo.jwtName + " failed. Make sure you passed the entire string JWT " +
|
|
141
|
-
("which represents " + this.shortNameArticle + " " + this.tokenInfo.shortName + ".") + verifyJwtTokenDocsMessage;
|
|
142
|
-
}
|
|
143
|
-
else if (typeof header.kid === 'undefined' && this.algorithm !== 'none') {
|
|
168
|
+
if (!isEmulator && typeof header.kid === 'undefined') {
|
|
144
169
|
var isCustomToken = (payload.aud === FIREBASE_AUDIENCE);
|
|
145
170
|
var isLegacyCustomToken = (header.alg === 'HS256' && payload.v === 0 && 'd' in payload && 'uid' in payload.d);
|
|
146
171
|
if (isCustomToken) {
|
|
@@ -156,8 +181,8 @@ var FirebaseTokenVerifier = /** @class */ (function () {
|
|
|
156
181
|
}
|
|
157
182
|
errorMessage += verifyJwtTokenDocsMessage;
|
|
158
183
|
}
|
|
159
|
-
else if (header.alg !==
|
|
160
|
-
errorMessage = this.tokenInfo.jwtName + " has incorrect algorithm. Expected \"" +
|
|
184
|
+
else if (!isEmulator && header.alg !== jwt_1.ALGORITHM_RS256) {
|
|
185
|
+
errorMessage = this.tokenInfo.jwtName + " has incorrect algorithm. Expected \"" + jwt_1.ALGORITHM_RS256 + '" but got ' +
|
|
161
186
|
'"' + header.alg + '".' + verifyJwtTokenDocsMessage;
|
|
162
187
|
}
|
|
163
188
|
else if (payload.aud !== projectId) {
|
|
@@ -167,7 +192,7 @@ var FirebaseTokenVerifier = /** @class */ (function () {
|
|
|
167
192
|
}
|
|
168
193
|
else if (payload.iss !== this.issuer + projectId) {
|
|
169
194
|
errorMessage = this.tokenInfo.jwtName + " has incorrect \"iss\" (issuer) claim. Expected " +
|
|
170
|
-
("\"" + this.issuer
|
|
195
|
+
("\"" + this.issuer) + projectId + '" but got "' +
|
|
171
196
|
payload.iss + '".' + projectIdMatchMessage + verifyJwtTokenDocsMessage;
|
|
172
197
|
}
|
|
173
198
|
else if (typeof payload.sub !== 'string') {
|
|
@@ -181,115 +206,43 @@ var FirebaseTokenVerifier = /** @class */ (function () {
|
|
|
181
206
|
verifyJwtTokenDocsMessage;
|
|
182
207
|
}
|
|
183
208
|
if (errorMessage) {
|
|
184
|
-
|
|
209
|
+
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, errorMessage);
|
|
185
210
|
}
|
|
186
|
-
// When the algorithm is set to 'none' there will be no signature and therefore we don't check
|
|
187
|
-
// the public keys.
|
|
188
|
-
if (this.algorithm === 'none') {
|
|
189
|
-
return this.verifyJwtSignatureWithKey(jwtToken, null);
|
|
190
|
-
}
|
|
191
|
-
return this.fetchPublicKeys().then(function (publicKeys) {
|
|
192
|
-
if (!Object.prototype.hasOwnProperty.call(publicKeys, header.kid)) {
|
|
193
|
-
return Promise.reject(new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, _this.tokenInfo.jwtName + " has \"kid\" claim which does not correspond to a known public key. " +
|
|
194
|
-
("Most likely the " + _this.tokenInfo.shortName + " is expired, so get a fresh token from your ") +
|
|
195
|
-
'client app and try again.'));
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
return _this.verifyJwtSignatureWithKey(jwtToken, publicKeys[header.kid]);
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
211
|
};
|
|
202
|
-
|
|
203
|
-
* Verifies the JWT signature using the provided public key.
|
|
204
|
-
* @param {string} jwtToken The JWT token to verify.
|
|
205
|
-
* @param {string} publicKey The public key certificate.
|
|
206
|
-
* @return {Promise<DecodedIdToken>} A promise that resolves with the decoded JWT claims on successful
|
|
207
|
-
* verification.
|
|
208
|
-
*/
|
|
209
|
-
FirebaseTokenVerifier.prototype.verifyJwtSignatureWithKey = function (jwtToken, publicKey) {
|
|
212
|
+
FirebaseTokenVerifier.prototype.verifySignature = function (jwtToken, isEmulator) {
|
|
210
213
|
var _this = this;
|
|
211
|
-
var
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
algorithms: [_this.algorithm],
|
|
216
|
-
}, function (error, decodedToken) {
|
|
217
|
-
if (error) {
|
|
218
|
-
if (error.name === 'TokenExpiredError') {
|
|
219
|
-
var errorMessage = _this.tokenInfo.jwtName + " has expired. Get a fresh " + _this.tokenInfo.shortName +
|
|
220
|
-
(" from your client app and try again (auth/" + _this.tokenInfo.expiredErrorCode.code + ").") +
|
|
221
|
-
verifyJwtTokenDocsMessage;
|
|
222
|
-
return reject(new error_1.FirebaseAuthError(_this.tokenInfo.expiredErrorCode, errorMessage));
|
|
223
|
-
}
|
|
224
|
-
else if (error.name === 'JsonWebTokenError') {
|
|
225
|
-
var errorMessage = _this.tokenInfo.jwtName + " has invalid signature." + verifyJwtTokenDocsMessage;
|
|
226
|
-
return reject(new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, errorMessage));
|
|
227
|
-
}
|
|
228
|
-
return reject(new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, error.message));
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
var decodedIdToken = decodedToken;
|
|
232
|
-
decodedIdToken.uid = decodedIdToken.sub;
|
|
233
|
-
resolve(decodedIdToken);
|
|
234
|
-
}
|
|
235
|
-
});
|
|
214
|
+
var verifier = isEmulator ? EMULATOR_VERIFIER : this.signatureVerifier;
|
|
215
|
+
return verifier.verify(jwtToken)
|
|
216
|
+
.catch(function (error) {
|
|
217
|
+
throw _this.mapJwtErrorToAuthError(error);
|
|
236
218
|
});
|
|
237
219
|
};
|
|
238
220
|
/**
|
|
239
|
-
*
|
|
221
|
+
* Maps JwtError to FirebaseAuthError
|
|
240
222
|
*
|
|
241
|
-
* @
|
|
223
|
+
* @param error - JwtError to be mapped.
|
|
224
|
+
* @returns FirebaseAuthError or Error instance.
|
|
242
225
|
*/
|
|
243
|
-
FirebaseTokenVerifier.prototype.
|
|
244
|
-
var
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
226
|
+
FirebaseTokenVerifier.prototype.mapJwtErrorToAuthError = function (error) {
|
|
227
|
+
var verifyJwtTokenDocsMessage = " See " + this.tokenInfo.url + " " +
|
|
228
|
+
("for details on how to retrieve " + this.shortNameArticle + " " + this.tokenInfo.shortName + ".");
|
|
229
|
+
if (error.code === jwt_1.JwtErrorCode.TOKEN_EXPIRED) {
|
|
230
|
+
var errorMessage = this.tokenInfo.jwtName + " has expired. Get a fresh " + this.tokenInfo.shortName +
|
|
231
|
+
(" from your client app and try again (auth/" + this.tokenInfo.expiredErrorCode.code + ").") +
|
|
232
|
+
verifyJwtTokenDocsMessage;
|
|
233
|
+
return new error_1.FirebaseAuthError(this.tokenInfo.expiredErrorCode, errorMessage);
|
|
250
234
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
if (Object.prototype.hasOwnProperty.call(resp.headers, 'cache-control')) {
|
|
264
|
-
var cacheControlHeader = resp.headers['cache-control'];
|
|
265
|
-
var parts = cacheControlHeader.split(',');
|
|
266
|
-
parts.forEach(function (part) {
|
|
267
|
-
var subParts = part.trim().split('=');
|
|
268
|
-
if (subParts[0] === 'max-age') {
|
|
269
|
-
var maxAge = +subParts[1];
|
|
270
|
-
_this.publicKeysExpireAt = Date.now() + (maxAge * 1000);
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
_this.publicKeys = resp.data;
|
|
275
|
-
return resp.data;
|
|
276
|
-
}).catch(function (err) {
|
|
277
|
-
if (err instanceof api_request_1.HttpError) {
|
|
278
|
-
var errorMessage = 'Error fetching public keys for Google certs: ';
|
|
279
|
-
var resp = err.response;
|
|
280
|
-
if (resp.isJson() && resp.data.error) {
|
|
281
|
-
errorMessage += "" + resp.data.error;
|
|
282
|
-
if (resp.data.error_description) {
|
|
283
|
-
errorMessage += ' (' + resp.data.error_description + ')';
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
else {
|
|
287
|
-
errorMessage += "" + resp.text;
|
|
288
|
-
}
|
|
289
|
-
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INTERNAL_ERROR, errorMessage);
|
|
290
|
-
}
|
|
291
|
-
throw err;
|
|
292
|
-
});
|
|
235
|
+
else if (error.code === jwt_1.JwtErrorCode.INVALID_SIGNATURE) {
|
|
236
|
+
var errorMessage = this.tokenInfo.jwtName + " has invalid signature." + verifyJwtTokenDocsMessage;
|
|
237
|
+
return new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, errorMessage);
|
|
238
|
+
}
|
|
239
|
+
else if (error.code === jwt_1.JwtErrorCode.NO_MATCHING_KID) {
|
|
240
|
+
var errorMessage = this.tokenInfo.jwtName + " has \"kid\" claim which does not " +
|
|
241
|
+
("correspond to a known public key. Most likely the " + this.tokenInfo.shortName + " ") +
|
|
242
|
+
'is expired, so get a fresh token from your client app and try again.';
|
|
243
|
+
return new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, errorMessage);
|
|
244
|
+
}
|
|
245
|
+
return new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, error.message);
|
|
293
246
|
};
|
|
294
247
|
return FirebaseTokenVerifier;
|
|
295
248
|
}());
|
|
@@ -297,24 +250,22 @@ exports.FirebaseTokenVerifier = FirebaseTokenVerifier;
|
|
|
297
250
|
/**
|
|
298
251
|
* Creates a new FirebaseTokenVerifier to verify Firebase ID tokens.
|
|
299
252
|
*
|
|
300
|
-
* @param {FirebaseApp} app Firebase app instance.
|
|
301
|
-
* @return {FirebaseTokenVerifier}
|
|
302
|
-
*
|
|
303
253
|
* @internal
|
|
254
|
+
* @param app - Firebase app instance.
|
|
255
|
+
* @returns FirebaseTokenVerifier
|
|
304
256
|
*/
|
|
305
257
|
function createIdTokenVerifier(app) {
|
|
306
|
-
return new FirebaseTokenVerifier(CLIENT_CERT_URL,
|
|
258
|
+
return new FirebaseTokenVerifier(CLIENT_CERT_URL, 'https://securetoken.google.com/', exports.ID_TOKEN_INFO, app);
|
|
307
259
|
}
|
|
308
260
|
exports.createIdTokenVerifier = createIdTokenVerifier;
|
|
309
261
|
/**
|
|
310
262
|
* Creates a new FirebaseTokenVerifier to verify Firebase session cookies.
|
|
311
263
|
*
|
|
312
|
-
* @param {FirebaseApp} app Firebase app instance.
|
|
313
|
-
* @return {FirebaseTokenVerifier}
|
|
314
|
-
*
|
|
315
264
|
* @internal
|
|
265
|
+
* @param app - Firebase app instance.
|
|
266
|
+
* @returns FirebaseTokenVerifier
|
|
316
267
|
*/
|
|
317
268
|
function createSessionCookieVerifier(app) {
|
|
318
|
-
return new FirebaseTokenVerifier(SESSION_COOKIE_CERT_URL,
|
|
269
|
+
return new FirebaseTokenVerifier(SESSION_COOKIE_CERT_URL, 'https://session.firebase.google.com/', exports.SESSION_COOKIE_INFO, app);
|
|
319
270
|
}
|
|
320
271
|
exports.createSessionCookieVerifier = createSessionCookieVerifier;
|