@firebase/auth 0.21.5 → 0.21.6-canary.a8d6499b1

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 (144) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +25 -0
  3. package/dist/auth-public.d.ts +137 -4
  4. package/dist/auth.d.ts +149 -4
  5. package/dist/browser-cjs/{index-ff477525.js → index-a031a7c0.js} +180 -5
  6. package/dist/browser-cjs/index-a031a7c0.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/core/errors.d.ts +1 -0
  15. package/dist/browser-cjs/src/core/index.d.ts +1 -0
  16. package/dist/browser-cjs/src/mfa/assertions/totp.d.ts +124 -0
  17. package/dist/browser-cjs/src/mfa/assertions/totp.test.d.ts +17 -0
  18. package/dist/browser-cjs/src/mfa/mfa_info.d.ts +5 -1
  19. package/dist/browser-cjs/src/model/enum_maps.d.ts +1 -0
  20. package/dist/browser-cjs/src/model/public_types.d.ts +18 -1
  21. package/dist/browser-cjs/test/helpers/integration/helpers.d.ts +3 -0
  22. package/dist/browser-cjs/test/integration/flows/totp.test.d.ts +17 -0
  23. package/dist/cordova/index.d.ts +2 -1
  24. package/dist/cordova/index.js +2 -2
  25. package/dist/cordova/internal.js +179 -3
  26. package/dist/cordova/internal.js.map +1 -1
  27. package/dist/cordova/{popup_redirect-a4d3c436.js → popup_redirect-69cff576.js} +31 -6
  28. package/dist/cordova/popup_redirect-69cff576.js.map +1 -0
  29. package/dist/cordova/src/api/account_management/mfa.d.ts +38 -4
  30. package/dist/cordova/src/api/authentication/mfa.d.ts +11 -0
  31. package/dist/cordova/src/core/errors.d.ts +1 -0
  32. package/dist/cordova/src/core/index.d.ts +1 -0
  33. package/dist/cordova/src/mfa/assertions/totp.d.ts +124 -0
  34. package/dist/cordova/src/mfa/assertions/totp.test.d.ts +17 -0
  35. package/dist/cordova/src/mfa/mfa_info.d.ts +5 -1
  36. package/dist/cordova/src/model/enum_maps.d.ts +1 -0
  37. package/dist/cordova/src/model/public_types.d.ts +18 -1
  38. package/dist/cordova/test/helpers/integration/helpers.d.ts +3 -0
  39. package/dist/cordova/test/integration/flows/totp.test.d.ts +17 -0
  40. package/dist/esm2017/{index-3363a72a.js → index-33f309f3.js} +179 -6
  41. package/dist/esm2017/index-33f309f3.js.map +1 -0
  42. package/dist/esm2017/index.d.ts +2 -1
  43. package/dist/esm2017/index.js +1 -1
  44. package/dist/esm2017/internal.js +2 -2
  45. package/dist/esm2017/src/api/account_management/mfa.d.ts +38 -4
  46. package/dist/esm2017/src/api/authentication/mfa.d.ts +11 -0
  47. package/dist/esm2017/src/core/errors.d.ts +1 -0
  48. package/dist/esm2017/src/core/index.d.ts +1 -0
  49. package/dist/esm2017/src/mfa/assertions/totp.d.ts +124 -0
  50. package/dist/esm2017/src/mfa/assertions/totp.test.d.ts +17 -0
  51. package/dist/esm2017/src/mfa/mfa_info.d.ts +5 -1
  52. package/dist/esm2017/src/model/enum_maps.d.ts +1 -0
  53. package/dist/esm2017/src/model/public_types.d.ts +18 -1
  54. package/dist/esm2017/test/helpers/integration/helpers.d.ts +3 -0
  55. package/dist/esm2017/test/integration/flows/totp.test.d.ts +17 -0
  56. package/dist/esm5/{index-3f05dc7b.js → index-588c4d42.js} +207 -6
  57. package/dist/esm5/index-588c4d42.js.map +1 -0
  58. package/dist/esm5/index.d.ts +2 -1
  59. package/dist/esm5/index.js +1 -1
  60. package/dist/esm5/internal.js +2 -2
  61. package/dist/esm5/src/api/account_management/mfa.d.ts +38 -4
  62. package/dist/esm5/src/api/authentication/mfa.d.ts +11 -0
  63. package/dist/esm5/src/core/errors.d.ts +1 -0
  64. package/dist/esm5/src/core/index.d.ts +1 -0
  65. package/dist/esm5/src/mfa/assertions/totp.d.ts +124 -0
  66. package/dist/esm5/src/mfa/assertions/totp.test.d.ts +17 -0
  67. package/dist/esm5/src/mfa/mfa_info.d.ts +5 -1
  68. package/dist/esm5/src/model/enum_maps.d.ts +1 -0
  69. package/dist/esm5/src/model/public_types.d.ts +18 -1
  70. package/dist/esm5/test/helpers/integration/helpers.d.ts +3 -0
  71. package/dist/esm5/test/integration/flows/totp.test.d.ts +17 -0
  72. package/dist/index.d.ts +2 -1
  73. package/dist/index.webworker.esm5.js +23 -4
  74. package/dist/index.webworker.esm5.js.map +1 -1
  75. package/dist/node/index.d.ts +2 -1
  76. package/dist/node/index.js +83 -81
  77. package/dist/node/index.js.map +1 -1
  78. package/dist/node/internal.js +144 -142
  79. package/dist/node/internal.js.map +1 -1
  80. package/dist/node/src/api/account_management/mfa.d.ts +38 -4
  81. package/dist/node/src/api/authentication/mfa.d.ts +11 -0
  82. package/dist/node/src/core/errors.d.ts +1 -0
  83. package/dist/node/src/core/index.d.ts +1 -0
  84. package/dist/node/src/mfa/assertions/totp.d.ts +124 -0
  85. package/dist/node/src/mfa/assertions/totp.test.d.ts +17 -0
  86. package/dist/node/src/mfa/mfa_info.d.ts +5 -1
  87. package/dist/node/src/model/enum_maps.d.ts +1 -0
  88. package/dist/node/src/model/public_types.d.ts +18 -1
  89. package/dist/node/test/helpers/integration/helpers.d.ts +3 -0
  90. package/dist/node/test/integration/flows/totp.test.d.ts +17 -0
  91. package/dist/node/{index-45468d80.js → totp-4f539e73.js} +243 -6
  92. package/dist/node/totp-4f539e73.js.map +1 -0
  93. package/dist/node-esm/index.d.ts +2 -1
  94. package/dist/node-esm/index.js +2 -2
  95. package/dist/node-esm/internal.js +3 -3
  96. package/dist/node-esm/src/api/account_management/mfa.d.ts +38 -4
  97. package/dist/node-esm/src/api/authentication/mfa.d.ts +11 -0
  98. package/dist/node-esm/src/core/errors.d.ts +1 -0
  99. package/dist/node-esm/src/core/index.d.ts +1 -0
  100. package/dist/node-esm/src/mfa/assertions/totp.d.ts +124 -0
  101. package/dist/node-esm/src/mfa/assertions/totp.test.d.ts +17 -0
  102. package/dist/node-esm/src/mfa/mfa_info.d.ts +5 -1
  103. package/dist/node-esm/src/model/enum_maps.d.ts +1 -0
  104. package/dist/node-esm/src/model/public_types.d.ts +18 -1
  105. package/dist/node-esm/test/helpers/integration/helpers.d.ts +3 -0
  106. package/dist/node-esm/test/integration/flows/totp.test.d.ts +17 -0
  107. package/dist/node-esm/{index-1f9492de.js → totp-aec70fa2.js} +213 -7
  108. package/dist/node-esm/totp-aec70fa2.js.map +1 -0
  109. package/dist/rn/index.d.ts +2 -1
  110. package/dist/rn/index.js +1 -1
  111. package/dist/rn/internal.js +176 -1
  112. package/dist/rn/internal.js.map +1 -1
  113. package/dist/rn/{phone-e7bf48a1.js → phone-a38a417c.js} +37 -5
  114. package/dist/rn/phone-a38a417c.js.map +1 -0
  115. package/dist/rn/src/api/account_management/mfa.d.ts +38 -4
  116. package/dist/rn/src/api/authentication/mfa.d.ts +11 -0
  117. package/dist/rn/src/core/errors.d.ts +1 -0
  118. package/dist/rn/src/core/index.d.ts +1 -0
  119. package/dist/rn/src/mfa/assertions/totp.d.ts +124 -0
  120. package/dist/rn/src/mfa/assertions/totp.test.d.ts +17 -0
  121. package/dist/rn/src/mfa/mfa_info.d.ts +5 -1
  122. package/dist/rn/src/model/enum_maps.d.ts +1 -0
  123. package/dist/rn/src/model/public_types.d.ts +18 -1
  124. package/dist/rn/test/helpers/integration/helpers.d.ts +3 -0
  125. package/dist/rn/test/integration/flows/totp.test.d.ts +17 -0
  126. package/dist/src/api/account_management/mfa.d.ts +38 -4
  127. package/dist/src/api/authentication/mfa.d.ts +11 -0
  128. package/dist/src/core/errors.d.ts +1 -0
  129. package/dist/src/core/index.d.ts +1 -0
  130. package/dist/src/mfa/assertions/totp.d.ts +124 -0
  131. package/dist/src/mfa/assertions/totp.test.d.ts +17 -0
  132. package/dist/src/mfa/mfa_info.d.ts +5 -1
  133. package/dist/src/model/enum_maps.d.ts +1 -0
  134. package/dist/src/model/public_types.d.ts +18 -1
  135. package/dist/test/helpers/integration/helpers.d.ts +3 -0
  136. package/dist/test/integration/flows/totp.test.d.ts +17 -0
  137. package/package.json +10 -8
  138. package/dist/browser-cjs/index-ff477525.js.map +0 -1
  139. package/dist/cordova/popup_redirect-a4d3c436.js.map +0 -1
  140. package/dist/esm2017/index-3363a72a.js.map +0 -1
  141. package/dist/esm5/index-3f05dc7b.js.map +0 -1
  142. package/dist/node/index-45468d80.js.map +0 -1
  143. package/dist/node-esm/index-1f9492de.js.map +0 -1
  144. package/dist/rn/phone-e7bf48a1.js.map +0 -1
