@firebase/auth 0.21.5 → 0.21.6-20230329040242

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.
Files changed (128) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +20 -0
  3. package/dist/auth-public.d.ts +136 -4
  4. package/dist/auth.d.ts +147 -4
  5. package/dist/browser-cjs/{index-ff477525.js → index-f0c95b47.js} +177 -4
  6. package/dist/browser-cjs/index-f0c95b47.js.map +1 -0
  7. package/dist/browser-cjs/index.d.ts +2 -1
  8. package/dist/browser-cjs/index.js +3 -1
  9. package/dist/browser-cjs/index.js.map +1 -1
  10. package/dist/browser-cjs/internal.js +3 -1
  11. package/dist/browser-cjs/internal.js.map +1 -1
  12. package/dist/browser-cjs/src/api/account_management/mfa.d.ts +38 -4
  13. package/dist/browser-cjs/src/api/authentication/mfa.d.ts +11 -0
  14. package/dist/browser-cjs/src/mfa/assertions/totp.d.ts +124 -0
  15. package/dist/browser-cjs/src/mfa/assertions/totp.test.d.ts +17 -0
  16. package/dist/browser-cjs/src/mfa/mfa_info.d.ts +5 -1
  17. package/dist/browser-cjs/src/model/enum_maps.d.ts +1 -0
  18. package/dist/browser-cjs/src/model/public_types.d.ts +18 -1
  19. package/dist/browser-cjs/test/helpers/integration/helpers.d.ts +3 -0
  20. package/dist/browser-cjs/test/integration/flows/totp.test.d.ts +17 -0
  21. package/dist/cordova/index.d.ts +2 -1
  22. package/dist/cordova/index.js +2 -2
  23. package/dist/cordova/internal.js +179 -3
  24. package/dist/cordova/internal.js.map +1 -1
  25. package/dist/cordova/{popup_redirect-a4d3c436.js → popup_redirect-ea399a63.js} +28 -5
  26. package/dist/cordova/popup_redirect-ea399a63.js.map +1 -0
  27. package/dist/cordova/src/api/account_management/mfa.d.ts +38 -4
  28. package/dist/cordova/src/api/authentication/mfa.d.ts +11 -0
  29. package/dist/cordova/src/mfa/assertions/totp.d.ts +124 -0
  30. package/dist/cordova/src/mfa/assertions/totp.test.d.ts +17 -0
  31. package/dist/cordova/src/mfa/mfa_info.d.ts +5 -1
  32. package/dist/cordova/src/model/enum_maps.d.ts +1 -0
  33. package/dist/cordova/src/model/public_types.d.ts +18 -1
  34. package/dist/cordova/test/helpers/integration/helpers.d.ts +3 -0
  35. package/dist/cordova/test/integration/flows/totp.test.d.ts +17 -0
  36. package/dist/esm2017/{index-3363a72a.js → index-998a92c6.js} +176 -5
  37. package/dist/esm2017/index-998a92c6.js.map +1 -0
  38. package/dist/esm2017/index.d.ts +2 -1
  39. package/dist/esm2017/index.js +1 -1
  40. package/dist/esm2017/internal.js +2 -2
  41. package/dist/esm2017/src/api/account_management/mfa.d.ts +38 -4
  42. package/dist/esm2017/src/api/authentication/mfa.d.ts +11 -0
  43. package/dist/esm2017/src/mfa/assertions/totp.d.ts +124 -0
  44. package/dist/esm2017/src/mfa/assertions/totp.test.d.ts +17 -0
  45. package/dist/esm2017/src/mfa/mfa_info.d.ts +5 -1
  46. package/dist/esm2017/src/model/enum_maps.d.ts +1 -0
  47. package/dist/esm2017/src/model/public_types.d.ts +18 -1
  48. package/dist/esm2017/test/helpers/integration/helpers.d.ts +3 -0
  49. package/dist/esm2017/test/integration/flows/totp.test.d.ts +17 -0
  50. package/dist/esm5/{index-3f05dc7b.js → index-14d0c8cb.js} +204 -5
  51. package/dist/esm5/index-14d0c8cb.js.map +1 -0
  52. package/dist/esm5/index.d.ts +2 -1
  53. package/dist/esm5/index.js +1 -1
  54. package/dist/esm5/internal.js +2 -2
  55. package/dist/esm5/src/api/account_management/mfa.d.ts +38 -4
  56. package/dist/esm5/src/api/authentication/mfa.d.ts +11 -0
  57. package/dist/esm5/src/mfa/assertions/totp.d.ts +124 -0
  58. package/dist/esm5/src/mfa/assertions/totp.test.d.ts +17 -0
  59. package/dist/esm5/src/mfa/mfa_info.d.ts +5 -1
  60. package/dist/esm5/src/model/enum_maps.d.ts +1 -0
  61. package/dist/esm5/src/model/public_types.d.ts +18 -1
  62. package/dist/esm5/test/helpers/integration/helpers.d.ts +3 -0
  63. package/dist/esm5/test/integration/flows/totp.test.d.ts +17 -0
  64. package/dist/index.d.ts +2 -1
  65. package/dist/index.webworker.esm5.js +20 -3
  66. package/dist/index.webworker.esm5.js.map +1 -1
  67. package/dist/node/index.d.ts +2 -1
  68. package/dist/node/index.js +83 -81
  69. package/dist/node/index.js.map +1 -1
  70. package/dist/node/internal.js +144 -142
  71. package/dist/node/internal.js.map +1 -1
  72. package/dist/node/src/api/account_management/mfa.d.ts +38 -4
  73. package/dist/node/src/api/authentication/mfa.d.ts +11 -0
  74. package/dist/node/src/mfa/assertions/totp.d.ts +124 -0
  75. package/dist/node/src/mfa/assertions/totp.test.d.ts +17 -0
  76. package/dist/node/src/mfa/mfa_info.d.ts +5 -1
  77. package/dist/node/src/model/enum_maps.d.ts +1 -0
  78. package/dist/node/src/model/public_types.d.ts +18 -1
  79. package/dist/node/test/helpers/integration/helpers.d.ts +3 -0
  80. package/dist/node/test/integration/flows/totp.test.d.ts +17 -0
  81. package/dist/node/{index-45468d80.js → totp-06ccbed7.js} +240 -5
  82. package/dist/node/totp-06ccbed7.js.map +1 -0
  83. package/dist/node-esm/index.d.ts +2 -1
  84. package/dist/node-esm/index.js +2 -2
  85. package/dist/node-esm/internal.js +3 -3
  86. package/dist/node-esm/src/api/account_management/mfa.d.ts +38 -4
  87. package/dist/node-esm/src/api/authentication/mfa.d.ts +11 -0
  88. package/dist/node-esm/src/mfa/assertions/totp.d.ts +124 -0
  89. package/dist/node-esm/src/mfa/assertions/totp.test.d.ts +17 -0
  90. package/dist/node-esm/src/mfa/mfa_info.d.ts +5 -1
  91. package/dist/node-esm/src/model/enum_maps.d.ts +1 -0
  92. package/dist/node-esm/src/model/public_types.d.ts +18 -1
  93. package/dist/node-esm/test/helpers/integration/helpers.d.ts +3 -0
  94. package/dist/node-esm/test/integration/flows/totp.test.d.ts +17 -0
  95. package/dist/node-esm/{index-1f9492de.js → totp-412ade8c.js} +210 -6
  96. package/dist/node-esm/totp-412ade8c.js.map +1 -0
  97. package/dist/rn/index.d.ts +2 -1
  98. package/dist/rn/index.js +1 -1
  99. package/dist/rn/internal.js +176 -1
  100. package/dist/rn/internal.js.map +1 -1
  101. package/dist/rn/{phone-e7bf48a1.js → phone-e85f18b7.js} +34 -4
  102. package/dist/rn/phone-e85f18b7.js.map +1 -0
  103. package/dist/rn/src/api/account_management/mfa.d.ts +38 -4
  104. package/dist/rn/src/api/authentication/mfa.d.ts +11 -0
  105. package/dist/rn/src/mfa/assertions/totp.d.ts +124 -0
  106. package/dist/rn/src/mfa/assertions/totp.test.d.ts +17 -0
  107. package/dist/rn/src/mfa/mfa_info.d.ts +5 -1
  108. package/dist/rn/src/model/enum_maps.d.ts +1 -0
  109. package/dist/rn/src/model/public_types.d.ts +18 -1
  110. package/dist/rn/test/helpers/integration/helpers.d.ts +3 -0
  111. package/dist/rn/test/integration/flows/totp.test.d.ts +17 -0
  112. package/dist/src/api/account_management/mfa.d.ts +38 -4
  113. package/dist/src/api/authentication/mfa.d.ts +11 -0
  114. package/dist/src/mfa/assertions/totp.d.ts +124 -0
  115. package/dist/src/mfa/assertions/totp.test.d.ts +17 -0
  116. package/dist/src/mfa/mfa_info.d.ts +5 -1
  117. package/dist/src/model/enum_maps.d.ts +1 -0
  118. package/dist/src/model/public_types.d.ts +18 -1
  119. package/dist/test/helpers/integration/helpers.d.ts +3 -0
  120. package/dist/test/integration/flows/totp.test.d.ts +17 -0
  121. package/package.json +5 -3
  122. package/dist/browser-cjs/index-ff477525.js.map +0 -1
  123. package/dist/cordova/popup_redirect-a4d3c436.js.map +0 -1
  124. package/dist/esm2017/index-3363a72a.js.map +0 -1
  125. package/dist/esm5/index-3f05dc7b.js.map +0 -1
  126. package/dist/node/index-45468d80.js.map +0 -1
  127. package/dist/node-esm/index-1f9492de.js.map +0 -1
  128. package/dist/rn/phone-e7bf48a1.js.map +0 -1
