Initial Commit

This commit is contained in:
2026-03-06 04:54:20 -04:00
commit 63677bfcf5
9332 changed files with 1507319 additions and 0 deletions

View File

@@ -0,0 +1,124 @@
/**
* @license
* Copyright 2022 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.
*/
import { TotpMultiFactorAssertion, MultiFactorSession } from '../../model/public_types';
import { AuthInternal } from '../../model/auth';
import { StartTotpMfaEnrollmentResponse, TotpVerificationInfo } from '../../api/account_management/mfa';
import { FinalizeMfaResponse } from '../../api/authentication/mfa';
import { MultiFactorAssertionImpl } from '../../mfa/mfa_assertion';
/**
* Provider for generating a {@link TotpMultiFactorAssertion}.
*
* @public
*/
export declare class TotpMultiFactorGenerator {
/**
* Provides a {@link TotpMultiFactorAssertion} to confirm ownership of
* the TOTP (time-based one-time password) second factor.
* This assertion is used to complete enrollment in TOTP second factor.
*
* @param secret A {@link TotpSecret} containing the shared secret key and other TOTP parameters.
* @param oneTimePassword One-time password from TOTP App.
* @returns A {@link TotpMultiFactorAssertion} which can be used with
* {@link MultiFactorUser.enroll}.
*/
static assertionForEnrollment(secret: TotpSecret, oneTimePassword: string): TotpMultiFactorAssertion;
/**
* Provides a {@link TotpMultiFactorAssertion} to confirm ownership of the TOTP second factor.
* This assertion is used to complete signIn with TOTP as the second factor.
*
* @param enrollmentId identifies the enrolled TOTP second factor.
* @param oneTimePassword One-time password from TOTP App.
* @returns A {@link TotpMultiFactorAssertion} which can be used with
* {@link MultiFactorResolver.resolveSignIn}.
*/
static assertionForSignIn(enrollmentId: string, oneTimePassword: string): TotpMultiFactorAssertion;
/**
* Returns a promise to {@link TotpSecret} which contains the TOTP shared secret key and other parameters.
* Creates a TOTP secret as part of enrolling a TOTP second factor.
* Used for generating a QR code URL or inputting into a TOTP app.
* This method uses the auth instance corresponding to the user in the multiFactorSession.
*
* @param session The {@link MultiFactorSession} that the user is part of.
* @returns A promise to {@link TotpSecret}.
*/
static generateSecret(session: MultiFactorSession): Promise<TotpSecret>;
/**
* The identifier of the TOTP second factor: `totp`.
*/
static FACTOR_ID: 'totp';
}
export declare class TotpMultiFactorAssertionImpl extends MultiFactorAssertionImpl implements TotpMultiFactorAssertion {
readonly otp: string;
readonly enrollmentId?: string | undefined;
readonly secret?: TotpSecret | undefined;
constructor(otp: string, enrollmentId?: string | undefined, secret?: TotpSecret | undefined);
/** @internal */
static _fromSecret(secret: TotpSecret, otp: string): TotpMultiFactorAssertionImpl;
/** @internal */
static _fromEnrollmentId(enrollmentId: string, otp: string): TotpMultiFactorAssertionImpl;
/** @internal */
_finalizeEnroll(auth: AuthInternal, idToken: string, displayName?: string | null): Promise<FinalizeMfaResponse>;
/** @internal */
_finalizeSignIn(auth: AuthInternal, mfaPendingCredential: string): Promise<FinalizeMfaResponse>;
}
/**
* Provider for generating a {@link TotpMultiFactorAssertion}.
*
* Stores the shared secret key and other parameters to generate time-based OTPs.
* Implements methods to retrieve the shared secret key and generate a QR code URL.
* @public
*/
export declare class TotpSecret {
private readonly sessionInfo;
private readonly auth;
/**
* Shared secret key/seed used for enrolling in TOTP MFA and generating OTPs.
*/
readonly secretKey: string;
/**
* Hashing algorithm used.
*/
readonly hashingAlgorithm: string;
/**
* Length of the one-time passwords to be generated.
*/
readonly codeLength: number;
/**
* The interval (in seconds) when the OTP codes should change.
*/
readonly codeIntervalSeconds: number;
/**
* The timestamp (UTC string) by which TOTP enrollment should be completed.
*/
readonly enrollmentCompletionDeadline: string;
private constructor();
/** @internal */
static _fromStartTotpMfaEnrollmentResponse(response: StartTotpMfaEnrollmentResponse, auth: AuthInternal): TotpSecret;
/** @internal */
_makeTotpVerificationInfo(otp: string): TotpVerificationInfo;
/**
* Returns a QR code URL as described in
* https://github.com/google/google-authenticator/wiki/Key-Uri-Format
* This can be displayed to the user as a QR code to be scanned into a TOTP app like Google Authenticator.
* If the optional parameters are unspecified, an accountName of <userEmail> and issuer of <firebaseAppName> are used.
*
* @param accountName the name of the account/app along with a user identifier.
* @param issuer issuer of the TOTP (likely the app name).
* @returns A QR code URL string.
*/
generateQrCodeUrl(accountName?: string, issuer?: string): string;
}

