@firebase/auth 1.3.0 → 1.3.1-canary.6e4e475f6

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 (82) hide show
  1. package/dist/auth-public.d.ts +25 -4
  2. package/dist/auth.d.ts +25 -4
  3. package/dist/browser-cjs/{index-68b50c51.js → index-e3e2566b.js} +133 -127
  4. package/dist/browser-cjs/index-e3e2566b.js.map +1 -0
  5. package/dist/browser-cjs/index.js +1 -1
  6. package/dist/browser-cjs/index.rn.d.ts +1 -0
  7. package/dist/browser-cjs/internal.js +1 -1
  8. package/dist/browser-cjs/src/api/authentication/recaptcha.d.ts +2 -2
  9. package/dist/browser-cjs/src/api/index.d.ts +10 -0
  10. package/dist/browser-cjs/src/platform_browser/recaptcha/recaptcha.d.ts +18 -3
  11. package/dist/browser-cjs/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +3 -0
  12. package/dist/cordova/index.js +2 -2
  13. package/dist/cordova/index.rn.d.ts +1 -0
  14. package/dist/cordova/internal.js +2 -2
  15. package/dist/cordova/{popup_redirect-0a78e29a.js → popup_redirect-9973210d.js} +183 -214
  16. package/dist/cordova/popup_redirect-9973210d.js.map +1 -0
  17. package/dist/cordova/src/api/authentication/recaptcha.d.ts +2 -2
  18. package/dist/cordova/src/api/index.d.ts +10 -0
  19. package/dist/cordova/src/platform_browser/recaptcha/recaptcha.d.ts +18 -3
  20. package/dist/cordova/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +3 -0
  21. package/dist/esm2017/{index-9a76d29a.js → index-aaffd0fc.js} +133 -127
  22. package/dist/esm2017/index-aaffd0fc.js.map +1 -0
  23. package/dist/esm2017/index.js +1 -1
  24. package/dist/esm2017/index.rn.d.ts +1 -0
  25. package/dist/esm2017/internal.js +2 -2
  26. package/dist/esm2017/src/api/authentication/recaptcha.d.ts +2 -2
  27. package/dist/esm2017/src/api/index.d.ts +10 -0
  28. package/dist/esm2017/src/platform_browser/recaptcha/recaptcha.d.ts +18 -3
  29. package/dist/esm2017/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +3 -0
  30. package/dist/esm5/{index-3f0ee8ce.js → index-044bfa44.js} +183 -214
  31. package/dist/esm5/index-044bfa44.js.map +1 -0
  32. package/dist/esm5/index.js +1 -1
  33. package/dist/esm5/index.rn.d.ts +1 -0
  34. package/dist/esm5/internal.js +2 -2
  35. package/dist/esm5/src/api/authentication/recaptcha.d.ts +2 -2
  36. package/dist/esm5/src/api/index.d.ts +10 -0
  37. package/dist/esm5/src/platform_browser/recaptcha/recaptcha.d.ts +18 -3
  38. package/dist/esm5/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +3 -0
  39. package/dist/index.rn.d.ts +1 -0
  40. package/dist/index.webworker.esm5.js +141 -172
  41. package/dist/index.webworker.esm5.js.map +1 -1
  42. package/dist/node/index.js +1 -1
  43. package/dist/node/index.rn.d.ts +1 -0
  44. package/dist/node/internal.js +1 -1
  45. package/dist/node/src/api/authentication/recaptcha.d.ts +2 -2
  46. package/dist/node/src/api/index.d.ts +10 -0
  47. package/dist/node/src/platform_browser/recaptcha/recaptcha.d.ts +18 -3
  48. package/dist/node/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +3 -0
  49. package/dist/node/{totp-cceb0d01.js → totp-c47e7a9e.js} +179 -210
  50. package/dist/node/totp-c47e7a9e.js.map +1 -0
  51. package/dist/node-esm/index.js +1 -1
  52. package/dist/node-esm/index.rn.d.ts +1 -0
  53. package/dist/node-esm/internal.js +2 -2
  54. package/dist/node-esm/src/api/authentication/recaptcha.d.ts +2 -2
  55. package/dist/node-esm/src/api/index.d.ts +10 -0
  56. package/dist/node-esm/src/platform_browser/recaptcha/recaptcha.d.ts +18 -3
  57. package/dist/node-esm/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +3 -0
  58. package/dist/node-esm/{totp-64a935f2.js → totp-898d4014.js} +129 -123
  59. package/dist/node-esm/totp-898d4014.js.map +1 -0
  60. package/dist/rn/{index-1dd41d18.js → index-9dc6fdd2.js} +359 -218
  61. package/dist/rn/index-9dc6fdd2.js.map +1 -0
  62. package/dist/rn/index.js +3 -1
  63. package/dist/rn/index.js.map +1 -1
  64. package/dist/rn/index.rn.d.ts +1 -0
  65. package/dist/rn/internal.js +3 -177
  66. package/dist/rn/internal.js.map +1 -1
  67. package/dist/rn/src/api/authentication/recaptcha.d.ts +2 -2
  68. package/dist/rn/src/api/index.d.ts +10 -0
  69. package/dist/rn/src/platform_browser/recaptcha/recaptcha.d.ts +18 -3
  70. package/dist/rn/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +3 -0
  71. package/dist/src/api/authentication/recaptcha.d.ts +2 -2
  72. package/dist/src/api/index.d.ts +10 -0
  73. package/dist/src/platform_browser/recaptcha/recaptcha.d.ts +18 -3
  74. package/dist/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +3 -0
  75. package/package.json +12 -12
  76. package/dist/browser-cjs/index-68b50c51.js.map +0 -1
  77. package/dist/cordova/popup_redirect-0a78e29a.js.map +0 -1
  78. package/dist/esm2017/index-9a76d29a.js.map +0 -1
  79. package/dist/esm5/index-3f0ee8ce.js.map +0 -1
  80. package/dist/node/totp-cceb0d01.js.map +0 -1
  81. package/dist/node-esm/totp-64a935f2.js.map +0 -1
  82. package/dist/rn/index-1dd41d18.js.map +0 -1