@@ -18,7 +18,7 @@ import { SignInWithPhoneNumberRequest } from '../authentication/sms';
18
18
  import { FinalizeMfaResponse } from '../authentication/mfa';
19
19
  import { AuthInternal } from '../../model/auth';
20
20
  /**
21
- * MFA Info as returned by the API
21
+ * MFA Info as returned by the API.
22
22
  */
23
23
  interface BaseMfaEnrollment {
24
24
  mfaEnrollmentId: string;
@@ -26,15 +26,20 @@ interface BaseMfaEnrollment {
26
26
  displayName?: string;
27
27
  }
28
28
  /**
29
- * An MFA provided by SMS verification
29
+ * An MFA provided by SMS verification.
30
30
  */
31
31
  export interface PhoneMfaEnrollment extends BaseMfaEnrollment {
32
32
  phoneInfo: string;
33
33
  }
34
34
  /**
35
- * MfaEnrollment can be any subtype of BaseMfaEnrollment, currently only PhoneMfaEnrollment is supported
35
+ * An MFA provided by TOTP (Time-based One Time Password).
36
36
  */
37
- export declare type MfaEnrollment = PhoneMfaEnrollment;
37
+ export interface TotpMfaEnrollment extends BaseMfaEnrollment {
38
+ }
39
+ /**
40
+ * MfaEnrollment can be any subtype of BaseMfaEnrollment, currently only PhoneMfaEnrollment and TotpMfaEnrollment are supported.
41
+ */
42
+ export declare type MfaEnrollment = PhoneMfaEnrollment | TotpMfaEnrollment;
38
43
  export interface StartPhoneMfaEnrollmentRequest {
39
44
  idToken: string;
40
45
  phoneEnrollmentInfo: {
@@ -58,6 +63,35 @@ export interface FinalizePhoneMfaEnrollmentRequest {
58
63
  export interface FinalizePhoneMfaEnrollmentResponse extends FinalizeMfaResponse {
59
64
  }
60
65
  export declare function finalizeEnrollPhoneMfa(auth: AuthInternal, request: FinalizePhoneMfaEnrollmentRequest): Promise<FinalizePhoneMfaEnrollmentResponse>;
66
+ export interface StartTotpMfaEnrollmentRequest {
67
+ idToken: string;
68
+ totpEnrollmentInfo: {};
69
+ tenantId?: string;
70
+ }
71
+ export interface StartTotpMfaEnrollmentResponse {
72
+ totpSessionInfo: {
73
+ sharedSecretKey: string;
74
+ verificationCodeLength: number;
75
+ hashingAlgorithm: string;
76
+ periodSec: number;
77
+ sessionInfo: string;
78
+ finalizeEnrollmentTime: number;
79
+ };
80
+ }
81
+ export declare function startEnrollTotpMfa(auth: AuthInternal, request: StartTotpMfaEnrollmentRequest): Promise<StartTotpMfaEnrollmentResponse>;
82
+ export interface TotpVerificationInfo {
83
+ sessionInfo: string;
84
+ verificationCode: string;
85
+ }
86
+ export interface FinalizeTotpMfaEnrollmentRequest {
87
+ idToken: string;
88
+ totpVerificationInfo: TotpVerificationInfo;
89
+ displayName?: string | null;
90
+ tenantId?: string;
91
+ }
92
+ export interface FinalizeTotpMfaEnrollmentResponse extends FinalizeMfaResponse {
93
+ }
94
+ export declare function finalizeEnrollTotpMfa(auth: AuthInternal, request: FinalizeTotpMfaEnrollmentRequest): Promise<FinalizeTotpMfaEnrollmentResponse>;
61
95
  export interface WithdrawMfaRequest {
62
96
  idToken: string;
63
97
  mfaEnrollmentId: string;
@@ -49,9 +49,20 @@ export interface FinalizePhoneMfaSignInRequest {
49
49
  phoneVerificationInfo: SignInWithPhoneNumberRequest;
50
50
  tenantId?: string;
51
51
  }
52
+ export interface FinalizeTotpMfaSignInRequest {
53
+ mfaPendingCredential: string;
54
+ totpVerificationInfo: {
55
+ verificationCode: string;
56
+ };
57
+ tenantId?: string;
58
+ mfaEnrollmentId: string;
59
+ }
52
60
  export interface FinalizePhoneMfaSignInResponse extends FinalizeMfaResponse {
53
61
  }
62
+ export interface FinalizeTotpMfaSignInResponse extends FinalizeMfaResponse {
63
+ }
54
64
  export declare function finalizeSignInPhoneMfa(auth: Auth, request: FinalizePhoneMfaSignInRequest): Promise<FinalizePhoneMfaSignInResponse>;
65
+ export declare function finalizeSignInTotpMfa(auth: Auth, request: FinalizeTotpMfaSignInRequest): Promise<FinalizeTotpMfaSignInResponse>;
55
66
  /**
56
67
  * @internal
57
68
  */
@@ -0,0 +1,124 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { TotpMultiFactorAssertion, MultiFactorSession, FactorId } from '../../model/public_types';
18
+ import { AuthInternal } from '../../model/auth';
19
+ import { StartTotpMfaEnrollmentResponse, TotpVerificationInfo } from '../../api/account_management/mfa';
20
+ import { FinalizeMfaResponse } from '../../api/authentication/mfa';
21
+ import { MultiFactorAssertionImpl } from '../../mfa/mfa_assertion';
22
+ /**
23
+ * Provider for generating a {@link TotpMultiFactorAssertion}.
24
+ *
25
+ * @public
26
+ */
27
+ export declare class TotpMultiFactorGenerator {
28
+ /**
29
+ * Provides a {@link TotpMultiFactorAssertion} to confirm ownership of
30
+ * the TOTP (time-based one-time password) second factor.
31
+ * This assertion is used to complete enrollment in TOTP second factor.
32
+ *
33
+ * @param secret A {@link TotpSecret} containing the shared secret key and other TOTP parameters.
34
+ * @param oneTimePassword One-time password from TOTP App.
35
+ * @returns A {@link TotpMultiFactorAssertion} which can be used with
36
+ * {@link MultiFactorUser.enroll}.
37
+ */
38
+ static assertionForEnrollment(secret: TotpSecret, oneTimePassword: string): TotpMultiFactorAssertion;
39
+ /**
40
+ * Provides a {@link TotpMultiFactorAssertion} to confirm ownership of the TOTP second factor.
41
+ * This assertion is used to complete signIn with TOTP as the second factor.
42
+ *
43
+ * @param enrollmentId identifies the enrolled TOTP second factor.
44
+ * @param oneTimePassword One-time password from TOTP App.
45
+ * @returns A {@link TotpMultiFactorAssertion} which can be used with
46
+ * {@link MultiFactorResolver.resolveSignIn}.
47
+ */
48
+ static assertionForSignIn(enrollmentId: string, oneTimePassword: string): TotpMultiFactorAssertion;
49
+ /**
50
+ * Returns a promise to {@link TotpSecret} which contains the TOTP shared secret key and other parameters.
51
+ * Creates a TOTP secret as part of enrolling a TOTP second factor.
52
+ * Used for generating a QR code URL or inputting into a TOTP app.
53
+ * This method uses the auth instance corresponding to the user in the multiFactorSession.
54
+ *
55
+ * @param session The {@link MultiFactorSession} that the user is part of.
56
+ * @returns A promise to {@link TotpSecret}.
57
+ */
58
+ static generateSecret(session: MultiFactorSession): Promise<TotpSecret>;
59
+ /**
60
+ * The identifier of the TOTP second factor: `totp`.
61
+ */
62
+ static FACTOR_ID: FactorId;
63
+ }
64
+ export declare class TotpMultiFactorAssertionImpl extends MultiFactorAssertionImpl implements TotpMultiFactorAssertion {
65
+ readonly otp: string;
66
+ readonly enrollmentId?: string | undefined;
67
+ readonly secret?: TotpSecret | undefined;
68
+ constructor(otp: string, enrollmentId?: string | undefined, secret?: TotpSecret | undefined);
69
+ /** @internal */
70
+ static _fromSecret(secret: TotpSecret, otp: string): TotpMultiFactorAssertionImpl;
71
+ /** @internal */
72
+ static _fromEnrollmentId(enrollmentId: string, otp: string): TotpMultiFactorAssertionImpl;
73
+ /** @internal */
74
+ _finalizeEnroll(auth: AuthInternal, idToken: string, displayName?: string | null): Promise<FinalizeMfaResponse>;
75
+ /** @internal */
76
+ _finalizeSignIn(auth: AuthInternal, mfaPendingCredential: string): Promise<FinalizeMfaResponse>;
77
+ }
78
+ /**
79
+ * Provider for generating a {@link TotpMultiFactorAssertion}.
80
+ *
81
+ * Stores the shared secret key and other parameters to generate time-based OTPs.
82
+ * Implements methods to retrieve the shared secret key and generate a QR code URL.
83
+ * @public
84
+ */
85
+ export declare class TotpSecret {
86
+ private readonly sessionInfo;
87
+ private readonly auth;
88
+ /**
89
+ * Shared secret key/seed used for enrolling in TOTP MFA and generating OTPs.
90
+ */
91
+ readonly secretKey: string;
92
+ /**
93
+ * Hashing algorithm used.
94
+ */
95
+ readonly hashingAlgorithm: string;
96
+ /**
97
+ * Length of the one-time passwords to be generated.
98
+ */
99
+ readonly codeLength: number;
100
+ /**
101
+ * The interval (in seconds) when the OTP codes should change.
102
+ */
103
+ readonly codeIntervalSeconds: number;
104
+ /**
105
+ * The timestamp (UTC string) by which TOTP enrollment should be completed.
106
+ */
107
+ readonly enrollmentCompletionDeadline: string;
108
+ private constructor();
109
+ /** @internal */
110
+ static _fromStartTotpMfaEnrollmentResponse(response: StartTotpMfaEnrollmentResponse, auth: AuthInternal): TotpSecret;
111
+ /** @internal */
112
+ _makeTotpVerificationInfo(otp: string): TotpVerificationInfo;
113
+ /**
114
+ * Returns a QR code URL as described in
115
+ * https://github.com/google/google-authenticator/wiki/Key-Uri-Format
116
+ * This can be displayed to the user as a QR code to be scanned into a TOTP app like Google Authenticator.
117
+ * If the optional parameters are unspecified, an accountName of <userEmail> and issuer of <firebaseAppName> are used.
118
+ *
119
+ * @param accountName the name of the account/app along with a user identifier.
120
+ * @param issuer issuer of the TOTP (likely the app name).
121
+ * @returns A QR code URL string.
122
+ */
123
+ generateQrCodeUrl(accountName?: string, issuer?: string): string;
124
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export {};
@@ -14,7 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { FactorId, MultiFactorInfo, PhoneMultiFactorInfo } from '../model/public_types';
17
+ import { FactorId, MultiFactorInfo, PhoneMultiFactorInfo, TotpMultiFactorInfo } from '../model/public_types';
18
18
  import { MfaEnrollment } from '../api/account_management/mfa';
19
19
  import { AuthInternal } from '../model/auth';
20
20
  export declare abstract class MultiFactorInfoImpl implements MultiFactorInfo {
@@ -30,3 +30,7 @@ export declare class PhoneMultiFactorInfoImpl extends MultiFactorInfoImpl implem
30
30
  private constructor();
31
31
  static _fromServerResponse(_auth: AuthInternal, enrollment: MfaEnrollment): PhoneMultiFactorInfoImpl;
32
32
  }
33
+ export declare class TotpMultiFactorInfoImpl extends MultiFactorInfoImpl implements TotpMultiFactorInfo {
34
+ private constructor();
35
+ static _fromServerResponse(_auth: AuthInternal, enrollment: MfaEnrollment): TotpMultiFactorInfoImpl;
36
+ }
@@ -22,6 +22,7 @@
22
22
  export declare const FactorId: {
23
23
  /** Phone as second factor */
24
24
  readonly PHONE: "phone";
25
+ readonly TOTP: "totp";
25
26
  };
26
27
  /**
27
28
  * Enumeration of supported providers.
@@ -502,7 +502,8 @@ export interface AuthProvider {
502
502
  */
503
503
  export declare const enum FactorId {
504
504
  /** Phone as second factor */
505
- PHONE = "phone"
505
+ PHONE = "phone",
506
+ TOTP = "totp"
506
507
  }
507
508
  /**
508
509
  * A result from a phone number sign-in, link, or reauthenticate call.
@@ -609,6 +610,13 @@ export interface PhoneMultiFactorInfo extends MultiFactorInfo {
609
610
  /** The phone number associated with the current second factor. */
610
611
  readonly phoneNumber: string;
611
612
  }
613
+ /**
614
+ * The subclass of the {@link MultiFactorInfo} interface for TOTP
615
+ * second factors. The `factorId` of this second factor is {@link FactorId}.TOTP.
616
+ * @public
617
+ */
618
+ export interface TotpMultiFactorInfo extends MultiFactorInfo {
619
+ }
612
620
  /**
613
621
  * The class used to facilitate recovery from {@link MultiFactorError} when a user needs to
614
622
  * provide a second factor to sign in.
@@ -1160,3 +1168,12 @@ export interface Dependencies {
1160
1168
  */
1161
1169
  errorMap?: AuthErrorMap;
1162
1170
  }
1171
+ /**
1172
+ * The class for asserting ownership of a TOTP second factor. Provided by
1173
+ * {@link TotpMultiFactorGenerator.assertionForEnrollment} and
1174
+ * {@link TotpMultiFactorGenerator.assertionForSignIn}.
1175
+ *
1176
+ * @public
1177
+ */
1178
+ export interface TotpMultiFactorAssertion extends MultiFactorAssertion {
1179
+ }
@@ -18,3 +18,6 @@ import { Auth } from '../../../src/model/public_types';
18
18
  export declare function randomEmail(): string;
19
19
  export declare function getTestInstance(requireEmulator?: boolean): Auth;
20
20
  export declare function cleanUpTestInstance(auth: Auth): Promise<void>;
21
+ export declare function getTotpCode(sharedSecretKey: string, periodSec: number, verificationCodeLength: number, timestamp: Date): string;
22
+ export declare const email = "totpuser-donotdelete@test.com";
23
+ export declare const incorrectTotpCode = "1000000";
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export {};
@@ -3,9 +3,9 @@
3
3
  var tslib = require('tslib');
4
4
  var util = require('@firebase/util');
5
5
  var app = require('@firebase/app');
6
- var logger = require('@firebase/logger');
7
6
  var component = require('@firebase/component');
8
7
  var fetchImpl = require('node-fetch');
8
+ var logger = require('@firebase/logger');
9
9
 
10
10
  function _interopNamespace(e) {
11
11
  if (e && e.__esModule) return e;
@@ -50,7 +50,8 @@ var fetchImpl__namespace = /*#__PURE__*/_interopNamespace(fetchImpl);
50
50
  */
51
51
  var FactorId = {
52
52
  /** Phone as second factor */
53
- PHONE: 'phone'
53
+ PHONE: 'phone',
54
+ TOTP: 'totp'
54
55
  };
55
56
  /**
56
57
  * Enumeration of supported providers.
@@ -1048,7 +1049,10 @@ function _performFetchWithErrorHandling(auth, customErrorMap, fetchFn) {
1048
1049
  if (e_1 instanceof util.FirebaseError) {
1049
1050
  throw e_1;
1050
1051
  }
1051
- _fail(auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */, { 'message': String(e_1) });
1052
+ // Changing this to a different error code will log user out when there is a network error
1053
+ // because we treat any error other than NETWORK_REQUEST_FAILED as token is invalid.
1054
+ // https://github.com/firebase/firebase-js-sdk/blob/4fbc73610d70be4e0852e7de63a39cb7897e8546/packages/auth/src/core/auth/auth_impl.ts#L309-L316
1055
+ _fail(auth, "network-request-failed" /* AuthErrorCode.NETWORK_REQUEST_FAILED */, { 'message': String(e_1) });
1052
1056
  return [3 /*break*/, 5];
1053
1057
  case 5: return [2 /*return*/];
1054
1058
  }
@@ -5699,6 +5703,9 @@ var MultiFactorInfoImpl = /** @class */ (function () {
5699
5703
  if ('phoneInfo' in enrollment) {
5700
5704
  return PhoneMultiFactorInfoImpl._fromServerResponse(auth, enrollment);
5701
5705
  }
5706
+ else if ('totpInfo' in enrollment) {
5707
+ return TotpMultiFactorInfoImpl._fromServerResponse(auth, enrollment);
5708
+ }
5702
5709
  return _fail(auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
5703
5710
  };
5704
5711
  return MultiFactorInfoImpl;
@@ -5714,6 +5721,16 @@ var PhoneMultiFactorInfoImpl = /** @class */ (function (_super) {
5714
5721
  return new PhoneMultiFactorInfoImpl(enrollment);
5715
5722
  };
5716
5723
  return PhoneMultiFactorInfoImpl;
5724
+ }(MultiFactorInfoImpl));
5725
+ var TotpMultiFactorInfoImpl = /** @class */ (function (_super) {
5726
+ tslib.__extends(TotpMultiFactorInfoImpl, _super);
5727
+ function TotpMultiFactorInfoImpl(response) {
5728
+ return _super.call(this, "totp" /* FactorId.TOTP */, response) || this;
5729
+ }
5730
+ TotpMultiFactorInfoImpl._fromServerResponse = function (_auth, enrollment) {
5731
+ return new TotpMultiFactorInfoImpl(enrollment);
5732
+ };
5733
+ return TotpMultiFactorInfoImpl;
5717
5734
  }(MultiFactorInfoImpl));
5718
5735
 
5719
5736
  /**
@@ -6936,6 +6953,12 @@ function getMultiFactorResolver(auth, error) {
6936
6953
  * See the License for the specific language governing permissions and
6937
6954
  * limitations under the License.
6938
6955
  */
6956
+ function startEnrollTotpMfa(auth, request) {
6957
+ return _performApiRequest(auth, "POST" /* HttpMethod.POST */, "/v2/accounts/mfaEnrollment:start" /* Endpoint.START_MFA_ENROLLMENT */, _addTidIfNecessary(auth, request));
6958
+ }
6959
+ function finalizeEnrollTotpMfa(auth, request) {
6960
+ return _performApiRequest(auth, "POST" /* HttpMethod.POST */, "/v2/accounts/mfaEnrollment:finalize" /* Endpoint.FINALIZE_MFA_ENROLLMENT */, _addTidIfNecessary(auth, request));
6961
+ }
6939
6962
  function withdrawMfa(auth, request) {
6940
6963
  return _performApiRequest(auth, "POST" /* HttpMethod.POST */, "/v2/accounts/mfaEnrollment:withdraw" /* Endpoint.WITHDRAW_MFA */, _addTidIfNecessary(auth, request));
6941
6964
  }
@@ -7066,7 +7089,7 @@ function multiFactor(user) {
7066
7089
  }
7067
7090
 
7068
7091
  var name = "@firebase/auth";
7069
- var version = "0.21.5";
7092
+ var version = "0.21.6-20230329040242";
7070
7093
 
7071
7094
  /**
7072
7095
  * @license
@@ -7321,6 +7344,216 @@ AuthImpl.prototype.setPersistence = function () { return tslib.__awaiter(void 0,
7321
7344
  return [2 /*return*/];
7322
7345
  }); }); };