@@ -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.
@@ -235,6 +236,7 @@ function _debugErrorMap() {
235
236
  _a["missing-or-invalid-nonce" /* AuthErrorCode.MISSING_OR_INVALID_NONCE */] = 'The request does not contain a valid nonce. This can occur if the ' +
236
237
  'SHA-256 hash of the provided raw nonce does not match the hashed nonce ' +
237
238
  'in the ID token payload.',
239
+ _a["missing-password" /* AuthErrorCode.MISSING_PASSWORD */] = 'A non-empty password must be provided',
238
240
  _a["missing-multi-factor-info" /* AuthErrorCode.MISSING_MFA_INFO */] = 'No second factor identifier is provided.',
239
241
  _a["missing-multi-factor-session" /* AuthErrorCode.MISSING_MFA_SESSION */] = 'The request is missing proof of first factor successful sign-in.',
240
242
  _a["missing-phone-number" /* AuthErrorCode.MISSING_PHONE_NUMBER */] = 'To send verification codes, provide a phone number for the recipient.',
@@ -879,7 +881,7 @@ var SERVER_ERROR_MAP = (_a$1 = {},
879
881
  // Sign in with email and password errors (some apply to sign up too).
880
882
  _a$1["INVALID_PASSWORD" /* ServerError.INVALID_PASSWORD */] = "wrong-password" /* AuthErrorCode.INVALID_PASSWORD */,
881
883
  // This can only happen if the SDK sends a bad request.
882
- _a$1["MISSING_PASSWORD" /* ServerError.MISSING_PASSWORD */] = "internal-error" /* AuthErrorCode.INTERNAL_ERROR */,
884
+ _a$1["MISSING_PASSWORD" /* ServerError.MISSING_PASSWORD */] = "missing-password" /* AuthErrorCode.MISSING_PASSWORD */,
883
885
  // Sign up with email and password errors.
884
886
  _a$1["EMAIL_EXISTS" /* ServerError.EMAIL_EXISTS */] = "email-already-in-use" /* AuthErrorCode.EMAIL_EXISTS */,
885
887
  _a$1["PASSWORD_LOGIN_DISABLED" /* ServerError.PASSWORD_LOGIN_DISABLED */] = "operation-not-allowed" /* AuthErrorCode.OPERATION_NOT_ALLOWED */,
@@ -1048,7 +1050,10 @@ function _performFetchWithErrorHandling(auth, customErrorMap, fetchFn) {
1048
1050
  if (e_1 instanceof util.FirebaseError) {
1049
1051
  throw e_1;
1050
1052
  }
1051
- _fail(auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */, { 'message': String(e_1) });
1053
+ // Changing this to a different error code will log user out when there is a network error
1054
+ // because we treat any error other than NETWORK_REQUEST_FAILED as token is invalid.
1055
+ // https://github.com/firebase/firebase-js-sdk/blob/4fbc73610d70be4e0852e7de63a39cb7897e8546/packages/auth/src/core/auth/auth_impl.ts#L309-L316
1056
+ _fail(auth, "network-request-failed" /* AuthErrorCode.NETWORK_REQUEST_FAILED */, { 'message': String(e_1) });
1052
1057
  return [3 /*break*/, 5];
1053
1058
  case 5: return [2 /*return*/];
1054
1059
  }
@@ -5699,6 +5704,9 @@ var MultiFactorInfoImpl = /** @class */ (function () {
5699
5704
  if ('phoneInfo' in enrollment) {
5700
5705
  return PhoneMultiFactorInfoImpl._fromServerResponse(auth, enrollment);
5701
5706
  }
5707
+ else if ('totpInfo' in enrollment) {
5708
+ return TotpMultiFactorInfoImpl._fromServerResponse(auth, enrollment);
5709
+ }
5702
5710
  return _fail(auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
5703
5711
  };
5704
5712
  return MultiFactorInfoImpl;
@@ -5714,6 +5722,16 @@ var PhoneMultiFactorInfoImpl = /** @class */ (function (_super) {
5714
5722
  return new PhoneMultiFactorInfoImpl(enrollment);
5715
5723
  };
5716
5724
  return PhoneMultiFactorInfoImpl;
5725
+ }(MultiFactorInfoImpl));
5726
+ var TotpMultiFactorInfoImpl = /** @class */ (function (_super) {
5727
+ tslib.__extends(TotpMultiFactorInfoImpl, _super);
5728
+ function TotpMultiFactorInfoImpl(response) {
5729
+ return _super.call(this, "totp" /* FactorId.TOTP */, response) || this;
5730
+ }
5731
+ TotpMultiFactorInfoImpl._fromServerResponse = function (_auth, enrollment) {
5732
+ return new TotpMultiFactorInfoImpl(enrollment);
5733
+ };
5734
+ return TotpMultiFactorInfoImpl;
5717
5735
  }(MultiFactorInfoImpl));
5718
5736
 
5719
5737
  /**
@@ -6680,6 +6698,7 @@ function setPersistence(auth, persistence) {
6680
6698
  *
6681
6699
  * @remarks
6682
6700
  * This includes sign-in, sign-out, and token refresh events.
6701
+ * This will not be triggered automatically upon ID token expiration. Use {@link User.getIdToken} to refresh the ID token.
6683
6702
  *
6684
6703
  * @param auth - The {@link Auth} instance.
6685
6704
  * @param nextOrObserver - callback triggered on change.
@@ -6936,6 +6955,12 @@ function getMultiFactorResolver(auth, error) {
6936
6955
  * See the License for the specific language governing permissions and
6937
6956
  * limitations under the License.
6938
6957
  */
6958
+ function startEnrollTotpMfa(auth, request) {
6959
+ return _performApiRequest(auth, "POST" /* HttpMethod.POST */, "/v2/accounts/mfaEnrollment:start" /* Endpoint.START_MFA_ENROLLMENT */, _addTidIfNecessary(auth, request));
6960
+ }
6961
+ function finalizeEnrollTotpMfa(auth, request) {
6962
+ return _performApiRequest(auth, "POST" /* HttpMethod.POST */, "/v2/accounts/mfaEnrollment:finalize" /* Endpoint.FINALIZE_MFA_ENROLLMENT */, _addTidIfNecessary(auth, request));
6963
+ }
6939
6964
  function withdrawMfa(auth, request) {
6940
6965
  return _performApiRequest(auth, "POST" /* HttpMethod.POST */, "/v2/accounts/mfaEnrollment:withdraw" /* Endpoint.WITHDRAW_MFA */, _addTidIfNecessary(auth, request));
6941
6966
  }
@@ -7066,7 +7091,7 @@ function multiFactor(user) {
7066
7091
  }
7067
7092
 
7068
7093
  var name = "@firebase/auth";
7069
- var version = "0.21.5";
7094
+ var version = "0.21.6-canary.a8d6499b1";
7070
7095
 
7071
7096
  /**
7072
7097
  * @license
@@ -7321,6 +7346,216 @@ AuthImpl.prototype.setPersistence = function () { return tslib.__awaiter(void 0,
7321
7346
  return [2 /*return*/];
7322
7347
  }); }); };
