/*! firebase-admin v14.0.0 */ "use strict"; /*! * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.TenantManager = exports.TenantAwareAuth = void 0; const validator = require("../utils/validator"); const utils = require("../utils/index"); const error_1 = require("./error"); const base_auth_1 = require("./base-auth"); const tenant_1 = require("./tenant"); const auth_api_request_1 = require("./auth-api-request"); /** * Tenant-aware `Auth` interface used for managing users, configuring SAML/OIDC providers, * generating email links for password reset, email verification, etc for specific tenants. * * Multi-tenancy support requires Google Cloud's Identity Platform * (GCIP). To learn more about GCIP, including pricing and features, * see the {@link https://cloud.google.com/identity-platform | GCIP documentation}. * * Each tenant contains its own identity providers, settings and sets of users. * Using `TenantAwareAuth`, users for a specific tenant and corresponding OIDC/SAML * configurations can also be managed, ID tokens for users signed in to a specific tenant * can be verified, and email action links can also be generated for users belonging to the * tenant. * * `TenantAwareAuth` instances for a specific `tenantId` can be instantiated by calling * {@link TenantManager.authForTenant}. */ class TenantAwareAuth extends base_auth_1.BaseAuth { /** * The TenantAwareAuth class constructor. * * @param app - The app that created this tenant. * @param tenantId - The corresponding tenant ID. * @param emHost - Optional emulator host captured at init time. * @constructor * @internal */ constructor(app, tenantId, emHost) { const emIsSet = emHost !== undefined; super(app, new auth_api_request_1.TenantAwareAuthRequestHandler(app, tenantId, emHost), (0, base_auth_1.createFirebaseTokenGenerator)(app, tenantId, emIsSet ? !!emHost : undefined)); utils.addReadonlyGetter(this, 'tenantId', tenantId); } /** * {@inheritdoc BaseAuth.verifyIdToken} */ verifyIdToken(idToken, checkRevoked = false) { return super.verifyIdToken(idToken, checkRevoked) .then((decodedClaims) => { // Validate tenant ID. if (decodedClaims.firebase.tenant !== this.tenantId) { throw new error_1.FirebaseAuthError(error_1.authClientErrorCode.MISMATCHING_TENANT_ID); } return decodedClaims; }); } /** * {@inheritdoc BaseAuth.createSessionCookie} */ createSessionCookie(idToken, sessionCookieOptions) { // Validate arguments before processing. if (!validator.isNonEmptyString(idToken)) { return Promise.reject(new error_1.FirebaseAuthError(error_1.authClientErrorCode.INVALID_ID_TOKEN)); } if (!validator.isNonNullObject(sessionCookieOptions) || !validator.isNumber(sessionCookieOptions.expiresIn)) { return Promise.reject(new error_1.FirebaseAuthError(error_1.authClientErrorCode.INVALID_SESSION_COOKIE_DURATION)); } // This will verify the ID token and then match the tenant ID before creating the session cookie. return this.verifyIdToken(idToken) .then(() => { return super.createSessionCookie(idToken, sessionCookieOptions); }); } /** * {@inheritdoc BaseAuth.verifySessionCookie} */ verifySessionCookie(sessionCookie, checkRevoked = false) { return super.verifySessionCookie(sessionCookie, checkRevoked) .then((decodedClaims) => { if (decodedClaims.firebase.tenant !== this.tenantId) { throw new error_1.FirebaseAuthError(error_1.authClientErrorCode.MISMATCHING_TENANT_ID); } return decodedClaims; }); } } exports.TenantAwareAuth = TenantAwareAuth; /** * Defines the tenant manager used to help manage tenant related operations. * This includes: *