GSI - Employe Self Service Mobile
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1837 lines
78 KiB

2 months ago
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var index = require('./index-69e083b1.js');
  4. var tslib = require('tslib');
  5. var util = require('@firebase/util');
  6. var app = require('@firebase/app');
  7. require('@firebase/logger');
  8. require('@firebase/component');
  9. require('node-fetch');
  10. /**
  11. * @license
  12. * Copyright 2020 Google LLC
  13. *
  14. * Licensed under the Apache License, Version 2.0 (the "License");
  15. * you may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at
  17. *
  18. * http://www.apache.org/licenses/LICENSE-2.0
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. */
  26. function _generateEventId(prefix, digits) {
  27. if (prefix === void 0) { prefix = ''; }
  28. if (digits === void 0) { digits = 10; }
  29. var random = '';
  30. for (var i = 0; i < digits; i++) {
  31. random += Math.floor(Math.random() * 10);
  32. }
  33. return prefix + random;
  34. }
  35. /**
  36. * @license
  37. * Copyright 2020 Google LLC.
  38. *
  39. * Licensed under the Apache License, Version 2.0 (the "License");
  40. * you may not use this file except in compliance with the License.
  41. * You may obtain a copy of the License at
  42. *
  43. * http://www.apache.org/licenses/LICENSE-2.0
  44. *
  45. * Unless required by applicable law or agreed to in writing, software
  46. * distributed under the License is distributed on an "AS IS" BASIS,
  47. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  48. * See the License for the specific language governing permissions and
  49. * limitations under the License.
  50. */
  51. var AuthPopup = /** @class */ (function () {
  52. function AuthPopup(window) {
  53. this.window = window;
  54. this.associatedEvent = null;
  55. }
  56. AuthPopup.prototype.close = function () {
  57. if (this.window) {
  58. try {
  59. this.window.close();
  60. }
  61. catch (e) { }
  62. }
  63. };
  64. return AuthPopup;
  65. }());
  66. /**
  67. * @license
  68. * Copyright 2021 Google LLC
  69. *
  70. * Licensed under the Apache License, Version 2.0 (the "License");
  71. * you may not use this file except in compliance with the License.
  72. * You may obtain a copy of the License at
  73. *
  74. * http://www.apache.org/licenses/LICENSE-2.0
  75. *
  76. * Unless required by applicable law or agreed to in writing, software
  77. * distributed under the License is distributed on an "AS IS" BASIS,
  78. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  79. * See the License for the specific language governing permissions and
  80. * limitations under the License.
  81. */
  82. /**
  83. * Chooses a popup/redirect resolver to use. This prefers the override (which
  84. * is directly passed in), and falls back to the property set on the auth
  85. * object. If neither are available, this function errors w/ an argument error.
  86. */
  87. function _withDefaultResolver(auth, resolverOverride) {
  88. if (resolverOverride) {
  89. return index._getInstance(resolverOverride);
  90. }
  91. index._assert(auth._popupRedirectResolver, auth, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
  92. return auth._popupRedirectResolver;
  93. }
  94. /**
  95. * @license
  96. * Copyright 2019 Google LLC
  97. *
  98. * Licensed under the Apache License, Version 2.0 (the "License");
  99. * you may not use this file except in compliance with the License.
  100. * You may obtain a copy of the License at
  101. *
  102. * http://www.apache.org/licenses/LICENSE-2.0
  103. *
  104. * Unless required by applicable law or agreed to in writing, software
  105. * distributed under the License is distributed on an "AS IS" BASIS,
  106. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  107. * See the License for the specific language governing permissions and
  108. * limitations under the License.
  109. */
  110. var IdpCredential = /** @class */ (function (_super) {
  111. tslib.__extends(IdpCredential, _super);
  112. function IdpCredential(params) {
  113. var _this = _super.call(this, "custom" /* ProviderId.CUSTOM */, "custom" /* ProviderId.CUSTOM */) || this;
  114. _this.params = params;
  115. return _this;
  116. }
  117. IdpCredential.prototype._getIdTokenResponse = function (auth) {
  118. return index.signInWithIdp(auth, this._buildIdpRequest());
  119. };
  120. IdpCredential.prototype._linkToIdToken = function (auth, idToken) {
  121. return index.signInWithIdp(auth, this._buildIdpRequest(idToken));
  122. };
  123. IdpCredential.prototype._getReauthenticationResolver = function (auth) {
  124. return index.signInWithIdp(auth, this._buildIdpRequest());
  125. };
  126. IdpCredential.prototype._buildIdpRequest = function (idToken) {
  127. var request = {
  128. requestUri: this.params.requestUri,
  129. sessionId: this.params.sessionId,
  130. postBody: this.params.postBody,
  131. tenantId: this.params.tenantId,
  132. pendingToken: this.params.pendingToken,
  133. returnSecureToken: true,
  134. returnIdpCredential: true
  135. };
  136. if (idToken) {
  137. request.idToken = idToken;
  138. }
  139. return request;
  140. };
  141. return IdpCredential;
  142. }(index.AuthCredential));
  143. function _signIn(params) {
  144. return index._signInWithCredential(params.auth, new IdpCredential(params), params.bypassAuthState);
  145. }
  146. function _reauth(params) {
  147. var auth = params.auth, user = params.user;
  148. index._assert(user, auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  149. return index._reauthenticate(user, new IdpCredential(params), params.bypassAuthState);
  150. }
  151. function _link(params) {
  152. return tslib.__awaiter(this, void 0, void 0, function () {
  153. var auth, user;
  154. return tslib.__generator(this, function (_a) {
  155. auth = params.auth, user = params.user;
  156. index._assert(user, auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  157. return [2 /*return*/, index._link(user, new IdpCredential(params), params.bypassAuthState)];
  158. });
  159. });
  160. }
  161. /**
  162. * @license
  163. * Copyright 2020 Google LLC
  164. *
  165. * Licensed under the Apache License, Version 2.0 (the "License");
  166. * you may not use this file except in compliance with the License.
  167. * You may obtain a copy of the License at
  168. *
  169. * http://www.apache.org/licenses/LICENSE-2.0
  170. *
  171. * Unless required by applicable law or agreed to in writing, software
  172. * distributed under the License is distributed on an "AS IS" BASIS,
  173. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  174. * See the License for the specific language governing permissions and
  175. * limitations under the License.
  176. */
  177. /**
  178. * Popup event manager. Handles the popup's entire lifecycle; listens to auth
  179. * events
  180. */
  181. var AbstractPopupRedirectOperation = /** @class */ (function () {
  182. function AbstractPopupRedirectOperation(auth, filter, resolver, user, bypassAuthState) {
  183. if (bypassAuthState === void 0) { bypassAuthState = false; }
  184. this.auth = auth;
  185. this.resolver = resolver;
  186. this.user = user;
  187. this.bypassAuthState = bypassAuthState;
  188. this.pendingPromise = null;
  189. this.eventManager = null;
  190. this.filter = Array.isArray(filter) ? filter : [filter];
  191. }
  192. AbstractPopupRedirectOperation.prototype.execute = function () {
  193. var _this = this;
  194. return new Promise(function (resolve, reject) { return tslib.__awaiter(_this, void 0, void 0, function () {
  195. var _a, e_1;
  196. return tslib.__generator(this, function (_b) {
  197. switch (_b.label) {
  198. case 0:
  199. this.pendingPromise = { resolve: resolve, reject: reject };
  200. _b.label = 1;
  201. case 1:
  202. _b.trys.push([1, 4, , 5]);
  203. _a = this;
  204. return [4 /*yield*/, this.resolver._initialize(this.auth)];
  205. case 2:
  206. _a.eventManager = _b.sent();
  207. return [4 /*yield*/, this.onExecution()];
  208. case 3:
  209. _b.sent();
  210. this.eventManager.registerConsumer(this);
  211. return [3 /*break*/, 5];
  212. case 4:
  213. e_1 = _b.sent();
  214. this.reject(e_1);
  215. return [3 /*break*/, 5];
  216. case 5: return [2 /*return*/];
  217. }
  218. });
  219. }); });
  220. };
  221. AbstractPopupRedirectOperation.prototype.onAuthEvent = function (event) {
  222. return tslib.__awaiter(this, void 0, void 0, function () {
  223. var urlResponse, sessionId, postBody, tenantId, error, type, params, _a, e_2;
  224. return tslib.__generator(this, function (_b) {
  225. switch (_b.label) {
  226. case 0:
  227. urlResponse = event.urlResponse, sessionId = event.sessionId, postBody = event.postBody, tenantId = event.tenantId, error = event.error, type = event.type;
  228. if (error) {
  229. this.reject(error);
  230. return [2 /*return*/];
  231. }
  232. params = {
  233. auth: this.auth,
  234. requestUri: urlResponse,
  235. sessionId: sessionId,
  236. tenantId: tenantId || undefined,
  237. postBody: postBody || undefined,
  238. user: this.user,
  239. bypassAuthState: this.bypassAuthState
  240. };
  241. _b.label = 1;
  242. case 1:
  243. _b.trys.push([1, 3, , 4]);
  244. _a = this.resolve;
  245. return [4 /*yield*/, this.getIdpTask(type)(params)];
  246. case 2:
  247. _a.apply(this, [_b.sent()]);
  248. return [3 /*break*/, 4];
  249. case 3:
  250. e_2 = _b.sent();
  251. this.reject(e_2);
  252. return [3 /*break*/, 4];
  253. case 4: return [2 /*return*/];
  254. }
  255. });
  256. });
  257. };
  258. AbstractPopupRedirectOperation.prototype.onError = function (error) {
  259. this.reject(error);
  260. };
  261. AbstractPopupRedirectOperation.prototype.getIdpTask = function (type) {
  262. switch (type) {
  263. case "signInViaPopup" /* AuthEventType.SIGN_IN_VIA_POPUP */:
  264. case "signInViaRedirect" /* AuthEventType.SIGN_IN_VIA_REDIRECT */:
  265. return _signIn;
  266. case "linkViaPopup" /* AuthEventType.LINK_VIA_POPUP */:
  267. case "linkViaRedirect" /* AuthEventType.LINK_VIA_REDIRECT */:
  268. return _link;
  269. case "reauthViaPopup" /* AuthEventType.REAUTH_VIA_POPUP */:
  270. case "reauthViaRedirect" /* AuthEventType.REAUTH_VIA_REDIRECT */:
  271. return _reauth;
  272. default:
  273. index._fail(this.auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
  274. }
  275. };
  276. AbstractPopupRedirectOperation.prototype.resolve = function (cred) {
  277. index.debugAssert(this.pendingPromise, 'Pending promise was never set');
  278. this.pendingPromise.resolve(cred);
  279. this.unregisterAndCleanUp();
  280. };
  281. AbstractPopupRedirectOperation.prototype.reject = function (error) {
  282. index.debugAssert(this.pendingPromise, 'Pending promise was never set');
  283. this.pendingPromise.reject(error);
  284. this.unregisterAndCleanUp();
  285. };
  286. AbstractPopupRedirectOperation.prototype.unregisterAndCleanUp = function () {
  287. if (this.eventManager) {
  288. this.eventManager.unregisterConsumer(this);
  289. }
  290. this.pendingPromise = null;
  291. this.cleanUp();
  292. };
  293. return AbstractPopupRedirectOperation;
  294. }());
  295. /**
  296. * @license
  297. * Copyright 2020 Google LLC
  298. *
  299. * Licensed under the Apache License, Version 2.0 (the "License");
  300. * you may not use this file except in compliance with the License.
  301. * You may obtain a copy of the License at
  302. *
  303. * http://www.apache.org/licenses/LICENSE-2.0
  304. *
  305. * Unless required by applicable law or agreed to in writing, software
  306. * distributed under the License is distributed on an "AS IS" BASIS,
  307. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  308. * See the License for the specific language governing permissions and
  309. * limitations under the License.
  310. */
  311. var PENDING_REDIRECT_KEY = 'pendingRedirect';
  312. // We only get one redirect outcome for any one auth, so just store it
  313. // in here.
  314. var redirectOutcomeMap = new Map();
  315. var RedirectAction = /** @class */ (function (_super) {
  316. tslib.__extends(RedirectAction, _super);
  317. function RedirectAction(auth, resolver, bypassAuthState) {
  318. if (bypassAuthState === void 0) { bypassAuthState = false; }
  319. var _this = _super.call(this, auth, [
  320. "signInViaRedirect" /* AuthEventType.SIGN_IN_VIA_REDIRECT */,
  321. "linkViaRedirect" /* AuthEventType.LINK_VIA_REDIRECT */,
  322. "reauthViaRedirect" /* AuthEventType.REAUTH_VIA_REDIRECT */,
  323. "unknown" /* AuthEventType.UNKNOWN */
  324. ], resolver, undefined, bypassAuthState) || this;
  325. _this.eventId = null;
  326. return _this;
  327. }
  328. /**
  329. * Override the execute function; if we already have a redirect result, then
  330. * just return it.
  331. */
  332. RedirectAction.prototype.execute = function () {
  333. return tslib.__awaiter(this, void 0, void 0, function () {
  334. var readyOutcome, hasPendingRedirect, result_1, _a, e_1;
  335. return tslib.__generator(this, function (_b) {
  336. switch (_b.label) {
  337. case 0:
  338. readyOutcome = redirectOutcomeMap.get(this.auth._key());
  339. if (!!readyOutcome) return [3 /*break*/, 8];
  340. _b.label = 1;
  341. case 1:
  342. _b.trys.push([1, 6, , 7]);
  343. return [4 /*yield*/, _getAndClearPendingRedirectStatus(this.resolver, this.auth)];
  344. case 2:
  345. hasPendingRedirect = _b.sent();
  346. if (!hasPendingRedirect) return [3 /*break*/, 4];
  347. return [4 /*yield*/, _super.prototype.execute.call(this)];
  348. case 3:
  349. _a = _b.sent();
  350. return [3 /*break*/, 5];
  351. case 4:
  352. _a = null;
  353. _b.label = 5;
  354. case 5:
  355. result_1 = _a;
  356. readyOutcome = function () { return Promise.resolve(result_1); };
  357. return [3 /*break*/, 7];
  358. case 6:
  359. e_1 = _b.sent();
  360. readyOutcome = function () { return Promise.reject(e_1); };
  361. return [3 /*break*/, 7];
  362. case 7:
  363. redirectOutcomeMap.set(this.auth._key(), readyOutcome);
  364. _b.label = 8;
  365. case 8:
  366. // If we're not bypassing auth state, the ready outcome should be set to
  367. // null.
  368. if (!this.bypassAuthState) {
  369. redirectOutcomeMap.set(this.auth._key(), function () { return Promise.resolve(null); });
  370. }
  371. return [2 /*return*/, readyOutcome()];
  372. }
  373. });
  374. });
  375. };
  376. RedirectAction.prototype.onAuthEvent = function (event) {
  377. return tslib.__awaiter(this, void 0, void 0, function () {
  378. var user;
  379. return tslib.__generator(this, function (_a) {
  380. switch (_a.label) {
  381. case 0:
  382. if (event.type === "signInViaRedirect" /* AuthEventType.SIGN_IN_VIA_REDIRECT */) {
  383. return [2 /*return*/, _super.prototype.onAuthEvent.call(this, event)];
  384. }
  385. else if (event.type === "unknown" /* AuthEventType.UNKNOWN */) {
  386. // This is a sentinel value indicating there's no pending redirect
  387. this.resolve(null);
  388. return [2 /*return*/];
  389. }
  390. if (!event.eventId) return [3 /*break*/, 2];
  391. return [4 /*yield*/, this.auth._redirectUserForId(event.eventId)];
  392. case 1:
  393. user = _a.sent();
  394. if (user) {
  395. this.user = user;
  396. return [2 /*return*/, _super.prototype.onAuthEvent.call(this, event)];
  397. }
  398. else {
  399. this.resolve(null);
  400. }
  401. _a.label = 2;
  402. case 2: return [2 /*return*/];
  403. }
  404. });
  405. });
  406. };
  407. RedirectAction.prototype.onExecution = function () {
  408. return tslib.__awaiter(this, void 0, void 0, function () { return tslib.__generator(this, function (_a) {
  409. return [2 /*return*/];
  410. }); });
  411. };
  412. RedirectAction.prototype.cleanUp = function () { };
  413. return RedirectAction;
  414. }(AbstractPopupRedirectOperation));
  415. function _getAndClearPendingRedirectStatus(resolver, auth) {
  416. return tslib.__awaiter(this, void 0, void 0, function () {
  417. var key, persistence, hasPendingRedirect;
  418. return tslib.__generator(this, function (_a) {
  419. switch (_a.label) {
  420. case 0:
  421. key = pendingRedirectKey(auth);
  422. persistence = resolverPersistence(resolver);
  423. return [4 /*yield*/, persistence._isAvailable()];
  424. case 1:
  425. if (!(_a.sent())) {
  426. return [2 /*return*/, false];
  427. }
  428. return [4 /*yield*/, persistence._get(key)];
  429. case 2:
  430. hasPendingRedirect = (_a.sent()) === 'true';
  431. return [4 /*yield*/, persistence._remove(key)];
  432. case 3:
  433. _a.sent();
  434. return [2 /*return*/, hasPendingRedirect];
  435. }
  436. });
  437. });
  438. }
  439. function _clearRedirectOutcomes() {
  440. redirectOutcomeMap.clear();
  441. }
  442. function _overrideRedirectResult(auth, result) {
  443. redirectOutcomeMap.set(auth._key(), result);
  444. }
  445. function resolverPersistence(resolver) {
  446. return index._getInstance(resolver._redirectPersistence);
  447. }
  448. function pendingRedirectKey(auth) {
  449. return index._persistenceKeyName(PENDING_REDIRECT_KEY, auth.config.apiKey, auth.name);
  450. }
  451. /**
  452. * @license
  453. * Copyright 2020 Google LLC
  454. *
  455. * Licensed under the Apache License, Version 2.0 (the "License");
  456. * you may not use this file except in compliance with the License.
  457. * You may obtain a copy of the License at
  458. *
  459. * http://www.apache.org/licenses/LICENSE-2.0
  460. *
  461. * Unless required by applicable law or agreed to in writing, software
  462. * distributed under the License is distributed on an "AS IS" BASIS,
  463. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  464. * See the License for the specific language governing permissions and
  465. * limitations under the License.
  466. */
  467. function _getRedirectResult(auth, resolverExtern, bypassAuthState) {
  468. if (bypassAuthState === void 0) { bypassAuthState = false; }
  469. return tslib.__awaiter(this, void 0, void 0, function () {
  470. var authInternal, resolver, action, result;
  471. return tslib.__generator(this, function (_a) {
  472. switch (_a.label) {
  473. case 0:
  474. authInternal = index._castAuth(auth);
  475. resolver = _withDefaultResolver(authInternal, resolverExtern);
  476. action = new RedirectAction(authInternal, resolver, bypassAuthState);
  477. return [4 /*yield*/, action.execute()];
  478. case 1:
  479. result = _a.sent();
  480. if (!(result && !bypassAuthState)) return [3 /*break*/, 4];
  481. delete result.user._redirectEventId;
  482. return [4 /*yield*/, authInternal._persistUserIfCurrent(result.user)];
  483. case 2:
  484. _a.sent();
  485. return [4 /*yield*/, authInternal._setRedirectUser(null, resolverExtern)];
  486. case 3:
  487. _a.sent();
  488. _a.label = 4;
  489. case 4: return [2 /*return*/, result];
  490. }
  491. });
  492. });
  493. }
  494. var STORAGE_AVAILABLE_KEY = '__sak';
  495. /**
  496. * @license
  497. * Copyright 2019 Google LLC
  498. *
  499. * Licensed under the Apache License, Version 2.0 (the "License");
  500. * you may not use this file except in compliance with the License.
  501. * You may obtain a copy of the License at
  502. *
  503. * http://www.apache.org/licenses/LICENSE-2.0
  504. *
  505. * Unless required by applicable law or agreed to in writing, software
  506. * distributed under the License is distributed on an "AS IS" BASIS,
  507. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  508. * See the License for the specific language governing permissions and
  509. * limitations under the License.
  510. */
  511. // There are two different browser persistence types: local and session.
  512. // Both have the same implementation but use a different underlying storage
  513. // object.
  514. var BrowserPersistenceClass = /** @class */ (function () {
  515. function BrowserPersistenceClass(storageRetriever, type) {
  516. this.storageRetriever = storageRetriever;
  517. this.type = type;
  518. }
  519. BrowserPersistenceClass.prototype._isAvailable = function () {
  520. try {
  521. if (!this.storage) {
  522. return Promise.resolve(false);
  523. }
  524. this.storage.setItem(STORAGE_AVAILABLE_KEY, '1');
  525. this.storage.removeItem(STORAGE_AVAILABLE_KEY);
  526. return Promise.resolve(true);
  527. }
  528. catch (_a) {
  529. return Promise.resolve(false);
  530. }
  531. };
  532. BrowserPersistenceClass.prototype._set = function (key, value) {
  533. this.storage.setItem(key, JSON.stringify(value));
  534. return Promise.resolve();
  535. };
  536. BrowserPersistenceClass.prototype._get = function (key) {
  537. var json = this.storage.getItem(key);
  538. return Promise.resolve(json ? JSON.parse(json) : null);
  539. };
  540. BrowserPersistenceClass.prototype._remove = function (key) {
  541. this.storage.removeItem(key);
  542. return Promise.resolve();
  543. };
  544. Object.defineProperty(BrowserPersistenceClass.prototype, "storage", {
  545. get: function () {
  546. return this.storageRetriever();
  547. },
  548. enumerable: false,
  549. configurable: true
  550. });
  551. return BrowserPersistenceClass;
  552. }());
  553. /**
  554. * @license
  555. * Copyright 2020 Google LLC
  556. *
  557. * Licensed under the Apache License, Version 2.0 (the "License");
  558. * you may not use this file except in compliance with the License.
  559. * You may obtain a copy of the License at
  560. *
  561. * http://www.apache.org/licenses/LICENSE-2.0
  562. *
  563. * Unless required by applicable law or agreed to in writing, software
  564. * distributed under the License is distributed on an "AS IS" BASIS,
  565. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  566. * See the License for the specific language governing permissions and
  567. * limitations under the License.
  568. */
  569. var BrowserSessionPersistence = /** @class */ (function (_super) {
  570. tslib.__extends(BrowserSessionPersistence, _super);
  571. function BrowserSessionPersistence() {
  572. return _super.call(this, function () { return window.sessionStorage; }, "SESSION" /* PersistenceType.SESSION */) || this;
  573. }
  574. BrowserSessionPersistence.prototype._addListener = function (_key, _listener) {
  575. // Listeners are not supported for session storage since it cannot be shared across windows
  576. return;
  577. };
  578. BrowserSessionPersistence.prototype._removeListener = function (_key, _listener) {
  579. // Listeners are not supported for session storage since it cannot be shared across windows
  580. return;
  581. };
  582. BrowserSessionPersistence.type = 'SESSION';
  583. return BrowserSessionPersistence;
  584. }(BrowserPersistenceClass));
  585. /**
  586. * An implementation of {@link Persistence} of `SESSION` using `sessionStorage`
  587. * for the underlying storage.
  588. *
  589. * @public
  590. */
  591. var browserSessionPersistence = BrowserSessionPersistence;
  592. /**
  593. * @license
  594. * Copyright 2021 Google LLC
  595. *
  596. * Licensed under the Apache License, Version 2.0 (the "License");
  597. * you may not use this file except in compliance with the License.
  598. * You may obtain a copy of the License at
  599. *
  600. * http://www.apache.org/licenses/LICENSE-2.0
  601. *
  602. * Unless required by applicable law or agreed to in writing, software
  603. * distributed under the License is distributed on an "AS IS" BASIS,
  604. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  605. * See the License for the specific language governing permissions and
  606. * limitations under the License.
  607. */
  608. /**
  609. * URL for Authentication widget which will initiate the OAuth handshake
  610. *
  611. * @internal
  612. */
  613. var WIDGET_PATH = '__/auth/handler';
  614. /**
  615. * URL for emulated environment
  616. *
  617. * @internal
  618. */
  619. var EMULATOR_WIDGET_PATH = 'emulator/auth/handler';
  620. function _getRedirectUrl(auth, provider, authType, redirectUrl, eventId, additionalParams) {
  621. index._assert(auth.config.authDomain, auth, "auth-domain-config-required" /* AuthErrorCode.MISSING_AUTH_DOMAIN */);
  622. index._assert(auth.config.apiKey, auth, "invalid-api-key" /* AuthErrorCode.INVALID_API_KEY */);
  623. var params = {
  624. apiKey: auth.config.apiKey,
  625. appName: auth.name,
  626. authType: authType,
  627. redirectUrl: redirectUrl,
  628. v: app.SDK_VERSION,
  629. eventId: eventId
  630. };
  631. if (provider instanceof index.FederatedAuthProvider) {
  632. provider.setDefaultLanguage(auth.languageCode);
  633. params.providerId = provider.providerId || '';
  634. if (!util.isEmpty(provider.getCustomParameters())) {
  635. params.customParameters = JSON.stringify(provider.getCustomParameters());
  636. }
  637. // TODO set additionalParams from the provider as well?
  638. for (var _i = 0, _a = Object.entries(additionalParams || {}); _i < _a.length; _i++) {
  639. var _b = _a[_i], key = _b[0], value = _b[1];
  640. params[key] = value;
  641. }
  642. }
  643. if (provider instanceof index.BaseOAuthProvider) {
  644. var scopes = provider.getScopes().filter(function (scope) { return scope !== ''; });
  645. if (scopes.length > 0) {
  646. params.scopes = scopes.join(',');
  647. }
  648. }
  649. if (auth.tenantId) {
  650. params.tid = auth.tenantId;
  651. }
  652. // TODO: maybe set eid as endipointId
  653. // TODO: maybe set fw as Frameworks.join(",")
  654. var paramsDict = params;
  655. for (var _c = 0, _d = Object.keys(paramsDict); _c < _d.length; _c++) {
  656. var key = _d[_c];
  657. if (paramsDict[key] === undefined) {
  658. delete paramsDict[key];
  659. }
  660. }
  661. return "".concat(getHandlerBase(auth), "?").concat(util.querystring(paramsDict).slice(1));
  662. }
  663. function getHandlerBase(_a) {
  664. var config = _a.config;
  665. if (!config.emulator) {
  666. return "https://".concat(config.authDomain, "/").concat(WIDGET_PATH);
  667. }
  668. return index._emulatorUrl(config, EMULATOR_WIDGET_PATH);
  669. }
  670. /**
  671. * @license
  672. * Copyright 2021 Google LLC
  673. *
  674. * Licensed under the Apache License, Version 2.0 (the "License");
  675. * you may not use this file except in compliance with the License.
  676. * You may obtain a copy of the License at
  677. *
  678. * http://www.apache.org/licenses/LICENSE-2.0
  679. *
  680. * Unless required by applicable law or agreed to in writing, software
  681. * distributed under the License is distributed on an "AS IS" BASIS,
  682. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  683. * See the License for the specific language governing permissions and
  684. * limitations under the License.
  685. */
  686. function _cordovaWindow() {
  687. return window;
  688. }
  689. /**
  690. * @license
  691. * Copyright 2020 Google LLC
  692. *
  693. * Licensed under the Apache License, Version 2.0 (the "License");
  694. * you may not use this file except in compliance with the License.
  695. * You may obtain a copy of the License at
  696. *
  697. * http://www.apache.org/licenses/LICENSE-2.0
  698. *
  699. * Unless required by applicable law or agreed to in writing, software
  700. * distributed under the License is distributed on an "AS IS" BASIS,
  701. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  702. * See the License for the specific language governing permissions and
  703. * limitations under the License.
  704. */
  705. function _getProjectConfig(auth, request) {
  706. if (request === void 0) { request = {}; }
  707. return tslib.__awaiter(this, void 0, void 0, function () {
  708. return tslib.__generator(this, function (_a) {
  709. return [2 /*return*/, index._performApiRequest(auth, "GET" /* HttpMethod.GET */, "/v1/projects" /* Endpoint.GET_PROJECT_CONFIG */, request)];
  710. });
  711. });
  712. }
  713. /**
  714. * @license
  715. * Copyright 2020 Google LLC
  716. *
  717. * Licensed under the Apache License, Version 2.0 (the "License");
  718. * you may not use this file except in compliance with the License.
  719. * You may obtain a copy of the License at
  720. *
  721. * http://www.apache.org/licenses/LICENSE-2.0
  722. *
  723. * Unless required by applicable law or agreed to in writing, software
  724. * distributed under the License is distributed on an "AS IS" BASIS,
  725. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  726. * See the License for the specific language governing permissions and
  727. * limitations under the License.
  728. */
  729. /**
  730. * How long to wait after the app comes back into focus before concluding that
  731. * the user closed the sign in tab.
  732. */
  733. var REDIRECT_TIMEOUT_MS = 2000;
  734. /**
  735. * Generates the URL for the OAuth handler.
  736. */
  737. function _generateHandlerUrl(auth, event, provider) {
  738. var _a;
  739. return tslib.__awaiter(this, void 0, void 0, function () {
  740. var BuildInfo, sessionDigest, additionalParams;
  741. return tslib.__generator(this, function (_b) {
  742. switch (_b.label) {
  743. case 0:
  744. BuildInfo = _cordovaWindow().BuildInfo;
  745. index.debugAssert(event.sessionId, 'AuthEvent did not contain a session ID');
  746. return [4 /*yield*/, computeSha256(event.sessionId)];
  747. case 1:
  748. sessionDigest = _b.sent();
  749. additionalParams = {};
  750. if (index._isIOS()) {
  751. // iOS app identifier
  752. additionalParams['ibi'] = BuildInfo.packageName;
  753. }
  754. else if (index._isAndroid()) {
  755. // Android app identifier
  756. additionalParams['apn'] = BuildInfo.packageName;
  757. }
  758. else {
  759. index._fail(auth, "operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */);
  760. }
  761. // Add the display name if available
  762. if (BuildInfo.displayName) {
  763. additionalParams['appDisplayName'] = BuildInfo.displayName;
  764. }
  765. // Attached the hashed session ID
  766. additionalParams['sessionId'] = sessionDigest;
  767. return [2 /*return*/, _getRedirectUrl(auth, provider, event.type, undefined, (_a = event.eventId) !== null && _a !== void 0 ? _a : undefined, additionalParams)];
  768. }
  769. });
  770. });
  771. }
  772. /**
  773. * Validates that this app is valid for this project configuration
  774. */
  775. function _validateOrigin(auth) {
  776. return tslib.__awaiter(this, void 0, void 0, function () {
  777. var BuildInfo, request;
  778. return tslib.__generator(this, function (_a) {
  779. switch (_a.label) {
  780. case 0:
  781. BuildInfo = _cordovaWindow().BuildInfo;
  782. request = {};
  783. if (index._isIOS()) {
  784. request.iosBundleId = BuildInfo.packageName;
  785. }
  786. else if (index._isAndroid()) {
  787. request.androidPackageName = BuildInfo.packageName;
  788. }
  789. else {
  790. index._fail(auth, "operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */);
  791. }
  792. // Will fail automatically if package name is not authorized
  793. return [4 /*yield*/, _getProjectConfig(auth, request)];
  794. case 1:
  795. // Will fail automatically if package name is not authorized
  796. _a.sent();
  797. return [2 /*return*/];
  798. }
  799. });
  800. });
  801. }
  802. function _performRedirect(handlerUrl) {
  803. // Get the cordova plugins
  804. var cordova = _cordovaWindow().cordova;
  805. return new Promise(function (resolve) {
  806. cordova.plugins.browsertab.isAvailable(function (browserTabIsAvailable) {
  807. var iabRef = null;
  808. if (browserTabIsAvailable) {
  809. cordova.plugins.browsertab.openUrl(handlerUrl);
  810. }
  811. else {
  812. // TODO: Return the inappbrowser ref that's returned from the open call
  813. iabRef = cordova.InAppBrowser.open(handlerUrl, index._isIOS7Or8() ? '_blank' : '_system', 'location=yes');
  814. }
  815. resolve(iabRef);
  816. });
  817. });
  818. }
  819. /**
  820. * This function waits for app activity to be seen before resolving. It does
  821. * this by attaching listeners to various dom events. Once the app is determined
  822. * to be visible, this promise resolves. AFTER that resolution, the listeners
  823. * are detached and any browser tabs left open will be closed.
  824. */
  825. function _waitForAppResume(auth, eventListener, iabRef) {
  826. return tslib.__awaiter(this, void 0, void 0, function () {
  827. var cordova, cleanup;
  828. return tslib.__generator(this, function (_a) {
  829. switch (_a.label) {
  830. case 0:
  831. cordova = _cordovaWindow().cordova;
  832. cleanup = function () { };
  833. _a.label = 1;
  834. case 1:
  835. _a.trys.push([1, , 3, 4]);
  836. return [4 /*yield*/, new Promise(function (resolve, reject) {
  837. var onCloseTimer = null;
  838. // DEFINE ALL THE CALLBACKS =====
  839. function authEventSeen() {
  840. var _a;
  841. // Auth event was detected. Resolve this promise and close the extra
  842. // window if it's still open.
  843. resolve();
  844. var closeBrowserTab = (_a = cordova.plugins.browsertab) === null || _a === void 0 ? void 0 : _a.close;
  845. if (typeof closeBrowserTab === 'function') {
  846. closeBrowserTab();
  847. }
  848. // Close inappbrowser emebedded webview in iOS7 and 8 case if still
  849. // open.
  850. if (typeof (iabRef === null || iabRef === void 0 ? void 0 : iabRef.close) === 'function') {
  851. iabRef.close();
  852. }
  853. }
  854. function resumed() {
  855. if (onCloseTimer) {
  856. // This code already ran; do not rerun.
  857. return;
  858. }
  859. onCloseTimer = window.setTimeout(function () {
  860. // Wait two seeconds after resume then reject.
  861. reject(index._createError(auth, "redirect-cancelled-by-user" /* AuthErrorCode.REDIRECT_CANCELLED_BY_USER */));
  862. }, REDIRECT_TIMEOUT_MS);
  863. }
  864. function visibilityChanged() {
  865. if ((document === null || document === void 0 ? void 0 : document.visibilityState) === 'visible') {
  866. resumed();
  867. }
  868. }
  869. // ATTACH ALL THE LISTENERS =====
  870. // Listen for the auth event
  871. eventListener.addPassiveListener(authEventSeen);
  872. // Listen for resume and visibility events
  873. document.addEventListener('resume', resumed, false);
  874. if (index._isAndroid()) {
  875. document.addEventListener('visibilitychange', visibilityChanged, false);
  876. }
  877. // SETUP THE CLEANUP FUNCTION =====
  878. cleanup = function () {
  879. eventListener.removePassiveListener(authEventSeen);
  880. document.removeEventListener('resume', resumed, false);
  881. document.removeEventListener('visibilitychange', visibilityChanged, false);
  882. if (onCloseTimer) {
  883. window.clearTimeout(onCloseTimer);
  884. }
  885. };
  886. })];
  887. case 2:
  888. _a.sent();
  889. return [3 /*break*/, 4];
  890. case 3:
  891. cleanup();
  892. return [7 /*endfinally*/];
  893. case 4: return [2 /*return*/];
  894. }
  895. });
  896. });
  897. }
  898. /**
  899. * Checks the configuration of the Cordova environment. This has no side effect
  900. * if the configuration is correct; otherwise it throws an error with the
  901. * missing plugin.
  902. */
  903. function _checkCordovaConfiguration(auth) {
  904. var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
  905. var win = _cordovaWindow();
  906. // Check all dependencies installed.
  907. // https://github.com/nordnet/cordova-universal-links-plugin
  908. // Note that cordova-universal-links-plugin has been abandoned.
  909. // A fork with latest fixes is available at:
  910. // https://www.npmjs.com/package/cordova-universal-links-plugin-fix
  911. index._assert(typeof ((_a = win === null || win === void 0 ? void 0 : win.universalLinks) === null || _a === void 0 ? void 0 : _a.subscribe) === 'function', auth, "invalid-cordova-configuration" /* AuthErrorCode.INVALID_CORDOVA_CONFIGURATION */, {
  912. missingPlugin: 'cordova-universal-links-plugin-fix'
  913. });
  914. // https://www.npmjs.com/package/cordova-plugin-buildinfo
  915. index._assert(typeof ((_b = win === null || win === void 0 ? void 0 : win.BuildInfo) === null || _b === void 0 ? void 0 : _b.packageName) !== 'undefined', auth, "invalid-cordova-configuration" /* AuthErrorCode.INVALID_CORDOVA_CONFIGURATION */, {
  916. missingPlugin: 'cordova-plugin-buildInfo'
  917. });
  918. // https://github.com/google/cordova-plugin-browsertab
  919. index._assert(typeof ((_e = (_d = (_c = win === null || win === void 0 ? void 0 : win.cordova) === null || _c === void 0 ? void 0 : _c.plugins) === null || _d === void 0 ? void 0 : _d.browsertab) === null || _e === void 0 ? void 0 : _e.openUrl) === 'function', auth, "invalid-cordova-configuration" /* AuthErrorCode.INVALID_CORDOVA_CONFIGURATION */, {
  920. missingPlugin: 'cordova-plugin-browsertab'
  921. });
  922. index._assert(typeof ((_h = (_g = (_f = win === null || win === void 0 ? void 0 : win.cordova) === null || _f === void 0 ? void 0 : _f.plugins) === null || _g === void 0 ? void 0 : _g.browsertab) === null || _h === void 0 ? void 0 : _h.isAvailable) === 'function', auth, "invalid-cordova-configuration" /* AuthErrorCode.INVALID_CORDOVA_CONFIGURATION */, {
  923. missingPlugin: 'cordova-plugin-browsertab'
  924. });
  925. // https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-inappbrowser/
  926. index._assert(typeof ((_k = (_j = win === null || win === void 0 ? void 0 : win.cordova) === null || _j === void 0 ? void 0 : _j.InAppBrowser) === null || _k === void 0 ? void 0 : _k.open) === 'function', auth, "invalid-cordova-configuration" /* AuthErrorCode.INVALID_CORDOVA_CONFIGURATION */, {
  927. missingPlugin: 'cordova-plugin-inappbrowser'
  928. });
  929. }
  930. /**
  931. * Computes the SHA-256 of a session ID. The SubtleCrypto interface is only
  932. * available in "secure" contexts, which covers Cordova (which is served on a file
  933. * protocol).
  934. */
  935. function computeSha256(sessionId) {
  936. return tslib.__awaiter(this, void 0, void 0, function () {
  937. var bytes, buf, arr;
  938. return tslib.__generator(this, function (_a) {
  939. switch (_a.label) {
  940. case 0:
  941. bytes = stringToArrayBuffer(sessionId);
  942. return [4 /*yield*/, crypto.subtle.digest('SHA-256', bytes)];
  943. case 1:
  944. buf = _a.sent();
  945. arr = Array.from(new Uint8Array(buf));
  946. return [2 /*return*/, arr.map(function (num) { return num.toString(16).padStart(2, '0'); }).join('')];
  947. }
  948. });
  949. });
  950. }
  951. function stringToArrayBuffer(str) {
  952. // This function is only meant to deal with an ASCII charset and makes
  953. // certain simplifying assumptions.
  954. index.debugAssert(/[0-9a-zA-Z]+/.test(str), 'Can only convert alpha-numeric strings');
  955. if (typeof TextEncoder !== 'undefined') {
  956. return new TextEncoder().encode(str);
  957. }
  958. var buff = new ArrayBuffer(str.length);
  959. var view = new Uint8Array(buff);
  960. for (var i = 0; i < str.length; i++) {
  961. view[i] = str.charCodeAt(i);
  962. }
  963. return view;
  964. }
  965. /**
  966. * @license
  967. * Copyright 2020 Google LLC
  968. *
  969. * Licensed under the Apache License, Version 2.0 (the "License");
  970. * you may not use this file except in compliance with the License.
  971. * You may obtain a copy of the License at
  972. *
  973. * http://www.apache.org/licenses/LICENSE-2.0
  974. *
  975. * Unless required by applicable law or agreed to in writing, software
  976. * distributed under the License is distributed on an "AS IS" BASIS,
  977. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  978. * See the License for the specific language governing permissions and
  979. * limitations under the License.
  980. */
  981. // The amount of time to store the UIDs of seen events; this is
  982. // set to 10 min by default
  983. var EVENT_DUPLICATION_CACHE_DURATION_MS = 10 * 60 * 1000;
  984. var AuthEventManager = /** @class */ (function () {
  985. function AuthEventManager(auth) {
  986. this.auth = auth;
  987. this.cachedEventUids = new Set();
  988. this.consumers = new Set();
  989. this.queuedRedirectEvent = null;
  990. this.hasHandledPotentialRedirect = false;
  991. this.lastProcessedEventTime = Date.now();
  992. }
  993. AuthEventManager.prototype.registerConsumer = function (authEventConsumer) {
  994. this.consumers.add(authEventConsumer);
  995. if (this.queuedRedirectEvent &&
  996. this.isEventForConsumer(this.queuedRedirectEvent, authEventConsumer)) {
  997. this.sendToConsumer(this.queuedRedirectEvent, authEventConsumer);
  998. this.saveEventToCache(this.queuedRedirectEvent);
  999. this.queuedRedirectEvent = null;
  1000. }
  1001. };
  1002. AuthEventManager.prototype.unregisterConsumer = function (authEventConsumer) {
  1003. this.consumers.delete(authEventConsumer);
  1004. };
  1005. AuthEventManager.prototype.onEvent = function (event) {
  1006. var _this = this;
  1007. // Check if the event has already been handled
  1008. if (this.hasEventBeenHandled(event)) {
  1009. return false;
  1010. }
  1011. var handled = false;
  1012. this.consumers.forEach(function (consumer) {
  1013. if (_this.isEventForConsumer(event, consumer)) {
  1014. handled = true;
  1015. _this.sendToConsumer(event, consumer);
  1016. _this.saveEventToCache(event);
  1017. }
  1018. });
  1019. if (this.hasHandledPotentialRedirect || !isRedirectEvent(event)) {
  1020. // If we've already seen a redirect before, or this is a popup event,
  1021. // bail now
  1022. return handled;
  1023. }
  1024. this.hasHandledPotentialRedirect = true;
  1025. // If the redirect wasn't handled, hang on to it
  1026. if (!handled) {
  1027. this.queuedRedirectEvent = event;
  1028. handled = true;
  1029. }
  1030. return handled;
  1031. };
  1032. AuthEventManager.prototype.sendToConsumer = function (event, consumer) {
  1033. var _a;
  1034. if (event.error && !isNullRedirectEvent(event)) {
  1035. var code = ((_a = event.error.code) === null || _a === void 0 ? void 0 : _a.split('auth/')[1]) ||
  1036. "internal-error" /* AuthErrorCode.INTERNAL_ERROR */;
  1037. consumer.onError(index._createError(this.auth, code));
  1038. }
  1039. else {
  1040. consumer.onAuthEvent(event);
  1041. }
  1042. };
  1043. AuthEventManager.prototype.isEventForConsumer = function (event, consumer) {
  1044. var eventIdMatches = consumer.eventId === null ||
  1045. (!!event.eventId && event.eventId === consumer.eventId);
  1046. return consumer.filter.includes(event.type) && eventIdMatches;
  1047. };
  1048. AuthEventManager.prototype.hasEventBeenHandled = function (event) {
  1049. if (Date.now() - this.lastProcessedEventTime >=
  1050. EVENT_DUPLICATION_CACHE_DURATION_MS) {
  1051. this.cachedEventUids.clear();
  1052. }
  1053. return this.cachedEventUids.has(eventUid(event));
  1054. };
  1055. AuthEventManager.prototype.saveEventToCache = function (event) {
  1056. this.cachedEventUids.add(eventUid(event));
  1057. this.lastProcessedEventTime = Date.now();
  1058. };
  1059. return AuthEventManager;
  1060. }());
  1061. function eventUid(e) {
  1062. return [e.type, e.eventId, e.sessionId, e.tenantId].filter(function (v) { return v; }).join('-');
  1063. }
  1064. function isNullRedirectEvent(_a) {
  1065. var type = _a.type, error = _a.error;
  1066. return (type === "unknown" /* AuthEventType.UNKNOWN */ &&
  1067. (error === null || error === void 0 ? void 0 : error.code) === "auth/".concat("no-auth-event" /* AuthErrorCode.NO_AUTH_EVENT */));
  1068. }
  1069. function isRedirectEvent(event) {
  1070. switch (event.type) {
  1071. case "signInViaRedirect" /* AuthEventType.SIGN_IN_VIA_REDIRECT */:
  1072. case "linkViaRedirect" /* AuthEventType.LINK_VIA_REDIRECT */:
  1073. case "reauthViaRedirect" /* AuthEventType.REAUTH_VIA_REDIRECT */:
  1074. return true;
  1075. case "unknown" /* AuthEventType.UNKNOWN */:
  1076. return isNullRedirectEvent(event);
  1077. default:
  1078. return false;
  1079. }
  1080. }
  1081. /**
  1082. * @license
  1083. * Copyright 2020 Google LLC
  1084. *
  1085. * Licensed under the Apache License, Version 2.0 (the "License");
  1086. * you may not use this file except in compliance with the License.
  1087. * You may obtain a copy of the License at
  1088. *
  1089. * http://www.apache.org/licenses/LICENSE-2.0
  1090. *
  1091. * Unless required by applicable law or agreed to in writing, software
  1092. * distributed under the License is distributed on an "AS IS" BASIS,
  1093. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1094. * See the License for the specific language governing permissions and
  1095. * limitations under the License.
  1096. */
  1097. function _iframeCannotSyncWebStorage() {
  1098. var ua = util.getUA();
  1099. return index._isSafari(ua) || index._isIOS(ua);
  1100. }
  1101. // The polling period in case events are not supported
  1102. var _POLLING_INTERVAL_MS = 1000;
  1103. // The IE 10 localStorage cross tab synchronization delay in milliseconds
  1104. var IE10_LOCAL_STORAGE_SYNC_DELAY = 10;
  1105. var BrowserLocalPersistence = /** @class */ (function (_super) {
  1106. tslib.__extends(BrowserLocalPersistence, _super);
  1107. function BrowserLocalPersistence() {
  1108. var _this = _super.call(this, function () { return window.localStorage; }, "LOCAL" /* PersistenceType.LOCAL */) || this;
  1109. _this.boundEventHandler = function (event, poll) { return _this.onStorageEvent(event, poll); };
  1110. _this.listeners = {};
  1111. _this.localCache = {};
  1112. // setTimeout return value is platform specific
  1113. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  1114. _this.pollTimer = null;
  1115. // Safari or iOS browser and embedded in an iframe.
  1116. _this.safariLocalStorageNotSynced = _iframeCannotSyncWebStorage() && index._isIframe();
  1117. // Whether to use polling instead of depending on window events
  1118. _this.fallbackToPolling = index._isMobileBrowser();
  1119. _this._shouldAllowMigration = true;
  1120. return _this;
  1121. }
  1122. BrowserLocalPersistence.prototype.forAllChangedKeys = function (cb) {
  1123. // Check all keys with listeners on them.
  1124. for (var _i = 0, _a = Object.keys(this.listeners); _i < _a.length; _i++) {
  1125. var key = _a[_i];
  1126. // Get value from localStorage.
  1127. var newValue = this.storage.getItem(key);
  1128. var oldValue = this.localCache[key];
  1129. // If local map value does not match, trigger listener with storage event.
  1130. // Differentiate this simulated event from the real storage event.
  1131. if (newValue !== oldValue) {
  1132. cb(key, oldValue, newValue);
  1133. }
  1134. }
  1135. };
  1136. BrowserLocalPersistence.prototype.onStorageEvent = function (event, poll) {
  1137. var _this = this;
  1138. if (poll === void 0) { poll = false; }
  1139. // Key would be null in some situations, like when localStorage is cleared
  1140. if (!event.key) {
  1141. this.forAllChangedKeys(function (key, _oldValue, newValue) {
  1142. _this.notifyListeners(key, newValue);
  1143. });
  1144. return;
  1145. }
  1146. var key = event.key;
  1147. // Check the mechanism how this event was detected.
  1148. // The first event will dictate the mechanism to be used.
  1149. if (poll) {
  1150. // Environment detects storage changes via polling.
  1151. // Remove storage event listener to prevent possible event duplication.
  1152. this.detachListener();
  1153. }
  1154. else {
  1155. // Environment detects storage changes via storage event listener.
  1156. // Remove polling listener to prevent possible event duplication.
  1157. this.stopPolling();
  1158. }
  1159. // Safari embedded iframe. Storage event will trigger with the delta
  1160. // changes but no changes will be applied to the iframe localStorage.
  1161. if (this.safariLocalStorageNotSynced) {
  1162. // Get current iframe page value.
  1163. var storedValue_1 = this.storage.getItem(key);
  1164. // Value not synchronized, synchronize manually.
  1165. if (event.newValue !== storedValue_1) {
  1166. if (event.newValue !== null) {
  1167. // Value changed from current value.
  1168. this.storage.setItem(key, event.newValue);
  1169. }
  1170. else {
  1171. // Current value deleted.
  1172. this.storage.removeItem(key);
  1173. }
  1174. }
  1175. else if (this.localCache[key] === event.newValue && !poll) {
  1176. // Already detected and processed, do not trigger listeners again.
  1177. return;
  1178. }
  1179. }
  1180. var triggerListeners = function () {
  1181. // Keep local map up to date in case storage event is triggered before
  1182. // poll.
  1183. var storedValue = _this.storage.getItem(key);
  1184. if (!poll && _this.localCache[key] === storedValue) {
  1185. // Real storage event which has already been detected, do nothing.
  1186. // This seems to trigger in some IE browsers for some reason.
  1187. return;
  1188. }
  1189. _this.notifyListeners(key, storedValue);
  1190. };
  1191. var storedValue = this.storage.getItem(key);
  1192. if (index._isIE10() &&
  1193. storedValue !== event.newValue &&
  1194. event.newValue !== event.oldValue) {
  1195. // IE 10 has this weird bug where a storage event would trigger with the
  1196. // correct key, oldValue and newValue but localStorage.getItem(key) does
  1197. // not yield the updated value until a few milliseconds. This ensures
  1198. // this recovers from that situation.
  1199. setTimeout(triggerListeners, IE10_LOCAL_STORAGE_SYNC_DELAY);
  1200. }
  1201. else {
  1202. triggerListeners();
  1203. }
  1204. };
  1205. BrowserLocalPersistence.prototype.notifyListeners = function (key, value) {
  1206. this.localCache[key] = value;
  1207. var listeners = this.listeners[key];
  1208. if (listeners) {
  1209. for (var _i = 0, _a = Array.from(listeners); _i < _a.length; _i++) {
  1210. var listener = _a[_i];
  1211. listener(value ? JSON.parse(value) : value);
  1212. }
  1213. }
  1214. };
  1215. BrowserLocalPersistence.prototype.startPolling = function () {
  1216. var _this = this;
  1217. this.stopPolling();
  1218. this.pollTimer = setInterval(function () {
  1219. _this.forAllChangedKeys(function (key, oldValue, newValue) {
  1220. _this.onStorageEvent(new StorageEvent('storage', {
  1221. key: key,
  1222. oldValue: oldValue,
  1223. newValue: newValue
  1224. }),
  1225. /* poll */ true);
  1226. });
  1227. }, _POLLING_INTERVAL_MS);
  1228. };
  1229. BrowserLocalPersistence.prototype.stopPolling = function () {
  1230. if (this.pollTimer) {
  1231. clearInterval(this.pollTimer);
  1232. this.pollTimer = null;
  1233. }
  1234. };
  1235. BrowserLocalPersistence.prototype.attachListener = function () {
  1236. window.addEventListener('storage', this.boundEventHandler);
  1237. };
  1238. BrowserLocalPersistence.prototype.detachListener = function () {
  1239. window.removeEventListener('storage', this.boundEventHandler);
  1240. };
  1241. BrowserLocalPersistence.prototype._addListener = function (key, listener) {
  1242. if (Object.keys(this.listeners).length === 0) {
  1243. // Whether browser can detect storage event when it had already been pushed to the background.
  1244. // This may happen in some mobile browsers. A localStorage change in the foreground window
  1245. // will not be detected in the background window via the storage event.
  1246. // This was detected in iOS 7.x mobile browsers
  1247. if (this.fallbackToPolling) {
  1248. this.startPolling();
  1249. }
  1250. else {
  1251. this.attachListener();
  1252. }
  1253. }
  1254. if (!this.listeners[key]) {
  1255. this.listeners[key] = new Set();
  1256. // Populate the cache to avoid spuriously triggering on first poll.
  1257. this.localCache[key] = this.storage.getItem(key);
  1258. }
  1259. this.listeners[key].add(listener);
  1260. };
  1261. BrowserLocalPersistence.prototype._removeListener = function (key, listener) {
  1262. if (this.listeners[key]) {
  1263. this.listeners[key].delete(listener);
  1264. if (this.listeners[key].size === 0) {
  1265. delete this.listeners[key];
  1266. }
  1267. }
  1268. if (Object.keys(this.listeners).length === 0) {
  1269. this.detachListener();
  1270. this.stopPolling();
  1271. }
  1272. };
  1273. // Update local cache on base operations:
  1274. BrowserLocalPersistence.prototype._set = function (key, value) {
  1275. return tslib.__awaiter(this, void 0, void 0, function () {
  1276. return tslib.__generator(this, function (_a) {
  1277. switch (_a.label) {
  1278. case 0: return [4 /*yield*/, _super.prototype._set.call(this, key, value)];
  1279. case 1:
  1280. _a.sent();
  1281. this.localCache[key] = JSON.stringify(value);
  1282. return [2 /*return*/];
  1283. }
  1284. });
  1285. });
  1286. };
  1287. BrowserLocalPersistence.prototype._get = function (key) {
  1288. return tslib.__awaiter(this, void 0, void 0, function () {
  1289. var value;
  1290. return tslib.__generator(this, function (_a) {
  1291. switch (_a.label) {
  1292. case 0: return [4 /*yield*/, _super.prototype._get.call(this, key)];
  1293. case 1:
  1294. value = _a.sent();
  1295. this.localCache[key] = JSON.stringify(value);
  1296. return [2 /*return*/, value];
  1297. }
  1298. });
  1299. });
  1300. };
  1301. BrowserLocalPersistence.prototype._remove = function (key) {
  1302. return tslib.__awaiter(this, void 0, void 0, function () {
  1303. return tslib.__generator(this, function (_a) {
  1304. switch (_a.label) {
  1305. case 0: return [4 /*yield*/, _super.prototype._remove.call(this, key)];
  1306. case 1:
  1307. _a.sent();
  1308. delete this.localCache[key];
  1309. return [2 /*return*/];
  1310. }
  1311. });
  1312. });
  1313. };
  1314. BrowserLocalPersistence.type = 'LOCAL';
  1315. return BrowserLocalPersistence;
  1316. }(BrowserPersistenceClass));
  1317. /**
  1318. * An implementation of {@link Persistence} of type `LOCAL` using `localStorage`
  1319. * for the underlying storage.
  1320. *
  1321. * @public
  1322. */
  1323. var browserLocalPersistence = BrowserLocalPersistence;
  1324. /**
  1325. * @license
  1326. * Copyright 2020 Google LLC
  1327. *
  1328. * Licensed under the Apache License, Version 2.0 (the "License");
  1329. * you may not use this file except in compliance with the License.
  1330. * You may obtain a copy of the License at
  1331. *
  1332. * http://www.apache.org/licenses/LICENSE-2.0
  1333. *
  1334. * Unless required by applicable law or agreed to in writing, software
  1335. * distributed under the License is distributed on an "AS IS" BASIS,
  1336. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1337. * See the License for the specific language governing permissions and
  1338. * limitations under the License.
  1339. */
  1340. var SESSION_ID_LENGTH = 20;
  1341. /** Custom AuthEventManager that adds passive listeners to events */
  1342. var CordovaAuthEventManager = /** @class */ (function (_super) {
  1343. tslib.__extends(CordovaAuthEventManager, _super);
  1344. function CordovaAuthEventManager() {
  1345. var _this = _super !== null && _super.apply(this, arguments) || this;
  1346. _this.passiveListeners = new Set();
  1347. _this.initPromise = new Promise(function (resolve) {
  1348. _this.resolveInialized = resolve;
  1349. });
  1350. return _this;
  1351. }
  1352. CordovaAuthEventManager.prototype.addPassiveListener = function (cb) {
  1353. this.passiveListeners.add(cb);
  1354. };
  1355. CordovaAuthEventManager.prototype.removePassiveListener = function (cb) {
  1356. this.passiveListeners.delete(cb);
  1357. };
  1358. // In a Cordova environment, this manager can live through multiple redirect
  1359. // operations
  1360. CordovaAuthEventManager.prototype.resetRedirect = function () {
  1361. this.queuedRedirectEvent = null;
  1362. this.hasHandledPotentialRedirect = false;
  1363. };
  1364. /** Override the onEvent method */
  1365. CordovaAuthEventManager.prototype.onEvent = function (event) {
  1366. this.resolveInialized();
  1367. this.passiveListeners.forEach(function (cb) { return cb(event); });
  1368. return _super.prototype.onEvent.call(this, event);
  1369. };
  1370. CordovaAuthEventManager.prototype.initialized = function () {
  1371. return tslib.__awaiter(this, void 0, void 0, function () {
  1372. return tslib.__generator(this, function (_a) {
  1373. switch (_a.label) {
  1374. case 0: return [4 /*yield*/, this.initPromise];
  1375. case 1:
  1376. _a.sent();
  1377. return [2 /*return*/];
  1378. }
  1379. });
  1380. });
  1381. };
  1382. return CordovaAuthEventManager;
  1383. }(AuthEventManager));
  1384. /**
  1385. * Generates a (partial) {@link AuthEvent}.
  1386. */
  1387. function _generateNewEvent(auth, type, eventId) {
  1388. if (eventId === void 0) { eventId = null; }
  1389. return {
  1390. type: type,
  1391. eventId: eventId,
  1392. urlResponse: null,
  1393. sessionId: generateSessionId(),
  1394. postBody: null,
  1395. tenantId: auth.tenantId,
  1396. error: index._createError(auth, "no-auth-event" /* AuthErrorCode.NO_AUTH_EVENT */)
  1397. };
  1398. }
  1399. function _savePartialEvent(auth, event) {
  1400. return storage()._set(persistenceKey(auth), event);
  1401. }
  1402. function _getAndRemoveEvent(auth) {
  1403. return tslib.__awaiter(this, void 0, void 0, function () {
  1404. var event;
  1405. return tslib.__generator(this, function (_a) {
  1406. switch (_a.label) {
  1407. case 0: return [4 /*yield*/, storage()._get(persistenceKey(auth))];
  1408. case 1:
  1409. event = (_a.sent());
  1410. if (!event) return [3 /*break*/, 3];
  1411. return [4 /*yield*/, storage()._remove(persistenceKey(auth))];
  1412. case 2:
  1413. _a.sent();
  1414. _a.label = 3;
  1415. case 3: return [2 /*return*/, event];
  1416. }
  1417. });
  1418. });
  1419. }
  1420. function _eventFromPartialAndUrl(partialEvent, url) {
  1421. var _a, _b;
  1422. // Parse the deep link within the dynamic link URL.
  1423. var callbackUrl = _getDeepLinkFromCallback(url);
  1424. // Confirm it is actually a callback URL.
  1425. // Currently the universal link will be of this format:
  1426. // https://<AUTH_DOMAIN>/__/auth/callback<OAUTH_RESPONSE>
  1427. // This is a fake URL but is not intended to take the user anywhere
  1428. // and just redirect to the app.
  1429. if (callbackUrl.includes('/__/auth/callback')) {
  1430. // Check if there is an error in the URL.
  1431. // This mechanism is also used to pass errors back to the app:
  1432. // https://<AUTH_DOMAIN>/__/auth/callback?firebaseError=<STRINGIFIED_ERROR>
  1433. var params = searchParamsOrEmpty(callbackUrl);
  1434. // Get the error object corresponding to the stringified error if found.
  1435. var errorObject = params['firebaseError']
  1436. ? parseJsonOrNull(decodeURIComponent(params['firebaseError']))
  1437. : null;
  1438. var code = (_b = (_a = errorObject === null || errorObject === void 0 ? void 0 : errorObject['code']) === null || _a === void 0 ? void 0 : _a.split('auth/')) === null || _b === void 0 ? void 0 : _b[1];
  1439. var error = code ? index._createError(code) : null;
  1440. if (error) {
  1441. return {
  1442. type: partialEvent.type,
  1443. eventId: partialEvent.eventId,
  1444. tenantId: partialEvent.tenantId,
  1445. error: error,
  1446. urlResponse: null,
  1447. sessionId: null,
  1448. postBody: null
  1449. };
  1450. }
  1451. else {
  1452. return {
  1453. type: partialEvent.type,
  1454. eventId: partialEvent.eventId,
  1455. tenantId: partialEvent.tenantId,
  1456. sessionId: partialEvent.sessionId,
  1457. urlResponse: callbackUrl,
  1458. postBody: null
  1459. };
  1460. }
  1461. }
  1462. return null;
  1463. }
  1464. function generateSessionId() {
  1465. var chars = [];
  1466. var allowedChars = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1467. for (var i = 0; i < SESSION_ID_LENGTH; i++) {
  1468. var idx = Math.floor(Math.random() * allowedChars.length);
  1469. chars.push(allowedChars.charAt(idx));
  1470. }
  1471. return chars.join('');
  1472. }
  1473. function storage() {
  1474. return index._getInstance(browserLocalPersistence);
  1475. }
  1476. function persistenceKey(auth) {
  1477. return index._persistenceKeyName("authEvent" /* KeyName.AUTH_EVENT */, auth.config.apiKey, auth.name);
  1478. }
  1479. function parseJsonOrNull(json) {
  1480. try {
  1481. return JSON.parse(json);
  1482. }
  1483. catch (e) {
  1484. return null;
  1485. }
  1486. }
  1487. // Exported for testing
  1488. function _getDeepLinkFromCallback(url) {
  1489. var params = searchParamsOrEmpty(url);
  1490. var link = params['link'] ? decodeURIComponent(params['link']) : undefined;
  1491. // Double link case (automatic redirect)
  1492. var doubleDeepLink = searchParamsOrEmpty(link)['link'];
  1493. // iOS custom scheme links.
  1494. var iOSDeepLink = params['deep_link_id']
  1495. ? decodeURIComponent(params['deep_link_id'])
  1496. : undefined;
  1497. var iOSDoubleDeepLink = searchParamsOrEmpty(iOSDeepLink)['link'];
  1498. return iOSDoubleDeepLink || iOSDeepLink || doubleDeepLink || link || url;
  1499. }
  1500. /**
  1501. * Optimistically tries to get search params from a string, or else returns an
  1502. * empty search params object.
  1503. */
  1504. function searchParamsOrEmpty(url) {
  1505. if (!(url === null || url === void 0 ? void 0 : url.includes('?'))) {
  1506. return {};
  1507. }
  1508. var _a = url.split('?'); _a[0]; var rest = _a.slice(1);
  1509. return util.querystringDecode(rest.join('?'));
  1510. }
  1511. /**
  1512. * @license
  1513. * Copyright 2021 Google LLC
  1514. *
  1515. * Licensed under the Apache License, Version 2.0 (the "License");
  1516. * you may not use this file except in compliance with the License.
  1517. * You may obtain a copy of the License at
  1518. *
  1519. * http://www.apache.org/licenses/LICENSE-2.0
  1520. *
  1521. * Unless required by applicable law or agreed to in writing, software
  1522. * distributed under the License is distributed on an "AS IS" BASIS,
  1523. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1524. * See the License for the specific language governing permissions and
  1525. * limitations under the License.
  1526. */
  1527. /**
  1528. * How long to wait for the initial auth event before concluding no
  1529. * redirect pending
  1530. */
  1531. var INITIAL_EVENT_TIMEOUT_MS = 500;
  1532. var CordovaPopupRedirectResolver = /** @class */ (function () {
  1533. function CordovaPopupRedirectResolver() {
  1534. this._redirectPersistence = browserSessionPersistence;
  1535. this._shouldInitProactively = true; // This is lightweight for Cordova
  1536. this.eventManagers = new Map();
  1537. this.originValidationPromises = {};
  1538. this._completeRedirectFn = _getRedirectResult;
  1539. this._overrideRedirectResult = _overrideRedirectResult;
  1540. }
  1541. CordovaPopupRedirectResolver.prototype._initialize = function (auth) {
  1542. return tslib.__awaiter(this, void 0, void 0, function () {
  1543. var key, manager;
  1544. return tslib.__generator(this, function (_a) {
  1545. key = auth._key();
  1546. manager = this.eventManagers.get(key);
  1547. if (!manager) {
  1548. manager = new CordovaAuthEventManager(auth);
  1549. this.eventManagers.set(key, manager);
  1550. this.attachCallbackListeners(auth, manager);
  1551. }
  1552. return [2 /*return*/, manager];
  1553. });
  1554. });
  1555. };
  1556. CordovaPopupRedirectResolver.prototype._openPopup = function (auth) {
  1557. index._fail(auth, "operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */);
  1558. };
  1559. CordovaPopupRedirectResolver.prototype._openRedirect = function (auth, provider, authType, eventId) {
  1560. return tslib.__awaiter(this, void 0, void 0, function () {
  1561. var manager, event, url, iabRef;
  1562. return tslib.__generator(this, function (_a) {
  1563. switch (_a.label) {
  1564. case 0:
  1565. _checkCordovaConfiguration(auth);
  1566. return [4 /*yield*/, this._initialize(auth)];
  1567. case 1:
  1568. manager = _a.sent();
  1569. return [4 /*yield*/, manager.initialized()];
  1570. case 2:
  1571. _a.sent();
  1572. // Reset the persisted redirect states. This does not matter on Web where
  1573. // the redirect always blows away application state entirely. On Cordova,
  1574. // the app maintains control flow through the redirect.
  1575. manager.resetRedirect();
  1576. _clearRedirectOutcomes();
  1577. return [4 /*yield*/, this._originValidation(auth)];
  1578. case 3:
  1579. _a.sent();
  1580. event = _generateNewEvent(auth, authType, eventId);
  1581. return [4 /*yield*/, _savePartialEvent(auth, event)];
  1582. case 4:
  1583. _a.sent();
  1584. return [4 /*yield*/, _generateHandlerUrl(auth, event, provider)];
  1585. case 5:
  1586. url = _a.sent();
  1587. return [4 /*yield*/, _performRedirect(url)];
  1588. case 6:
  1589. iabRef = _a.sent();
  1590. return [2 /*return*/, _waitForAppResume(auth, manager, iabRef)];
  1591. }
  1592. });
  1593. });
  1594. };
  1595. CordovaPopupRedirectResolver.prototype._isIframeWebStorageSupported = function (_auth, _cb) {
  1596. throw new Error('Method not implemented.');
  1597. };
  1598. CordovaPopupRedirectResolver.prototype._originValidation = function (auth) {
  1599. var key = auth._key();
  1600. if (!this.originValidationPromises[key]) {
  1601. this.originValidationPromises[key] = _validateOrigin(auth);
  1602. }
  1603. return this.originValidationPromises[key];
  1604. };
  1605. CordovaPopupRedirectResolver.prototype.attachCallbackListeners = function (auth, manager) {
  1606. var _this = this;
  1607. // Get the global plugins
  1608. var _a = _cordovaWindow(), universalLinks = _a.universalLinks, handleOpenURL = _a.handleOpenURL, BuildInfo = _a.BuildInfo;
  1609. var noEventTimeout = setTimeout(function () { return tslib.__awaiter(_this, void 0, void 0, function () {
  1610. return tslib.__generator(this, function (_a) {
  1611. switch (_a.label) {
  1612. case 0:
  1613. // We didn't see that initial event. Clear any pending object and
  1614. // dispatch no event
  1615. return [4 /*yield*/, _getAndRemoveEvent(auth)];
  1616. case 1:
  1617. // We didn't see that initial event. Clear any pending object and
  1618. // dispatch no event
  1619. _a.sent();
  1620. manager.onEvent(generateNoEvent());
  1621. return [2 /*return*/];
  1622. }
  1623. });
  1624. }); }, INITIAL_EVENT_TIMEOUT_MS);
  1625. var universalLinksCb = function (eventData) { return tslib.__awaiter(_this, void 0, void 0, function () {
  1626. var partialEvent, finalEvent;
  1627. return tslib.__generator(this, function (_a) {
  1628. switch (_a.label) {
  1629. case 0:
  1630. // We have an event so we can clear the no event timeout
  1631. clearTimeout(noEventTimeout);
  1632. return [4 /*yield*/, _getAndRemoveEvent(auth)];
  1633. case 1:
  1634. partialEvent = _a.sent();
  1635. finalEvent = null;
  1636. if (partialEvent && (eventData === null || eventData === void 0 ? void 0 : eventData['url'])) {
  1637. finalEvent = _eventFromPartialAndUrl(partialEvent, eventData['url']);
  1638. }
  1639. // If finalEvent is never filled, trigger with no event
  1640. manager.onEvent(finalEvent || generateNoEvent());
  1641. return [2 /*return*/];
  1642. }
  1643. });
  1644. }); };
  1645. // Universal links subscriber doesn't exist for iOS, so we need to check
  1646. if (typeof universalLinks !== 'undefined' &&
  1647. typeof universalLinks.subscribe === 'function') {
  1648. universalLinks.subscribe(null, universalLinksCb);
  1649. }
  1650. // iOS 7 or 8 custom URL schemes.
  1651. // This is also the current default behavior for iOS 9+.
  1652. // For this to work, cordova-plugin-customurlscheme needs to be installed.
  1653. // https://github.com/EddyVerbruggen/Custom-URL-scheme
  1654. // Do not overwrite the existing developer's URL handler.
  1655. var existingHandleOpenURL = handleOpenURL;
  1656. var packagePrefix = "".concat(BuildInfo.packageName.toLowerCase(), "://");
  1657. _cordovaWindow().handleOpenURL = function (url) { return tslib.__awaiter(_this, void 0, void 0, function () {
  1658. return tslib.__generator(this, function (_a) {
  1659. if (url.toLowerCase().startsWith(packagePrefix)) {
  1660. // We want this intentionally to float
  1661. // eslint-disable-next-line @typescript-eslint/no-floating-promises
  1662. universalLinksCb({ url: url });
  1663. }
  1664. // Call the developer's handler if it is present.
  1665. if (typeof existingHandleOpenURL === 'function') {
  1666. try {
  1667. existingHandleOpenURL(url);
  1668. }
  1669. catch (e) {
  1670. // This is a developer error. Don't stop the flow of the SDK.
  1671. console.error(e);
  1672. }
  1673. }
  1674. return [2 /*return*/];
  1675. });
  1676. }); };
  1677. };
  1678. return CordovaPopupRedirectResolver;
  1679. }());
  1680. /**
  1681. * An implementation of {@link PopupRedirectResolver} suitable for Cordova
  1682. * based applications.
  1683. *
  1684. * @public
  1685. */
  1686. var cordovaPopupRedirectResolver = CordovaPopupRedirectResolver;
  1687. function generateNoEvent() {
  1688. return {
  1689. type: "unknown" /* AuthEventType.UNKNOWN */,
  1690. eventId: null,
  1691. sessionId: null,
  1692. urlResponse: null,
  1693. postBody: null,
  1694. tenantId: null,
  1695. error: index._createError("no-auth-event" /* AuthErrorCode.NO_AUTH_EVENT */)
  1696. };
  1697. }
  1698. /**
  1699. * @license
  1700. * Copyright 2017 Google LLC
  1701. *
  1702. * Licensed under the Apache License, Version 2.0 (the "License");
  1703. * you may not use this file except in compliance with the License.
  1704. * You may obtain a copy of the License at
  1705. *
  1706. * http://www.apache.org/licenses/LICENSE-2.0
  1707. *
  1708. * Unless required by applicable law or agreed to in writing, software
  1709. * distributed under the License is distributed on an "AS IS" BASIS,
  1710. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1711. * See the License for the specific language governing permissions and
  1712. * limitations under the License.
  1713. */
  1714. // This function should only be called by frameworks (e.g. FirebaseUI-web) to log their usage.
  1715. // It is not intended for direct use by developer apps. NO jsdoc here to intentionally leave it out
  1716. // of autogenerated documentation pages to reduce accidental misuse.
  1717. function addFrameworkForLogging(auth, framework) {
  1718. index._castAuth(auth)._logFramework(framework);
  1719. }
  1720. exports.ActionCodeOperation = index.ActionCodeOperation;
  1721. exports.ActionCodeURL = index.ActionCodeURL;
  1722. exports.AuthCredential = index.AuthCredential;
  1723. exports.AuthErrorCodes = index.AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY;
  1724. exports.AuthImpl = index.AuthImpl;
  1725. exports.EmailAuthCredential = index.EmailAuthCredential;
  1726. exports.EmailAuthProvider = index.EmailAuthProvider;
  1727. exports.FacebookAuthProvider = index.FacebookAuthProvider;
  1728. exports.FactorId = index.FactorId;
  1729. exports.FetchProvider = index.FetchProvider;
  1730. exports.GithubAuthProvider = index.GithubAuthProvider;
  1731. exports.GoogleAuthProvider = index.GoogleAuthProvider;
  1732. exports.OAuthCredential = index.OAuthCredential;
  1733. exports.OAuthProvider = index.OAuthProvider;
  1734. exports.OperationType = index.OperationType;
  1735. exports.PhoneAuthCredential = index.PhoneAuthCredential;
  1736. exports.PhoneAuthProvider = index.PhoneAuthProvider;
  1737. exports.PhoneMultiFactorGenerator = index.PhoneMultiFactorGenerator;
  1738. exports.ProviderId = index.ProviderId;
  1739. exports.RecaptchaVerifier = index.RecaptchaVerifier;
  1740. exports.SAMLAuthCredential = index.SAMLAuthCredential;
  1741. exports.SAMLAuthProvider = index.SAMLAuthProvider;
  1742. exports.SignInMethod = index.SignInMethod;
  1743. exports.TwitterAuthProvider = index.TwitterAuthProvider;
  1744. exports.UserImpl = index.UserImpl;
  1745. exports._assert = index._assert;
  1746. exports._castAuth = index._castAuth;
  1747. exports._fail = index._fail;
  1748. exports._getClientVersion = index._getClientVersion;
  1749. exports._getInstance = index._getInstance;
  1750. exports._persistenceKeyName = index._persistenceKeyName;
  1751. exports.applyActionCode = index.applyActionCode;
  1752. exports.beforeAuthStateChanged = index.beforeAuthStateChanged;
  1753. exports.browserLocalPersistence = index.browserLocalPersistence;
  1754. exports.browserPopupRedirectResolver = index.browserPopupRedirectResolver;
  1755. exports.browserSessionPersistence = index.browserSessionPersistence;
  1756. exports.checkActionCode = index.checkActionCode;
  1757. exports.confirmPasswordReset = index.confirmPasswordReset;
  1758. exports.connectAuthEmulator = index.connectAuthEmulator;
  1759. exports.createUserWithEmailAndPassword = index.createUserWithEmailAndPassword;
  1760. exports.debugErrorMap = index.debugErrorMap;
  1761. exports.deleteUser = index.deleteUser;
  1762. exports.fetchSignInMethodsForEmail = index.fetchSignInMethodsForEmail;
  1763. exports.getAdditionalUserInfo = index.getAdditionalUserInfo;
  1764. exports.getAuth = index.getAuth;
  1765. exports.getIdToken = index.getIdToken;
  1766. exports.getIdTokenResult = index.getIdTokenResult;
  1767. exports.getMultiFactorResolver = index.getMultiFactorResolver;
  1768. exports.getRedirectResult = index.getRedirectResult;
  1769. exports.inMemoryPersistence = index.inMemoryPersistence;
  1770. exports.indexedDBLocalPersistence = index.indexedDBLocalPersistence;
  1771. exports.initializeAuth = index.initializeAuth;
  1772. exports.isSignInWithEmailLink = index.isSignInWithEmailLink;
  1773. exports.linkWithCredential = index.linkWithCredential;
  1774. exports.linkWithPhoneNumber = index.linkWithPhoneNumber;
  1775. exports.linkWithPopup = index.linkWithPopup;
  1776. exports.linkWithRedirect = index.linkWithRedirect;
  1777. exports.multiFactor = index.multiFactor;
  1778. exports.onAuthStateChanged = index.onAuthStateChanged;
  1779. exports.onIdTokenChanged = index.onIdTokenChanged;
  1780. exports.parseActionCodeURL = index.parseActionCodeURL;
  1781. exports.prodErrorMap = index.prodErrorMap;
  1782. exports.reauthenticateWithCredential = index.reauthenticateWithCredential;
  1783. exports.reauthenticateWithPhoneNumber = index.reauthenticateWithPhoneNumber;
  1784. exports.reauthenticateWithPopup = index.reauthenticateWithPopup;
  1785. exports.reauthenticateWithRedirect = index.reauthenticateWithRedirect;
  1786. exports.reload = index.reload;
  1787. exports.sendEmailVerification = index.sendEmailVerification;
  1788. exports.sendPasswordResetEmail = index.sendPasswordResetEmail;
  1789. exports.sendSignInLinkToEmail = index.sendSignInLinkToEmail;
  1790. exports.setPersistence = index.setPersistence;
  1791. exports.signInAnonymously = index.signInAnonymously;
  1792. exports.signInWithCredential = index.signInWithCredential;
  1793. exports.signInWithCustomToken = index.signInWithCustomToken;
  1794. exports.signInWithEmailAndPassword = index.signInWithEmailAndPassword;
  1795. exports.signInWithEmailLink = index.signInWithEmailLink;
  1796. exports.signInWithPhoneNumber = index.signInWithPhoneNumber;
  1797. exports.signInWithPopup = index.signInWithPopup;
  1798. exports.signInWithRedirect = index.signInWithRedirect;
  1799. exports.signOut = index.signOut;
  1800. exports.unlink = index.unlink;
  1801. exports.updateCurrentUser = index.updateCurrentUser;
  1802. exports.updateEmail = index.updateEmail;
  1803. exports.updatePassword = index.updatePassword;
  1804. exports.updatePhoneNumber = index.updatePhoneNumber;
  1805. exports.updateProfile = index.updateProfile;
  1806. exports.useDeviceLanguage = index.useDeviceLanguage;
  1807. exports.verifyBeforeUpdateEmail = index.verifyBeforeUpdateEmail;
  1808. exports.verifyPasswordResetCode = index.verifyPasswordResetCode;
  1809. exports.AuthPopup = AuthPopup;
  1810. exports._generateEventId = _generateEventId;
  1811. exports._getRedirectResult = _getRedirectResult;
  1812. exports._overrideRedirectResult = _overrideRedirectResult;
  1813. exports.addFrameworkForLogging = addFrameworkForLogging;
  1814. exports.cordovaPopupRedirectResolver = cordovaPopupRedirectResolver;
  1815. //# sourceMappingURL=internal.js.map