@@ -6,53 +6,6 @@ var app = require('@firebase/app');
6
6
  var component = require('@firebase/component');
7
7
  var logger = require('@firebase/logger');
8
8
 
9
- /**
10
- * @license
11
- * Copyright 2020 Google LLC
12
- *
13
- * Licensed under the Apache License, Version 2.0 (the "License");
14
- * you may not use this file except in compliance with the License.
15
- * You may obtain a copy of the License at
16
- *
17
- * http://www.apache.org/licenses/LICENSE-2.0
18
- *
19
- * Unless required by applicable law or agreed to in writing, software
20
- * distributed under the License is distributed on an "AS IS" BASIS,
21
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
- * See the License for the specific language governing permissions and
23
- * limitations under the License.
24
- */
25
- function isV2(grecaptcha) {
26
- return (grecaptcha !== undefined &&
27
- grecaptcha.getResponse !== undefined);
28
- }
29
- function isEnterprise(grecaptcha) {
30
- return (grecaptcha !== undefined &&
31
- grecaptcha.enterprise !== undefined);
32
- }
33
- var RecaptchaConfig = /** @class */ (function () {
34
- function RecaptchaConfig(response) {
35
- /**
36
- * The reCAPTCHA site key.
37
- */
38
- this.siteKey = '';
39
- /**
40
- * The reCAPTCHA enablement status of the {@link EmailAuthProvider} for the current tenant.
41
- */
42
- this.emailPasswordEnabled = false;
43
- if (response.recaptchaKey === undefined) {
44
- throw new Error('recaptchaKey undefined');
45
- }
46
- // Example response.recaptchaKey: "projects/proj123/keys/sitekey123"
47
- this.siteKey = response.recaptchaKey.split('/')[3];
48
- this.emailPasswordEnabled = response.recaptchaEnforcementState.some(function (enforcementState) {
49
- return enforcementState.provider === 'EMAIL_PASSWORD_PROVIDER' &&
50
- enforcementState.enforcementState !== 'OFF';
51
- });
52
- }
53
- return RecaptchaConfig;
54
- }());
55
-
56
9
  /**
57
10
  * @license
58
11
  * Copyright 2020 Google LLC
@@ -693,6 +646,12 @@ var FetchProvider = /** @class */ (function () {
693
646
  if (typeof self !== 'undefined' && 'fetch' in self) {
694
647
  return self.fetch;
695
648
  }
649
+ if (typeof globalThis !== 'undefined' && globalThis.fetch) {
650
+ return globalThis.fetch;
651
+ }
652
+ if (typeof fetch !== 'undefined') {
653
+ return fetch;
654
+ }
696
655
  debugFail('Could not find fetch implementation, make sure you call FetchProvider.initialize() with an appropriate polyfill');
697
656
  };
698
657
  FetchProvider.headers = function () {
@@ -702,6 +661,12 @@ var FetchProvider = /** @class */ (function () {
702
661
  if (typeof self !== 'undefined' && 'Headers' in self) {
703
662
  return self.Headers;
704
663
  }
664
+ if (typeof globalThis !== 'undefined' && globalThis.Headers) {
665
+ return globalThis.Headers;
666
+ }
667
+ if (typeof Headers !== 'undefined') {
668
+ return Headers;
669
+ }
705
670
  debugFail('Could not find Headers implementation, make sure you call FetchProvider.initialize() with an appropriate polyfill');
706
671
  };
707
672
  FetchProvider.response = function () {
@@ -711,6 +676,12 @@ var FetchProvider = /** @class */ (function () {
711
676
  if (typeof self !== 'undefined' && 'Response' in self) {
712
677
  return self.Response;
713
678
  }
679
+ if (typeof globalThis !== 'undefined' && globalThis.Response) {
680
+ return globalThis.Response;
681
+ }
682
+ if (typeof Response !== 'undefined') {
683
+ return Response;
684
+ }
714
685
  debugFail('Could not find Response implementation, make sure you call FetchProvider.initialize() with an appropriate polyfill');
715
686
  };
716
687
  return FetchProvider;
@@ -963,6 +934,18 @@ function _getFinalTarget(auth, host, path, query) {
963
934
  }
964
935
  return _emulatorUrl(auth.config, base);
965
936
  }
937
+ function _parseEnforcementState(enforcementStateStr) {
938
+ switch (enforcementStateStr) {
939
+ case 'ENFORCE':
940
+ return "ENFORCE" /* EnforcementState.ENFORCE */;
941
+ case 'AUDIT':
942
+ return "AUDIT" /* EnforcementState.AUDIT */;
943
+ case 'OFF':
944
+ return "OFF" /* EnforcementState.OFF */;
945
+ default:
946
+ return "ENFORCEMENT_STATE_UNSPECIFIED" /* EnforcementState.ENFORCEMENT_STATE_UNSPECIFIED */;
947
+ }
948
+ }
966
949
  var NetworkTimeout = /** @class */ (function () {
967
950
  function NetworkTimeout(auth) {
968
951
  var _this = this;
@@ -998,6 +981,81 @@ function _makeTaggedError(auth, code, response) {
998
981
  return error;
999
982
  }
1000
983
 
984
+ /**
985
+ * @license
986
+ * Copyright 2020 Google LLC
987
+ *
988
+ * Licensed under the Apache License, Version 2.0 (the "License");
989
+ * you may not use this file except in compliance with the License.
990
+ * You may obtain a copy of the License at
991
+ *
992
+ * http://www.apache.org/licenses/LICENSE-2.0
993
+ *
994
+ * Unless required by applicable law or agreed to in writing, software
995
+ * distributed under the License is distributed on an "AS IS" BASIS,
996
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
997
+ * See the License for the specific language governing permissions and
998
+ * limitations under the License.
999
+ */
1000
+ function isV2(grecaptcha) {
1001
+ return (grecaptcha !== undefined &&
1002
+ grecaptcha.getResponse !== undefined);
1003
+ }
1004
+ function isEnterprise(grecaptcha) {
1005
+ return (grecaptcha !== undefined &&
1006
+ grecaptcha.enterprise !== undefined);
1007
+ }
1008
+ var RecaptchaConfig = /** @class */ (function () {
1009
+ function RecaptchaConfig(response) {
1010
+ /**
1011
+ * The reCAPTCHA site key.
1012
+ */
1013
+ this.siteKey = '';
1014
+ /**
1015
+ * The list of providers and their enablement status for reCAPTCHA Enterprise.
1016
+ */
1017
+ this.recaptchaEnforcementState = [];
1018
+ if (response.recaptchaKey === undefined) {
1019
+ throw new Error('recaptchaKey undefined');
1020
+ }
1021
+ // Example response.recaptchaKey: "projects/proj123/keys/sitekey123"
1022
+ this.siteKey = response.recaptchaKey.split('/')[3];
1023
+ this.recaptchaEnforcementState = response.recaptchaEnforcementState;
1024
+ }
1025
+ /**
1026
+ * Returns the reCAPTCHA Enterprise enforcement state for the given provider.
1027
+ *
1028
+ * @param providerStr - The provider whose enforcement state is to be returned.
1029
+ * @returns The reCAPTCHA Enterprise enforcement state for the given provider.
1030
+ */
1031
+ RecaptchaConfig.prototype.getProviderEnforcementState = function (providerStr) {
1032
+ if (!this.recaptchaEnforcementState ||
1033
+ this.recaptchaEnforcementState.length === 0) {
1034
+ return null;
1035
+ }
1036
+ for (var _i = 0, _a = this.recaptchaEnforcementState; _i < _a.length; _i++) {
1037
+ var recaptchaEnforcementState = _a[_i];
1038
+ if (recaptchaEnforcementState.provider &&
1039
+ recaptchaEnforcementState.provider === providerStr) {
1040
+ return _parseEnforcementState(recaptchaEnforcementState.enforcementState);
1041
+ }
1042
+ }
1043
+ return null;
1044
+ };
1045
+ /**
1046
+ * Returns true if the reCAPTCHA Enterprise enforcement state for the provider is set to ENFORCE or AUDIT.
1047
+ *
1048
+ * @param providerStr - The provider whose enablement state is to be returned.
1049
+ * @returns Whether or not reCAPTCHA Enterprise protection is enabled for the given provider.
1050
+ */
1051
+ RecaptchaConfig.prototype.isProviderEnabled = function (providerStr) {
1052
+ return (this.getProviderEnforcementState(providerStr) ===
1053
+ "ENFORCE" /* EnforcementState.ENFORCE */ ||
1054
+ this.getProviderEnforcementState(providerStr) === "AUDIT" /* EnforcementState.AUDIT */);
1055
+ };
1056
+ return RecaptchaConfig;
1057
+ }());
1058
+
1001
1059
  /**
1002
1060
  * @license
1003
1061
  * Copyright 2020 Google LLC
@@ -3680,6 +3738,39 @@ function injectRecaptchaFields(auth, request, action, captchaResp) {
3680
3738
  });
3681
3739
  });
3682
3740
  }
3741
+ function handleRecaptchaFlow(authInstance, request, actionName, actionMethod) {
3742
+ var _a;
3743
+ return tslib.__awaiter(this, void 0, void 0, function () {
3744
+ var requestWithRecaptcha;
3745
+ var _this = this;
3746
+ return tslib.__generator(this, function (_b) {
3747
+ switch (_b.label) {
3748
+ case 0:
3749
+ if (!((_a = authInstance
3750
+ ._getRecaptchaConfig()) === null || _a === void 0 ? void 0 : _a.isProviderEnabled("EMAIL_PASSWORD_PROVIDER" /* RecaptchaProvider.EMAIL_PASSWORD_PROVIDER */))) return [3 /*break*/, 2];
3751
+ return [4 /*yield*/, injectRecaptchaFields(authInstance, request, actionName, actionName === "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */)];
3752
+ case 1:
3753
+ requestWithRecaptcha = _b.sent();
3754
+ return [2 /*return*/, actionMethod(authInstance, requestWithRecaptcha)];
3755
+ case 2: return [2 /*return*/, actionMethod(authInstance, request).catch(function (error) { return tslib.__awaiter(_this, void 0, void 0, function () {
3756
+ var requestWithRecaptcha;
3757
+ return tslib.__generator(this, function (_a) {
3758
+ switch (_a.label) {
3759
+ case 0:
3760
+ if (!(error.code === "auth/".concat("missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */))) return [3 /*break*/, 2];
3761
+ console.log("".concat(actionName, " is protected by reCAPTCHA Enterprise for this project. Automatically triggering the reCAPTCHA flow and restarting the flow."));
3762
+ return [4 /*yield*/, injectRecaptchaFields(authInstance, request, actionName, actionName === "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */)];
3763
+ case 1:
3764
+ requestWithRecaptcha = _a.sent();
3765
+ return [2 /*return*/, actionMethod(authInstance, requestWithRecaptcha)];
3766
+ case 2: return [2 /*return*/, Promise.reject(error)];
3767
+ }
3768
+ });
3769
+ }); })];
3770
+ }
3771
+ });
3772
+ });
3773
+ }
3683
3774
  function _initializeRecaptchaConfig(auth) {
3684
3775
  return tslib.__awaiter(this, void 0, void 0, function () {
3685
3776
  var authInternal, response, config, verifier;
@@ -3700,7 +3791,7 @@ function _initializeRecaptchaConfig(auth) {
3700
3791
  else {
3701
3792
  authInternal._tenantRecaptchaConfigs[authInternal.tenantId] = config;
3702
3793
  }
3703
- if (config.emailPasswordEnabled) {
3794
+ if (config.isProviderEnabled("EMAIL_PASSWORD_PROVIDER" /* RecaptchaProvider.EMAIL_PASSWORD_PROVIDER */)) {
3704
3795
  verifier = new RecaptchaEnterpriseVerifier(authInternal);
3705
3796
  void verifier.verify();
3706
3797
  }
@@ -4166,55 +4257,27 @@ var EmailAuthCredential = /** @class */ (function (_super) {
4166
4257
  };
4167
4258
  /** @internal */
4168
4259
  EmailAuthCredential.prototype._getIdTokenResponse = function (auth) {
4169
- var _a;
4170
4260
  return tslib.__awaiter(this, void 0, void 0, function () {
4171
- var _b, request_1, requestWithRecaptcha;
4172
- var _this = this;
4173
- return tslib.__generator(this, function (_c) {
4174
- switch (_c.label) {
4175
- case 0:
4176
- _b = this.signInMethod;
4177
- switch (_b) {
4178
- case "password" /* SignInMethod.EMAIL_PASSWORD */: return [3 /*break*/, 1];
4179
- case "emailLink" /* SignInMethod.EMAIL_LINK */: return [3 /*break*/, 4];
4180
- }
4181
- return [3 /*break*/, 5];
4182
- case 1:
4183
- request_1 = {
4261
+ var request;
4262
+ return tslib.__generator(this, function (_a) {
4263
+ switch (this.signInMethod) {
4264
+ case "password" /* SignInMethod.EMAIL_PASSWORD */:
4265
+ request = {
4184
4266
  returnSecureToken: true,
4185
4267
  email: this._email,
4186
4268
  password: this._password,
4187
4269
  clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */
4188
4270
  };
4189
- if (!((_a = auth._getRecaptchaConfig()) === null || _a === void 0 ? void 0 : _a.emailPasswordEnabled)) return [3 /*break*/, 3];
4190
- return [4 /*yield*/, injectRecaptchaFields(auth, request_1, "signInWithPassword" /* RecaptchaActionName.SIGN_IN_WITH_PASSWORD */)];
4191
- case 2:
4192
- requestWithRecaptcha = _c.sent();
4193
- return [2 /*return*/, signInWithPassword(auth, requestWithRecaptcha)];
4194
- case 3: return [2 /*return*/, signInWithPassword(auth, request_1).catch(function (error) { return tslib.__awaiter(_this, void 0, void 0, function () {
4195
- var requestWithRecaptcha;
4196
- return tslib.__generator(this, function (_a) {
4197
- switch (_a.label) {
4198
- case 0:
4199
- if (!(error.code === "auth/".concat("missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */))) return [3 /*break*/, 2];
4200
- console.log('Sign-in with email address and password is protected by reCAPTCHA for this project. Automatically triggering the reCAPTCHA flow and restarting the sign-in flow.');
4201
- return [4 /*yield*/, injectRecaptchaFields(auth, request_1, "signInWithPassword" /* RecaptchaActionName.SIGN_IN_WITH_PASSWORD */)];
4202
- case 1:
4203
- requestWithRecaptcha = _a.sent();
4204
- return [2 /*return*/, signInWithPassword(auth, requestWithRecaptcha)];
4205
- case 2: return [2 /*return*/, Promise.reject(error)];
4206
- }
4207
- });
4208
- }); })];
4209
- case 4: return [2 /*return*/, signInWithEmailLink$1(auth, {
4210
- email: this._email,
4211
- oobCode: this._password
4212
- })];
4213
- case 5:
4271
+ return [2 /*return*/, handleRecaptchaFlow(auth, request, "signInWithPassword" /* RecaptchaActionName.SIGN_IN_WITH_PASSWORD */, signInWithPassword)];
4272
+ case "emailLink" /* SignInMethod.EMAIL_LINK */:
4273
+ return [2 /*return*/, signInWithEmailLink$1(auth, {
4274
+ email: this._email,
4275
+ oobCode: this._password
4276
+ })];
4277
+ default:
4214
4278
  _fail(auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
4215
- _c.label = 6;
4216
- case 6: return [2 /*return*/];
4217
4279
  }
4280
+ return [2 /*return*/];
4218
4281
  });
4219
4282
  });
4220
4283
  };
@@ -6431,12 +6494,10 @@ function recachePasswordPolicy(auth) {
6431
6494
  * @public
6432
6495
  */
6433
6496
  function sendPasswordResetEmail(auth, email, actionCodeSettings) {
6434
- var _a;
6435
6497
  return tslib.__awaiter(this, void 0, void 0, function () {
6436
- var authInternal, request, requestWithRecaptcha;
6437
- var _this = this;
6438
- return tslib.__generator(this, function (_b) {
6439
- switch (_b.label) {
6498
+ var authInternal, request;
6499
+ return tslib.__generator(this, function (_a) {
6500
+ switch (_a.label) {
6440
6501
  case 0:
6441
6502
  authInternal = _castAuth(auth);
6442
6503
  request = {
@@ -6444,48 +6505,13 @@ function sendPasswordResetEmail(auth, email, actionCodeSettings) {
6444
6505
  email: email,
6445
6506
  clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */
6446
6507
  };
6447
- if (!((_a = authInternal._getRecaptchaConfig()) === null || _a === void 0 ? void 0 : _a.emailPasswordEnabled)) return [3 /*break*/, 3];
6448
- return [4 /*yield*/, injectRecaptchaFields(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, true)];
6449
- case 1:
6450
- requestWithRecaptcha = _b.sent();
6451
- if (actionCodeSettings) {
6452
- _setActionCodeSettingsOnRequest(authInternal, requestWithRecaptcha, actionCodeSettings);
6453
- }
6454
- return [4 /*yield*/, sendPasswordResetEmail$1(authInternal, requestWithRecaptcha)];
6455
- case 2:
6456
- _b.sent();
6457
- return [3 /*break*/, 5];
6458
- case 3:
6459
6508
  if (actionCodeSettings) {
6460
6509
  _setActionCodeSettingsOnRequest(authInternal, request, actionCodeSettings);
6461
6510
  }
6462
- return [4 /*yield*/, sendPasswordResetEmail$1(authInternal, request)
6463
- .catch(function (error) { return tslib.__awaiter(_this, void 0, void 0, function () {
6464
- var requestWithRecaptcha;
6465
- return tslib.__generator(this, function (_a) {
6466
- switch (_a.label) {
6467
- case 0:
6468
- if (!(error.code === "auth/".concat("missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */))) return [3 /*break*/, 3];
6469
- console.log('Password resets are protected by reCAPTCHA for this project. Automatically triggering the reCAPTCHA flow and restarting the password reset flow.');
6470
- return [4 /*yield*/, injectRecaptchaFields(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, true)];
6471
- case 1:
6472
- requestWithRecaptcha = _a.sent();
6473
- if (actionCodeSettings) {
6474
- _setActionCodeSettingsOnRequest(authInternal, requestWithRecaptcha, actionCodeSettings);
6475
- }
6476
- return [4 /*yield*/, sendPasswordResetEmail$1(authInternal, requestWithRecaptcha)];
6477
- case 2:
6478
- _a.sent();
6479
- return [3 /*break*/, 4];
6480
- case 3: return [2 /*return*/, Promise.reject(error)];
6481
- case 4: return [2 /*return*/];
6482
- }
6483
- });
6484
- }); })];
6485
- case 4:
6486
- _b.sent();
6487
- _b.label = 5;
6488
- case 5: return [2 /*return*/];
6511
+ return [4 /*yield*/, handleRecaptchaFlow(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, sendPasswordResetEmail$1)];
6512
+ case 1:
6513
+ _a.sent();
6514
+ return [2 /*return*/];
6489
6515
  }
6490
6516
  });
6491
6517
  });
@@ -6640,12 +6666,10 @@ function verifyPasswordResetCode(auth, code) {
6640
6666
  * @public
6641
6667
  */
6642
6668
  function createUserWithEmailAndPassword(auth, email, password) {
6643
- var _a;
6644
6669
  return tslib.__awaiter(this, void 0, void 0, function () {
6645
- var authInternal, request, signUpResponse, requestWithRecaptcha, response, userCredential;
6646
- var _this = this;
6647
- return tslib.__generator(this, function (_b) {
6648
- switch (_b.label) {
6670
+ var authInternal, request, signUpResponse, response, userCredential;
6671
+ return tslib.__generator(this, function (_a) {
6672
+ switch (_a.label) {
6649
6673
  case 0:
6650
6674
  authInternal = _castAuth(auth);
6651
6675
  request = {
@@ -6654,43 +6678,21 @@ function createUserWithEmailAndPassword(auth, email, password) {
6654
6678
  password: password,
6655
6679
  clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */
6656
6680
  };
6657
- if (!((_a = authInternal._getRecaptchaConfig()) === null || _a === void 0 ? void 0 : _a.emailPasswordEnabled)) return [3 /*break*/, 2];
6658
- return [4 /*yield*/, injectRecaptchaFields(authInternal, request, "signUpPassword" /* RecaptchaActionName.SIGN_UP_PASSWORD */)];
6659
- case 1:
6660
- requestWithRecaptcha = _b.sent();
6661
- signUpResponse = signUp(authInternal, requestWithRecaptcha);
6662
- return [3 /*break*/, 3];
6663
- case 2:
6664
- signUpResponse = signUp(authInternal, request).catch(function (error) { return tslib.__awaiter(_this, void 0, void 0, function () {
6665
- var requestWithRecaptcha;
6666
- return tslib.__generator(this, function (_a) {
6667
- switch (_a.label) {
6668
- case 0:
6669
- if (!(error.code === "auth/".concat("missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */))) return [3 /*break*/, 2];
6670
- console.log('Sign-up is protected by reCAPTCHA for this project. Automatically triggering the reCAPTCHA flow and restarting the sign-up flow.');
6671
- return [4 /*yield*/, injectRecaptchaFields(authInternal, request, "signUpPassword" /* RecaptchaActionName.SIGN_UP_PASSWORD */)];
6672
- case 1:
6673
- requestWithRecaptcha = _a.sent();
6674
- return [2 /*return*/, signUp(authInternal, requestWithRecaptcha)];
6675
- case 2: throw error;
6681
+ signUpResponse = handleRecaptchaFlow(authInternal, request, "signUpPassword" /* RecaptchaActionName.SIGN_UP_PASSWORD */, signUp);
6682
+ return [4 /*yield*/, signUpResponse.catch(function (error) {
6683
+ if (error.code === "auth/".concat("password-does-not-meet-requirements" /* AuthErrorCode.PASSWORD_DOES_NOT_MEET_REQUIREMENTS */)) {
6684
+ void recachePasswordPolicy(auth);
6676
6685
  }
6677
- });
6678
- }); });
6679
- _b.label = 3;
6680
- case 3: return [4 /*yield*/, signUpResponse.catch(function (error) {
6681
- if (error.code === "auth/".concat("password-does-not-meet-requirements" /* AuthErrorCode.PASSWORD_DOES_NOT_MEET_REQUIREMENTS */)) {
6682
- void recachePasswordPolicy(auth);
6683
- }
6684
- throw error;
6685
- })];
6686
- case 4:
6687
- response = _b.sent();
6686
+ throw error;
6687
+ })];
6688
+ case 1:
6689
+ response = _a.sent();
6688
6690
  return [4 /*yield*/, UserCredentialImpl._fromIdTokenResponse(authInternal, "signIn" /* OperationType.SIGN_IN */, response)];
6689
- case 5:
6690
- userCredential = _b.sent();
6691
+ case 2:
6692
+ userCredential = _a.sent();
6691
6693
  return [4 /*yield*/, authInternal._updateCurrentUser(userCredential.user)];
6692
- case 6:
6693
- _b.sent();
6694
+ case 3:
6695
+ _a.sent();
6694
6696
  return [2 /*return*/, userCredential];
6695
6697
  }
6696
6698
  });
@@ -6779,7 +6781,6 @@ function signInWithEmailAndPassword(auth, email, password) {
6779
6781
  * @public
6780
6782
  */
6781
6783
  function sendSignInLinkToEmail(auth, email, actionCodeSettings) {
6782
- var _a;
6783
6784
  return tslib.__awaiter(this, void 0, void 0, function () {
6784
6785
  function setActionCodeSettings(request, actionCodeSettings) {
6785
6786
  _assert(actionCodeSettings.handleCodeInApp, authInternal, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
@@ -6787,10 +6788,9 @@ function sendSignInLinkToEmail(auth, email, actionCodeSettings) {
6787
6788
  _setActionCodeSettingsOnRequest(authInternal, request, actionCodeSettings);
6788
6789
  }
6789
6790
  }
6790
- var authInternal, request, requestWithRecaptcha;
6791
- var _this = this;
6792
- return tslib.__generator(this, function (_b) {
6793
- switch (_b.label) {
6791
+ var authInternal, request;
6792
+ return tslib.__generator(this, function (_a) {
6793
+ switch (_a.label) {
6794
6794
  case 0:
6795
6795
  authInternal = _castAuth(auth);
6796
6796
  request = {
@@ -6798,42 +6798,11 @@ function sendSignInLinkToEmail(auth, email, actionCodeSettings) {
6798
6798
  email: email,
6799
6799
  clientType: "CLIENT_TYPE_WEB" /* RecaptchaClientType.WEB */
6800
6800
  };
6801
- if (!((_a = authInternal._getRecaptchaConfig()) === null || _a === void 0 ? void 0 : _a.emailPasswordEnabled)) return [3 /*break*/, 3];
6802
- return [4 /*yield*/, injectRecaptchaFields(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, true)];
6803
- case 1:
6804
- requestWithRecaptcha = _b.sent();
6805
- setActionCodeSettings(requestWithRecaptcha, actionCodeSettings);
6806
- return [4 /*yield*/, sendSignInLinkToEmail$1(authInternal, requestWithRecaptcha)];
6807
- case 2:
6808
- _b.sent();
6809
- return [3 /*break*/, 5];
6810
- case 3:
6811
6801
  setActionCodeSettings(request, actionCodeSettings);
6812
- return [4 /*yield*/, sendSignInLinkToEmail$1(authInternal, request)
6813
- .catch(function (error) { return tslib.__awaiter(_this, void 0, void 0, function () {
6814
- var requestWithRecaptcha;
6815
- return tslib.__generator(this, function (_a) {
6816
- switch (_a.label) {
6817
- case 0:
6818
- if (!(error.code === "auth/".concat("missing-recaptcha-token" /* AuthErrorCode.MISSING_RECAPTCHA_TOKEN */))) return [3 /*break*/, 3];
6819
- console.log('Email link sign-in is protected by reCAPTCHA for this project. Automatically triggering the reCAPTCHA flow and restarting the sign-in flow.');
6820
- return [4 /*yield*/, injectRecaptchaFields(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, true)];
6821
- case 1:
6822
- requestWithRecaptcha = _a.sent();
6823
- setActionCodeSettings(requestWithRecaptcha, actionCodeSettings);
6824
- return [4 /*yield*/, sendSignInLinkToEmail$1(authInternal, requestWithRecaptcha)];
6825
- case 2:
6826
- _a.sent();
6827
- return [3 /*break*/, 4];
6828
- case 3: return [2 /*return*/, Promise.reject(error)];
6829
- case 4: return [2 /*return*/];
6830
- }
6831
- });
6832
- }); })];
6833
- case 4:
6834
- _b.sent();
6835
- _b.label = 5;
6836
- case 5: return [2 /*return*/];
6802
+ return [4 /*yield*/, handleRecaptchaFlow(authInternal, request, "getOobCode" /* RecaptchaActionName.GET_OOB_CODE */, sendSignInLinkToEmail$1)];
6803
+ case 1:
6804
+ _a.sent();
6805
+ return [2 /*return*/];
6837
6806
  }
6838
6807
  });
6839
6808
  });
@@ -7913,7 +7882,7 @@ function multiFactor(user) {
7913
7882
  }
7914
7883
 
7915
7884
  var name = "@firebase/auth";
7916
- var version = "1.3.0";
7885
+ var version = "1.3.1-canary.6e4e475f6";
7917
7886
 
7918
7887
  /**
7919
7888
  * @license
@@ -9278,6 +9247,180 @@ var PhoneMultiFactorGenerator = /** @class */ (function () {
9278
9247
  return PhoneMultiFactorGenerator;
9279
9248
  }());
9280
9249
 
9250
+ /**
9251
+ * Provider for generating a {@link TotpMultiFactorAssertion}.
9252
+ *
9253
+ * @public
9254
+ */
9255
+ var TotpMultiFactorGenerator = /** @class */ (function () {
9256
+ function TotpMultiFactorGenerator() {
9257
+ }
9258
+ /**
9259
+ * Provides a {@link TotpMultiFactorAssertion} to confirm ownership of
9260
+ * the TOTP (time-based one-time password) second factor.
9261
+ * This assertion is used to complete enrollment in TOTP second factor.
9262
+ *
9263
+ * @param secret A {@link TotpSecret} containing the shared secret key and other TOTP parameters.
9264
+ * @param oneTimePassword One-time password from TOTP App.
9265
+ * @returns A {@link TotpMultiFactorAssertion} which can be used with
9266
+ * {@link MultiFactorUser.enroll}.
9267
+ */
9268
+ TotpMultiFactorGenerator.assertionForEnrollment = function (secret, oneTimePassword) {
9269
+ return TotpMultiFactorAssertionImpl._fromSecret(secret, oneTimePassword);
9270
+ };
9271
+ /**
9272
+ * Provides a {@link TotpMultiFactorAssertion} to confirm ownership of the TOTP second factor.
9273
+ * This assertion is used to complete signIn with TOTP as the second factor.
9274
+ *
9275
+ * @param enrollmentId identifies the enrolled TOTP second factor.
9276
+ * @param oneTimePassword One-time password from TOTP App.
9277
+ * @returns A {@link TotpMultiFactorAssertion} which can be used with
9278
+ * {@link MultiFactorResolver.resolveSignIn}.
9279
+ */
9280
+ TotpMultiFactorGenerator.assertionForSignIn = function (enrollmentId, oneTimePassword) {
9281
+ return TotpMultiFactorAssertionImpl._fromEnrollmentId(enrollmentId, oneTimePassword);
9282
+ };
9283
+ /**
9284
+ * Returns a promise to {@link TotpSecret} which contains the TOTP shared secret key and other parameters.
9285
+ * Creates a TOTP secret as part of enrolling a TOTP second factor.
9286
+ * Used for generating a QR code URL or inputting into a TOTP app.
9287
+ * This method uses the auth instance corresponding to the user in the multiFactorSession.
9288
+ *
9289
+ * @param session The {@link MultiFactorSession} that the user is part of.
9290
+ * @returns A promise to {@link TotpSecret}.
9291
+ */
9292
+ TotpMultiFactorGenerator.generateSecret = function (session) {
9293
+ var _a;
9294
+ return tslib.__awaiter(this, void 0, void 0, function () {
9295
+ var mfaSession, response;
9296
+ return tslib.__generator(this, function (_b) {
9297
+ switch (_b.label) {
9298
+ case 0:
9299
+ mfaSession = session;
9300
+ _assert(typeof ((_a = mfaSession.user) === null || _a === void 0 ? void 0 : _a.auth) !== 'undefined', "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
9301
+ return [4 /*yield*/, startEnrollTotpMfa(mfaSession.user.auth, {
9302
+ idToken: mfaSession.credential,
9303
+ totpEnrollmentInfo: {}
9304
+ })];
9305
+ case 1:
9306
+ response = _b.sent();
9307
+ return [2 /*return*/, TotpSecret._fromStartTotpMfaEnrollmentResponse(response, mfaSession.user.auth)];
9308
+ }
9309
+ });
9310
+ });
9311
+ };
9312
+ /**
9313
+ * The identifier of the TOTP second factor: `totp`.
9314
+ */
9315
+ TotpMultiFactorGenerator.FACTOR_ID = "totp" /* FactorId.TOTP */;
9316
+ return TotpMultiFactorGenerator;
9317
+ }());
9318
+ var TotpMultiFactorAssertionImpl = /** @class */ (function (_super) {
9319
+ tslib.__extends(TotpMultiFactorAssertionImpl, _super);
9320
+ function TotpMultiFactorAssertionImpl(otp, enrollmentId, secret) {
9321
+ var _this = _super.call(this, "totp" /* FactorId.TOTP */) || this;
9322
+ _this.otp = otp;
9323
+ _this.enrollmentId = enrollmentId;
9324
+ _this.secret = secret;
9325
+ return _this;
9326
+ }
9327
+ /** @internal */
9328
+ TotpMultiFactorAssertionImpl._fromSecret = function (secret, otp) {
9329
+ return new TotpMultiFactorAssertionImpl(otp, undefined, secret);
9330
+ };
9331
+ /** @internal */
9332
+ TotpMultiFactorAssertionImpl._fromEnrollmentId = function (enrollmentId, otp) {
9333
+ return new TotpMultiFactorAssertionImpl(otp, enrollmentId);
9334
+ };
9335
+ /** @internal */
9336
+ TotpMultiFactorAssertionImpl.prototype._finalizeEnroll = function (auth, idToken, displayName) {
9337
+ return tslib.__awaiter(this, void 0, void 0, function () {
9338
+ return tslib.__generator(this, function (_a) {
9339
+ _assert(typeof this.secret !== 'undefined', auth, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
9340
+ return [2 /*return*/, finalizeEnrollTotpMfa(auth, {
9341
+ idToken: idToken,
9342
+ displayName: displayName,
9343
+ totpVerificationInfo: this.secret._makeTotpVerificationInfo(this.otp)
9344
+ })];
9345
+ });
9346
+ });
9347
+ };
9348
+ /** @internal */
9349
+ TotpMultiFactorAssertionImpl.prototype._finalizeSignIn = function (auth, mfaPendingCredential) {
9350
+ return tslib.__awaiter(this, void 0, void 0, function () {
9351
+ var totpVerificationInfo;
9352
+ return tslib.__generator(this, function (_a) {
9353
+ _assert(this.enrollmentId !== undefined && this.otp !== undefined, auth, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
9354
+ totpVerificationInfo = { verificationCode: this.otp };
9355
+ return [2 /*return*/, finalizeSignInTotpMfa(auth, {
9356
+ mfaPendingCredential: mfaPendingCredential,
9357
+ mfaEnrollmentId: this.enrollmentId,
9358
+ totpVerificationInfo: totpVerificationInfo
9359
+ })];
9360
+ });
9361
+ });
9362
+ };
9363
+ return TotpMultiFactorAssertionImpl;
9364
+ }(MultiFactorAssertionImpl));
9365
+ /**
9366
+ * Provider for generating a {@link TotpMultiFactorAssertion}.
9367
+ *
9368
+ * Stores the shared secret key and other parameters to generate time-based OTPs.
9369
+ * Implements methods to retrieve the shared secret key and generate a QR code URL.
9370
+ * @public
9371
+ */
9372
+ var TotpSecret = /** @class */ (function () {
9373
+ // The public members are declared outside the constructor so the docs can be generated.
9374
+ function TotpSecret(secretKey, hashingAlgorithm, codeLength, codeIntervalSeconds, enrollmentCompletionDeadline, sessionInfo, auth) {
9375
+ this.sessionInfo = sessionInfo;
9376
+ this.auth = auth;
9377
+ this.secretKey = secretKey;
9378
+ this.hashingAlgorithm = hashingAlgorithm;
9379
+ this.codeLength = codeLength;
9380
+ this.codeIntervalSeconds = codeIntervalSeconds;
9381
+ this.enrollmentCompletionDeadline = enrollmentCompletionDeadline;
9382
+ }
9383
+ /** @internal */
9384
+ TotpSecret._fromStartTotpMfaEnrollmentResponse = function (response, auth) {
9385
+ 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);
9386
+ };
9387
+ /** @internal */
9388
+ TotpSecret.prototype._makeTotpVerificationInfo = function (otp) {
9389
+ return { sessionInfo: this.sessionInfo, verificationCode: otp };
9390
+ };
9391
+ /**
9392
+ * Returns a QR code URL as described in
9393
+ * https://github.com/google/google-authenticator/wiki/Key-Uri-Format
9394
+ * This can be displayed to the user as a QR code to be scanned into a TOTP app like Google Authenticator.
9395
+ * If the optional parameters are unspecified, an accountName of <userEmail> and issuer of <firebaseAppName> are used.
9396
+ *
9397
+ * @param accountName the name of the account/app along with a user identifier.
9398
+ * @param issuer issuer of the TOTP (likely the app name).
9399
+ * @returns A QR code URL string.
9400
+ */
9401
+ TotpSecret.prototype.generateQrCodeUrl = function (accountName, issuer) {
9402
+ var _a;
9403
+ var useDefaults = false;
9404
+ if (_isEmptyString(accountName) || _isEmptyString(issuer)) {
9405
+ useDefaults = true;
9406
+ }
9407
+ if (useDefaults) {
9408
+ if (_isEmptyString(accountName)) {
9409
+ accountName = ((_a = this.auth.currentUser) === null || _a === void 0 ? void 0 : _a.email) || 'unknownuser';
9410
+ }
9411
+ if (_isEmptyString(issuer)) {
9412
+ issuer = this.auth.name;
9413
+ }
9414
+ }
9415
+ return "otpauth://totp/".concat(issuer, ":").concat(accountName, "?secret=").concat(this.secretKey, "&issuer=").concat(issuer, "&algorithm=").concat(this.hashingAlgorithm, "&digits=").concat(this.codeLength);
9416
+ };
9417
+ return TotpSecret;
9418
+ }());
9419
+ /** @internal */
9420
+ function _isEmptyString(input) {
9421
+ return typeof input === 'undefined' || (input === null || input === void 0 ? void 0 : input.length) === 0;
9422
+ }
9423
+
9281
9424
  var STORAGE_AVAILABLE_KEY = '__sak';
9282
9425
 
9283
9426
  exports.AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY = AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY;
@@ -9295,7 +9438,6 @@ exports.FederatedAuthProvider = FederatedAuthProvider;
9295
9438
  exports.FetchProvider = FetchProvider;
9296
9439
  exports.GithubAuthProvider = GithubAuthProvider;
9297
9440
  exports.GoogleAuthProvider = GoogleAuthProvider;
9298
- exports.MultiFactorAssertionImpl = MultiFactorAssertionImpl;
9299
9441
  exports.OAuthCredential = OAuthCredential;
9300
9442
  exports.OAuthProvider = OAuthProvider;
9301
9443
  exports.OperationType = OperationType;
@@ -9308,6 +9450,8 @@ exports.SAMLAuthCredential = SAMLAuthCredential;
9308
9450
  exports.SAMLAuthProvider = SAMLAuthProvider;
9309
9451
  exports.STORAGE_AVAILABLE_KEY = STORAGE_AVAILABLE_KEY;
9310
9452
  exports.SignInMethod = SignInMethod;
9453
+ exports.TotpMultiFactorGenerator = TotpMultiFactorGenerator;
9454
+ exports.TotpSecret = TotpSecret;
9311
9455
  exports.TwitterAuthProvider = TwitterAuthProvider;
9312
9456
  exports.UserImpl = UserImpl;
9313
9457
  exports._assert = _assert;
@@ -9354,8 +9498,6 @@ exports.debugAssert = debugAssert;
9354
9498
  exports.debugErrorMap = debugErrorMap;
9355
9499
  exports.deleteUser = deleteUser;
9356
9500
  exports.fetchSignInMethodsForEmail = fetchSignInMethodsForEmail;
9357
- exports.finalizeEnrollTotpMfa = finalizeEnrollTotpMfa;
9358
- exports.finalizeSignInTotpMfa = finalizeSignInTotpMfa;
9359
9501
  exports.getAdditionalUserInfo = getAdditionalUserInfo;
9360
9502
  exports.getIdToken = getIdToken;
9361
9503
  exports.getIdTokenResult = getIdTokenResult;
@@ -9387,7 +9529,6 @@ exports.signInWithEmailLink = signInWithEmailLink;
9387
9529
  exports.signInWithIdp = signInWithIdp;
9388
9530
  exports.signInWithPhoneNumber = signInWithPhoneNumber;
9389
9531
  exports.signOut = signOut;
9390
- exports.startEnrollTotpMfa = startEnrollTotpMfa;
9391
9532
  exports.unlink = unlink;
9392
9533
  exports.updateCurrentUser = updateCurrentUser;
9393
9534
  exports.updateEmail = updateEmail;
@@ -9398,4 +9539,4 @@ exports.useDeviceLanguage = useDeviceLanguage;
9398
9539
  exports.validatePassword = validatePassword;
9399
9540
  exports.verifyBeforeUpdateEmail = verifyBeforeUpdateEmail;
9400
9541
  exports.verifyPasswordResetCode = verifyPasswordResetCode;
9401
- //# sourceMappingURL=index-1dd41d18.js.map
9542
+ //# sourceMappingURL=index-9dc6fdd2.js.map