1 | import { ap as _isIOS7Or8, aq as debugAssert, ar as _isIOS, as as _isAndroid, at as _fail, au as _getRedirectUrl, av as _getProjectConfig, aw as _createError, ax as _assert, ay as _getInstance, b as browserLocalPersistence, az as _persistenceKeyName, aA as AuthEventManager, a as browserSessionPersistence, aB as _getRedirectResult, aC as _overrideRedirectResult, aD as _clearRedirectOutcomes, aE as _castAuth } from './index-3b632d0b.js';
|
2 | export { A as ActionCodeOperation, ad as ActionCodeURL, H as AuthCredential, D as AuthErrorCodes, aG as AuthImpl, aJ as AuthPopup, I as EmailAuthCredential, M as EmailAuthProvider, N as FacebookAuthProvider, F as FactorId, aK as FetchProvider, T as GithubAuthProvider, Q as GoogleAuthProvider, J as OAuthCredential, U as OAuthProvider, O as OperationType, K as PhoneAuthCredential, P as PhoneAuthProvider, m as PhoneMultiFactorGenerator, o as ProviderId, R as RecaptchaVerifier, aL as SAMLAuthCredential, V as SAMLAuthProvider, S as SignInMethod, W as TwitterAuthProvider, aF as UserImpl, ax as _assert, aE as _castAuth, at as _fail, aI as _generateEventId, aH as _getClientVersion, ay as _getInstance, aB as _getRedirectResult, aC as _overrideRedirectResult, az as _persistenceKeyName, a2 as applyActionCode, t as beforeAuthStateChanged, b as browserLocalPersistence, k as browserPopupRedirectResolver, a as browserSessionPersistence, a3 as checkActionCode, a1 as confirmPasswordReset, G as connectAuthEmulator, a5 as createUserWithEmailAndPassword, B as debugErrorMap, z as deleteUser, aa as fetchSignInMethodsForEmail, al as getAdditionalUserInfo, n as getAuth, ai as getIdToken, aj as getIdTokenResult, an as getMultiFactorResolver, j as getRedirectResult, L as inMemoryPersistence, i as indexedDBLocalPersistence, E as initializeAuth, a8 as isSignInWithEmailLink, Z as linkWithCredential, l as linkWithPhoneNumber, d as linkWithPopup, g as linkWithRedirect, ao as multiFactor, v as onAuthStateChanged, q as onIdTokenChanged, ae as parseActionCodeURL, C as prodErrorMap, _ as reauthenticateWithCredential, r as reauthenticateWithPhoneNumber, e as reauthenticateWithPopup, h as reauthenticateWithRedirect, am as reload, ab as sendEmailVerification, a0 as sendPasswordResetEmail, a7 as sendSignInLinkToEmail, p as setPersistence, X as signInAnonymously, Y as signInWithCredential, $ as signInWithCustomToken, a6 as signInWithEmailAndPassword, a9 as signInWithEmailLink, s as signInWithPhoneNumber, c as signInWithPopup, f as signInWithRedirect, y as signOut, ak as unlink, x as updateCurrentUser, ag as updateEmail, ah as updatePassword, u as updatePhoneNumber, af as updateProfile, w as useDeviceLanguage, ac as verifyBeforeUpdateEmail, a4 as verifyPasswordResetCode } from './index-3b632d0b.js';
|
3 | import { querystringDecode } from '@firebase/util';
|
4 | import '@firebase/app';
|
5 | import 'tslib';
|
6 | import '@firebase/logger';
|
7 | import '@firebase/component';
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | function _cordovaWindow() {
|
26 | return window;
|
27 | }
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | const REDIRECT_TIMEOUT_MS = 2000;
|
50 |
|
51 |
|
52 |
|
53 | async function _generateHandlerUrl(auth, event, provider) {
|
54 | var _a;
|
55 |
|
56 | const { BuildInfo } = _cordovaWindow();
|
57 | debugAssert(event.sessionId, 'AuthEvent did not contain a session ID');
|
58 | const sessionDigest = await computeSha256(event.sessionId);
|
59 | const additionalParams = {};
|
60 | if (_isIOS()) {
|
61 |
|
62 | additionalParams['ibi'] = BuildInfo.packageName;
|
63 | }
|
64 | else if (_isAndroid()) {
|
65 |
|
66 | additionalParams['apn'] = BuildInfo.packageName;
|
67 | }
|
68 | else {
|
69 | _fail(auth, "operation-not-supported-in-this-environment" );
|
70 | }
|
71 |
|
72 | if (BuildInfo.displayName) {
|
73 | additionalParams['appDisplayName'] = BuildInfo.displayName;
|
74 | }
|
75 |
|
76 | additionalParams['sessionId'] = sessionDigest;
|
77 | return _getRedirectUrl(auth, provider, event.type, undefined, (_a = event.eventId) !== null && _a !== void 0 ? _a : undefined, additionalParams);
|
78 | }
|
79 |
|
80 |
|
81 |
|
82 | async function _validateOrigin(auth) {
|
83 | const { BuildInfo } = _cordovaWindow();
|
84 | const request = {};
|
85 | if (_isIOS()) {
|
86 | request.iosBundleId = BuildInfo.packageName;
|
87 | }
|
88 | else if (_isAndroid()) {
|
89 | request.androidPackageName = BuildInfo.packageName;
|
90 | }
|
91 | else {
|
92 | _fail(auth, "operation-not-supported-in-this-environment" );
|
93 | }
|
94 |
|
95 | await _getProjectConfig(auth, request);
|
96 | }
|
97 | function _performRedirect(handlerUrl) {
|
98 |
|
99 | const { cordova } = _cordovaWindow();
|
100 | return new Promise(resolve => {
|
101 | cordova.plugins.browsertab.isAvailable(browserTabIsAvailable => {
|
102 | let iabRef = null;
|
103 | if (browserTabIsAvailable) {
|
104 | cordova.plugins.browsertab.openUrl(handlerUrl);
|
105 | }
|
106 | else {
|
107 |
|
108 | iabRef = cordova.InAppBrowser.open(handlerUrl, _isIOS7Or8() ? '_blank' : '_system', 'location=yes');
|
109 | }
|
110 | resolve(iabRef);
|
111 | });
|
112 | });
|
113 | }
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 | async function _waitForAppResume(auth, eventListener, iabRef) {
|
121 |
|
122 | const { cordova } = _cordovaWindow();
|
123 | let cleanup = () => { };
|
124 | try {
|
125 | await new Promise((resolve, reject) => {
|
126 | let onCloseTimer = null;
|
127 |
|
128 | function authEventSeen() {
|
129 | var _a;
|
130 |
|
131 |
|
132 | resolve();
|
133 | const closeBrowserTab = (_a = cordova.plugins.browsertab) === null || _a === void 0 ? void 0 : _a.close;
|
134 | if (typeof closeBrowserTab === 'function') {
|
135 | closeBrowserTab();
|
136 | }
|
137 |
|
138 |
|
139 | if (typeof (iabRef === null || iabRef === void 0 ? void 0 : iabRef.close) === 'function') {
|
140 | iabRef.close();
|
141 | }
|
142 | }
|
143 | function resumed() {
|
144 | if (onCloseTimer) {
|
145 |
|
146 | return;
|
147 | }
|
148 | onCloseTimer = window.setTimeout(() => {
|
149 |
|
150 | reject(_createError(auth, "redirect-cancelled-by-user" ));
|
151 | }, REDIRECT_TIMEOUT_MS);
|
152 | }
|
153 | function visibilityChanged() {
|
154 | if ((document === null || document === void 0 ? void 0 : document.visibilityState) === 'visible') {
|
155 | resumed();
|
156 | }
|
157 | }
|
158 |
|
159 |
|
160 | eventListener.addPassiveListener(authEventSeen);
|
161 |
|
162 | document.addEventListener('resume', resumed, false);
|
163 | if (_isAndroid()) {
|
164 | document.addEventListener('visibilitychange', visibilityChanged, false);
|
165 | }
|
166 |
|
167 | cleanup = () => {
|
168 | eventListener.removePassiveListener(authEventSeen);
|
169 | document.removeEventListener('resume', resumed, false);
|
170 | document.removeEventListener('visibilitychange', visibilityChanged, false);
|
171 | if (onCloseTimer) {
|
172 | window.clearTimeout(onCloseTimer);
|
173 | }
|
174 | };
|
175 | });
|
176 | }
|
177 | finally {
|
178 | cleanup();
|
179 | }
|
180 | }
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 | function _checkCordovaConfiguration(auth) {
|
187 | var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
188 | const win = _cordovaWindow();
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 | _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" , {
|
195 | missingPlugin: 'cordova-universal-links-plugin-fix'
|
196 | });
|
197 |
|
198 | _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" , {
|
199 | missingPlugin: 'cordova-plugin-buildInfo'
|
200 | });
|
201 |
|
202 | _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" , {
|
203 | missingPlugin: 'cordova-plugin-browsertab'
|
204 | });
|
205 | _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" , {
|
206 | missingPlugin: 'cordova-plugin-browsertab'
|
207 | });
|
208 |
|
209 | _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" , {
|
210 | missingPlugin: 'cordova-plugin-inappbrowser'
|
211 | });
|
212 | }
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 | async function computeSha256(sessionId) {
|
219 | const bytes = stringToArrayBuffer(sessionId);
|
220 |
|
221 |
|
222 |
|
223 |
|
224 | const buf = await crypto.subtle.digest('SHA-256', bytes);
|
225 | const arr = Array.from(new Uint8Array(buf));
|
226 | return arr.map(num => num.toString(16).padStart(2, '0')).join('');
|
227 | }
|
228 | function stringToArrayBuffer(str) {
|
229 |
|
230 |
|
231 | debugAssert(/[0-9a-zA-Z]+/.test(str), 'Can only convert alpha-numeric strings');
|
232 | if (typeof TextEncoder !== 'undefined') {
|
233 | return new TextEncoder().encode(str);
|
234 | }
|
235 | const buff = new ArrayBuffer(str.length);
|
236 | const view = new Uint8Array(buff);
|
237 | for (let i = 0; i < str.length; i++) {
|
238 | view[i] = str.charCodeAt(i);
|
239 | }
|
240 | return view;
|
241 | }
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 | const SESSION_ID_LENGTH = 20;
|
260 |
|
261 | class CordovaAuthEventManager extends AuthEventManager {
|
262 | constructor() {
|
263 | super(...arguments);
|
264 | this.passiveListeners = new Set();
|
265 | this.initPromise = new Promise(resolve => {
|
266 | this.resolveInialized = resolve;
|
267 | });
|
268 | }
|
269 | addPassiveListener(cb) {
|
270 | this.passiveListeners.add(cb);
|
271 | }
|
272 | removePassiveListener(cb) {
|
273 | this.passiveListeners.delete(cb);
|
274 | }
|
275 |
|
276 |
|
277 | resetRedirect() {
|
278 | this.queuedRedirectEvent = null;
|
279 | this.hasHandledPotentialRedirect = false;
|
280 | }
|
281 |
|
282 | onEvent(event) {
|
283 | this.resolveInialized();
|
284 | this.passiveListeners.forEach(cb => cb(event));
|
285 | return super.onEvent(event);
|
286 | }
|
287 | async initialized() {
|
288 | await this.initPromise;
|
289 | }
|
290 | }
|
291 |
|
292 |
|
293 |
|
294 | function _generateNewEvent(auth, type, eventId = null) {
|
295 | return {
|
296 | type,
|
297 | eventId,
|
298 | urlResponse: null,
|
299 | sessionId: generateSessionId(),
|
300 | postBody: null,
|
301 | tenantId: auth.tenantId,
|
302 | error: _createError(auth, "no-auth-event" )
|
303 | };
|
304 | }
|
305 | function _savePartialEvent(auth, event) {
|
306 | return storage()._set(persistenceKey(auth), event);
|
307 | }
|
308 | async function _getAndRemoveEvent(auth) {
|
309 | const event = (await storage()._get(persistenceKey(auth)));
|
310 | if (event) {
|
311 | await storage()._remove(persistenceKey(auth));
|
312 | }
|
313 | return event;
|
314 | }
|
315 | function _eventFromPartialAndUrl(partialEvent, url) {
|
316 | var _a, _b;
|
317 |
|
318 | const callbackUrl = _getDeepLinkFromCallback(url);
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 | if (callbackUrl.includes('/__/auth/callback')) {
|
325 |
|
326 |
|
327 |
|
328 | const params = searchParamsOrEmpty(callbackUrl);
|
329 |
|
330 | const errorObject = params['firebaseError']
|
331 | ? parseJsonOrNull(decodeURIComponent(params['firebaseError']))
|
332 | : null;
|
333 | const 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];
|
334 | const error = code ? _createError(code) : null;
|
335 | if (error) {
|
336 | return {
|
337 | type: partialEvent.type,
|
338 | eventId: partialEvent.eventId,
|
339 | tenantId: partialEvent.tenantId,
|
340 | error,
|
341 | urlResponse: null,
|
342 | sessionId: null,
|
343 | postBody: null
|
344 | };
|
345 | }
|
346 | else {
|
347 | return {
|
348 | type: partialEvent.type,
|
349 | eventId: partialEvent.eventId,
|
350 | tenantId: partialEvent.tenantId,
|
351 | sessionId: partialEvent.sessionId,
|
352 | urlResponse: callbackUrl,
|
353 | postBody: null
|
354 | };
|
355 | }
|
356 | }
|
357 | return null;
|
358 | }
|
359 | function generateSessionId() {
|
360 | const chars = [];
|
361 | const allowedChars = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
362 | for (let i = 0; i < SESSION_ID_LENGTH; i++) {
|
363 | const idx = Math.floor(Math.random() * allowedChars.length);
|
364 | chars.push(allowedChars.charAt(idx));
|
365 | }
|
366 | return chars.join('');
|
367 | }
|
368 | function storage() {
|
369 | return _getInstance(browserLocalPersistence);
|
370 | }
|
371 | function persistenceKey(auth) {
|
372 | return _persistenceKeyName("authEvent" , auth.config.apiKey, auth.name);
|
373 | }
|
374 | function parseJsonOrNull(json) {
|
375 | try {
|
376 | return JSON.parse(json);
|
377 | }
|
378 | catch (e) {
|
379 | return null;
|
380 | }
|
381 | }
|
382 |
|
383 | function _getDeepLinkFromCallback(url) {
|
384 | const params = searchParamsOrEmpty(url);
|
385 | const link = params['link'] ? decodeURIComponent(params['link']) : undefined;
|
386 |
|
387 | const doubleDeepLink = searchParamsOrEmpty(link)['link'];
|
388 |
|
389 | const iOSDeepLink = params['deep_link_id']
|
390 | ? decodeURIComponent(params['deep_link_id'])
|
391 | : undefined;
|
392 | const iOSDoubleDeepLink = searchParamsOrEmpty(iOSDeepLink)['link'];
|
393 | return iOSDoubleDeepLink || iOSDeepLink || doubleDeepLink || link || url;
|
394 | }
|
395 |
|
396 |
|
397 |
|
398 |
|
399 | function searchParamsOrEmpty(url) {
|
400 | if (!(url === null || url === void 0 ? void 0 : url.includes('?'))) {
|
401 | return {};
|
402 | }
|
403 | const [_, ...rest] = url.split('?');
|
404 | return querystringDecode(rest.join('?'));
|
405 | }
|
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 |
|
425 |
|
426 |
|
427 | const INITIAL_EVENT_TIMEOUT_MS = 500;
|
428 | class CordovaPopupRedirectResolver {
|
429 | constructor() {
|
430 | this._redirectPersistence = browserSessionPersistence;
|
431 | this._shouldInitProactively = true;
|
432 | this.eventManagers = new Map();
|
433 | this.originValidationPromises = {};
|
434 | this._completeRedirectFn = _getRedirectResult;
|
435 | this._overrideRedirectResult = _overrideRedirectResult;
|
436 | }
|
437 | async _initialize(auth) {
|
438 | const key = auth._key();
|
439 | let manager = this.eventManagers.get(key);
|
440 | if (!manager) {
|
441 | manager = new CordovaAuthEventManager(auth);
|
442 | this.eventManagers.set(key, manager);
|
443 | this.attachCallbackListeners(auth, manager);
|
444 | }
|
445 | return manager;
|
446 | }
|
447 | _openPopup(auth) {
|
448 | _fail(auth, "operation-not-supported-in-this-environment" );
|
449 | }
|
450 | async _openRedirect(auth, provider, authType, eventId) {
|
451 | _checkCordovaConfiguration(auth);
|
452 | const manager = await this._initialize(auth);
|
453 | await manager.initialized();
|
454 |
|
455 |
|
456 |
|
457 | manager.resetRedirect();
|
458 | _clearRedirectOutcomes();
|
459 | await this._originValidation(auth);
|
460 | const event = _generateNewEvent(auth, authType, eventId);
|
461 | await _savePartialEvent(auth, event);
|
462 | const url = await _generateHandlerUrl(auth, event, provider);
|
463 | const iabRef = await _performRedirect(url);
|
464 | return _waitForAppResume(auth, manager, iabRef);
|
465 | }
|
466 | _isIframeWebStorageSupported(_auth, _cb) {
|
467 | throw new Error('Method not implemented.');
|
468 | }
|
469 | _originValidation(auth) {
|
470 | const key = auth._key();
|
471 | if (!this.originValidationPromises[key]) {
|
472 | this.originValidationPromises[key] = _validateOrigin(auth);
|
473 | }
|
474 | return this.originValidationPromises[key];
|
475 | }
|
476 | attachCallbackListeners(auth, manager) {
|
477 |
|
478 | const { universalLinks, handleOpenURL, BuildInfo } = _cordovaWindow();
|
479 | const noEventTimeout = setTimeout(async () => {
|
480 |
|
481 |
|
482 | await _getAndRemoveEvent(auth);
|
483 | manager.onEvent(generateNoEvent());
|
484 | }, INITIAL_EVENT_TIMEOUT_MS);
|
485 | const universalLinksCb = async (eventData) => {
|
486 |
|
487 | clearTimeout(noEventTimeout);
|
488 | const partialEvent = await _getAndRemoveEvent(auth);
|
489 | let finalEvent = null;
|
490 | if (partialEvent && (eventData === null || eventData === void 0 ? void 0 : eventData['url'])) {
|
491 | finalEvent = _eventFromPartialAndUrl(partialEvent, eventData['url']);
|
492 | }
|
493 |
|
494 | manager.onEvent(finalEvent || generateNoEvent());
|
495 | };
|
496 |
|
497 | if (typeof universalLinks !== 'undefined' &&
|
498 | typeof universalLinks.subscribe === 'function') {
|
499 | universalLinks.subscribe(null, universalLinksCb);
|
500 | }
|
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 | const existingHandleOpenURL = handleOpenURL;
|
507 | const packagePrefix = `${BuildInfo.packageName.toLowerCase()}://`;
|
508 | _cordovaWindow().handleOpenURL = async (url) => {
|
509 | if (url.toLowerCase().startsWith(packagePrefix)) {
|
510 |
|
511 |
|
512 | universalLinksCb({ url });
|
513 | }
|
514 |
|
515 | if (typeof existingHandleOpenURL === 'function') {
|
516 | try {
|
517 | existingHandleOpenURL(url);
|
518 | }
|
519 | catch (e) {
|
520 |
|
521 | console.error(e);
|
522 | }
|
523 | }
|
524 | };
|
525 | }
|
526 | }
|
527 |
|
528 |
|
529 |
|
530 |
|
531 |
|
532 |
|
533 | const cordovaPopupRedirectResolver = CordovaPopupRedirectResolver;
|
534 | function generateNoEvent() {
|
535 | return {
|
536 | type: "unknown" ,
|
537 | eventId: null,
|
538 | sessionId: null,
|
539 | urlResponse: null,
|
540 | postBody: null,
|
541 | tenantId: null,
|
542 | error: _createError("no-auth-event" )
|
543 | };
|
544 | }
|
545 |
|
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 |
|
552 |
|
553 |
|
554 |
|
555 |
|
556 |
|
557 |
|
558 |
|
559 |
|
560 |
|
561 |
|
562 |
|
563 |
|
564 |
|
565 | function addFrameworkForLogging(auth, framework) {
|
566 | _castAuth(auth)._logFramework(framework);
|
567 | }
|
568 |
|
569 | export { addFrameworkForLogging, cordovaPopupRedirectResolver };
|
570 |
|