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