View File

@@ -0,0 +1,18 @@
/**
* @license
* Copyright 2020 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.
*/
export { getMultiFactorResolver } from './mfa_resolver';
export { multiFactor } from './mfa_user';

View File

@@ -0,0 +1,27 @@
/**
* @license
* Copyright 2020 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.
*/
import { FactorId, MultiFactorAssertion } from '../model/public_types';
import { MultiFactorSessionImpl } from './mfa_session';
import { FinalizeMfaResponse } from '../api/authentication/mfa';
import { AuthInternal } from '../model/auth';
export declare abstract class MultiFactorAssertionImpl implements MultiFactorAssertion {
readonly factorId: FactorId;
protected constructor(factorId: FactorId);
_process(auth: AuthInternal, session: MultiFactorSessionImpl, displayName?: string | null): Promise<FinalizeMfaResponse>;
abstract _finalizeEnroll(auth: AuthInternal, idToken: string, displayName?: string | null): Promise<FinalizeMfaResponse>;
abstract _finalizeSignIn(auth: AuthInternal, mfaPendingCredential: string): Promise<FinalizeMfaResponse>;
}

View File

@@ -0,0 +1,35 @@
/**
* @license
* Copyright 2020 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.
*/
import { MultiFactorError as MultiFactorErrorPublic } from '../model/public_types';
import { FirebaseError } from '@firebase/util';
import { AuthInternal } from '../model/auth';
import { IdTokenResponse } from '../model/id_token';
import { UserInternal } from '../model/user';
import { AuthCredential } from '../core/credentials';
import { IdTokenMfaResponse } from '../api/authentication/mfa';
import { OperationType } from '../model/enums';
export type MultiFactorErrorData = MultiFactorErrorPublic['customData'] & {
_serverResponse: IdTokenMfaResponse;
};
export declare class MultiFactorError extends FirebaseError implements MultiFactorErrorPublic {
readonly operationType: OperationType;
readonly user?: UserInternal | undefined;
readonly customData: MultiFactorErrorData;
private constructor();
static _fromErrorAndOperation(auth: AuthInternal, error: FirebaseError, operationType: OperationType, user?: UserInternal): MultiFactorError;
}
export declare function _processCredentialSavingMfaContextIfNecessary(auth: AuthInternal, operationType: OperationType, credential: AuthCredential, user?: UserInternal): Promise<IdTokenResponse>;

View File

