@firebase/auth 0.18.3 → 0.19.0
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.
- package/CHANGELOG.md +16 -0
- package/dist/auth-public.d.ts +28 -19
- package/dist/auth.d.ts +29 -20
- package/dist/cordova/index.js +2 -2
- package/dist/cordova/index.rn.d.ts +3 -0
- package/dist/cordova/internal.js +7 -3
- package/dist/cordova/internal.js.map +1 -1
- package/dist/cordova/{popup_redirect-f608cd47.js → popup_redirect-c65b3459.js} +46 -26
- package/dist/cordova/popup_redirect-c65b3459.js.map +1 -0
- package/dist/cordova/src/core/errors.d.ts +2 -2
- package/dist/cordova/src/core/strategies/abstract_popup_redirect_operation.d.ts +1 -1
- package/dist/cordova/src/mfa/mfa_error.d.ts +4 -5
- package/dist/cordova/src/model/public_types.d.ts +25 -19
- package/dist/cordova/src/platform_browser/persistence/browser.d.ts +4 -3
- package/dist/cordova/src/platform_browser/persistence/browser.test.d.ts +17 -0
- package/dist/cordova/src/platform_browser/strategies/phone.d.ts +3 -0
- package/dist/cordova/test/helpers/erroring_unavailable_persistence.d.ts +36 -0
- package/dist/esm2017/{index-f41a0691.js → index-238d6fa9.js} +41 -24
- package/dist/esm2017/index-238d6fa9.js.map +1 -0
- package/dist/esm2017/index.js +1 -1
- package/dist/esm2017/index.rn.d.ts +3 -0
- package/dist/esm2017/internal.js +2 -2
- package/dist/esm2017/src/core/errors.d.ts +2 -2
- package/dist/esm2017/src/core/strategies/abstract_popup_redirect_operation.d.ts +1 -1
- package/dist/esm2017/src/mfa/mfa_error.d.ts +4 -5
- package/dist/esm2017/src/model/public_types.d.ts +25 -19
- package/dist/esm2017/src/platform_browser/persistence/browser.d.ts +4 -3
- package/dist/esm2017/src/platform_browser/persistence/browser.test.d.ts +17 -0
- package/dist/esm2017/src/platform_browser/strategies/phone.d.ts +3 -0
- package/dist/esm2017/test/helpers/erroring_unavailable_persistence.d.ts +36 -0
- package/dist/esm5/{index-fd8b7af5.js → index-47dd1018.js} +51 -27
- package/dist/esm5/index-47dd1018.js.map +1 -0
- package/dist/esm5/index.js +1 -1
- package/dist/esm5/index.rn.d.ts +3 -0
- package/dist/esm5/internal.js +2 -2
- package/dist/esm5/src/core/errors.d.ts +2 -2
- package/dist/esm5/src/core/strategies/abstract_popup_redirect_operation.d.ts +1 -1
- package/dist/esm5/src/mfa/mfa_error.d.ts +4 -5
- package/dist/esm5/src/model/public_types.d.ts +25 -19
- package/dist/esm5/src/platform_browser/persistence/browser.d.ts +4 -3
- package/dist/esm5/src/platform_browser/persistence/browser.test.d.ts +17 -0
- package/dist/esm5/src/platform_browser/strategies/phone.d.ts +3 -0
- package/dist/esm5/test/helpers/erroring_unavailable_persistence.d.ts +36 -0
- package/dist/index.rn.d.ts +3 -0
- package/dist/index.webworker.esm5.js +17 -16
- package/dist/index.webworker.esm5.js.map +1 -1
- package/dist/node/{index-358613ec.js → index-da4673cf.js} +18 -17
- package/dist/node/index-da4673cf.js.map +1 -0
- package/dist/node/index.js +1 -1
- package/dist/node/index.rn.d.ts +3 -0
- package/dist/node/internal.js +29 -10
- package/dist/node/internal.js.map +1 -1
- package/dist/node/src/core/errors.d.ts +2 -2
- package/dist/node/src/core/strategies/abstract_popup_redirect_operation.d.ts +1 -1
- package/dist/node/src/mfa/mfa_error.d.ts +4 -5
- package/dist/node/src/model/public_types.d.ts +25 -19
- package/dist/node/src/platform_browser/persistence/browser.d.ts +4 -3
- package/dist/node/src/platform_browser/persistence/browser.test.d.ts +17 -0
- package/dist/node/src/platform_browser/strategies/phone.d.ts +3 -0
- package/dist/node/test/helpers/erroring_unavailable_persistence.d.ts +36 -0
- package/dist/rn/index.js +70 -64
- package/dist/rn/index.js.map +1 -1
- package/dist/rn/index.rn.d.ts +3 -0
- package/dist/rn/internal.js +338 -1465
- package/dist/rn/internal.js.map +1 -1
- package/dist/rn/{enum_maps-81db3ff6.js → phone-e3d3bcce.js} +1187 -27
- package/dist/rn/phone-e3d3bcce.js.map +1 -0
- package/dist/rn/src/core/errors.d.ts +2 -2
- package/dist/rn/src/core/strategies/abstract_popup_redirect_operation.d.ts +1 -1
- package/dist/rn/src/mfa/mfa_error.d.ts +4 -5
- package/dist/rn/src/model/public_types.d.ts +25 -19
- package/dist/rn/src/platform_browser/persistence/browser.d.ts +4 -3
- package/dist/rn/src/platform_browser/persistence/browser.test.d.ts +17 -0
- package/dist/rn/src/platform_browser/strategies/phone.d.ts +3 -0
- package/dist/rn/test/helpers/erroring_unavailable_persistence.d.ts +36 -0
- package/dist/src/core/errors.d.ts +2 -2
- package/dist/src/core/strategies/abstract_popup_redirect_operation.d.ts +1 -1
- package/dist/src/mfa/mfa_error.d.ts +4 -5
- package/dist/src/model/public_types.d.ts +25 -19
- package/dist/src/platform_browser/persistence/browser.d.ts +4 -3
- package/dist/src/platform_browser/persistence/browser.test.d.ts +17 -0
- package/dist/src/platform_browser/strategies/phone.d.ts +3 -0
- package/dist/test/helpers/erroring_unavailable_persistence.d.ts +36 -0
- package/package.json +2 -2
- package/dist/cordova/popup_redirect-f608cd47.js.map +0 -1
- package/dist/esm2017/index-f41a0691.js.map +0 -1
- package/dist/esm5/index-fd8b7af5.js.map +0 -1
- package/dist/node/index-358613ec.js.map +0 -1
- package/dist/rn/enum_maps-81db3ff6.js.map +0 -1
|
@@ -946,7 +946,7 @@ function _performSignInRequest(auth, method, path, request, customErrorMap) {
|
|
|
946
946
|
serverResponse = (_a.sent());
|
|
947
947
|
if ('mfaPendingCredential' in serverResponse) {
|
|
948
948
|
_fail(auth, "multi-factor-auth-required" /* MFA_REQUIRED */, {
|
|
949
|
-
|
|
949
|
+
_serverResponse: serverResponse
|
|
950
950
|
});
|
|
951
951
|
}
|
|
952
952
|
return [2 /*return*/, serverResponse];
|
|
@@ -3555,14 +3555,14 @@ function sendPhoneVerificationCode(auth, request) {
|
|
|
3555
3555
|
});
|
|
3556
3556
|
});
|
|
3557
3557
|
}
|
|
3558
|
-
function signInWithPhoneNumber(auth, request) {
|
|
3558
|
+
function signInWithPhoneNumber$1(auth, request) {
|
|
3559
3559
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
3560
3560
|
return tslib.__generator(this, function (_a) {
|
|
3561
3561
|
return [2 /*return*/, _performSignInRequest(auth, "POST" /* POST */, "/v1/accounts:signInWithPhoneNumber" /* SIGN_IN_WITH_PHONE_NUMBER */, _addTidIfNecessary(auth, request))];
|
|
3562
3562
|
});
|
|
3563
3563
|
});
|
|
3564
3564
|
}
|
|
3565
|
-
function linkWithPhoneNumber(auth, request) {
|
|
3565
|
+
function linkWithPhoneNumber$1(auth, request) {
|
|
3566
3566
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
3567
3567
|
var response;
|
|
3568
3568
|
return tslib.__generator(this, function (_a) {
|
|
@@ -3629,11 +3629,11 @@ var PhoneAuthCredential = /** @class */ (function (_super) {
|
|
|
3629
3629
|
};
|
|
3630
3630
|
/** @internal */
|
|
3631
3631
|
PhoneAuthCredential.prototype._getIdTokenResponse = function (auth) {
|
|
3632
|
-
return signInWithPhoneNumber(auth, this._makeVerificationRequest());
|
|
3632
|
+
return signInWithPhoneNumber$1(auth, this._makeVerificationRequest());
|
|
3633
3633
|
};
|
|
3634
3634
|
/** @internal */
|
|
3635
3635
|
PhoneAuthCredential.prototype._linkToIdToken = function (auth, idToken) {
|
|
3636
|
-
return linkWithPhoneNumber(auth, tslib.__assign({ idToken: idToken }, this._makeVerificationRequest()));
|
|
3636
|
+
return linkWithPhoneNumber$1(auth, tslib.__assign({ idToken: idToken }, this._makeVerificationRequest()));
|
|
3637
3637
|
};
|
|
3638
3638
|
/** @internal */
|
|
3639
3639
|
PhoneAuthCredential.prototype._getReauthenticationResolver = function (auth) {
|
|
@@ -4983,14 +4983,14 @@ var MultiFactorError = /** @class */ (function (_super) {
|
|
|
4983
4983
|
var _this = _super.call(this, error.code, error.message) || this;
|
|
4984
4984
|
_this.operationType = operationType;
|
|
4985
4985
|
_this.user = user;
|
|
4986
|
-
_this.name = 'FirebaseError';
|
|
4987
4986
|
// https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
|
|
4988
4987
|
Object.setPrototypeOf(_this, MultiFactorError.prototype);
|
|
4989
|
-
_this.
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
4988
|
+
_this.customData = {
|
|
4989
|
+
appName: auth.name,
|
|
4990
|
+
tenantId: (_a = auth.tenantId) !== null && _a !== void 0 ? _a : undefined,
|
|
4991
|
+
_serverResponse: error.customData._serverResponse,
|
|
4992
|
+
operationType: operationType,
|
|
4993
|
+
};
|
|
4994
4994
|
return _this;
|
|
4995
4995
|
}
|
|
4996
4996
|
MultiFactorError._fromErrorAndOperation = function (auth, error, operationType, user) {
|
|
@@ -6528,11 +6528,12 @@ var MultiFactorResolverImpl = /** @class */ (function () {
|
|
|
6528
6528
|
MultiFactorResolverImpl._fromError = function (authExtern, error) {
|
|
6529
6529
|
var _this = this;
|
|
6530
6530
|
var auth = _castAuth(authExtern);
|
|
6531
|
-
var
|
|
6531
|
+
var serverResponse = error.customData._serverResponse;
|
|
6532
|
+
var hints = (serverResponse.mfaInfo || []).map(function (enrollment) {
|
|
6532
6533
|
return MultiFactorInfoImpl._fromServerResponse(auth, enrollment);
|
|
6533
6534
|
});
|
|
6534
|
-
_assert(
|
|
6535
|
-
var session = MultiFactorSessionImpl._fromMfaPendingCredential(
|
|
6535
|
+
_assert(serverResponse.mfaPendingCredential, auth, "internal-error" /* INTERNAL_ERROR */);
|
|
6536
|
+
var session = MultiFactorSessionImpl._fromMfaPendingCredential(serverResponse.mfaPendingCredential);
|
|
6536
6537
|
return new MultiFactorResolverImpl(session, hints, function (assertion) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
6537
6538
|
var mfaResponse, idTokenResponse, _a, userCredential;
|
|
6538
6539
|
return tslib.__generator(this, function (_b) {
|
|
@@ -6541,9 +6542,9 @@ var MultiFactorResolverImpl = /** @class */ (function () {
|
|
|
6541
6542
|
case 1:
|
|
6542
6543
|
mfaResponse = _b.sent();
|
|
6543
6544
|
// Clear out the unneeded fields from the old login response
|
|
6544
|
-
delete
|
|
6545
|
-
delete
|
|
6546
|
-
idTokenResponse = tslib.__assign(tslib.__assign({},
|
|
6545
|
+
delete serverResponse.mfaInfo;
|
|
6546
|
+
delete serverResponse.mfaPendingCredential;
|
|
6547
|
+
idTokenResponse = tslib.__assign(tslib.__assign({}, serverResponse), { idToken: mfaResponse.idToken, refreshToken: mfaResponse.refreshToken });
|
|
6547
6548
|
_a = error.operationType;
|
|
6548
6549
|
switch (_a) {
|
|
6549
6550
|
case "signIn" /* SIGN_IN */: return [3 /*break*/, 2];
|
|
@@ -6593,8 +6594,8 @@ function getMultiFactorResolver(auth, error) {
|
|
|
6593
6594
|
var _a;
|
|
6594
6595
|
var authModular = util.getModularInstance(auth);
|
|
6595
6596
|
var errorInternal = error;
|
|
6596
|
-
_assert(error.operationType, authModular, "argument-error" /* ARGUMENT_ERROR */);
|
|
6597
|
-
_assert((_a = errorInternal.
|
|
6597
|
+
_assert(error.customData.operationType, authModular, "argument-error" /* ARGUMENT_ERROR */);
|
|
6598
|
+
_assert((_a = errorInternal.customData._serverResponse) === null || _a === void 0 ? void 0 : _a.mfaPendingCredential, authModular, "argument-error" /* ARGUMENT_ERROR */);
|
|
6598
6599
|
return MultiFactorResolverImpl._fromError(authModular, errorInternal);
|
|
6599
6600
|
}
|
|
6600
6601
|
|
|
@@ -6753,7 +6754,7 @@ function multiFactor(user) {
|
|
|
6753
6754
|
}
|
|
6754
6755
|
|
|
6755
6756
|
var name = "@firebase/auth";
|
|
6756
|
-
var version = "0.
|
|
6757
|
+
var version = "0.19.0";
|
|
6757
6758
|
|
|
6758
6759
|
/**
|
|
6759
6760
|
* @license
|
|
@@ -7016,6 +7017,1156 @@ var ActionCodeOperation = {
|
|
|
7016
7017
|
VERIFY_EMAIL: 'VERIFY_EMAIL'
|
|
7017
7018
|
};
|
|
7018
7019
|
|
|
7020
|
+
/**
|
|
7021
|
+
* @license
|
|
7022
|
+
* Copyright 2020 Google LLC
|
|
7023
|
+
*
|
|
7024
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7025
|
+
* you may not use this file except in compliance with the License.
|
|
7026
|
+
* You may obtain a copy of the License at
|
|
7027
|
+
*
|
|
7028
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7029
|
+
*
|
|
7030
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
7031
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
7032
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
7033
|
+
* See the License for the specific language governing permissions and
|
|
7034
|
+
* limitations under the License.
|
|
7035
|
+
*/
|
|
7036
|
+
function startSignInPhoneMfa(auth, request) {
|
|
7037
|
+
return _performApiRequest(auth, "POST" /* POST */, "/v2/accounts/mfaSignIn:start" /* START_PHONE_MFA_SIGN_IN */, _addTidIfNecessary(auth, request));
|
|
7038
|
+
}
|
|
7039
|
+
function finalizeSignInPhoneMfa(auth, request) {
|
|
7040
|
+
return _performApiRequest(auth, "POST" /* POST */, "/v2/accounts/mfaSignIn:finalize" /* FINALIZE_PHONE_MFA_SIGN_IN */, _addTidIfNecessary(auth, request));
|
|
7041
|
+
}
|
|
7042
|
+
|
|
7043
|
+
/**
|
|
7044
|
+
* @license
|
|
7045
|
+
* Copyright 2020 Google LLC
|
|
7046
|
+
*
|
|
7047
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7048
|
+
* you may not use this file except in compliance with the License.
|
|
7049
|
+
* You may obtain a copy of the License at
|
|
7050
|
+
*
|
|
7051
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7052
|
+
*
|
|
7053
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
7054
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
7055
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
7056
|
+
* See the License for the specific language governing permissions and
|
|
7057
|
+
* limitations under the License.
|
|
7058
|
+
*/
|
|
7059
|
+
function getRecaptchaParams(auth) {
|
|
7060
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
7061
|
+
return tslib.__generator(this, function (_a) {
|
|
7062
|
+
switch (_a.label) {
|
|
7063
|
+
case 0: return [4 /*yield*/, _performApiRequest(auth, "GET" /* GET */, "/v1/recaptchaParams" /* GET_RECAPTCHA_PARAM */)];
|
|
7064
|
+
case 1: return [2 /*return*/, ((_a.sent()).recaptchaSiteKey || '')];
|
|
7065
|
+
}
|
|
7066
|
+
});
|
|
7067
|
+
});
|
|
7068
|
+
}
|
|
7069
|
+
|
|
7070
|
+
/**
|
|
7071
|
+
* @license
|
|
7072
|
+
* Copyright 2020 Google LLC
|
|
7073
|
+
*
|
|
7074
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7075
|
+
* you may not use this file except in compliance with the License.
|
|
7076
|
+
* You may obtain a copy of the License at
|
|
7077
|
+
*
|
|
7078
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7079
|
+
*
|
|
7080
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
7081
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
7082
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
7083
|
+
* See the License for the specific language governing permissions and
|
|
7084
|
+
* limitations under the License.
|
|
7085
|
+
*/
|
|
7086
|
+
/**
|
|
7087
|
+
* Lazy accessor for window, since the compat layer won't tree shake this out,
|
|
7088
|
+
* we need to make sure not to mess with window unless we have to
|
|
7089
|
+
*/
|
|
7090
|
+
function _window() {
|
|
7091
|
+
return window;
|
|
7092
|
+
}
|
|
7093
|
+
function _setWindowLocation(url) {
|
|
7094
|
+
_window().location.href = url;
|
|
7095
|
+
}
|
|
7096
|
+
|
|
7097
|
+
/**
|
|
7098
|
+
* @license
|
|
7099
|
+
* Copyright 2020 Google LLC.
|
|
7100
|
+
*
|
|
7101
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7102
|
+
* you may not use this file except in compliance with the License.
|
|
7103
|
+
* You may obtain a copy of the License at
|
|
7104
|
+
*
|
|
7105
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7106
|
+
*
|
|
7107
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
7108
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
7109
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
7110
|
+
* See the License for the specific language governing permissions and
|
|
7111
|
+
* limitations under the License.
|
|
7112
|
+
*/
|
|
7113
|
+
function _isWorker() {
|
|
7114
|
+
return (typeof _window()['WorkerGlobalScope'] !== 'undefined' &&
|
|
7115
|
+
typeof _window()['importScripts'] === 'function');
|
|
7116
|
+
}
|
|
7117
|
+
function _getActiveServiceWorker() {
|
|
7118
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
7119
|
+
var registration;
|
|
7120
|
+
return tslib.__generator(this, function (_b) {
|
|
7121
|
+
switch (_b.label) {
|
|
7122
|
+
case 0:
|
|
7123
|
+
if (!(navigator === null || navigator === void 0 ? void 0 : navigator.serviceWorker)) {
|
|
7124
|
+
return [2 /*return*/, null];
|
|
7125
|
+
}
|
|
7126
|
+
_b.label = 1;
|
|
7127
|
+
case 1:
|
|
7128
|
+
_b.trys.push([1, 3, , 4]);
|
|
7129
|
+
return [4 /*yield*/, navigator.serviceWorker.ready];
|
|
7130
|
+
case 2:
|
|
7131
|
+
registration = _b.sent();
|
|
7132
|
+
return [2 /*return*/, registration.active];
|
|
7133
|
+
case 3:
|
|
7134
|
+
_b.sent();
|
|
7135
|
+
return [2 /*return*/, null];
|
|
7136
|
+
case 4: return [2 /*return*/];
|
|
7137
|
+
}
|
|
7138
|
+
});
|
|
7139
|
+
});
|
|
7140
|
+
}
|
|
7141
|
+
function _getServiceWorkerController() {
|
|
7142
|
+
var _a;
|
|
7143
|
+
return ((_a = navigator === null || navigator === void 0 ? void 0 : navigator.serviceWorker) === null || _a === void 0 ? void 0 : _a.controller) || null;
|
|
7144
|
+
}
|
|
7145
|
+
function _getWorkerGlobalScope() {
|
|
7146
|
+
return _isWorker() ? self : null;
|
|
7147
|
+
}
|
|
7148
|
+
|
|
7149
|
+
/**
|
|
7150
|
+
* @license
|
|
7151
|
+
* Copyright 2020 Google LLC
|
|
7152
|
+
*
|
|
7153
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7154
|
+
* you may not use this file except in compliance with the License.
|
|
7155
|
+
* You may obtain a copy of the License at
|
|
7156
|
+
*
|
|
7157
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7158
|
+
*
|
|
7159
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
7160
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
7161
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
7162
|
+
* See the License for the specific language governing permissions and
|
|
7163
|
+
* limitations under the License.
|
|
7164
|
+
*/
|
|
7165
|
+
function getScriptParentElement() {
|
|
7166
|
+
var _a, _b;
|
|
7167
|
+
return (_b = (_a = document.getElementsByTagName('head')) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : document;
|
|
7168
|
+
}
|
|
7169
|
+
function _loadJS(url) {
|
|
7170
|
+
// TODO: consider adding timeout support & cancellation
|
|
7171
|
+
return new Promise(function (resolve, reject) {
|
|
7172
|
+
var el = document.createElement('script');
|
|
7173
|
+
el.setAttribute('src', url);
|
|
7174
|
+
el.onload = resolve;
|
|
7175
|
+
el.onerror = function (e) {
|
|
7176
|
+
var error = _createError("internal-error" /* INTERNAL_ERROR */);
|
|
7177
|
+
error.customData = e;
|
|
7178
|
+
reject(error);
|
|
7179
|
+
};
|
|
7180
|
+
el.type = 'text/javascript';
|
|
7181
|
+
el.charset = 'UTF-8';
|
|
7182
|
+
getScriptParentElement().appendChild(el);
|
|
7183
|
+
});
|
|
7184
|
+
}
|
|
7185
|
+
function _generateCallbackName(prefix) {
|
|
7186
|
+
return "__" + prefix + Math.floor(Math.random() * 1000000);
|
|
7187
|
+
}
|
|
7188
|
+
|
|
7189
|
+
/**
|
|
7190
|
+
* @license
|
|
7191
|
+
* Copyright 2020 Google LLC
|
|
7192
|
+
*
|
|
7193
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7194
|
+
* you may not use this file except in compliance with the License.
|
|
7195
|
+
* You may obtain a copy of the License at
|
|
7196
|
+
*
|
|
7197
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7198
|
+
*
|
|
7199
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
7200
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
7201
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
7202
|
+
* See the License for the specific language governing permissions and
|
|
7203
|
+
* limitations under the License.
|
|
7204
|
+
*/
|
|
7205
|
+
var _SOLVE_TIME_MS = 500;
|
|
7206
|
+
var _EXPIRATION_TIME_MS = 60000;
|
|
7207
|
+
var _WIDGET_ID_START = 1000000000000;
|
|
7208
|
+
var MockReCaptcha = /** @class */ (function () {
|
|
7209
|
+
function MockReCaptcha(auth) {
|
|
7210
|
+
this.auth = auth;
|
|
7211
|
+
this.counter = _WIDGET_ID_START;
|
|
7212
|
+
this._widgets = new Map();
|
|
7213
|
+
}
|
|
7214
|
+
MockReCaptcha.prototype.render = function (container, parameters) {
|
|
7215
|
+
var id = this.counter;
|
|
7216
|
+
this._widgets.set(id, new MockWidget(container, this.auth.name, parameters || {}));
|
|
7217
|
+
this.counter++;
|
|
7218
|
+
return id;
|
|
7219
|
+
};
|
|
7220
|
+
MockReCaptcha.prototype.reset = function (optWidgetId) {
|
|
7221
|
+
var _a;
|
|
7222
|
+
var id = optWidgetId || _WIDGET_ID_START;
|
|
7223
|
+
void ((_a = this._widgets.get(id)) === null || _a === void 0 ? void 0 : _a.delete());
|
|
7224
|
+
this._widgets.delete(id);
|
|
7225
|
+
};
|
|
7226
|
+
MockReCaptcha.prototype.getResponse = function (optWidgetId) {
|
|
7227
|
+
var _a;
|
|
7228
|
+
var id = optWidgetId || _WIDGET_ID_START;
|
|
7229
|
+
return ((_a = this._widgets.get(id)) === null || _a === void 0 ? void 0 : _a.getResponse()) || '';
|
|
7230
|
+
};
|
|
7231
|
+
MockReCaptcha.prototype.execute = function (optWidgetId) {
|
|
7232
|
+
var _a;
|
|
7233
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
7234
|
+
var id;
|
|
7235
|
+
return tslib.__generator(this, function (_b) {
|
|
7236
|
+
id = optWidgetId || _WIDGET_ID_START;
|
|
7237
|
+
void ((_a = this._widgets.get(id)) === null || _a === void 0 ? void 0 : _a.execute());
|
|
7238
|
+
return [2 /*return*/, ''];
|
|
7239
|
+
});
|
|
7240
|
+
});
|
|
7241
|
+
};
|
|
7242
|
+
return MockReCaptcha;
|
|
7243
|
+
}());
|
|
7244
|
+
var MockWidget = /** @class */ (function () {
|
|
7245
|
+
function MockWidget(containerOrId, appName, params) {
|
|
7246
|
+
var _this = this;
|
|
7247
|
+
this.params = params;
|
|
7248
|
+
this.timerId = null;
|
|
7249
|
+
this.deleted = false;
|
|
7250
|
+
this.responseToken = null;
|
|
7251
|
+
this.clickHandler = function () {
|
|
7252
|
+
_this.execute();
|
|
7253
|
+
};
|
|
7254
|
+
var container = typeof containerOrId === 'string'
|
|
7255
|
+
? document.getElementById(containerOrId)
|
|
7256
|
+
: containerOrId;
|
|
7257
|
+
_assert(container, "argument-error" /* ARGUMENT_ERROR */, { appName: appName });
|
|
7258
|
+
this.container = container;
|
|
7259
|
+
this.isVisible = this.params.size !== 'invisible';
|
|
7260
|
+
if (this.isVisible) {
|
|
7261
|
+
this.execute();
|
|
7262
|
+
}
|
|
7263
|
+
else {
|
|
7264
|
+
this.container.addEventListener('click', this.clickHandler);
|
|
7265
|
+
}
|
|
7266
|
+
}
|
|
7267
|
+
MockWidget.prototype.getResponse = function () {
|
|
7268
|
+
this.checkIfDeleted();
|
|
7269
|
+
return this.responseToken;
|
|
7270
|
+
};
|
|
7271
|
+
MockWidget.prototype.delete = function () {
|
|
7272
|
+
this.checkIfDeleted();
|
|
7273
|
+
this.deleted = true;
|
|
7274
|
+
if (this.timerId) {
|
|
7275
|
+
clearTimeout(this.timerId);
|
|
7276
|
+
this.timerId = null;
|
|
7277
|
+
}
|
|
7278
|
+
this.container.removeEventListener('click', this.clickHandler);
|
|
7279
|
+
};
|
|
7280
|
+
MockWidget.prototype.execute = function () {
|
|
7281
|
+
var _this = this;
|
|
7282
|
+
this.checkIfDeleted();
|
|
7283
|
+
if (this.timerId) {
|
|
7284
|
+
return;
|
|
7285
|
+
}
|
|
7286
|
+
this.timerId = window.setTimeout(function () {
|
|
7287
|
+
_this.responseToken = generateRandomAlphaNumericString(50);
|
|
7288
|
+
var _a = _this.params, callback = _a.callback, expiredCallback = _a["expired-callback"];
|
|
7289
|
+
if (callback) {
|
|
7290
|
+
try {
|
|
7291
|
+
callback(_this.responseToken);
|
|
7292
|
+
}
|
|
7293
|
+
catch (e) { }
|
|
7294
|
+
}
|
|
7295
|
+
_this.timerId = window.setTimeout(function () {
|
|
7296
|
+
_this.timerId = null;
|
|
7297
|
+
_this.responseToken = null;
|
|
7298
|
+
if (expiredCallback) {
|
|
7299
|
+
try {
|
|
7300
|
+
expiredCallback();
|
|
7301
|
+
}
|
|
7302
|
+
catch (e) { }
|
|
7303
|
+
}
|
|
7304
|
+
if (_this.isVisible) {
|
|
7305
|
+
_this.execute();
|
|
7306
|
+
}
|
|
7307
|
+
}, _EXPIRATION_TIME_MS);
|
|
7308
|
+
}, _SOLVE_TIME_MS);
|
|
7309
|
+
};
|
|
7310
|
+
MockWidget.prototype.checkIfDeleted = function () {
|
|
7311
|
+
if (this.deleted) {
|
|
7312
|
+
throw new Error('reCAPTCHA mock was already deleted!');
|
|
7313
|
+
}
|
|
7314
|
+
};
|
|
7315
|
+
return MockWidget;
|
|
7316
|
+
}());
|
|
7317
|
+
function generateRandomAlphaNumericString(len) {
|
|
7318
|
+
var chars = [];
|
|
7319
|
+
var allowedChars = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
7320
|
+
for (var i = 0; i < len; i++) {
|
|
7321
|
+
chars.push(allowedChars.charAt(Math.floor(Math.random() * allowedChars.length)));
|
|
7322
|
+
}
|
|
7323
|
+
return chars.join('');
|
|
7324
|
+
}
|
|
7325
|
+
|
|
7326
|
+
/**
|
|
7327
|
+
* @license
|
|
7328
|
+
* Copyright 2020 Google LLC
|
|
7329
|
+
*
|
|
7330
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7331
|
+
* you may not use this file except in compliance with the License.
|
|
7332
|
+
* You may obtain a copy of the License at
|
|
7333
|
+
*
|
|
7334
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7335
|
+
*
|
|
7336
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
7337
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
7338
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
7339
|
+
* See the License for the specific language governing permissions and
|
|
7340
|
+
* limitations under the License.
|
|
7341
|
+
*/
|
|
7342
|
+
// ReCaptcha will load using the same callback, so the callback function needs
|
|
7343
|
+
// to be kept around
|
|
7344
|
+
var _JSLOAD_CALLBACK = _generateCallbackName('rcb');
|
|
7345
|
+
var NETWORK_TIMEOUT_DELAY = new Delay(30000, 60000);
|
|
7346
|
+
var RECAPTCHA_BASE = 'https://www.google.com/recaptcha/api.js?';
|
|
7347
|
+
/**
|
|
7348
|
+
* Loader for the GReCaptcha library. There should only ever be one of this.
|
|
7349
|
+
*/
|
|
7350
|
+
var ReCaptchaLoaderImpl = /** @class */ (function () {
|
|
7351
|
+
function ReCaptchaLoaderImpl() {
|
|
7352
|
+
this.hostLanguage = '';
|
|
7353
|
+
this.counter = 0;
|
|
7354
|
+
this.librarySeparatelyLoaded = !!_window().grecaptcha;
|
|
7355
|
+
}
|
|
7356
|
+
ReCaptchaLoaderImpl.prototype.load = function (auth, hl) {
|
|
7357
|
+
var _this = this;
|
|
7358
|
+
if (hl === void 0) { hl = ''; }
|
|
7359
|
+
_assert(isHostLanguageValid(hl), auth, "argument-error" /* ARGUMENT_ERROR */);
|
|
7360
|
+
if (this.shouldResolveImmediately(hl)) {
|
|
7361
|
+
return Promise.resolve(_window().grecaptcha);
|
|
7362
|
+
}
|
|
7363
|
+
return new Promise(function (resolve, reject) {
|
|
7364
|
+
var networkTimeout = _window().setTimeout(function () {
|
|
7365
|
+
reject(_createError(auth, "network-request-failed" /* NETWORK_REQUEST_FAILED */));
|
|
7366
|
+
}, NETWORK_TIMEOUT_DELAY.get());
|
|
7367
|
+
_window()[_JSLOAD_CALLBACK] = function () {
|
|
7368
|
+
_window().clearTimeout(networkTimeout);
|
|
7369
|
+
delete _window()[_JSLOAD_CALLBACK];
|
|
7370
|
+
var recaptcha = _window().grecaptcha;
|
|
7371
|
+
if (!recaptcha) {
|
|
7372
|
+
reject(_createError(auth, "internal-error" /* INTERNAL_ERROR */));
|
|
7373
|
+
return;
|
|
7374
|
+
}
|
|
7375
|
+
// Wrap the greptcha render function so that we know if the developer has
|
|
7376
|
+
// called it separately
|
|
7377
|
+
var render = recaptcha.render;
|
|
7378
|
+
recaptcha.render = function (container, params) {
|
|
7379
|
+
var widgetId = render(container, params);
|
|
7380
|
+
_this.counter++;
|
|
7381
|
+
return widgetId;
|
|
7382
|
+
};
|
|
7383
|
+
_this.hostLanguage = hl;
|
|
7384
|
+
resolve(recaptcha);
|
|
7385
|
+
};
|
|
7386
|
+
var url = RECAPTCHA_BASE + "?" + util.querystring({
|
|
7387
|
+
onload: _JSLOAD_CALLBACK,
|
|
7388
|
+
render: 'explicit',
|
|
7389
|
+
hl: hl
|
|
7390
|
+
});
|
|
7391
|
+
_loadJS(url).catch(function () {
|
|
7392
|
+
clearTimeout(networkTimeout);
|
|
7393
|
+
reject(_createError(auth, "internal-error" /* INTERNAL_ERROR */));
|
|
7394
|
+
});
|
|
7395
|
+
});
|
|
7396
|
+
};
|
|
7397
|
+
ReCaptchaLoaderImpl.prototype.clearedOneInstance = function () {
|
|
7398
|
+
this.counter--;
|
|
7399
|
+
};
|
|
7400
|
+
ReCaptchaLoaderImpl.prototype.shouldResolveImmediately = function (hl) {
|
|
7401
|
+
// We can resolve immediately if:
|
|
7402
|
+
// • grecaptcha is already defined AND (
|
|
7403
|
+
// 1. the requested language codes are the same OR
|
|
7404
|
+
// 2. there exists already a ReCaptcha on the page
|
|
7405
|
+
// 3. the library was already loaded by the app
|
|
7406
|
+
// In cases (2) and (3), we _can't_ reload as it would break the recaptchas
|
|
7407
|
+
// that are already in the page
|
|
7408
|
+
return (!!_window().grecaptcha &&
|
|
7409
|
+
(hl === this.hostLanguage ||
|
|
7410
|
+
this.counter > 0 ||
|
|
7411
|
+
this.librarySeparatelyLoaded));
|
|
7412
|
+
};
|
|
7413
|
+
return ReCaptchaLoaderImpl;
|
|
7414
|
+
}());
|
|
7415
|
+
function isHostLanguageValid(hl) {
|
|
7416
|
+
return hl.length <= 6 && /^\s*[a-zA-Z0-9\-]*\s*$/.test(hl);
|
|
7417
|
+
}
|
|
7418
|
+
var MockReCaptchaLoaderImpl = /** @class */ (function () {
|
|
7419
|
+
function MockReCaptchaLoaderImpl() {
|
|
7420
|
+
}
|
|
7421
|
+
MockReCaptchaLoaderImpl.prototype.load = function (auth) {
|
|
7422
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
7423
|
+
return tslib.__generator(this, function (_a) {
|
|
7424
|
+
return [2 /*return*/, new MockReCaptcha(auth)];
|
|
7425
|
+
});
|
|
7426
|
+
});
|
|
7427
|
+
};
|
|
7428
|
+
MockReCaptchaLoaderImpl.prototype.clearedOneInstance = function () { };
|
|
7429
|
+
return MockReCaptchaLoaderImpl;
|
|
7430
|
+
}());
|
|
7431
|
+
|
|
7432
|
+
/**
|
|
7433
|
+
* @license
|
|
7434
|
+
* Copyright 2020 Google LLC
|
|
7435
|
+
*
|
|
7436
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7437
|
+
* you may not use this file except in compliance with the License.
|
|
7438
|
+
* You may obtain a copy of the License at
|
|
7439
|
+
*
|
|
7440
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7441
|
+
*
|
|
7442
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
7443
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
7444
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
7445
|
+
* See the License for the specific language governing permissions and
|
|
7446
|
+
* limitations under the License.
|
|
7447
|
+
*/
|
|
7448
|
+
var RECAPTCHA_VERIFIER_TYPE = 'recaptcha';
|
|
7449
|
+
var DEFAULT_PARAMS = {
|
|
7450
|
+
theme: 'light',
|
|
7451
|
+
type: 'image'
|
|
7452
|
+
};
|
|
7453
|
+
/**
|
|
7454
|
+
* An {@link https://www.google.com/recaptcha/ | reCAPTCHA}-based application verifier.
|
|
7455
|
+
*
|
|
7456
|
+
* @public
|
|
7457
|
+
*/
|
|
7458
|
+
var RecaptchaVerifier = /** @class */ (function () {
|
|
7459
|
+
/**
|
|
7460
|
+
*
|
|
7461
|
+
* @param containerOrId - The reCAPTCHA container parameter.
|
|
7462
|
+
*
|
|
7463
|
+
* @remarks
|
|
7464
|
+
* This has different meaning depending on whether the reCAPTCHA is hidden or visible. For a
|
|
7465
|
+
* visible reCAPTCHA the container must be empty. If a string is used, it has to correspond to
|
|
7466
|
+
* an element ID. The corresponding element must also must be in the DOM at the time of
|
|
7467
|
+
* initialization.
|
|
7468
|
+
*
|
|
7469
|
+
* @param parameters - The optional reCAPTCHA parameters.
|
|
7470
|
+
*
|
|
7471
|
+
* @remarks
|
|
7472
|
+
* Check the reCAPTCHA docs for a comprehensive list. All parameters are accepted except for
|
|
7473
|
+
* the sitekey. Firebase Auth backend provisions a reCAPTCHA for each project and will
|
|
7474
|
+
* configure this upon rendering. For an invisible reCAPTCHA, a size key must have the value
|
|
7475
|
+
* 'invisible'.
|
|
7476
|
+
*
|
|
7477
|
+
* @param authExtern - The corresponding Firebase {@link Auth} instance.
|
|
7478
|
+
*
|
|
7479
|
+
* @remarks
|
|
7480
|
+
* If none is provided, the default Firebase {@link Auth} instance is used. A Firebase {@link Auth} instance
|
|
7481
|
+
* must be initialized with an API key, otherwise an error will be thrown.
|
|
7482
|
+
*/
|
|
7483
|
+
function RecaptchaVerifier(containerOrId, parameters, authExtern) {
|
|
7484
|
+
if (parameters === void 0) { parameters = tslib.__assign({}, DEFAULT_PARAMS); }
|
|
7485
|
+
this.parameters = parameters;
|
|
7486
|
+
/**
|
|
7487
|
+
* The application verifier type.
|
|
7488
|
+
*
|
|
7489
|
+
* @remarks
|
|
7490
|
+
* For a reCAPTCHA verifier, this is 'recaptcha'.
|
|
7491
|
+
*/
|
|
7492
|
+
this.type = RECAPTCHA_VERIFIER_TYPE;
|
|
7493
|
+
this.destroyed = false;
|
|
7494
|
+
this.widgetId = null;
|
|
7495
|
+
this.tokenChangeListeners = new Set();
|
|
7496
|
+
this.renderPromise = null;
|
|
7497
|
+
this.recaptcha = null;
|
|
7498
|
+
this.auth = _castAuth(authExtern);
|
|
7499
|
+
this.isInvisible = this.parameters.size === 'invisible';
|
|
7500
|
+
_assert(typeof document !== 'undefined', this.auth, "operation-not-supported-in-this-environment" /* OPERATION_NOT_SUPPORTED */);
|
|
7501
|
+
var container = typeof containerOrId === 'string'
|
|
7502
|
+
? document.getElementById(containerOrId)
|
|
7503
|
+
: containerOrId;
|
|
7504
|
+
_assert(container, this.auth, "argument-error" /* ARGUMENT_ERROR */);
|
|
7505
|
+
this.container = container;
|
|
7506
|
+
this.parameters.callback = this.makeTokenCallback(this.parameters.callback);
|
|
7507
|
+
this._recaptchaLoader = this.auth.settings.appVerificationDisabledForTesting
|
|
7508
|
+
? new MockReCaptchaLoaderImpl()
|
|
7509
|
+
: new ReCaptchaLoaderImpl();
|
|
7510
|
+
this.validateStartingState();
|
|
7511
|
+
// TODO: Figure out if sdk version is needed
|
|
7512
|
+
}
|
|
7513
|
+
/**
|
|
7514
|
+
* Waits for the user to solve the reCAPTCHA and resolves with the reCAPTCHA token.
|
|
7515
|
+
*
|
|
7516
|
+
* @returns A Promise for the reCAPTCHA token.
|
|
7517
|
+
*/
|
|
7518
|
+
RecaptchaVerifier.prototype.verify = function () {
|
|
7519
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
7520
|
+
var id, recaptcha, response;
|
|
7521
|
+
var _this = this;
|
|
7522
|
+
return tslib.__generator(this, function (_a) {
|
|
7523
|
+
switch (_a.label) {
|
|
7524
|
+
case 0:
|
|
7525
|
+
this.assertNotDestroyed();
|
|
7526
|
+
return [4 /*yield*/, this.render()];
|
|
7527
|
+
case 1:
|
|
7528
|
+
id = _a.sent();
|
|
7529
|
+
recaptcha = this.getAssertedRecaptcha();
|
|
7530
|
+
response = recaptcha.getResponse(id);
|
|
7531
|
+
if (response) {
|
|
7532
|
+
return [2 /*return*/, response];
|
|
7533
|
+
}
|
|
7534
|
+
return [2 /*return*/, new Promise(function (resolve) {
|
|
7535
|
+
var tokenChange = function (token) {
|
|
7536
|
+
if (!token) {
|
|
7537
|
+
return; // Ignore token expirations.
|
|
7538
|
+
}
|
|
7539
|
+
_this.tokenChangeListeners.delete(tokenChange);
|
|
7540
|
+
resolve(token);
|
|
7541
|
+
};
|
|
7542
|
+
_this.tokenChangeListeners.add(tokenChange);
|
|
7543
|
+
if (_this.isInvisible) {
|
|
7544
|
+
recaptcha.execute(id);
|
|
7545
|
+
}
|
|
7546
|
+
})];
|
|
7547
|
+
}
|
|
7548
|
+
});
|
|
7549
|
+
});
|
|
7550
|
+
};
|
|
7551
|
+
/**
|
|
7552
|
+
* Renders the reCAPTCHA widget on the page.
|
|
7553
|
+
*
|
|
7554
|
+
* @returns A Promise that resolves with the reCAPTCHA widget ID.
|
|
7555
|
+
*/
|
|
7556
|
+
RecaptchaVerifier.prototype.render = function () {
|
|
7557
|
+
var _this = this;
|
|
7558
|
+
try {
|
|
7559
|
+
this.assertNotDestroyed();
|
|
7560
|
+
}
|
|
7561
|
+
catch (e) {
|
|
7562
|
+
// This method returns a promise. Since it's not async (we want to return the
|
|
7563
|
+
// _same_ promise if rendering is still occurring), the API surface should
|
|
7564
|
+
// reject with the error rather than just throw
|
|
7565
|
+
return Promise.reject(e);
|
|
7566
|
+
}
|
|
7567
|
+
if (this.renderPromise) {
|
|
7568
|
+
return this.renderPromise;
|
|
7569
|
+
}
|
|
7570
|
+
this.renderPromise = this.makeRenderPromise().catch(function (e) {
|
|
7571
|
+
_this.renderPromise = null;
|
|
7572
|
+
throw e;
|
|
7573
|
+
});
|
|
7574
|
+
return this.renderPromise;
|
|
7575
|
+
};
|
|
7576
|
+
/** @internal */
|
|
7577
|
+
RecaptchaVerifier.prototype._reset = function () {
|
|
7578
|
+
this.assertNotDestroyed();
|
|
7579
|
+
if (this.widgetId !== null) {
|
|
7580
|
+
this.getAssertedRecaptcha().reset(this.widgetId);
|
|
7581
|
+
}
|
|
7582
|
+
};
|
|
7583
|
+
/**
|
|
7584
|
+
* Clears the reCAPTCHA widget from the page and destroys the instance.
|
|
7585
|
+
*/
|
|
7586
|
+
RecaptchaVerifier.prototype.clear = function () {
|
|
7587
|
+
var _this = this;
|
|
7588
|
+
this.assertNotDestroyed();
|
|
7589
|
+
this.destroyed = true;
|
|
7590
|
+
this._recaptchaLoader.clearedOneInstance();
|
|
7591
|
+
if (!this.isInvisible) {
|
|
7592
|
+
this.container.childNodes.forEach(function (node) {
|
|
7593
|
+
_this.container.removeChild(node);
|
|
7594
|
+
});
|
|
7595
|
+
}
|
|
7596
|
+
};
|
|
7597
|
+
RecaptchaVerifier.prototype.validateStartingState = function () {
|
|
7598
|
+
_assert(!this.parameters.sitekey, this.auth, "argument-error" /* ARGUMENT_ERROR */);
|
|
7599
|
+
_assert(this.isInvisible || !this.container.hasChildNodes(), this.auth, "argument-error" /* ARGUMENT_ERROR */);
|
|
7600
|
+
_assert(typeof document !== 'undefined', this.auth, "operation-not-supported-in-this-environment" /* OPERATION_NOT_SUPPORTED */);
|
|
7601
|
+
};
|
|
7602
|
+
RecaptchaVerifier.prototype.makeTokenCallback = function (existing) {
|
|
7603
|
+
var _this = this;
|
|
7604
|
+
return function (token) {
|
|
7605
|
+
_this.tokenChangeListeners.forEach(function (listener) { return listener(token); });
|
|
7606
|
+
if (typeof existing === 'function') {
|
|
7607
|
+
existing(token);
|
|
7608
|
+
}
|
|
7609
|
+
else if (typeof existing === 'string') {
|
|
7610
|
+
var globalFunc = _window()[existing];
|
|
7611
|
+
if (typeof globalFunc === 'function') {
|
|
7612
|
+
globalFunc(token);
|
|
7613
|
+
}
|
|
7614
|
+
}
|
|
7615
|
+
};
|
|
7616
|
+
};
|
|
7617
|
+
RecaptchaVerifier.prototype.assertNotDestroyed = function () {
|
|
7618
|
+
_assert(!this.destroyed, this.auth, "internal-error" /* INTERNAL_ERROR */);
|
|
7619
|
+
};
|
|
7620
|
+
RecaptchaVerifier.prototype.makeRenderPromise = function () {
|
|
7621
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
7622
|
+
var container, guaranteedEmpty;
|
|
7623
|
+
return tslib.__generator(this, function (_a) {
|
|
7624
|
+
switch (_a.label) {
|
|
7625
|
+
case 0: return [4 /*yield*/, this.init()];
|
|
7626
|
+
case 1:
|
|
7627
|
+
_a.sent();
|
|
7628
|
+
if (!this.widgetId) {
|
|
7629
|
+
container = this.container;
|
|
7630
|
+
if (!this.isInvisible) {
|
|
7631
|
+
guaranteedEmpty = document.createElement('div');
|
|
7632
|
+
container.appendChild(guaranteedEmpty);
|
|
7633
|
+
container = guaranteedEmpty;
|
|
7634
|
+
}
|
|
7635
|
+
this.widgetId = this.getAssertedRecaptcha().render(container, this.parameters);
|
|
7636
|
+
}
|
|
7637
|
+
return [2 /*return*/, this.widgetId];
|
|
7638
|
+
}
|
|
7639
|
+
});
|
|
7640
|
+
});
|
|
7641
|
+
};
|
|
7642
|
+
RecaptchaVerifier.prototype.init = function () {
|
|
7643
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
7644
|
+
var _a, siteKey;
|
|
7645
|
+
return tslib.__generator(this, function (_b) {
|
|
7646
|
+
switch (_b.label) {
|
|
7647
|
+
case 0:
|
|
7648
|
+
_assert(_isHttpOrHttps() && !_isWorker(), this.auth, "internal-error" /* INTERNAL_ERROR */);
|
|
7649
|
+
return [4 /*yield*/, domReady()];
|
|
7650
|
+
case 1:
|
|
7651
|
+
_b.sent();
|
|
7652
|
+
_a = this;
|
|
7653
|
+
return [4 /*yield*/, this._recaptchaLoader.load(this.auth, this.auth.languageCode || undefined)];
|
|
7654
|
+
case 2:
|
|
7655
|
+
_a.recaptcha = _b.sent();
|
|
7656
|
+
return [4 /*yield*/, getRecaptchaParams(this.auth)];
|
|
7657
|
+
case 3:
|
|
7658
|
+
siteKey = _b.sent();
|
|
7659
|
+
_assert(siteKey, this.auth, "internal-error" /* INTERNAL_ERROR */);
|
|
7660
|
+
this.parameters.sitekey = siteKey;
|
|
7661
|
+
return [2 /*return*/];
|
|
7662
|
+
}
|
|
7663
|
+
});
|
|
7664
|
+
});
|
|
7665
|
+
};
|
|
7666
|
+
RecaptchaVerifier.prototype.getAssertedRecaptcha = function () {
|
|
7667
|
+
_assert(this.recaptcha, this.auth, "internal-error" /* INTERNAL_ERROR */);
|
|
7668
|
+
return this.recaptcha;
|
|
7669
|
+
};
|
|
7670
|
+
return RecaptchaVerifier;
|
|
7671
|
+
}());
|
|
7672
|
+
function domReady() {
|
|
7673
|
+
var resolver = null;
|
|
7674
|
+
return new Promise(function (resolve) {
|
|
7675
|
+
if (document.readyState === 'complete') {
|
|
7676
|
+
resolve();
|
|
7677
|
+
return;
|
|
7678
|
+
}
|
|
7679
|
+
// Document not ready, wait for load before resolving.
|
|
7680
|
+
// Save resolver, so we can remove listener in case it was externally
|
|
7681
|
+
// cancelled.
|
|
7682
|
+
resolver = function () { return resolve(); };
|
|
7683
|
+
window.addEventListener('load', resolver);
|
|
7684
|
+
}).catch(function (e) {
|
|
7685
|
+
if (resolver) {
|
|
7686
|
+
window.removeEventListener('load', resolver);
|
|
7687
|
+
}
|
|
7688
|
+
throw e;
|
|
7689
|
+
});
|
|
7690
|
+
}
|
|
7691
|
+
|
|
7692
|
+
/**
|
|
7693
|
+
* @license
|
|
7694
|
+
* Copyright 2020 Google LLC
|
|
7695
|
+
*
|
|
7696
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7697
|
+
* you may not use this file except in compliance with the License.
|
|
7698
|
+
* You may obtain a copy of the License at
|
|
7699
|
+
*
|
|
7700
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7701
|
+
*
|
|
7702
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
7703
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
7704
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
7705
|
+
* See the License for the specific language governing permissions and
|
|
7706
|
+
* limitations under the License.
|
|
7707
|
+
*/
|
|
7708
|
+
var ConfirmationResultImpl = /** @class */ (function () {
|
|
7709
|
+
function ConfirmationResultImpl(verificationId, onConfirmation) {
|
|
7710
|
+
this.verificationId = verificationId;
|
|
7711
|
+
this.onConfirmation = onConfirmation;
|
|
7712
|
+
}
|
|
7713
|
+
ConfirmationResultImpl.prototype.confirm = function (verificationCode) {
|
|
7714
|
+
var authCredential = PhoneAuthCredential._fromVerification(this.verificationId, verificationCode);
|
|
7715
|
+
return this.onConfirmation(authCredential);
|
|
7716
|
+
};
|
|
7717
|
+
return ConfirmationResultImpl;
|
|
7718
|
+
}());
|
|
7719
|
+
/**
|
|
7720
|
+
* Asynchronously signs in using a phone number.
|
|
7721
|
+
*
|
|
7722
|
+
* @remarks
|
|
7723
|
+
* This method sends a code via SMS to the given
|
|
7724
|
+
* phone number, and returns a {@link ConfirmationResult}. After the user
|
|
7725
|
+
* provides the code sent to their phone, call {@link ConfirmationResult.confirm}
|
|
7726
|
+
* with the code to sign the user in.
|
|
7727
|
+
*
|
|
7728
|
+
* For abuse prevention, this method also requires a {@link ApplicationVerifier}.
|
|
7729
|
+
* This SDK includes a reCAPTCHA-based implementation, {@link RecaptchaVerifier}.
|
|
7730
|
+
* This function can work on other platforms that do not support the
|
|
7731
|
+
* {@link RecaptchaVerifier} (like React Native), but you need to use a
|
|
7732
|
+
* third-party {@link ApplicationVerifier} implementation.
|
|
7733
|
+
*
|
|
7734
|
+
* @example
|
|
7735
|
+
* ```javascript
|
|
7736
|
+
* // 'recaptcha-container' is the ID of an element in the DOM.
|
|
7737
|
+
* const applicationVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container');
|
|
7738
|
+
* const confirmationResult = await signInWithPhoneNumber(auth, phoneNumber, applicationVerifier);
|
|
7739
|
+
* // Obtain a verificationCode from the user.
|
|
7740
|
+
* const credential = await confirmationResult.confirm(verificationCode);
|
|
7741
|
+
* ```
|
|
7742
|
+
*
|
|
7743
|
+
* @param auth - The {@link Auth} instance.
|
|
7744
|
+
* @param phoneNumber - The user's phone number in E.164 format (e.g. +16505550101).
|
|
7745
|
+
* @param appVerifier - The {@link ApplicationVerifier}.
|
|
7746
|
+
*
|
|
7747
|
+
* @public
|
|
7748
|
+
*/
|
|
7749
|
+
function signInWithPhoneNumber(auth, phoneNumber, appVerifier) {
|
|
7750
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
7751
|
+
var authInternal, verificationId;
|
|
7752
|
+
return tslib.__generator(this, function (_a) {
|
|
7753
|
+
switch (_a.label) {
|
|
7754
|
+
case 0:
|
|
7755
|
+
authInternal = _castAuth(auth);
|
|
7756
|
+
return [4 /*yield*/, _verifyPhoneNumber(authInternal, phoneNumber, util.getModularInstance(appVerifier))];
|
|
7757
|
+
case 1:
|
|
7758
|
+
verificationId = _a.sent();
|
|
7759
|
+
return [2 /*return*/, new ConfirmationResultImpl(verificationId, function (cred) {
|
|
7760
|
+
return signInWithCredential(authInternal, cred);
|
|
7761
|
+
})];
|
|
7762
|
+
}
|
|
7763
|
+
});
|
|
7764
|
+
});
|
|
7765
|
+
}
|
|
7766
|
+
/**
|
|
7767
|
+
* Links the user account with the given phone number.
|
|
7768
|
+
*
|
|
7769
|
+
* @param user - The user.
|
|
7770
|
+
* @param phoneNumber - The user's phone number in E.164 format (e.g. +16505550101).
|
|
7771
|
+
* @param appVerifier - The {@link ApplicationVerifier}.
|
|
7772
|
+
*
|
|
7773
|
+
* @public
|
|
7774
|
+
*/
|
|
7775
|
+
function linkWithPhoneNumber(user, phoneNumber, appVerifier) {
|
|
7776
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
7777
|
+
var userInternal, verificationId;
|
|
7778
|
+
return tslib.__generator(this, function (_a) {
|
|
7779
|
+
switch (_a.label) {
|
|
7780
|
+
case 0:
|
|
7781
|
+
userInternal = util.getModularInstance(user);
|
|
7782
|
+
return [4 /*yield*/, _assertLinkedStatus(false, userInternal, "phone" /* PHONE */)];
|
|
7783
|
+
case 1:
|
|
7784
|
+
_a.sent();
|
|
7785
|
+
return [4 /*yield*/, _verifyPhoneNumber(userInternal.auth, phoneNumber, util.getModularInstance(appVerifier))];
|
|
7786
|
+
case 2:
|
|
7787
|
+
verificationId = _a.sent();
|
|
7788
|
+
return [2 /*return*/, new ConfirmationResultImpl(verificationId, function (cred) {
|
|
7789
|
+
return linkWithCredential(userInternal, cred);
|
|
7790
|
+
})];
|
|
7791
|
+
}
|
|
7792
|
+
});
|
|
7793
|
+
});
|
|
7794
|
+
}
|
|
7795
|
+
/**
|
|
7796
|
+
* Re-authenticates a user using a fresh phone credential.
|
|
7797
|
+
*
|
|
7798
|
+
* @remarks Use before operations such as {@link updatePassword} that require tokens from recent sign-in attempts.
|
|
7799
|
+
*
|
|
7800
|
+
* @param user - The user.
|
|
7801
|
+
* @param phoneNumber - The user's phone number in E.164 format (e.g. +16505550101).
|
|
7802
|
+
* @param appVerifier - The {@link ApplicationVerifier}.
|
|
7803
|
+
*
|
|
7804
|
+
* @public
|
|
7805
|
+
*/
|
|
7806
|
+
function reauthenticateWithPhoneNumber(user, phoneNumber, appVerifier) {
|
|
7807
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
7808
|
+
var userInternal, verificationId;
|
|
7809
|
+
return tslib.__generator(this, function (_a) {
|
|
7810
|
+
switch (_a.label) {
|
|
7811
|
+
case 0:
|
|
7812
|
+
userInternal = util.getModularInstance(user);
|
|
7813
|
+
return [4 /*yield*/, _verifyPhoneNumber(userInternal.auth, phoneNumber, util.getModularInstance(appVerifier))];
|
|
7814
|
+
case 1:
|
|
7815
|
+
verificationId = _a.sent();
|
|
7816
|
+
return [2 /*return*/, new ConfirmationResultImpl(verificationId, function (cred) {
|
|
7817
|
+
return reauthenticateWithCredential(userInternal, cred);
|
|
7818
|
+
})];
|
|
7819
|
+
}
|
|
7820
|
+
});
|
|
7821
|
+
});
|
|
7822
|
+
}
|
|
7823
|
+
/**
|
|
7824
|
+
* Returns a verification ID to be used in conjunction with the SMS code that is sent.
|
|
7825
|
+
*
|
|
7826
|
+
*/
|
|
7827
|
+
function _verifyPhoneNumber(auth, options, verifier) {
|
|
7828
|
+
var _a;
|
|
7829
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
7830
|
+
var recaptchaToken, phoneInfoOptions, session, response, mfaEnrollmentId, response, sessionInfo;
|
|
7831
|
+
return tslib.__generator(this, function (_b) {
|
|
7832
|
+
switch (_b.label) {
|
|
7833
|
+
case 0: return [4 /*yield*/, verifier.verify()];
|
|
7834
|
+
case 1:
|
|
7835
|
+
recaptchaToken = _b.sent();
|
|
7836
|
+
_b.label = 2;
|
|
7837
|
+
case 2:
|
|
7838
|
+
_b.trys.push([2, , 10, 11]);
|
|
7839
|
+
_assert(typeof recaptchaToken === 'string', auth, "argument-error" /* ARGUMENT_ERROR */);
|
|
7840
|
+
_assert(verifier.type === RECAPTCHA_VERIFIER_TYPE, auth, "argument-error" /* ARGUMENT_ERROR */);
|
|
7841
|
+
phoneInfoOptions = void 0;
|
|
7842
|
+
if (typeof options === 'string') {
|
|
7843
|
+
phoneInfoOptions = {
|
|
7844
|
+
phoneNumber: options
|
|
7845
|
+
};
|
|
7846
|
+
}
|
|
7847
|
+
else {
|
|
7848
|
+
phoneInfoOptions = options;
|
|
7849
|
+
}
|
|
7850
|
+
if (!('session' in phoneInfoOptions)) return [3 /*break*/, 7];
|
|
7851
|
+
session = phoneInfoOptions.session;
|
|
7852
|
+
if (!('phoneNumber' in phoneInfoOptions)) return [3 /*break*/, 4];
|
|
7853
|
+
_assert(session.type === "enroll" /* ENROLL */, auth, "internal-error" /* INTERNAL_ERROR */);
|
|
7854
|
+
return [4 /*yield*/, startEnrollPhoneMfa(auth, {
|
|
7855
|
+
idToken: session.credential,
|
|
7856
|
+
phoneEnrollmentInfo: {
|
|
7857
|
+
phoneNumber: phoneInfoOptions.phoneNumber,
|
|
7858
|
+
recaptchaToken: recaptchaToken
|
|
7859
|
+
}
|
|
7860
|
+
})];
|
|
7861
|
+
case 3:
|
|
7862
|
+
response = _b.sent();
|
|
7863
|
+
return [2 /*return*/, response.phoneSessionInfo.sessionInfo];
|
|
7864
|
+
case 4:
|
|
7865
|
+
_assert(session.type === "signin" /* SIGN_IN */, auth, "internal-error" /* INTERNAL_ERROR */);
|
|
7866
|
+
mfaEnrollmentId = ((_a = phoneInfoOptions.multiFactorHint) === null || _a === void 0 ? void 0 : _a.uid) ||
|
|
7867
|
+
phoneInfoOptions.multiFactorUid;
|
|
7868
|
+
_assert(mfaEnrollmentId, auth, "missing-multi-factor-info" /* MISSING_MFA_INFO */);
|
|
7869
|
+
return [4 /*yield*/, startSignInPhoneMfa(auth, {
|
|
7870
|
+
mfaPendingCredential: session.credential,
|
|
7871
|
+
mfaEnrollmentId: mfaEnrollmentId,
|
|
7872
|
+
phoneSignInInfo: {
|
|
7873
|
+
recaptchaToken: recaptchaToken
|
|
7874
|
+
}
|
|
7875
|
+
})];
|
|
7876
|
+
case 5:
|
|
7877
|
+
response = _b.sent();
|
|
7878
|
+
return [2 /*return*/, response.phoneResponseInfo.sessionInfo];
|
|
7879
|
+
case 6: return [3 /*break*/, 9];
|
|
7880
|
+
case 7: return [4 /*yield*/, sendPhoneVerificationCode(auth, {
|
|
7881
|
+
phoneNumber: phoneInfoOptions.phoneNumber,
|
|
7882
|
+
recaptchaToken: recaptchaToken
|
|
7883
|
+
})];
|
|
7884
|
+
case 8:
|
|
7885
|
+
sessionInfo = (_b.sent()).sessionInfo;
|
|
7886
|
+
return [2 /*return*/, sessionInfo];
|
|
7887
|
+
case 9: return [3 /*break*/, 11];
|
|
7888
|
+
case 10:
|
|
7889
|
+
verifier._reset();
|
|
7890
|
+
return [7 /*endfinally*/];
|
|
7891
|
+
case 11: return [2 /*return*/];
|
|
7892
|
+
}
|
|
7893
|
+
});
|
|
7894
|
+
});
|
|
7895
|
+
}
|
|
7896
|
+
/**
|
|
7897
|
+
* Updates the user's phone number.
|
|
7898
|
+
*
|
|
7899
|
+
* @example
|
|
7900
|
+
* ```
|
|
7901
|
+
* // 'recaptcha-container' is the ID of an element in the DOM.
|
|
7902
|
+
* const applicationVerifier = new RecaptchaVerifier('recaptcha-container');
|
|
7903
|
+
* const provider = new PhoneAuthProvider(auth);
|
|
7904
|
+
* const verificationId = await provider.verifyPhoneNumber('+16505550101', applicationVerifier);
|
|
7905
|
+
* // Obtain the verificationCode from the user.
|
|
7906
|
+
* const phoneCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
|
|
7907
|
+
* await updatePhoneNumber(user, phoneCredential);
|
|
7908
|
+
* ```
|
|
7909
|
+
*
|
|
7910
|
+
* @param user - The user.
|
|
7911
|
+
* @param credential - A credential authenticating the new phone number.
|
|
7912
|
+
*
|
|
7913
|
+
* @public
|
|
7914
|
+
*/
|
|
7915
|
+
function updatePhoneNumber(user, credential) {
|
|
7916
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
7917
|
+
return tslib.__generator(this, function (_a) {
|
|
7918
|
+
switch (_a.label) {
|
|
7919
|
+
case 0: return [4 /*yield*/, _link(util.getModularInstance(user), credential)];
|
|
7920
|
+
case 1:
|
|
7921
|
+
_a.sent();
|
|
7922
|
+
return [2 /*return*/];
|
|
7923
|
+
}
|
|
7924
|
+
});
|
|
7925
|
+
});
|
|
7926
|
+
}
|
|
7927
|
+
|
|
7928
|
+
/**
|
|
7929
|
+
* @license
|
|
7930
|
+
* Copyright 2020 Google LLC
|
|
7931
|
+
*
|
|
7932
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7933
|
+
* you may not use this file except in compliance with the License.
|
|
7934
|
+
* You may obtain a copy of the License at
|
|
7935
|
+
*
|
|
7936
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7937
|
+
*
|
|
7938
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
7939
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
7940
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
7941
|
+
* See the License for the specific language governing permissions and
|
|
7942
|
+
* limitations under the License.
|
|
7943
|
+
*/
|
|
7944
|
+
/**
|
|
7945
|
+
* Provider for generating an {@link PhoneAuthCredential}.
|
|
7946
|
+
*
|
|
7947
|
+
* @example
|
|
7948
|
+
* ```javascript
|
|
7949
|
+
* // 'recaptcha-container' is the ID of an element in the DOM.
|
|
7950
|
+
* const applicationVerifier = new RecaptchaVerifier('recaptcha-container');
|
|
7951
|
+
* const provider = new PhoneAuthProvider(auth);
|
|
7952
|
+
* const verificationId = await provider.verifyPhoneNumber('+16505550101', applicationVerifier);
|
|
7953
|
+
* // Obtain the verificationCode from the user.
|
|
7954
|
+
* const phoneCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
|
|
7955
|
+
* const userCredential = await signInWithCredential(auth, phoneCredential);
|
|
7956
|
+
* ```
|
|
7957
|
+
*
|
|
7958
|
+
* @public
|
|
7959
|
+
*/
|
|
7960
|
+
var PhoneAuthProvider = /** @class */ (function () {
|
|
7961
|
+
/**
|
|
7962
|
+
* @param auth - The Firebase {@link Auth} instance in which sign-ins should occur.
|
|
7963
|
+
*
|
|
7964
|
+
*/
|
|
7965
|
+
function PhoneAuthProvider(auth) {
|
|
7966
|
+
/** Always set to {@link ProviderId}.PHONE. */
|
|
7967
|
+
this.providerId = PhoneAuthProvider.PROVIDER_ID;
|
|
7968
|
+
this.auth = _castAuth(auth);
|
|
7969
|
+
}
|
|
7970
|
+
/**
|
|
7971
|
+
*
|
|
7972
|
+
* Starts a phone number authentication flow by sending a verification code to the given phone
|
|
7973
|
+
* number.
|
|
7974
|
+
*
|
|
7975
|
+
* @example
|
|
7976
|
+
* ```javascript
|
|
7977
|
+
* const provider = new PhoneAuthProvider(auth);
|
|
7978
|
+
* const verificationId = await provider.verifyPhoneNumber(phoneNumber, applicationVerifier);
|
|
7979
|
+
* // Obtain verificationCode from the user.
|
|
7980
|
+
* const authCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
|
|
7981
|
+
* const userCredential = await signInWithCredential(auth, authCredential);
|
|
7982
|
+
* ```
|
|
7983
|
+
*
|
|
7984
|
+
* @example
|
|
7985
|
+
* An alternative flow is provided using the `signInWithPhoneNumber` method.
|
|
7986
|
+
* ```javascript
|
|
7987
|
+
* const confirmationResult = signInWithPhoneNumber(auth, phoneNumber, applicationVerifier);
|
|
7988
|
+
* // Obtain verificationCode from the user.
|
|
7989
|
+
* const userCredential = confirmationResult.confirm(verificationCode);
|
|
7990
|
+
* ```
|
|
7991
|
+
*
|
|
7992
|
+
* @param phoneInfoOptions - The user's {@link PhoneInfoOptions}. The phone number should be in
|
|
7993
|
+
* E.164 format (e.g. +16505550101).
|
|
7994
|
+
* @param applicationVerifier - For abuse prevention, this method also requires a
|
|
7995
|
+
* {@link ApplicationVerifier}. This SDK includes a reCAPTCHA-based implementation,
|
|
7996
|
+
* {@link RecaptchaVerifier}.
|
|
7997
|
+
*
|
|
7998
|
+
* @returns A Promise for a verification ID that can be passed to
|
|
7999
|
+
* {@link PhoneAuthProvider.credential} to identify this flow..
|
|
8000
|
+
*/
|
|
8001
|
+
PhoneAuthProvider.prototype.verifyPhoneNumber = function (phoneOptions, applicationVerifier) {
|
|
8002
|
+
return _verifyPhoneNumber(this.auth, phoneOptions, util.getModularInstance(applicationVerifier));
|
|
8003
|
+
};
|
|
8004
|
+
/**
|
|
8005
|
+
* Creates a phone auth credential, given the verification ID from
|
|
8006
|
+
* {@link PhoneAuthProvider.verifyPhoneNumber} and the code that was sent to the user's
|
|
8007
|
+
* mobile device.
|
|
8008
|
+
*
|
|
8009
|
+
* @example
|
|
8010
|
+
* ```javascript
|
|
8011
|
+
* const provider = new PhoneAuthProvider(auth);
|
|
8012
|
+
* const verificationId = provider.verifyPhoneNumber(phoneNumber, applicationVerifier);
|
|
8013
|
+
* // Obtain verificationCode from the user.
|
|
8014
|
+
* const authCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
|
|
8015
|
+
* const userCredential = signInWithCredential(auth, authCredential);
|
|
8016
|
+
* ```
|
|
8017
|
+
*
|
|
8018
|
+
* @example
|
|
8019
|
+
* An alternative flow is provided using the `signInWithPhoneNumber` method.
|
|
8020
|
+
* ```javascript
|
|
8021
|
+
* const confirmationResult = await signInWithPhoneNumber(auth, phoneNumber, applicationVerifier);
|
|
8022
|
+
* // Obtain verificationCode from the user.
|
|
8023
|
+
* const userCredential = await confirmationResult.confirm(verificationCode);
|
|
8024
|
+
* ```
|
|
8025
|
+
*
|
|
8026
|
+
* @param verificationId - The verification ID returned from {@link PhoneAuthProvider.verifyPhoneNumber}.
|
|
8027
|
+
* @param verificationCode - The verification code sent to the user's mobile device.
|
|
8028
|
+
*
|
|
8029
|
+
* @returns The auth provider credential.
|
|
8030
|
+
*/
|
|
8031
|
+
PhoneAuthProvider.credential = function (verificationId, verificationCode) {
|
|
8032
|
+
return PhoneAuthCredential._fromVerification(verificationId, verificationCode);
|
|
8033
|
+
};
|
|
8034
|
+
/**
|
|
8035
|
+
* Generates an {@link AuthCredential} from a {@link UserCredential}.
|
|
8036
|
+
* @param userCredential - The user credential.
|
|
8037
|
+
*/
|
|
8038
|
+
PhoneAuthProvider.credentialFromResult = function (userCredential) {
|
|
8039
|
+
var credential = userCredential;
|
|
8040
|
+
return PhoneAuthProvider.credentialFromTaggedObject(credential);
|
|
8041
|
+
};
|
|
8042
|
+
/**
|
|
8043
|
+
* Returns an {@link AuthCredential} when passed an error.
|
|
8044
|
+
*
|
|
8045
|
+
* @remarks
|
|
8046
|
+
*
|
|
8047
|
+
* This method works for errors like
|
|
8048
|
+
* `auth/account-exists-with-different-credentials`. This is useful for
|
|
8049
|
+
* recovering when attempting to set a user's phone number but the number
|
|
8050
|
+
* in question is already tied to another account. For example, the following
|
|
8051
|
+
* code tries to update the current user's phone number, and if that
|
|
8052
|
+
* fails, links the user with the account associated with that number:
|
|
8053
|
+
*
|
|
8054
|
+
* ```js
|
|
8055
|
+
* const provider = new PhoneAuthProvider(auth);
|
|
8056
|
+
* const verificationId = await provider.verifyPhoneNumber(number, verifier);
|
|
8057
|
+
* try {
|
|
8058
|
+
* const code = ''; // Prompt the user for the verification code
|
|
8059
|
+
* await updatePhoneNumber(
|
|
8060
|
+
* auth.currentUser,
|
|
8061
|
+
* PhoneAuthProvider.credential(verificationId, code));
|
|
8062
|
+
* } catch (e) {
|
|
8063
|
+
* if (e.code === 'auth/account-exists-with-different-credential') {
|
|
8064
|
+
* const cred = PhoneAuthProvider.credentialFromError(e);
|
|
8065
|
+
* await linkWithCredential(auth.currentUser, cred);
|
|
8066
|
+
* }
|
|
8067
|
+
* }
|
|
8068
|
+
*
|
|
8069
|
+
* // At this point, auth.currentUser.phoneNumber === number.
|
|
8070
|
+
* ```
|
|
8071
|
+
*
|
|
8072
|
+
* @param error - The error to generate a credential from.
|
|
8073
|
+
*/
|
|
8074
|
+
PhoneAuthProvider.credentialFromError = function (error) {
|
|
8075
|
+
return PhoneAuthProvider.credentialFromTaggedObject((error.customData || {}));
|
|
8076
|
+
};
|
|
8077
|
+
PhoneAuthProvider.credentialFromTaggedObject = function (_a) {
|
|
8078
|
+
var tokenResponse = _a._tokenResponse;
|
|
8079
|
+
if (!tokenResponse) {
|
|
8080
|
+
return null;
|
|
8081
|
+
}
|
|
8082
|
+
var _b = tokenResponse, phoneNumber = _b.phoneNumber, temporaryProof = _b.temporaryProof;
|
|
8083
|
+
if (phoneNumber && temporaryProof) {
|
|
8084
|
+
return PhoneAuthCredential._fromTokenResponse(phoneNumber, temporaryProof);
|
|
8085
|
+
}
|
|
8086
|
+
return null;
|
|
8087
|
+
};
|
|
8088
|
+
/** Always set to {@link ProviderId}.PHONE. */
|
|
8089
|
+
PhoneAuthProvider.PROVIDER_ID = "phone" /* PHONE */;
|
|
8090
|
+
/** Always set to {@link SignInMethod}.PHONE. */
|
|
8091
|
+
PhoneAuthProvider.PHONE_SIGN_IN_METHOD = "phone" /* PHONE */;
|
|
8092
|
+
return PhoneAuthProvider;
|
|
8093
|
+
}());
|
|
8094
|
+
|
|
8095
|
+
var MultiFactorAssertionImpl = /** @class */ (function () {
|
|
8096
|
+
function MultiFactorAssertionImpl(factorId) {
|
|
8097
|
+
this.factorId = factorId;
|
|
8098
|
+
}
|
|
8099
|
+
MultiFactorAssertionImpl.prototype._process = function (auth, session, displayName) {
|
|
8100
|
+
switch (session.type) {
|
|
8101
|
+
case "enroll" /* ENROLL */:
|
|
8102
|
+
return this._finalizeEnroll(auth, session.credential, displayName);
|
|
8103
|
+
case "signin" /* SIGN_IN */:
|
|
8104
|
+
return this._finalizeSignIn(auth, session.credential);
|
|
8105
|
+
default:
|
|
8106
|
+
return debugFail('unexpected MultiFactorSessionType');
|
|
8107
|
+
}
|
|
8108
|
+
};
|
|
8109
|
+
return MultiFactorAssertionImpl;
|
|
8110
|
+
}());
|
|
8111
|
+
|
|
8112
|
+
/**
|
|
8113
|
+
* {@inheritdoc PhoneMultiFactorAssertion}
|
|
8114
|
+
*
|
|
8115
|
+
* @public
|
|
8116
|
+
*/
|
|
8117
|
+
var PhoneMultiFactorAssertionImpl = /** @class */ (function (_super) {
|
|
8118
|
+
tslib.__extends(PhoneMultiFactorAssertionImpl, _super);
|
|
8119
|
+
function PhoneMultiFactorAssertionImpl(credential) {
|
|
8120
|
+
var _this = _super.call(this, "phone" /* PHONE */) || this;
|
|
8121
|
+
_this.credential = credential;
|
|
8122
|
+
return _this;
|
|
8123
|
+
}
|
|
8124
|
+
/** @internal */
|
|
8125
|
+
PhoneMultiFactorAssertionImpl._fromCredential = function (credential) {
|
|
8126
|
+
return new PhoneMultiFactorAssertionImpl(credential);
|
|
8127
|
+
};
|
|
8128
|
+
/** @internal */
|
|
8129
|
+
PhoneMultiFactorAssertionImpl.prototype._finalizeEnroll = function (auth, idToken, displayName) {
|
|
8130
|
+
return finalizeEnrollPhoneMfa(auth, {
|
|
8131
|
+
idToken: idToken,
|
|
8132
|
+
displayName: displayName,
|
|
8133
|
+
phoneVerificationInfo: this.credential._makeVerificationRequest()
|
|
8134
|
+
});
|
|
8135
|
+
};
|
|
8136
|
+
/** @internal */
|
|
8137
|
+
PhoneMultiFactorAssertionImpl.prototype._finalizeSignIn = function (auth, mfaPendingCredential) {
|
|
8138
|
+
return finalizeSignInPhoneMfa(auth, {
|
|
8139
|
+
mfaPendingCredential: mfaPendingCredential,
|
|
8140
|
+
phoneVerificationInfo: this.credential._makeVerificationRequest()
|
|
8141
|
+
});
|
|
8142
|
+
};
|
|
8143
|
+
return PhoneMultiFactorAssertionImpl;
|
|
8144
|
+
}(MultiFactorAssertionImpl));
|
|
8145
|
+
/**
|
|
8146
|
+
* Provider for generating a {@link PhoneMultiFactorAssertion}.
|
|
8147
|
+
*
|
|
8148
|
+
* @public
|
|
8149
|
+
*/
|
|
8150
|
+
var PhoneMultiFactorGenerator = /** @class */ (function () {
|
|
8151
|
+
function PhoneMultiFactorGenerator() {
|
|
8152
|
+
}
|
|
8153
|
+
/**
|
|
8154
|
+
* Provides a {@link PhoneMultiFactorAssertion} to confirm ownership of the phone second factor.
|
|
8155
|
+
*
|
|
8156
|
+
* @param phoneAuthCredential - A credential provided by {@link PhoneAuthProvider.credential}.
|
|
8157
|
+
* @returns A {@link PhoneMultiFactorAssertion} which can be used with
|
|
8158
|
+
* {@link MultiFactorResolver.resolveSignIn}
|
|
8159
|
+
*/
|
|
8160
|
+
PhoneMultiFactorGenerator.assertion = function (credential) {
|
|
8161
|
+
return PhoneMultiFactorAssertionImpl._fromCredential(credential);
|
|
8162
|
+
};
|
|
8163
|
+
/**
|
|
8164
|
+
* The identifier of the phone second factor: `phone`.
|
|
8165
|
+
*/
|
|
8166
|
+
PhoneMultiFactorGenerator.FACTOR_ID = 'phone';
|
|
8167
|
+
return PhoneMultiFactorGenerator;
|
|
8168
|
+
}());
|
|
8169
|
+
|
|
7019
8170
|
exports.AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY = AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY;
|
|
7020
8171
|
exports.ActionCodeOperation = ActionCodeOperation;
|
|
7021
8172
|
exports.ActionCodeURL = ActionCodeURL;
|
|
@@ -7035,14 +8186,16 @@ exports.OAuthCredential = OAuthCredential;
|
|
|
7035
8186
|
exports.OAuthProvider = OAuthProvider;
|
|
7036
8187
|
exports.OperationType = OperationType;
|
|
7037
8188
|
exports.PhoneAuthCredential = PhoneAuthCredential;
|
|
8189
|
+
exports.PhoneAuthProvider = PhoneAuthProvider;
|
|
8190
|
+
exports.PhoneMultiFactorGenerator = PhoneMultiFactorGenerator;
|
|
7038
8191
|
exports.ProviderId = ProviderId;
|
|
8192
|
+
exports.RecaptchaVerifier = RecaptchaVerifier;
|
|
7039
8193
|
exports.SAMLAuthCredential = SAMLAuthCredential;
|
|
7040
8194
|
exports.SAMLAuthProvider = SAMLAuthProvider;
|
|
7041
8195
|
exports.STORAGE_AVAILABLE_KEY = STORAGE_AVAILABLE_KEY;
|
|
7042
8196
|
exports.SignInMethod = SignInMethod;
|
|
7043
8197
|
exports.TwitterAuthProvider = TwitterAuthProvider;
|
|
7044
8198
|
exports.UserImpl = UserImpl;
|
|
7045
|
-
exports._addTidIfNecessary = _addTidIfNecessary;
|
|
7046
8199
|
exports._assert = _assert;
|
|
7047
8200
|
exports._assertInstanceOf = _assertInstanceOf;
|
|
7048
8201
|
exports._assertLinkedStatus = _assertLinkedStatus;
|
|
@@ -7050,13 +8203,16 @@ exports._castAuth = _castAuth;
|
|
|
7050
8203
|
exports._createError = _createError;
|
|
7051
8204
|
exports._emulatorUrl = _emulatorUrl;
|
|
7052
8205
|
exports._fail = _fail;
|
|
8206
|
+
exports._generateCallbackName = _generateCallbackName;
|
|
8207
|
+
exports._getActiveServiceWorker = _getActiveServiceWorker;
|
|
7053
8208
|
exports._getClientVersion = _getClientVersion;
|
|
7054
8209
|
exports._getCurrentUrl = _getCurrentUrl;
|
|
7055
8210
|
exports._getInstance = _getInstance;
|
|
8211
|
+
exports._getServiceWorkerController = _getServiceWorkerController;
|
|
8212
|
+
exports._getWorkerGlobalScope = _getWorkerGlobalScope;
|
|
7056
8213
|
exports._isAndroid = _isAndroid;
|
|
7057
8214
|
exports._isChromeIOS = _isChromeIOS;
|
|
7058
8215
|
exports._isFirefox = _isFirefox;
|
|
7059
|
-
exports._isHttpOrHttps = _isHttpOrHttps;
|
|
7060
8216
|
exports._isIE10 = _isIE10;
|
|
7061
8217
|
exports._isIOS = _isIOS;
|
|
7062
8218
|
exports._isIOS7Or8 = _isIOS7Or8;
|
|
@@ -7064,11 +8220,15 @@ exports._isIOSStandalone = _isIOSStandalone;
|
|
|
7064
8220
|
exports._isIframe = _isIframe;
|
|
7065
8221
|
exports._isMobileBrowser = _isMobileBrowser;
|
|
7066
8222
|
exports._isSafari = _isSafari;
|
|
8223
|
+
exports._isWorker = _isWorker;
|
|
7067
8224
|
exports._link = _link;
|
|
8225
|
+
exports._loadJS = _loadJS;
|
|
7068
8226
|
exports._performApiRequest = _performApiRequest;
|
|
7069
8227
|
exports._persistenceKeyName = _persistenceKeyName;
|
|
7070
8228
|
exports._reauthenticate = _reauthenticate;
|
|
8229
|
+
exports._setWindowLocation = _setWindowLocation;
|
|
7071
8230
|
exports._signInWithCredential = _signInWithCredential;
|
|
8231
|
+
exports._window = _window;
|
|
7072
8232
|
exports.applyActionCode = applyActionCode;
|
|
7073
8233
|
exports.checkActionCode = checkActionCode;
|
|
7074
8234
|
exports.confirmPasswordReset = confirmPasswordReset;
|
|
@@ -7076,10 +8236,8 @@ exports.connectAuthEmulator = connectAuthEmulator;
|
|
|
7076
8236
|
exports.createUserWithEmailAndPassword = createUserWithEmailAndPassword;
|
|
7077
8237
|
exports.debugAssert = debugAssert;
|
|
7078
8238
|
exports.debugErrorMap = debugErrorMap;
|
|
7079
|
-
exports.debugFail = debugFail;
|
|
7080
8239
|
exports.deleteUser = deleteUser;
|
|
7081
8240
|
exports.fetchSignInMethodsForEmail = fetchSignInMethodsForEmail;
|
|
7082
|
-
exports.finalizeEnrollPhoneMfa = finalizeEnrollPhoneMfa;
|
|
7083
8241
|
exports.getAdditionalUserInfo = getAdditionalUserInfo;
|
|
7084
8242
|
exports.getIdToken = getIdToken;
|
|
7085
8243
|
exports.getIdTokenResult = getIdTokenResult;
|
|
@@ -7088,17 +8246,18 @@ exports.inMemoryPersistence = inMemoryPersistence;
|
|
|
7088
8246
|
exports.initializeAuth = initializeAuth;
|
|
7089
8247
|
exports.isSignInWithEmailLink = isSignInWithEmailLink;
|
|
7090
8248
|
exports.linkWithCredential = linkWithCredential;
|
|
8249
|
+
exports.linkWithPhoneNumber = linkWithPhoneNumber;
|
|
7091
8250
|
exports.multiFactor = multiFactor;
|
|
7092
8251
|
exports.onAuthStateChanged = onAuthStateChanged;
|
|
7093
8252
|
exports.onIdTokenChanged = onIdTokenChanged;
|
|
7094
8253
|
exports.parseActionCodeURL = parseActionCodeURL;
|
|
7095
8254
|
exports.prodErrorMap = prodErrorMap;
|
|
7096
8255
|
exports.reauthenticateWithCredential = reauthenticateWithCredential;
|
|
8256
|
+
exports.reauthenticateWithPhoneNumber = reauthenticateWithPhoneNumber;
|
|
7097
8257
|
exports.registerAuth = registerAuth;
|
|
7098
8258
|
exports.reload = reload;
|
|
7099
8259
|
exports.sendEmailVerification = sendEmailVerification;
|
|
7100
8260
|
exports.sendPasswordResetEmail = sendPasswordResetEmail;
|
|
7101
|
-
exports.sendPhoneVerificationCode = sendPhoneVerificationCode;
|
|
7102
8261
|
exports.sendSignInLinkToEmail = sendSignInLinkToEmail;
|
|
7103
8262
|
exports.setPersistence = setPersistence;
|
|
7104
8263
|
exports.signInAnonymously = signInAnonymously;
|
|
@@ -7107,14 +8266,15 @@ exports.signInWithCustomToken = signInWithCustomToken;
|
|
|
7107
8266
|
exports.signInWithEmailAndPassword = signInWithEmailAndPassword;
|
|
7108
8267
|
exports.signInWithEmailLink = signInWithEmailLink;
|
|
7109
8268
|
exports.signInWithIdp = signInWithIdp;
|
|
8269
|
+
exports.signInWithPhoneNumber = signInWithPhoneNumber;
|
|
7110
8270
|
exports.signOut = signOut;
|
|
7111
|
-
exports.startEnrollPhoneMfa = startEnrollPhoneMfa;
|
|
7112
8271
|
exports.unlink = unlink;
|
|
7113
8272
|
exports.updateCurrentUser = updateCurrentUser;
|
|
7114
8273
|
exports.updateEmail = updateEmail;
|
|
7115
8274
|
exports.updatePassword = updatePassword;
|
|
8275
|
+
exports.updatePhoneNumber = updatePhoneNumber;
|
|
7116
8276
|
exports.updateProfile = updateProfile;
|
|
7117
8277
|
exports.useDeviceLanguage = useDeviceLanguage;
|
|
7118
8278
|
exports.verifyBeforeUpdateEmail = verifyBeforeUpdateEmail;
|
|
7119
8279
|
exports.verifyPasswordResetCode = verifyPasswordResetCode;
|
|
7120
|
-
//# sourceMappingURL=
|
|
8280
|
+
//# sourceMappingURL=phone-e3d3bcce.js.map
|