firebase-admin 10.3.0 → 11.0.0
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 -2
- 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 +1 -1
- package/lib/app/credential-internal.js +97 -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 +61 -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 +1 -1
- package/lib/functions/functions-api-client-internal.js +71 -93
- 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 +1 -1
- package/lib/security-rules/security-rules-api-client-internal.js +95 -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 +82 -91
- 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 +5 -5
package/lib/auth/identifier.d.ts
CHANGED
package/lib/auth/identifier.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.0 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* Copyright 2020 Google Inc.
|
|
@@ -34,7 +34,7 @@ function isPhoneIdentifier(id) {
|
|
|
34
34
|
}
|
|
35
35
|
exports.isPhoneIdentifier = isPhoneIdentifier;
|
|
36
36
|
function isProviderIdentifier(id) {
|
|
37
|
-
|
|
37
|
+
const pid = id;
|
|
38
38
|
return pid.providerId !== undefined && pid.providerUid !== undefined;
|
|
39
39
|
}
|
|
40
40
|
exports.isProviderIdentifier = isProviderIdentifier;
|
package/lib/auth/index.d.ts
CHANGED
package/lib/auth/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.0 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* Copyright 2020 Google Inc.
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.getAuth = void 0;
|
|
19
|
+
exports.UserRecord = exports.UserMetadata = exports.UserInfo = exports.PhoneMultiFactorInfo = exports.MultiFactorSettings = exports.MultiFactorInfo = exports.TenantManager = exports.TenantAwareAuth = exports.Tenant = exports.BaseAuth = exports.Auth = exports.getAuth = void 0;
|
|
20
20
|
/**
|
|
21
21
|
* Firebase Authentication.
|
|
22
22
|
*
|
|
23
23
|
* @packageDocumentation
|
|
24
24
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const index_1 = require("../app/index");
|
|
26
|
+
const auth_1 = require("./auth");
|
|
27
27
|
/**
|
|
28
28
|
* Gets the {@link Auth} service for the default app or a
|
|
29
29
|
* given app.
|
|
@@ -47,10 +47,10 @@ var auth_1 = require("./auth");
|
|
|
47
47
|
*/
|
|
48
48
|
function getAuth(app) {
|
|
49
49
|
if (typeof app === 'undefined') {
|
|
50
|
-
app = index_1.getApp();
|
|
50
|
+
app = (0, index_1.getApp)();
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
return firebaseApp.getOrInitService('auth',
|
|
52
|
+
const firebaseApp = app;
|
|
53
|
+
return firebaseApp.getOrInitService('auth', (app) => new auth_1.Auth(app));
|
|
54
54
|
}
|
|
55
55
|
exports.getAuth = getAuth;
|
|
56
56
|
var auth_2 = require("./auth");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.0 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* Copyright 2019 Google Inc.
|
|
@@ -15,27 +15,14 @@
|
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
|
-
var __extends = (this && this.__extends) || (function () {
|
|
19
|
-
var extendStatics = function (d, b) {
|
|
20
|
-
extendStatics = Object.setPrototypeOf ||
|
|
21
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
22
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
23
|
-
return extendStatics(d, b);
|
|
24
|
-
};
|
|
25
|
-
return function (d, b) {
|
|
26
|
-
extendStatics(d, b);
|
|
27
|
-
function __() { this.constructor = d; }
|
|
28
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
29
|
-
};
|
|
30
|
-
})();
|
|
31
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
19
|
exports.TenantManager = exports.TenantAwareAuth = void 0;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
20
|
+
const validator = require("../utils/validator");
|
|
21
|
+
const utils = require("../utils/index");
|
|
22
|
+
const error_1 = require("../utils/error");
|
|
23
|
+
const base_auth_1 = require("./base-auth");
|
|
24
|
+
const tenant_1 = require("./tenant");
|
|
25
|
+
const auth_api_request_1 = require("./auth-api-request");
|
|
39
26
|
/**
|
|
40
27
|
* Tenant-aware `Auth` interface used for managing users, configuring SAML/OIDC providers,
|
|
41
28
|
* generating email links for password reset, email verification, etc for specific tenants.
|
|
@@ -53,8 +40,7 @@ var auth_api_request_1 = require("./auth-api-request");
|
|
|
53
40
|
* `TenantAwareAuth` instances for a specific `tenantId` can be instantiated by calling
|
|
54
41
|
* {@link TenantManager.authForTenant}.
|
|
55
42
|
*/
|
|
56
|
-
|
|
57
|
-
__extends(TenantAwareAuth, _super);
|
|
43
|
+
class TenantAwareAuth extends base_auth_1.BaseAuth {
|
|
58
44
|
/**
|
|
59
45
|
* The TenantAwareAuth class constructor.
|
|
60
46
|
*
|
|
@@ -63,31 +49,27 @@ var TenantAwareAuth = /** @class */ (function (_super) {
|
|
|
63
49
|
* @constructor
|
|
64
50
|
* @internal
|
|
65
51
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
utils.addReadonlyGetter(
|
|
69
|
-
return _this;
|
|
52
|
+
constructor(app, tenantId) {
|
|
53
|
+
super(app, new auth_api_request_1.TenantAwareAuthRequestHandler(app, tenantId), (0, base_auth_1.createFirebaseTokenGenerator)(app, tenantId));
|
|
54
|
+
utils.addReadonlyGetter(this, 'tenantId', tenantId);
|
|
70
55
|
}
|
|
71
56
|
/**
|
|
72
57
|
* {@inheritdoc BaseAuth.verifyIdToken}
|
|
73
58
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return _super.prototype.verifyIdToken.call(this, idToken, checkRevoked)
|
|
78
|
-
.then(function (decodedClaims) {
|
|
59
|
+
verifyIdToken(idToken, checkRevoked = false) {
|
|
60
|
+
return super.verifyIdToken(idToken, checkRevoked)
|
|
61
|
+
.then((decodedClaims) => {
|
|
79
62
|
// Validate tenant ID.
|
|
80
|
-
if (decodedClaims.firebase.tenant !==
|
|
63
|
+
if (decodedClaims.firebase.tenant !== this.tenantId) {
|
|
81
64
|
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.MISMATCHING_TENANT_ID);
|
|
82
65
|
}
|
|
83
66
|
return decodedClaims;
|
|
84
67
|
});
|
|
85
|
-
}
|
|
68
|
+
}
|
|
86
69
|
/**
|
|
87
70
|
* {@inheritdoc BaseAuth.createSessionCookie}
|
|
88
71
|
*/
|
|
89
|
-
|
|
90
|
-
var _this = this;
|
|
72
|
+
createSessionCookie(idToken, sessionCookieOptions) {
|
|
91
73
|
// Validate arguments before processing.
|
|
92
74
|
if (!validator.isNonEmptyString(idToken)) {
|
|
93
75
|
return Promise.reject(new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ID_TOKEN));
|
|
@@ -98,26 +80,23 @@ var TenantAwareAuth = /** @class */ (function (_super) {
|
|
|
98
80
|
}
|
|
99
81
|
// This will verify the ID token and then match the tenant ID before creating the session cookie.
|
|
100
82
|
return this.verifyIdToken(idToken)
|
|
101
|
-
.then(
|
|
102
|
-
return
|
|
83
|
+
.then(() => {
|
|
84
|
+
return super.createSessionCookie(idToken, sessionCookieOptions);
|
|
103
85
|
});
|
|
104
|
-
}
|
|
86
|
+
}
|
|
105
87
|
/**
|
|
106
88
|
* {@inheritdoc BaseAuth.verifySessionCookie}
|
|
107
89
|
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
.then(function (decodedClaims) {
|
|
113
|
-
if (decodedClaims.firebase.tenant !== _this.tenantId) {
|
|
90
|
+
verifySessionCookie(sessionCookie, checkRevoked = false) {
|
|
91
|
+
return super.verifySessionCookie(sessionCookie, checkRevoked)
|
|
92
|
+
.then((decodedClaims) => {
|
|
93
|
+
if (decodedClaims.firebase.tenant !== this.tenantId) {
|
|
114
94
|
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.MISMATCHING_TENANT_ID);
|
|
115
95
|
}
|
|
116
96
|
return decodedClaims;
|
|
117
97
|
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
}(base_auth_1.BaseAuth));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
121
100
|
exports.TenantAwareAuth = TenantAwareAuth;
|
|
122
101
|
/**
|
|
123
102
|
* Defines the tenant manager used to help manage tenant related operations.
|
|
@@ -130,7 +109,7 @@ exports.TenantAwareAuth = TenantAwareAuth;
|
|
|
130
109
|
* email link generation, etc) in the context of a specified tenant.</li>
|
|
131
110
|
* </ul>
|
|
132
111
|
*/
|
|
133
|
-
|
|
112
|
+
class TenantManager {
|
|
134
113
|
/**
|
|
135
114
|
* Initializes a TenantManager instance for a specified FirebaseApp.
|
|
136
115
|
*
|
|
@@ -139,7 +118,7 @@ var TenantManager = /** @class */ (function () {
|
|
|
139
118
|
* @constructor
|
|
140
119
|
* @internal
|
|
141
120
|
*/
|
|
142
|
-
|
|
121
|
+
constructor(app) {
|
|
143
122
|
this.app = app;
|
|
144
123
|
this.authRequestHandler = new auth_api_request_1.AuthRequestHandler(app);
|
|
145
124
|
this.tenantsMap = {};
|
|
@@ -151,7 +130,7 @@ var TenantManager = /** @class */ (function () {
|
|
|
151
130
|
*
|
|
152
131
|
* @returns The `TenantAwareAuth` instance corresponding to this tenant identifier.
|
|
153
132
|
*/
|
|
154
|
-
|
|
133
|
+
authForTenant(tenantId) {
|
|
155
134
|
if (!validator.isNonEmptyString(tenantId)) {
|
|
156
135
|
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_TENANT_ID);
|
|
157
136
|
}
|
|
@@ -159,7 +138,7 @@ var TenantManager = /** @class */ (function () {
|
|
|
159
138
|
this.tenantsMap[tenantId] = new TenantAwareAuth(this.app, tenantId);
|
|
160
139
|
}
|
|
161
140
|
return this.tenantsMap[tenantId];
|
|
162
|
-
}
|
|
141
|
+
}
|
|
163
142
|
/**
|
|
164
143
|
* Gets the tenant configuration for the tenant corresponding to a given `tenantId`.
|
|
165
144
|
*
|
|
@@ -167,12 +146,12 @@ var TenantManager = /** @class */ (function () {
|
|
|
167
146
|
*
|
|
168
147
|
* @returns A promise fulfilled with the tenant configuration to the provided `tenantId`.
|
|
169
148
|
*/
|
|
170
|
-
|
|
149
|
+
getTenant(tenantId) {
|
|
171
150
|
return this.authRequestHandler.getTenant(tenantId)
|
|
172
|
-
.then(
|
|
151
|
+
.then((response) => {
|
|
173
152
|
return new tenant_1.Tenant(response);
|
|
174
153
|
});
|
|
175
|
-
}
|
|
154
|
+
}
|
|
176
155
|
/**
|
|
177
156
|
* Retrieves a list of tenants (single batch only) with a size of `maxResults`
|
|
178
157
|
* starting from the offset as specified by `pageToken`. This is used to
|
|
@@ -186,18 +165,18 @@ var TenantManager = /** @class */ (function () {
|
|
|
186
165
|
* @returns A promise that resolves with
|
|
187
166
|
* a batch of downloaded tenants and the next page token.
|
|
188
167
|
*/
|
|
189
|
-
|
|
168
|
+
listTenants(maxResults, pageToken) {
|
|
190
169
|
return this.authRequestHandler.listTenants(maxResults, pageToken)
|
|
191
|
-
.then(
|
|
170
|
+
.then((response) => {
|
|
192
171
|
// List of tenants to return.
|
|
193
|
-
|
|
172
|
+
const tenants = [];
|
|
194
173
|
// Convert each user response to a Tenant.
|
|
195
|
-
response.tenants.forEach(
|
|
174
|
+
response.tenants.forEach((tenantResponse) => {
|
|
196
175
|
tenants.push(new tenant_1.Tenant(tenantResponse));
|
|
197
176
|
});
|
|
198
177
|
// Return list of tenants and the next page token if available.
|
|
199
|
-
|
|
200
|
-
tenants
|
|
178
|
+
const result = {
|
|
179
|
+
tenants,
|
|
201
180
|
pageToken: response.nextPageToken,
|
|
202
181
|
};
|
|
203
182
|
// Delete result.pageToken if undefined.
|
|
@@ -206,7 +185,7 @@ var TenantManager = /** @class */ (function () {
|
|
|
206
185
|
}
|
|
207
186
|
return result;
|
|
208
187
|
});
|
|
209
|
-
}
|
|
188
|
+
}
|
|
210
189
|
/**
|
|
211
190
|
* Deletes an existing tenant.
|
|
212
191
|
*
|
|
@@ -214,9 +193,9 @@ var TenantManager = /** @class */ (function () {
|
|
|
214
193
|
*
|
|
215
194
|
* @returns An empty promise fulfilled once the tenant has been deleted.
|
|
216
195
|
*/
|
|
217
|
-
|
|
196
|
+
deleteTenant(tenantId) {
|
|
218
197
|
return this.authRequestHandler.deleteTenant(tenantId);
|
|
219
|
-
}
|
|
198
|
+
}
|
|
220
199
|
/**
|
|
221
200
|
* Creates a new tenant.
|
|
222
201
|
* When creating new tenants, tenants that use separate billing and quota will require their
|
|
@@ -227,12 +206,12 @@ var TenantManager = /** @class */ (function () {
|
|
|
227
206
|
* @returns A promise fulfilled with the tenant configuration corresponding to the newly
|
|
228
207
|
* created tenant.
|
|
229
208
|
*/
|
|
230
|
-
|
|
209
|
+
createTenant(tenantOptions) {
|
|
231
210
|
return this.authRequestHandler.createTenant(tenantOptions)
|
|
232
|
-
.then(
|
|
211
|
+
.then((response) => {
|
|
233
212
|
return new tenant_1.Tenant(response);
|
|
234
213
|
});
|
|
235
|
-
}
|
|
214
|
+
}
|
|
236
215
|
/**
|
|
237
216
|
* Updates an existing tenant configuration.
|
|
238
217
|
*
|
|
@@ -241,12 +220,11 @@ var TenantManager = /** @class */ (function () {
|
|
|
241
220
|
*
|
|
242
221
|
* @returns A promise fulfilled with the update tenant data.
|
|
243
222
|
*/
|
|
244
|
-
|
|
223
|
+
updateTenant(tenantId, tenantOptions) {
|
|
245
224
|
return this.authRequestHandler.updateTenant(tenantId, tenantOptions)
|
|
246
|
-
.then(
|
|
225
|
+
.then((response) => {
|
|
247
226
|
return new tenant_1.Tenant(response);
|
|
248
227
|
});
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
}());
|
|
228
|
+
}
|
|
229
|
+
}
|
|
252
230
|
exports.TenantManager = TenantManager;
|
package/lib/auth/tenant.d.ts
CHANGED
package/lib/auth/tenant.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.0 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* Copyright 2019 Google Inc.
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.Tenant = void 0;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
const validator = require("../utils/validator");
|
|
21
|
+
const deep_copy_1 = require("../utils/deep-copy");
|
|
22
|
+
const error_1 = require("../utils/error");
|
|
23
|
+
const auth_config_1 = require("./auth-config");
|
|
24
24
|
/**
|
|
25
25
|
* Represents a tenant configuration.
|
|
26
26
|
*
|
|
@@ -41,7 +41,7 @@ var auth_config_1 = require("./auth-config");
|
|
|
41
41
|
* All other settings of a tenant will also be inherited. These will need to be managed
|
|
42
42
|
* from the Cloud Console UI.
|
|
43
43
|
*/
|
|
44
|
-
|
|
44
|
+
class Tenant {
|
|
45
45
|
/**
|
|
46
46
|
* The Tenant object constructor.
|
|
47
47
|
*
|
|
@@ -49,8 +49,8 @@ var Tenant = /** @class */ (function () {
|
|
|
49
49
|
* @constructor
|
|
50
50
|
* @internal
|
|
51
51
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
constructor(response) {
|
|
53
|
+
const tenantId = Tenant.getTenantIdFromResourceName(response.name);
|
|
54
54
|
if (!tenantId) {
|
|
55
55
|
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INTERNAL_ERROR, 'INTERNAL ASSERT FAILED: Invalid tenant response');
|
|
56
56
|
}
|
|
@@ -70,7 +70,7 @@ var Tenant = /** @class */ (function () {
|
|
|
70
70
|
this.multiFactorConfig_ = new auth_config_1.MultiFactorAuthConfig(response.mfaConfig);
|
|
71
71
|
}
|
|
72
72
|
if (typeof response.testPhoneNumbers !== 'undefined') {
|
|
73
|
-
this.testPhoneNumbers = deep_copy_1.deepCopy(response.testPhoneNumbers || {});
|
|
73
|
+
this.testPhoneNumbers = (0, deep_copy_1.deepCopy)(response.testPhoneNumbers || {});
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
@@ -82,10 +82,9 @@ var Tenant = /** @class */ (function () {
|
|
|
82
82
|
*
|
|
83
83
|
* @internal
|
|
84
84
|
*/
|
|
85
|
-
|
|
86
|
-
var _a;
|
|
85
|
+
static buildServerRequest(tenantOptions, createRequest) {
|
|
87
86
|
Tenant.validate(tenantOptions, createRequest);
|
|
88
|
-
|
|
87
|
+
let request = {};
|
|
89
88
|
if (typeof tenantOptions.emailSignInConfig !== 'undefined') {
|
|
90
89
|
request = auth_config_1.EmailSignInConfig.buildServerRequest(tenantOptions.emailSignInConfig);
|
|
91
90
|
}
|
|
@@ -100,10 +99,10 @@ var Tenant = /** @class */ (function () {
|
|
|
100
99
|
}
|
|
101
100
|
if (typeof tenantOptions.testPhoneNumbers !== 'undefined') {
|
|
102
101
|
// null will clear existing test phone numbers. Translate to empty object.
|
|
103
|
-
request.testPhoneNumbers =
|
|
102
|
+
request.testPhoneNumbers = tenantOptions.testPhoneNumbers ?? {};
|
|
104
103
|
}
|
|
105
104
|
return request;
|
|
106
|
-
}
|
|
105
|
+
}
|
|
107
106
|
/**
|
|
108
107
|
* Returns the tenant ID corresponding to the resource name if available.
|
|
109
108
|
*
|
|
@@ -112,42 +111,42 @@ var Tenant = /** @class */ (function () {
|
|
|
112
111
|
*
|
|
113
112
|
* @internal
|
|
114
113
|
*/
|
|
115
|
-
|
|
114
|
+
static getTenantIdFromResourceName(resourceName) {
|
|
116
115
|
// name is of form projects/project1/tenants/tenant1
|
|
117
|
-
|
|
116
|
+
const matchTenantRes = resourceName.match(/\/tenants\/(.*)$/);
|
|
118
117
|
if (!matchTenantRes || matchTenantRes.length < 2) {
|
|
119
118
|
return null;
|
|
120
119
|
}
|
|
121
120
|
return matchTenantRes[1];
|
|
122
|
-
}
|
|
121
|
+
}
|
|
123
122
|
/**
|
|
124
123
|
* Validates a tenant options object. Throws an error on failure.
|
|
125
124
|
*
|
|
126
125
|
* @param request - The tenant options object to validate.
|
|
127
126
|
* @param createRequest - Whether this is a create request.
|
|
128
127
|
*/
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
static validate(request, createRequest) {
|
|
129
|
+
const validKeys = {
|
|
131
130
|
displayName: true,
|
|
132
131
|
emailSignInConfig: true,
|
|
133
132
|
anonymousSignInEnabled: true,
|
|
134
133
|
multiFactorConfig: true,
|
|
135
134
|
testPhoneNumbers: true,
|
|
136
135
|
};
|
|
137
|
-
|
|
136
|
+
const label = createRequest ? 'CreateTenantRequest' : 'UpdateTenantRequest';
|
|
138
137
|
if (!validator.isNonNullObject(request)) {
|
|
139
|
-
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, "
|
|
138
|
+
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, `"${label}" must be a valid non-null object.`);
|
|
140
139
|
}
|
|
141
140
|
// Check for unsupported top level attributes.
|
|
142
|
-
for (
|
|
141
|
+
for (const key in request) {
|
|
143
142
|
if (!(key in validKeys)) {
|
|
144
|
-
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, "
|
|
143
|
+
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, `"${key}" is not a valid ${label} parameter.`);
|
|
145
144
|
}
|
|
146
145
|
}
|
|
147
146
|
// Validate displayName type if provided.
|
|
148
147
|
if (typeof request.displayName !== 'undefined' &&
|
|
149
148
|
!validator.isNonEmptyString(request.displayName)) {
|
|
150
|
-
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, "
|
|
149
|
+
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, `"${label}.displayName" must be a valid non-empty string.`);
|
|
151
150
|
}
|
|
152
151
|
// Validate emailSignInConfig type if provided.
|
|
153
152
|
if (typeof request.emailSignInConfig !== 'undefined') {
|
|
@@ -157,50 +156,41 @@ var Tenant = /** @class */ (function () {
|
|
|
157
156
|
// Validate test phone numbers if provided.
|
|
158
157
|
if (typeof request.testPhoneNumbers !== 'undefined' &&
|
|
159
158
|
request.testPhoneNumbers !== null) {
|
|
160
|
-
auth_config_1.validateTestPhoneNumbers(request.testPhoneNumbers);
|
|
159
|
+
(0, auth_config_1.validateTestPhoneNumbers)(request.testPhoneNumbers);
|
|
161
160
|
}
|
|
162
161
|
else if (request.testPhoneNumbers === null && createRequest) {
|
|
163
162
|
// null allowed only for update operations.
|
|
164
|
-
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, "
|
|
163
|
+
throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, `"${label}.testPhoneNumbers" must be a non-null object.`);
|
|
165
164
|
}
|
|
166
165
|
// Validate multiFactorConfig type if provided.
|
|
167
166
|
if (typeof request.multiFactorConfig !== 'undefined') {
|
|
168
167
|
// This will throw an error if invalid.
|
|
169
168
|
auth_config_1.MultiFactorAuthConfig.buildServerRequest(request.multiFactorConfig);
|
|
170
169
|
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
* The multi-factor auth configuration on the current tenant.
|
|
185
|
-
*/
|
|
186
|
-
get: function () {
|
|
187
|
-
return this.multiFactorConfig_;
|
|
188
|
-
},
|
|
189
|
-
enumerable: false,
|
|
190
|
-
configurable: true
|
|
191
|
-
});
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* The email sign in provider configuration.
|
|
173
|
+
*/
|
|
174
|
+
get emailSignInConfig() {
|
|
175
|
+
return this.emailSignInConfig_;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* The multi-factor auth configuration on the current tenant.
|
|
179
|
+
*/
|
|
180
|
+
get multiFactorConfig() {
|
|
181
|
+
return this.multiFactorConfig_;
|
|
182
|
+
}
|
|
192
183
|
/**
|
|
193
184
|
* Returns a JSON-serializable representation of this object.
|
|
194
185
|
*
|
|
195
186
|
* @returns A JSON-serializable representation of this object.
|
|
196
187
|
*/
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
var json = {
|
|
188
|
+
toJSON() {
|
|
189
|
+
const json = {
|
|
200
190
|
tenantId: this.tenantId,
|
|
201
191
|
displayName: this.displayName,
|
|
202
|
-
emailSignInConfig:
|
|
203
|
-
multiFactorConfig:
|
|
192
|
+
emailSignInConfig: this.emailSignInConfig_?.toJSON(),
|
|
193
|
+
multiFactorConfig: this.multiFactorConfig_?.toJSON(),
|
|
204
194
|
anonymousSignInEnabled: this.anonymousSignInEnabled,
|
|
205
195
|
testPhoneNumbers: this.testPhoneNumbers,
|
|
206
196
|
};
|
|
@@ -211,7 +201,6 @@ var Tenant = /** @class */ (function () {
|
|
|
211
201
|
delete json.testPhoneNumbers;
|
|
212
202
|
}
|
|
213
203
|
return json;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
}());
|
|
204
|
+
}
|
|
205
|
+
}
|
|
217
206
|
exports.Tenant = Tenant;
|