@@ -0,0 +1,36 @@
/**
* @license
* Copyright 2020 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.
*/
import { FactorId, MultiFactorInfo, PhoneMultiFactorInfo, TotpMultiFactorInfo } from '../model/public_types';
import { MfaEnrollment } from '../api/account_management/mfa';
import { AuthInternal } from '../model/auth';
export declare abstract class MultiFactorInfoImpl implements MultiFactorInfo {
readonly factorId: FactorId;
readonly uid: string;
readonly displayName?: string | null;
readonly enrollmentTime: string;
protected constructor(factorId: FactorId, response: MfaEnrollment);
static _fromServerResponse(auth: AuthInternal, enrollment: MfaEnrollment): MultiFactorInfoImpl;
}
export declare class PhoneMultiFactorInfoImpl extends MultiFactorInfoImpl implements PhoneMultiFactorInfo {
readonly phoneNumber: string;
private constructor();
static _fromServerResponse(_auth: AuthInternal, enrollment: MfaEnrollment): PhoneMultiFactorInfoImpl;
}
export declare class TotpMultiFactorInfoImpl extends MultiFactorInfoImpl implements TotpMultiFactorInfo {
private constructor();
static _fromServerResponse(_auth: AuthInternal, enrollment: MfaEnrollment): TotpMultiFactorInfoImpl;
}

View File

@@ -0,0 +1,41 @@
/**
* @license
* Copyright 2020 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.
*/
import { Auth, MultiFactorResolver, UserCredential, MultiFactorError } from '../model/public_types';
import { MultiFactorAssertionImpl } from './mfa_assertion';
import { MultiFactorError as MultiFactorErrorInternal } from './mfa_error';
import { MultiFactorInfoImpl } from './mfa_info';
import { MultiFactorSessionImpl } from './mfa_session';
export declare class MultiFactorResolverImpl implements MultiFactorResolver {
readonly session: MultiFactorSessionImpl;
readonly hints: MultiFactorInfoImpl[];
private readonly signInResolver;
private constructor();
/** @internal */
static _fromError(authExtern: Auth, error: MultiFactorErrorInternal): MultiFactorResolverImpl;
resolveSignIn(assertionExtern: MultiFactorAssertionImpl): Promise<UserCredential>;
}
/**
* Provides a {@link MultiFactorResolver} suitable for completion of a
* multi-factor flow.
*
* @param auth - The {@link Auth} instance.
* @param error - The {@link MultiFactorError} raised during a sign-in, or
* reauthentication operation.
*
* @public
*/
export declare function getMultiFactorResolver(auth: Auth, error: MultiFactorError): MultiFactorResolver;

View File

@@ -0,0 +1,39 @@
/**
* @license
* Copyright 2020 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.
*/
import { UserInternal } from '../model/user';
import { MultiFactorSession } from '../model/public_types';
export declare const enum MultiFactorSessionType {
ENROLL = "enroll",
SIGN_IN = "signin"
}
interface SerializedMultiFactorSession {
multiFactorSession: {
idToken?: string;
pendingCredential?: string;
};
}
export declare class MultiFactorSessionImpl implements MultiFactorSession {
readonly type: MultiFactorSessionType;
readonly credential: string;
readonly user?: UserInternal | undefined;
private constructor();
static _fromIdtoken(idToken: string, user?: UserInternal): MultiFactorSessionImpl;
static _fromMfaPendingCredential(mfaPendingCredential: string): MultiFactorSessionImpl;
toJSON(): SerializedMultiFactorSession;
static fromJSON(obj: Partial<SerializedMultiFactorSession>): MultiFactorSessionImpl | null;
}
export {};

View File

@@ -0,0 +1,38 @@
/**
* @license
* Copyright 2020 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.
*/
import { MultiFactorAssertion, MultiFactorInfo, MultiFactorSession, MultiFactorUser, User } from '../model/public_types';
import { UserInternal } from '../model/user';
export declare class MultiFactorUserImpl implements MultiFactorUser {
readonly user: UserInternal;
enrolledFactors: MultiFactorInfo[];
private constructor();
static _fromUser(user: UserInternal): MultiFactorUserImpl;
getSession(): Promise<MultiFactorSession>;
enroll(assertionExtern: MultiFactorAssertion, displayName?: string | null): Promise<void>;
unenroll(infoOrUid: MultiFactorInfo | string): Promise<void>;
}
/**
* The {@link MultiFactorUser} corresponding to the user.
*
* @remarks
* This is used to access all multi-factor properties and operations related to the user.
*
* @param user - The user.
*
* @public
*/
export declare function multiFactor(user: User): MultiFactorUser;