7323
7346
 
7347
+ /**
7348
+ * @license
7349
+ * Copyright 2020 Google LLC
7350
+ *
7351
+ * Licensed under the Apache License, Version 2.0 (the "License");
7352
+ * you may not use this file except in compliance with the License.
7353
+ * You may obtain a copy of the License at
7354
+ *
7355
+ * http://www.apache.org/licenses/LICENSE-2.0
7356
+ *
7357
+ * Unless required by applicable law or agreed to in writing, software
7358
+ * distributed under the License is distributed on an "AS IS" BASIS,
7359
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7360
+ * See the License for the specific language governing permissions and
7361
+ * limitations under the License.
7362
+ */
7363
+ function finalizeSignInTotpMfa(auth, request) {
7364
+ return _performApiRequest(auth, "POST" /* HttpMethod.POST */, "/v2/accounts/mfaSignIn:finalize" /* Endpoint.FINALIZE_MFA_SIGN_IN */, _addTidIfNecessary(auth, request));
7365
+ }
7366
+
7367
+ var MultiFactorAssertionImpl = /** @class */ (function () {
7368
+ function MultiFactorAssertionImpl(factorId) {
7369
+ this.factorId = factorId;
7370
+ }
7371
+ MultiFactorAssertionImpl.prototype._process = function (auth, session, displayName) {
7372
+ switch (session.type) {
7373
+ case "enroll" /* MultiFactorSessionType.ENROLL */:
7374
+ return this._finalizeEnroll(auth, session.credential, displayName);
7375
+ case "signin" /* MultiFactorSessionType.SIGN_IN */:
7376
+ return this._finalizeSignIn(auth, session.credential);
7377
+ default:
7378
+ return debugFail('unexpected MultiFactorSessionType');
7379
+ }
7380
+ };
7381
+ return MultiFactorAssertionImpl;
7382
+ }());
7383
+
7384
+ /**
7385
+ * Provider for generating a {@link TotpMultiFactorAssertion}.
7386
+ *
7387
+ * @public
7388
+ */
7389
+ var TotpMultiFactorGenerator = /** @class */ (function () {
7390
+ function TotpMultiFactorGenerator() {
7391
+ }
7392
+ /**
7393
+ * Provides a {@link TotpMultiFactorAssertion} to confirm ownership of
7394
+ * the TOTP (time-based one-time password) second factor.
7395
+ * This assertion is used to complete enrollment in TOTP second factor.
7396
+ *
7397
+ * @param secret A {@link TotpSecret} containing the shared secret key and other TOTP parameters.
7398
+ * @param oneTimePassword One-time password from TOTP App.
7399
+ * @returns A {@link TotpMultiFactorAssertion} which can be used with
7400
+ * {@link MultiFactorUser.enroll}.
7401
+ */
7402
+ TotpMultiFactorGenerator.assertionForEnrollment = function (secret, oneTimePassword) {
7403
+ return TotpMultiFactorAssertionImpl._fromSecret(secret, oneTimePassword);
7404
+ };
7405
+ /**
7406
+ * Provides a {@link TotpMultiFactorAssertion} to confirm ownership of the TOTP second factor.
7407
+ * This assertion is used to complete signIn with TOTP as the second factor.
7408
+ *
7409
+ * @param enrollmentId identifies the enrolled TOTP second factor.
7410
+ * @param oneTimePassword One-time password from TOTP App.
7411
+ * @returns A {@link TotpMultiFactorAssertion} which can be used with
7412
+ * {@link MultiFactorResolver.resolveSignIn}.
7413
+ */
7414
+ TotpMultiFactorGenerator.assertionForSignIn = function (enrollmentId, oneTimePassword) {
7415
+ return TotpMultiFactorAssertionImpl._fromEnrollmentId(enrollmentId, oneTimePassword);
7416
+ };
7417
+ /**
7418
+ * Returns a promise to {@link TotpSecret} which contains the TOTP shared secret key and other parameters.
7419
+ * Creates a TOTP secret as part of enrolling a TOTP second factor.
7420
+ * Used for generating a QR code URL or inputting into a TOTP app.
7421
+ * This method uses the auth instance corresponding to the user in the multiFactorSession.
7422
+ *
7423
+ * @param session The {@link MultiFactorSession} that the user is part of.
7424
+ * @returns A promise to {@link TotpSecret}.
7425
+ */
7426
+ TotpMultiFactorGenerator.generateSecret = function (session) {
7427
+ return tslib.__awaiter(this, void 0, void 0, function () {
7428
+ var mfaSession, response;
7429
+ return tslib.__generator(this, function (_a) {
7430
+ switch (_a.label) {
7431
+ case 0:
7432
+ mfaSession = session;
7433
+ _assert(typeof mfaSession.auth !== 'undefined', "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
7434
+ return [4 /*yield*/, startEnrollTotpMfa(mfaSession.auth, {
7435
+ idToken: mfaSession.credential,
7436
+ totpEnrollmentInfo: {}
7437
+ })];
7438
+ case 1:
7439
+ response = _a.sent();
7440
+ return [2 /*return*/, TotpSecret._fromStartTotpMfaEnrollmentResponse(response, mfaSession.auth)];
7441
+ }
7442
+ });
7443
+ });
7444
+ };
7445
+ /**
7446
+ * The identifier of the TOTP second factor: `totp`.
7447
+ */
7448
+ TotpMultiFactorGenerator.FACTOR_ID = "totp" /* FactorId.TOTP */;
7449
+ return TotpMultiFactorGenerator;
7450
+ }());
7451
+ var TotpMultiFactorAssertionImpl = /** @class */ (function (_super) {
7452
+ tslib.__extends(TotpMultiFactorAssertionImpl, _super);
7453
+ function TotpMultiFactorAssertionImpl(otp, enrollmentId, secret) {
7454
+ var _this = _super.call(this, "totp" /* FactorId.TOTP */) || this;
7455
+ _this.otp = otp;
7456
+ _this.enrollmentId = enrollmentId;
7457
+ _this.secret = secret;
7458
+ return _this;
7459
+ }
7460
+ /** @internal */
7461
+ TotpMultiFactorAssertionImpl._fromSecret = function (secret, otp) {
7462
+ return new TotpMultiFactorAssertionImpl(otp, undefined, secret);
7463
+ };
7464
+ /** @internal */
7465
+ TotpMultiFactorAssertionImpl._fromEnrollmentId = function (enrollmentId, otp) {
7466
+ return new TotpMultiFactorAssertionImpl(otp, enrollmentId);
7467
+ };
7468
+ /** @internal */
7469
+ TotpMultiFactorAssertionImpl.prototype._finalizeEnroll = function (auth, idToken, displayName) {
7470
+ return tslib.__awaiter(this, void 0, void 0, function () {
7471
+ return tslib.__generator(this, function (_a) {
7472
+ _assert(typeof this.secret !== 'undefined', auth, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
7473
+ return [2 /*return*/, finalizeEnrollTotpMfa(auth, {
7474
+ idToken: idToken,
7475
+ displayName: displayName,
7476
+ totpVerificationInfo: this.secret._makeTotpVerificationInfo(this.otp)
7477
+ })];
7478
+ });
7479
+ });
7480
+ };
7481
+ /** @internal */
7482
+ TotpMultiFactorAssertionImpl.prototype._finalizeSignIn = function (auth, mfaPendingCredential) {
7483
+ return tslib.__awaiter(this, void 0, void 0, function () {
7484
+ var totpVerificationInfo;
7485
+ return tslib.__generator(this, function (_a) {
7486
+ _assert(this.enrollmentId !== undefined && this.otp !== undefined, auth, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
7487
+ totpVerificationInfo = { verificationCode: this.otp };
7488
+ return [2 /*return*/, finalizeSignInTotpMfa(auth, {
7489
+ mfaPendingCredential: mfaPendingCredential,
7490
+ mfaEnrollmentId: this.enrollmentId,
7491
+ totpVerificationInfo: totpVerificationInfo
7492
+ })];
7493
+ });
7494
+ });
7495
+ };
7496
+ return TotpMultiFactorAssertionImpl;
7497
+ }(MultiFactorAssertionImpl));
7498
+ /**
7499
+ * Provider for generating a {@link TotpMultiFactorAssertion}.
7500
+ *
7501
+ * Stores the shared secret key and other parameters to generate time-based OTPs.
7502
+ * Implements methods to retrieve the shared secret key and generate a QR code URL.
7503
+ * @public
7504
+ */
7505
+ var TotpSecret = /** @class */ (function () {
7506
+ // The public members are declared outside the constructor so the docs can be generated.
7507
+ function TotpSecret(secretKey, hashingAlgorithm, codeLength, codeIntervalSeconds, enrollmentCompletionDeadline, sessionInfo, auth) {
7508
+ this.sessionInfo = sessionInfo;
7509
+ this.auth = auth;
7510
+ this.secretKey = secretKey;
7511
+ this.hashingAlgorithm = hashingAlgorithm;
7512
+ this.codeLength = codeLength;
7513
+ this.codeIntervalSeconds = codeIntervalSeconds;
7514
+ this.enrollmentCompletionDeadline = enrollmentCompletionDeadline;
7515
+ }
7516
+ /** @internal */
7517
+ TotpSecret._fromStartTotpMfaEnrollmentResponse = function (response, auth) {
7518
+ return new TotpSecret(response.totpSessionInfo.sharedSecretKey, response.totpSessionInfo.hashingAlgorithm, response.totpSessionInfo.verificationCodeLength, response.totpSessionInfo.periodSec, new Date(response.totpSessionInfo.finalizeEnrollmentTime).toUTCString(), response.totpSessionInfo.sessionInfo, auth);
7519
+ };
7520
+ /** @internal */
7521
+ TotpSecret.prototype._makeTotpVerificationInfo = function (otp) {
7522
+ return { sessionInfo: this.sessionInfo, verificationCode: otp };
7523
+ };
7524
+ /**
7525
+ * Returns a QR code URL as described in
7526
+ * https://github.com/google/google-authenticator/wiki/Key-Uri-Format
7527
+ * This can be displayed to the user as a QR code to be scanned into a TOTP app like Google Authenticator.
7528
+ * If the optional parameters are unspecified, an accountName of <userEmail> and issuer of <firebaseAppName> are used.
7529
+ *
7530
+ * @param accountName the name of the account/app along with a user identifier.
7531
+ * @param issuer issuer of the TOTP (likely the app name).
7532
+ * @returns A QR code URL string.
7533
+ */
7534
+ TotpSecret.prototype.generateQrCodeUrl = function (accountName, issuer) {
7535
+ var _a;
7536
+ var useDefaults = false;
7537
+ if (_isEmptyString(accountName) || _isEmptyString(issuer)) {
7538
+ useDefaults = true;
7539
+ }
7540
+ if (useDefaults) {
7541
+ if (_isEmptyString(accountName)) {
7542
+ accountName = ((_a = this.auth.currentUser) === null || _a === void 0 ? void 0 : _a.email) || 'unknownuser';
7543
+ }
7544
+ if (_isEmptyString(issuer)) {
7545
+ issuer = this.auth.name;
7546
+ }
7547
+ }
7548
+ return "otpauth://totp/".concat(issuer, ":").concat(accountName, "?secret=").concat(this.secretKey, "&issuer=").concat(issuer, "&algorithm=").concat(this.hashingAlgorithm, "&digits=").concat(this.codeLength);
7549
+ };
7550
+ return TotpSecret;
7551
+ }());
7552
+ /** @internal */
7553
+ function _isEmptyString(input) {
7554
+ return typeof input === 'undefined' || (input === null || input === void 0 ? void 0 : input.length) === 0;
7555
+ }
7556
+
7324
7557
  exports.AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY = AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY;
7325
7558
  exports.ActionCodeOperation = ActionCodeOperation;
7326
7559
  exports.ActionCodeURL = ActionCodeURL;
@@ -7346,6 +7579,8 @@ exports.RecaptchaVerifier = RecaptchaVerifier;
7346
7579
  exports.SAMLAuthCredential = SAMLAuthCredential;
7347
7580
  exports.SAMLAuthProvider = SAMLAuthProvider;
7348
7581
  exports.SignInMethod = SignInMethod;
7582
+ exports.TotpMultiFactorGenerator = TotpMultiFactorGenerator;
7583
+ exports.TotpSecret = TotpSecret;
7349
7584
  exports.TwitterAuthProvider = TwitterAuthProvider;
7350
7585
  exports.UserImpl = UserImpl;
7351
7586
  exports._assert = _assert;
@@ -7427,4 +7662,4 @@ exports.updateProfile = updateProfile;
7427
7662
  exports.useDeviceLanguage = useDeviceLanguage;
7428
7663
  exports.verifyBeforeUpdateEmail = verifyBeforeUpdateEmail;
7429
7664
  exports.verifyPasswordResetCode = verifyPasswordResetCode;
7430
- //# sourceMappingURL=index-45468d80.js.map
7665
+ //# sourceMappingURL=totp-06ccbed7.js.map