7323
7348
 
7349
+ /**
7350
+ * @license
7351
+ * Copyright 2020 Google LLC
7352
+ *
7353
+ * Licensed under the Apache License, Version 2.0 (the "License");
7354
+ * you may not use this file except in compliance with the License.
7355
+ * You may obtain a copy of the License at
7356
+ *
7357
+ * http://www.apache.org/licenses/LICENSE-2.0
7358
+ *
7359
+ * Unless required by applicable law or agreed to in writing, software
7360
+ * distributed under the License is distributed on an "AS IS" BASIS,
7361
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7362
+ * See the License for the specific language governing permissions and
7363
+ * limitations under the License.
7364
+ */
7365
+ function finalizeSignInTotpMfa(auth, request) {
7366
+ return _performApiRequest(auth, "POST" /* HttpMethod.POST */, "/v2/accounts/mfaSignIn:finalize" /* Endpoint.FINALIZE_MFA_SIGN_IN */, _addTidIfNecessary(auth, request));
7367
+ }
7368
+
7369
+ var MultiFactorAssertionImpl = /** @class */ (function () {
7370
+ function MultiFactorAssertionImpl(factorId) {
7371
+ this.factorId = factorId;
7372
+ }
7373
+ MultiFactorAssertionImpl.prototype._process = function (auth, session, displayName) {
7374
+ switch (session.type) {
7375
+ case "enroll" /* MultiFactorSessionType.ENROLL */:
7376
+ return this._finalizeEnroll(auth, session.credential, displayName);
7377
+ case "signin" /* MultiFactorSessionType.SIGN_IN */:
7378
+ return this._finalizeSignIn(auth, session.credential);
7379
+ default:
7380
+ return debugFail('unexpected MultiFactorSessionType');
7381
+ }
7382
+ };
7383
+ return MultiFactorAssertionImpl;
7384
+ }());
7385
+
7386
+ /**
7387
+ * Provider for generating a {@link TotpMultiFactorAssertion}.
7388
+ *
7389
+ * @public
7390
+ */
7391
+ var TotpMultiFactorGenerator = /** @class */ (function () {
7392
+ function TotpMultiFactorGenerator() {
7393
+ }
7394
+ /**
7395
+ * Provides a {@link TotpMultiFactorAssertion} to confirm ownership of
7396
+ * the TOTP (time-based one-time password) second factor.
7397
+ * This assertion is used to complete enrollment in TOTP second factor.
7398
+ *
7399
+ * @param secret A {@link TotpSecret} containing the shared secret key and other TOTP parameters.
7400
+ * @param oneTimePassword One-time password from TOTP App.
7401
+ * @returns A {@link TotpMultiFactorAssertion} which can be used with
7402
+ * {@link MultiFactorUser.enroll}.
7403
+ */
7404
+ TotpMultiFactorGenerator.assertionForEnrollment = function (secret, oneTimePassword) {
7405
+ return TotpMultiFactorAssertionImpl._fromSecret(secret, oneTimePassword);
7406
+ };
7407
+ /**
7408
+ * Provides a {@link TotpMultiFactorAssertion} to confirm ownership of the TOTP second factor.
7409
+ * This assertion is used to complete signIn with TOTP as the second factor.
7410
+ *
7411
+ * @param enrollmentId identifies the enrolled TOTP second factor.
7412
+ * @param oneTimePassword One-time password from TOTP App.
7413
+ * @returns A {@link TotpMultiFactorAssertion} which can be used with
7414
+ * {@link MultiFactorResolver.resolveSignIn}.
7415
+ */
7416
+ TotpMultiFactorGenerator.assertionForSignIn = function (enrollmentId, oneTimePassword) {
7417
+ return TotpMultiFactorAssertionImpl._fromEnrollmentId(enrollmentId, oneTimePassword);
7418
+ };
7419
+ /**
7420
+ * Returns a promise to {@link TotpSecret} which contains the TOTP shared secret key and other parameters.
7421
+ * Creates a TOTP secret as part of enrolling a TOTP second factor.
7422
+ * Used for generating a QR code URL or inputting into a TOTP app.
7423
+ * This method uses the auth instance corresponding to the user in the multiFactorSession.
7424
+ *
7425
+ * @param session The {@link MultiFactorSession} that the user is part of.
7426
+ * @returns A promise to {@link TotpSecret}.
7427
+ */
7428
+ TotpMultiFactorGenerator.generateSecret = function (session) {
7429
+ return tslib.__awaiter(this, void 0, void 0, function () {
7430
+ var mfaSession, response;
7431
+ return tslib.__generator(this, function (_a) {
7432
+ switch (_a.label) {
7433
+ case 0:
7434
+ mfaSession = session;
7435
+ _assert(typeof mfaSession.auth !== 'undefined', "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
7436
+ return [4 /*yield*/, startEnrollTotpMfa(mfaSession.auth, {
7437
+ idToken: mfaSession.credential,
7438
+ totpEnrollmentInfo: {}
7439
+ })];
7440
+ case 1:
7441
+ response = _a.sent();
7442
+ return [2 /*return*/, TotpSecret._fromStartTotpMfaEnrollmentResponse(response, mfaSession.auth)];
7443
+ }
7444
+ });
7445
+ });
7446
+ };
7447
+ /**
7448
+ * The identifier of the TOTP second factor: `totp`.
7449
+ */
7450
+ TotpMultiFactorGenerator.FACTOR_ID = "totp" /* FactorId.TOTP */;
7451
+ return TotpMultiFactorGenerator;
7452
+ }());
7453
+ var TotpMultiFactorAssertionImpl = /** @class */ (function (_super) {
7454
+ tslib.__extends(TotpMultiFactorAssertionImpl, _super);
7455
+ function TotpMultiFactorAssertionImpl(otp, enrollmentId, secret) {
7456
+ var _this = _super.call(this, "totp" /* FactorId.TOTP */) || this;
7457
+ _this.otp = otp;
7458
+ _this.enrollmentId = enrollmentId;
7459
+ _this.secret = secret;
7460
+ return _this;
7461
+ }
7462
+ /** @internal */
7463
+ TotpMultiFactorAssertionImpl._fromSecret = function (secret, otp) {
7464
+ return new TotpMultiFactorAssertionImpl(otp, undefined, secret);
7465
+ };
7466
+ /** @internal */
7467
+ TotpMultiFactorAssertionImpl._fromEnrollmentId = function (enrollmentId, otp) {
7468
+ return new TotpMultiFactorAssertionImpl(otp, enrollmentId);
7469
+ };
7470
+ /** @internal */
7471
+ TotpMultiFactorAssertionImpl.prototype._finalizeEnroll = function (auth, idToken, displayName) {
7472
+ return tslib.__awaiter(this, void 0, void 0, function () {
7473
+ return tslib.__generator(this, function (_a) {
7474
+ _assert(typeof this.secret !== 'undefined', auth, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
7475
+ return [2 /*return*/, finalizeEnrollTotpMfa(auth, {
7476
+ idToken: idToken,
7477
+ displayName: displayName,
7478
+ totpVerificationInfo: this.secret._makeTotpVerificationInfo(this.otp)
7479
+ })];
7480
+ });
7481
+ });
7482
+ };
7483
+ /** @internal */
7484
+ TotpMultiFactorAssertionImpl.prototype._finalizeSignIn = function (auth, mfaPendingCredential) {
7485
+ return tslib.__awaiter(this, void 0, void 0, function () {
7486
+ var totpVerificationInfo;
7487
+ return tslib.__generator(this, function (_a) {
7488
+ _assert(this.enrollmentId !== undefined && this.otp !== undefined, auth, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
7489
+ totpVerificationInfo = { verificationCode: this.otp };
7490
+ return [2 /*return*/, finalizeSignInTotpMfa(auth, {
7491
+ mfaPendingCredential: mfaPendingCredential,
7492
+ mfaEnrollmentId: this.enrollmentId,
7493
+ totpVerificationInfo: totpVerificationInfo
7494
+ })];
7495
+ });
7496
+ });
7497
+ };
7498
+ return TotpMultiFactorAssertionImpl;
7499
+ }(MultiFactorAssertionImpl));
7500
+ /**
7501
+ * Provider for generating a {@link TotpMultiFactorAssertion}.
7502
+ *
7503
+ * Stores the shared secret key and other parameters to generate time-based OTPs.
7504
+ * Implements methods to retrieve the shared secret key and generate a QR code URL.
7505
+ * @public
7506
+ */
7507
+ var TotpSecret = /** @class */ (function () {
7508
+ // The public members are declared outside the constructor so the docs can be generated.
7509
+ function TotpSecret(secretKey, hashingAlgorithm, codeLength, codeIntervalSeconds, enrollmentCompletionDeadline, sessionInfo, auth) {
7510
+ this.sessionInfo = sessionInfo;
7511
+ this.auth = auth;
7512
+ this.secretKey = secretKey;
7513
+ this.hashingAlgorithm = hashingAlgorithm;
7514
+ this.codeLength = codeLength;
7515
+ this.codeIntervalSeconds = codeIntervalSeconds;
7516
+ this.enrollmentCompletionDeadline = enrollmentCompletionDeadline;
7517
+ }
7518
+ /** @internal */
7519
+ TotpSecret._fromStartTotpMfaEnrollmentResponse = function (response, auth) {
7520
+ 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);
7521
+ };
7522
+ /** @internal */
7523
+ TotpSecret.prototype._makeTotpVerificationInfo = function (otp) {
7524
+ return { sessionInfo: this.sessionInfo, verificationCode: otp };
7525
+ };
7526
+ /**
7527
+ * Returns a QR code URL as described in
7528
+ * https://github.com/google/google-authenticator/wiki/Key-Uri-Format
7529
+ * This can be displayed to the user as a QR code to be scanned into a TOTP app like Google Authenticator.
7530
+ * If the optional parameters are unspecified, an accountName of <userEmail> and issuer of <firebaseAppName> are used.
7531
+ *
7532
+ * @param accountName the name of the account/app along with a user identifier.
7533
+ * @param issuer issuer of the TOTP (likely the app name).
7534
+ * @returns A QR code URL string.
7535
+ */
7536
+ TotpSecret.prototype.generateQrCodeUrl = function (accountName, issuer) {
7537
+ var _a;
7538
+ var useDefaults = false;
7539
+ if (_isEmptyString(accountName) || _isEmptyString(issuer)) {
7540
+ useDefaults = true;
7541
+ }
7542
+ if (useDefaults) {
7543
+ if (_isEmptyString(accountName)) {
7544
+ accountName = ((_a = this.auth.currentUser) === null || _a === void 0 ? void 0 : _a.email) || 'unknownuser';
7545
+ }
7546
+ if (_isEmptyString(issuer)) {
7547
+ issuer = this.auth.name;
7548
+ }
7549
+ }
7550
+ return "otpauth://totp/".concat(issuer, ":").concat(accountName, "?secret=").concat(this.secretKey, "&issuer=").concat(issuer, "&algorithm=").concat(this.hashingAlgorithm, "&digits=").concat(this.codeLength);
7551
+ };
7552
+ return TotpSecret;
7553
+ }());
7554
+ /** @internal */
7555
+ function _isEmptyString(input) {
7556
+ return typeof input === 'undefined' || (input === null || input === void 0 ? void 0 : input.length) === 0;
7557
+ }
7558
+
7324
7559
  exports.AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY = AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY;
7325
7560
  exports.ActionCodeOperation = ActionCodeOperation;
7326
7561
  exports.ActionCodeURL = ActionCodeURL;
@@ -7346,6 +7581,8 @@ exports.RecaptchaVerifier = RecaptchaVerifier;
7346
7581
  exports.SAMLAuthCredential = SAMLAuthCredential;
7347
7582
  exports.SAMLAuthProvider = SAMLAuthProvider;
7348
7583
  exports.SignInMethod = SignInMethod;
7584
+ exports.TotpMultiFactorGenerator = TotpMultiFactorGenerator;
7585
+ exports.TotpSecret = TotpSecret;
7349
7586
  exports.TwitterAuthProvider = TwitterAuthProvider;
7350
7587
  exports.UserImpl = UserImpl;
7351
7588
  exports._assert = _assert;
@@ -7427,4 +7664,4 @@ exports.updateProfile = updateProfile;
7427
7664
  exports.useDeviceLanguage = useDeviceLanguage;
7428
7665
  exports.verifyBeforeUpdateEmail = verifyBeforeUpdateEmail;
7429
7666
  exports.verifyPasswordResetCode = verifyPasswordResetCode;
7430
- //# sourceMappingURL=index-45468d80.js.map
7667
+ //# sourceMappingURL=totp-4f539e73.js.map