@firebase/auth 1.7.9 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -1
- package/dist/auth-public.d.ts +22 -10
- package/dist/auth.d.ts +22 -10
- package/dist/browser-cjs/{index-e2e765e6.js → index-b60d3212.js} +393 -176
- package/dist/browser-cjs/index-b60d3212.js.map +1 -0
- package/dist/browser-cjs/index.js +1 -1
- package/dist/browser-cjs/internal.js +1 -1
- package/dist/browser-cjs/src/api/account_management/mfa.d.ts +5 -1
- package/dist/browser-cjs/src/api/authentication/mfa.d.ts +5 -1
- package/dist/browser-cjs/src/api/authentication/sms.d.ts +5 -1
- package/dist/browser-cjs/src/api/index.d.ts +7 -3
- package/dist/browser-cjs/src/platform_browser/providers/phone.d.ts +7 -5
- package/dist/browser-cjs/src/platform_browser/recaptcha/recaptcha.d.ts +7 -0
- package/dist/browser-cjs/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +4 -4
- package/dist/browser-cjs/src/platform_browser/strategies/phone.d.ts +10 -6
- package/dist/cordova/auth-cordova-public.d.ts +7 -0
- package/dist/cordova/auth-cordova.d.ts +7 -0
- package/dist/cordova/index.js +6 -7
- package/dist/cordova/index.js.map +1 -1
- package/dist/cordova/internal.js +660 -985
- package/dist/cordova/internal.js.map +1 -1
- package/dist/cordova/popup_redirect-6fcd583a.js +9635 -0
- package/dist/cordova/popup_redirect-6fcd583a.js.map +1 -0
- package/dist/cordova/src/api/account_management/mfa.d.ts +5 -1
- package/dist/cordova/src/api/authentication/mfa.d.ts +5 -1
- package/dist/cordova/src/api/authentication/sms.d.ts +5 -1
- package/dist/cordova/src/api/index.d.ts +7 -3
- package/dist/cordova/src/platform_browser/providers/phone.d.ts +7 -5
- package/dist/cordova/src/platform_browser/recaptcha/recaptcha.d.ts +7 -0
- package/dist/cordova/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +4 -4
- package/dist/cordova/src/platform_browser/strategies/phone.d.ts +10 -6
- package/dist/{esm5/src/api/account_management/mfa.test.d.ts → cordova/test/integration/flows/recaptcha_enterprise.test.d.ts} +1 -1
- package/dist/esm2017/{index-68602d24.js → index-a7d5cfcc.js} +393 -176
- package/dist/esm2017/index-a7d5cfcc.js.map +1 -0
- package/dist/esm2017/index.js +1 -1
- package/dist/esm2017/internal.js +2 -2
- package/dist/esm2017/src/api/account_management/mfa.d.ts +5 -1
- package/dist/esm2017/src/api/authentication/mfa.d.ts +5 -1
- package/dist/esm2017/src/api/authentication/sms.d.ts +5 -1
- package/dist/esm2017/src/api/index.d.ts +7 -3
- package/dist/esm2017/src/platform_browser/providers/phone.d.ts +7 -5
- package/dist/esm2017/src/platform_browser/recaptcha/recaptcha.d.ts +7 -0
- package/dist/esm2017/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +4 -4
- package/dist/esm2017/src/platform_browser/strategies/phone.d.ts +10 -6
- package/dist/{esm5/src/api/account_management/email_and_password.test.d.ts → esm2017/test/integration/flows/recaptcha_enterprise.test.d.ts} +1 -1
- package/dist/index.webworker.js +7912 -0
- package/dist/index.webworker.js.map +1 -0
- package/dist/node/index.js +2 -3
- package/dist/node/index.js.map +1 -1
- package/dist/node/internal.js +555 -844
- package/dist/node/internal.js.map +1 -1
- package/dist/node/src/api/account_management/mfa.d.ts +5 -1
- package/dist/node/src/api/authentication/mfa.d.ts +5 -1
- package/dist/node/src/api/authentication/sms.d.ts +5 -1
- package/dist/node/src/api/index.d.ts +7 -3
- package/dist/node/src/platform_browser/providers/phone.d.ts +7 -5
- package/dist/node/src/platform_browser/recaptcha/recaptcha.d.ts +7 -0
- package/dist/node/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +4 -4
- package/dist/node/src/platform_browser/strategies/phone.d.ts +10 -6
- package/dist/node/test/integration/flows/recaptcha_enterprise.test.d.ts +17 -0
- package/dist/node/totp-ab108bed.js +7582 -0
- package/dist/node/totp-ab108bed.js.map +1 -0
- package/dist/node-esm/index.js +1 -2
- package/dist/node-esm/index.js.map +1 -1
- package/dist/node-esm/internal.js +2 -3
- package/dist/node-esm/internal.js.map +1 -1
- package/dist/node-esm/src/api/account_management/mfa.d.ts +5 -1
- package/dist/node-esm/src/api/authentication/mfa.d.ts +5 -1
- package/dist/node-esm/src/api/authentication/sms.d.ts +5 -1
- package/dist/node-esm/src/api/index.d.ts +7 -3
- package/dist/node-esm/src/platform_browser/providers/phone.d.ts +7 -5
- package/dist/node-esm/src/platform_browser/recaptcha/recaptcha.d.ts +7 -0
- package/dist/node-esm/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +4 -4
- package/dist/node-esm/src/platform_browser/strategies/phone.d.ts +10 -6
- package/dist/{esm5/scripts/run_node_tests.d.ts → node-esm/test/integration/flows/recaptcha_enterprise.test.d.ts} +1 -1
- package/dist/node-esm/{totp-219bb96f.js → totp-f311e20a.js} +170 -33
- package/dist/node-esm/totp-f311e20a.js.map +1 -0
- package/dist/rn/index-4d73adbf.js +8575 -0
- package/dist/rn/index-4d73adbf.js.map +1 -0
- package/dist/rn/index.js +45 -55
- package/dist/rn/index.js.map +1 -1
- package/dist/rn/internal.js +1195 -1890
- package/dist/rn/internal.js.map +1 -1
- package/dist/rn/src/api/account_management/mfa.d.ts +5 -1
- package/dist/rn/src/api/authentication/mfa.d.ts +5 -1
- package/dist/rn/src/api/authentication/sms.d.ts +5 -1
- package/dist/rn/src/api/index.d.ts +7 -3
- package/dist/rn/src/platform_browser/providers/phone.d.ts +7 -5
- package/dist/rn/src/platform_browser/recaptcha/recaptcha.d.ts +7 -0
- package/dist/rn/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +4 -4
- package/dist/rn/src/platform_browser/strategies/phone.d.ts +10 -6
- package/dist/rn/test/integration/flows/recaptcha_enterprise.test.d.ts +17 -0
- package/dist/src/api/account_management/mfa.d.ts +5 -1
- package/dist/src/api/authentication/mfa.d.ts +5 -1
- package/dist/src/api/authentication/sms.d.ts +5 -1
- package/dist/src/api/index.d.ts +7 -3
- package/dist/src/platform_browser/providers/phone.d.ts +7 -5
- package/dist/src/platform_browser/recaptcha/recaptcha.d.ts +7 -0
- package/dist/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +4 -4
- package/dist/src/platform_browser/strategies/phone.d.ts +10 -6
- package/dist/test/integration/flows/recaptcha_enterprise.test.d.ts +17 -0
- package/dist/web-extension-cjs/index.js +1 -1
- package/dist/web-extension-cjs/internal.js +115 -147
- package/dist/web-extension-cjs/internal.js.map +1 -1
- package/dist/web-extension-cjs/{register-674a8250.js → register-17c71bd5.js} +284 -31
- package/dist/web-extension-cjs/register-17c71bd5.js.map +1 -0
- package/dist/web-extension-cjs/src/api/account_management/mfa.d.ts +5 -1
- package/dist/web-extension-cjs/src/api/authentication/mfa.d.ts +5 -1
- package/dist/web-extension-cjs/src/api/authentication/sms.d.ts +5 -1
- package/dist/web-extension-cjs/src/api/index.d.ts +7 -3
- package/dist/web-extension-cjs/src/platform_browser/providers/phone.d.ts +7 -5
- package/dist/web-extension-cjs/src/platform_browser/recaptcha/recaptcha.d.ts +7 -0
- package/dist/web-extension-cjs/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +4 -4
- package/dist/web-extension-cjs/src/platform_browser/strategies/phone.d.ts +10 -6
- package/dist/web-extension-cjs/test/integration/flows/recaptcha_enterprise.test.d.ts +17 -0
- package/dist/web-extension-esm2017/auth-web-extension-public.d.ts +7 -0
- package/dist/web-extension-esm2017/auth-web-extension.d.ts +7 -0
- package/dist/web-extension-esm2017/index.js +2 -2
- package/dist/web-extension-esm2017/internal.js +115 -147
- package/dist/web-extension-esm2017/internal.js.map +1 -1
- package/dist/web-extension-esm2017/{register-428f8789.js → register-77f1d56a.js} +281 -32
- package/dist/web-extension-esm2017/register-77f1d56a.js.map +1 -0
- package/dist/web-extension-esm2017/src/api/account_management/mfa.d.ts +5 -1
- package/dist/web-extension-esm2017/src/api/authentication/mfa.d.ts +5 -1
- package/dist/web-extension-esm2017/src/api/authentication/sms.d.ts +5 -1
- package/dist/web-extension-esm2017/src/api/index.d.ts +7 -3
- package/dist/web-extension-esm2017/src/platform_browser/providers/phone.d.ts +7 -5
- package/dist/web-extension-esm2017/src/platform_browser/recaptcha/recaptcha.d.ts +7 -0
- package/dist/web-extension-esm2017/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +4 -4
- package/dist/web-extension-esm2017/src/platform_browser/strategies/phone.d.ts +10 -6
- package/dist/web-extension-esm2017/test/integration/flows/recaptcha_enterprise.test.d.ts +17 -0
- package/internal/package.json +5 -3
- package/package.json +10 -11
- package/dist/browser-cjs/index-e2e765e6.js.map +0 -1
- package/dist/cordova/popup_redirect-abcbab4c.js +0 -11249
- package/dist/cordova/popup_redirect-abcbab4c.js.map +0 -1
- package/dist/esm2017/index-68602d24.js.map +0 -1
- package/dist/esm5/index-c0803b14.js +0 -12741
- package/dist/esm5/index-c0803b14.js.map +0 -1
- package/dist/esm5/index.cordova.d.ts +0 -32
- package/dist/esm5/index.d.ts +0 -37
- package/dist/esm5/index.doc.d.ts +0 -24
- package/dist/esm5/index.js +0 -7
- package/dist/esm5/index.js.map +0 -1
- package/dist/esm5/index.node.d.ts +0 -17
- package/dist/esm5/index.rn.d.ts +0 -40
- package/dist/esm5/index.shared.d.ts +0 -19
- package/dist/esm5/index.web-extension.d.ts +0 -31
- package/dist/esm5/index.webworker.d.ts +0 -21
- package/dist/esm5/internal/index.d.ts +0 -42
- package/dist/esm5/internal.js +0 -682
- package/dist/esm5/internal.js.map +0 -1
- package/dist/esm5/src/api/account_management/account.d.ts +0 -59
- package/dist/esm5/src/api/account_management/account.test.d.ts +0 -17
- package/dist/esm5/src/api/account_management/email_and_password.d.ts +0 -49
- package/dist/esm5/src/api/account_management/mfa.d.ts +0 -103
- package/dist/esm5/src/api/account_management/profile.d.ts +0 -29
- package/dist/esm5/src/api/account_management/profile.test.d.ts +0 -17
- package/dist/esm5/src/api/authentication/create_auth_uri.d.ts +0 -26
- package/dist/esm5/src/api/authentication/create_auth_uri.test.d.ts +0 -17
- package/dist/esm5/src/api/authentication/custom_token.d.ts +0 -26
- package/dist/esm5/src/api/authentication/custom_token.test.d.ts +0 -17
- package/dist/esm5/src/api/authentication/email_and_password.d.ts +0 -85
- package/dist/esm5/src/api/authentication/email_and_password.test.d.ts +0 -17
- package/dist/esm5/src/api/authentication/email_link.d.ts +0 -32
- package/dist/esm5/src/api/authentication/email_link.test.d.ts +0 -17
- package/dist/esm5/src/api/authentication/idp.d.ts +0 -40
- package/dist/esm5/src/api/authentication/idp.test.d.ts +0 -17
- package/dist/esm5/src/api/authentication/mfa.d.ts +0 -69
- package/dist/esm5/src/api/authentication/mfa.test.d.ts +0 -17
- package/dist/esm5/src/api/authentication/recaptcha.d.ts +0 -34
- package/dist/esm5/src/api/authentication/recaptcha.test.d.ts +0 -17
- package/dist/esm5/src/api/authentication/sign_up.d.ts +0 -34
- package/dist/esm5/src/api/authentication/sign_up.test.d.ts +0 -17
- package/dist/esm5/src/api/authentication/sms.d.ts +0 -50
- package/dist/esm5/src/api/authentication/sms.test.d.ts +0 -17
- package/dist/esm5/src/api/authentication/token.d.ts +0 -37
- package/dist/esm5/src/api/authentication/token.test.d.ts +0 -17
- package/dist/esm5/src/api/errors.d.ts +0 -128
- package/dist/esm5/src/api/index.d.ts +0 -97
- package/dist/esm5/src/api/index.test.d.ts +0 -17
- package/dist/esm5/src/api/password_policy/get_password_policy.d.ts +0 -48
- package/dist/esm5/src/api/password_policy/get_password_policy.test.d.ts +0 -17
- package/dist/esm5/src/api/project_config/get_project_config.d.ts +0 -25
- package/dist/esm5/src/api/project_config/get_project_config.test.d.ts +0 -17
- package/dist/esm5/src/core/action_code_url.d.ts +0 -73
- package/dist/esm5/src/core/action_code_url.test.d.ts +0 -17
- package/dist/esm5/src/core/auth/auth_event_manager.d.ts +0 -34
- package/dist/esm5/src/core/auth/auth_event_manager.test.d.ts +0 -17
- package/dist/esm5/src/core/auth/auth_impl.d.ts +0 -130
- package/dist/esm5/src/core/auth/auth_impl.test.d.ts +0 -17
- package/dist/esm5/src/core/auth/emulator.d.ts +0 -42
- package/dist/esm5/src/core/auth/emulator.test.d.ts +0 -17
- package/dist/esm5/src/core/auth/firebase_internal.d.ts +0 -35
- package/dist/esm5/src/core/auth/firebase_internal.test.d.ts +0 -17
- package/dist/esm5/src/core/auth/initialize.d.ts +0 -46
- package/dist/esm5/src/core/auth/initialize.test.d.ts +0 -17
- package/dist/esm5/src/core/auth/middleware.d.ts +0 -25
- package/dist/esm5/src/core/auth/middleware.test.d.ts +0 -17
- package/dist/esm5/src/core/auth/password_policy_impl.d.ts +0 -59
- package/dist/esm5/src/core/auth/password_policy_impl.test.d.ts +0 -17
- package/dist/esm5/src/core/auth/register.d.ts +0 -23
- package/dist/esm5/src/core/credentials/auth_credential.d.ts +0 -75
- package/dist/esm5/src/core/credentials/email.d.ts +0 -60
- package/dist/esm5/src/core/credentials/email.test.d.ts +0 -17
- package/dist/esm5/src/core/credentials/index.d.ts +0 -23
- package/dist/esm5/src/core/credentials/oauth.d.ts +0 -81
- package/dist/esm5/src/core/credentials/oauth.test.d.ts +0 -17
- package/dist/esm5/src/core/credentials/phone.d.ts +0 -52
- package/dist/esm5/src/core/credentials/phone.test.d.ts +0 -17
- package/dist/esm5/src/core/credentials/saml.d.ts +0 -52
- package/dist/esm5/src/core/credentials/saml.test.d.ts +0 -17
- package/dist/esm5/src/core/errors.d.ts +0 -325
- package/dist/esm5/src/core/errors.test.d.ts +0 -17
- package/dist/esm5/src/core/index.d.ts +0 -230
- package/dist/esm5/src/core/persistence/in_memory.d.ts +0 -35
- package/dist/esm5/src/core/persistence/in_memory.test.d.ts +0 -17
- package/dist/esm5/src/core/persistence/index.d.ts +0 -41
- package/dist/esm5/src/core/persistence/persistence_user_manager.d.ts +0 -45
- package/dist/esm5/src/core/persistence/persistence_user_manager.test.d.ts +0 -17
- package/dist/esm5/src/core/providers/email.d.ts +0 -83
- package/dist/esm5/src/core/providers/email.test.d.ts +0 -17
- package/dist/esm5/src/core/providers/facebook.d.ts +0 -93
- package/dist/esm5/src/core/providers/facebook.test.d.ts +0 -17
- package/dist/esm5/src/core/providers/federated.d.ts +0 -64
- package/dist/esm5/src/core/providers/federated.test.d.ts +0 -17
- package/dist/esm5/src/core/providers/github.d.ts +0 -89
- package/dist/esm5/src/core/providers/github.test.d.ts +0 -17
- package/dist/esm5/src/core/providers/google.d.ts +0 -96
- package/dist/esm5/src/core/providers/google.test.d.ts +0 -17
- package/dist/esm5/src/core/providers/oauth.d.ts +0 -151
- package/dist/esm5/src/core/providers/oauth.test.d.ts +0 -17
- package/dist/esm5/src/core/providers/saml.d.ts +0 -62
- package/dist/esm5/src/core/providers/saml.test.d.ts +0 -17
- package/dist/esm5/src/core/providers/twitter.d.ts +0 -103
- package/dist/esm5/src/core/providers/twitter.test.d.ts +0 -17
- package/dist/esm5/src/core/strategies/abstract_popup_redirect_operation.d.ts +0 -44
- package/dist/esm5/src/core/strategies/abstract_popup_redirect_operation.test.d.ts +0 -17
- package/dist/esm5/src/core/strategies/action_code_settings.d.ts +0 -19
- package/dist/esm5/src/core/strategies/action_code_settings.test.d.ts +0 -17
- package/dist/esm5/src/core/strategies/anonymous.d.ts +0 -32
- package/dist/esm5/src/core/strategies/anonymous.test.d.ts +0 -17
- package/dist/esm5/src/core/strategies/credential.d.ts +0 -64
- package/dist/esm5/src/core/strategies/credential.test.d.ts +0 -17
- package/dist/esm5/src/core/strategies/custom_token.d.ts +0 -37
- package/dist/esm5/src/core/strategies/custom_token.test.d.ts +0 -17
- package/dist/esm5/src/core/strategies/email.d.ts +0 -104
- package/dist/esm5/src/core/strategies/email.test.d.ts +0 -17
- package/dist/esm5/src/core/strategies/email_and_password.d.ts +0 -139
- package/dist/esm5/src/core/strategies/email_and_password.test.d.ts +0 -17
- package/dist/esm5/src/core/strategies/email_link.d.ts +0 -107
- package/dist/esm5/src/core/strategies/email_link.test.d.ts +0 -17
- package/dist/esm5/src/core/strategies/idp.d.ts +0 -32
- package/dist/esm5/src/core/strategies/idp.test.d.ts +0 -17
- package/dist/esm5/src/core/strategies/redirect.d.ts +0 -36
- package/dist/esm5/src/core/strategies/redirect.test.d.ts +0 -17
- package/dist/esm5/src/core/user/account_info.d.ts +0 -68
- package/dist/esm5/src/core/user/account_info.test.d.ts +0 -17
- package/dist/esm5/src/core/user/additional_user_info.d.ts +0 -31
- package/dist/esm5/src/core/user/additional_user_info.test.d.ts +0 -17
- package/dist/esm5/src/core/user/id_token_result.d.ts +0 -48
- package/dist/esm5/src/core/user/id_token_result.test.d.ts +0 -17
- package/dist/esm5/src/core/user/invalidation.d.ts +0 -18
- package/dist/esm5/src/core/user/invalidation.test.d.ts +0 -17
- package/dist/esm5/src/core/user/link_unlink.d.ts +0 -30
- package/dist/esm5/src/core/user/link_unlink.test.d.ts +0 -17
- package/dist/esm5/src/core/user/proactive_refresh.d.ts +0 -34
- package/dist/esm5/src/core/user/proactive_refresh.test.d.ts +0 -17
- package/dist/esm5/src/core/user/reauthenticate.d.ts +0 -20
- package/dist/esm5/src/core/user/reauthenticate.test.d.ts +0 -17
- package/dist/esm5/src/core/user/reload.d.ts +0 -29
- package/dist/esm5/src/core/user/reload.test.d.ts +0 -17
- package/dist/esm5/src/core/user/token_manager.d.ts +0 -50
- package/dist/esm5/src/core/user/token_manager.test.d.ts +0 -17
- package/dist/esm5/src/core/user/user_credential_impl.d.ts +0 -37
- package/dist/esm5/src/core/user/user_credential_impl.test.d.ts +0 -17
- package/dist/esm5/src/core/user/user_impl.d.ts +0 -74
- package/dist/esm5/src/core/user/user_impl.test.d.ts +0 -17
- package/dist/esm5/src/core/user/user_metadata.d.ts +0 -27
- package/dist/esm5/src/core/util/assert.d.ts +0 -94
- package/dist/esm5/src/core/util/assert.test.d.ts +0 -17
- package/dist/esm5/src/core/util/browser.d.ts +0 -50
- package/dist/esm5/src/core/util/browser.test.d.ts +0 -17
- package/dist/esm5/src/core/util/delay.d.ts +0 -31
- package/dist/esm5/src/core/util/delay.test.d.ts +0 -17
- package/dist/esm5/src/core/util/emulator.d.ts +0 -18
- package/dist/esm5/src/core/util/emulator.test.d.ts +0 -17
- package/dist/esm5/src/core/util/event_id.d.ts +0 -17
- package/dist/esm5/src/core/util/event_id.test.d.ts +0 -17
- package/dist/esm5/src/core/util/fetch_provider.d.ts +0 -25
- package/dist/esm5/src/core/util/handler.d.ts +0 -20
- package/dist/esm5/src/core/util/instantiator.d.ts +0 -28
- package/dist/esm5/src/core/util/instantiator.test.d.ts +0 -17
- package/dist/esm5/src/core/util/location.d.ts +0 -19
- package/dist/esm5/src/core/util/log.d.ts +0 -23
- package/dist/esm5/src/core/util/navigator.d.ts +0 -21
- package/dist/esm5/src/core/util/providers.d.ts +0 -23
- package/dist/esm5/src/core/util/resolver.d.ts +0 -25
- package/dist/esm5/src/core/util/time.d.ts +0 -17
- package/dist/esm5/src/core/util/validate_origin.d.ts +0 -18
- package/dist/esm5/src/core/util/validate_origin.test.d.ts +0 -17
- package/dist/esm5/src/core/util/version.d.ts +0 -31
- package/dist/esm5/src/core/util/version.test.d.ts +0 -17
- package/dist/esm5/src/index.d.ts +0 -18
- package/dist/esm5/src/mfa/assertions/totp.d.ts +0 -124
- package/dist/esm5/src/mfa/assertions/totp.test.d.ts +0 -17
- package/dist/esm5/src/mfa/index.d.ts +0 -18
- package/dist/esm5/src/mfa/mfa_assertion.d.ts +0 -27
- package/dist/esm5/src/mfa/mfa_error.d.ts +0 -35
- package/dist/esm5/src/mfa/mfa_info.d.ts +0 -36
- package/dist/esm5/src/mfa/mfa_info.test.d.ts +0 -17
- package/dist/esm5/src/mfa/mfa_resolver.d.ts +0 -41
- package/dist/esm5/src/mfa/mfa_resolver.test.d.ts +0 -17
- package/dist/esm5/src/mfa/mfa_session.d.ts +0 -39
- package/dist/esm5/src/mfa/mfa_session.test.d.ts +0 -17
- package/dist/esm5/src/mfa/mfa_user.d.ts +0 -38
- package/dist/esm5/src/mfa/mfa_user.test.d.ts +0 -17
- package/dist/esm5/src/model/application_verifier.d.ts +0 -23
- package/dist/esm5/src/model/auth.d.ts +0 -87
- package/dist/esm5/src/model/enum_maps.d.ts +0 -98
- package/dist/esm5/src/model/enums.d.ts +0 -74
- package/dist/esm5/src/model/id_token.d.ts +0 -87
- package/dist/esm5/src/model/password_policy.d.ts +0 -111
- package/dist/esm5/src/model/popup_redirect.d.ts +0 -94
- package/dist/esm5/src/model/public_types.d.ts +0 -1285
- package/dist/esm5/src/model/user.d.ts +0 -83
- package/dist/esm5/src/platform_browser/auth.test.d.ts +0 -17
- package/dist/esm5/src/platform_browser/auth_window.d.ts +0 -37
- package/dist/esm5/src/platform_browser/iframe/gapi.d.ts +0 -19
- package/dist/esm5/src/platform_browser/iframe/gapi.iframes.d.ts +0 -47
- package/dist/esm5/src/platform_browser/iframe/gapi.test.d.ts +0 -17
- package/dist/esm5/src/platform_browser/iframe/iframe.d.ts +0 -18
- package/dist/esm5/src/platform_browser/iframe/iframe.test.d.ts +0 -17
- package/dist/esm5/src/platform_browser/index.d.ts +0 -27
- package/dist/esm5/src/platform_browser/load_js.d.ts +0 -29
- package/dist/esm5/src/platform_browser/load_js.test.d.ts +0 -17
- package/dist/esm5/src/platform_browser/messagechannel/index.d.ts +0 -87
- package/dist/esm5/src/platform_browser/messagechannel/promise.d.ts +0 -33
- package/dist/esm5/src/platform_browser/messagechannel/promise.test.d.ts +0 -17
- package/dist/esm5/src/platform_browser/messagechannel/receiver.d.ts +0 -63
- package/dist/esm5/src/platform_browser/messagechannel/receiver.test.d.ts +0 -17
- package/dist/esm5/src/platform_browser/messagechannel/sender.d.ts +0 -46
- package/dist/esm5/src/platform_browser/messagechannel/sender.test.d.ts +0 -17
- package/dist/esm5/src/platform_browser/mfa/assertions/phone.d.ts +0 -59
- package/dist/esm5/src/platform_browser/mfa/assertions/phone.test.d.ts +0 -17
- package/dist/esm5/src/platform_browser/persistence/browser.d.ts +0 -27
- package/dist/esm5/src/platform_browser/persistence/browser.test.d.ts +0 -17
- package/dist/esm5/src/platform_browser/persistence/indexed_db.d.ts +0 -33
- package/dist/esm5/src/platform_browser/persistence/indexed_db.test.d.ts +0 -17
- package/dist/esm5/src/platform_browser/persistence/local_storage.d.ts +0 -25
- package/dist/esm5/src/platform_browser/persistence/local_storage.test.d.ts +0 -17
- package/dist/esm5/src/platform_browser/persistence/session_storage.d.ts +0 -24
- package/dist/esm5/src/platform_browser/persistence/session_storage.test.d.ts +0 -17
- package/dist/esm5/src/platform_browser/popup_redirect.d.ts +0 -27
- package/dist/esm5/src/platform_browser/popup_redirect.test.d.ts +0 -17
- package/dist/esm5/src/platform_browser/providers/phone.d.ts +0 -152
- package/dist/esm5/src/platform_browser/providers/phone.test.d.ts +0 -17
- package/dist/esm5/src/platform_browser/recaptcha/recaptcha.d.ts +0 -71
- package/dist/esm5/src/platform_browser/recaptcha/recaptcha.test.d.ts +0 -17
- package/dist/esm5/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +0 -45
- package/dist/esm5/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.test.d.ts +0 -17
- package/dist/esm5/src/platform_browser/recaptcha/recaptcha_loader.d.ts +0 -49
- package/dist/esm5/src/platform_browser/recaptcha/recaptcha_loader.test.d.ts +0 -17
- package/dist/esm5/src/platform_browser/recaptcha/recaptcha_mock.d.ts +0 -66
- package/dist/esm5/src/platform_browser/recaptcha/recaptcha_mock.test.d.ts +0 -17
- package/dist/esm5/src/platform_browser/recaptcha/recaptcha_verifier.d.ts +0 -92
- package/dist/esm5/src/platform_browser/recaptcha/recaptcha_verifier.test.d.ts +0 -17
- package/dist/esm5/src/platform_browser/strategies/phone.d.ts +0 -112
- package/dist/esm5/src/platform_browser/strategies/phone.test.d.ts +0 -17
- package/dist/esm5/src/platform_browser/strategies/popup.d.ts +0 -109
- package/dist/esm5/src/platform_browser/strategies/popup.test.d.ts +0 -17
- package/dist/esm5/src/platform_browser/strategies/redirect.d.ts +0 -176
- package/dist/esm5/src/platform_browser/strategies/redirect.test.d.ts +0 -17
- package/dist/esm5/src/platform_browser/util/popup.d.ts +0 -24
- package/dist/esm5/src/platform_browser/util/popup.test.d.ts +0 -17
- package/dist/esm5/src/platform_browser/util/worker.d.ts +0 -20
- package/dist/esm5/src/platform_cordova/plugins.d.ts +0 -42
- package/dist/esm5/src/platform_cordova/popup_redirect/events.d.ts +0 -39
- package/dist/esm5/src/platform_cordova/popup_redirect/events.test.d.ts +0 -17
- package/dist/esm5/src/platform_cordova/popup_redirect/popup_redirect.d.ts +0 -24
- package/dist/esm5/src/platform_cordova/popup_redirect/popup_redirect.test.d.ts +0 -17
- package/dist/esm5/src/platform_cordova/popup_redirect/utils.d.ts +0 -47
- package/dist/esm5/src/platform_cordova/popup_redirect/utils.test.d.ts +0 -17
- package/dist/esm5/src/platform_cordova/strategies/redirect.d.ts +0 -20
- package/dist/esm5/src/platform_node/index.d.ts +0 -50
- package/dist/esm5/src/platform_react_native/persistence/react_native.d.ts +0 -25
- package/dist/esm5/src/platform_react_native/persistence/react_native.test.d.ts +0 -17
- package/dist/esm5/test/helpers/api/helper.d.ts +0 -22
- package/dist/esm5/test/helpers/delay.d.ts +0 -20
- package/dist/esm5/test/helpers/erroring_unavailable_persistence.d.ts +0 -36
- package/dist/esm5/test/helpers/fake_service_worker.d.ts +0 -22
- package/dist/esm5/test/helpers/id_token_response.d.ts +0 -18
- package/dist/esm5/test/helpers/iframe_event.d.ts +0 -19
- package/dist/esm5/test/helpers/integration/emulator_rest_helpers.d.ts +0 -35
- package/dist/esm5/test/helpers/integration/helpers.d.ts +0 -32
- package/dist/esm5/test/helpers/integration/settings.d.ts +0 -23
- package/dist/esm5/test/helpers/jwt.d.ts +0 -17
- package/dist/esm5/test/helpers/mock_auth.d.ts +0 -47
- package/dist/esm5/test/helpers/mock_auth_credential.d.ts +0 -31
- package/dist/esm5/test/helpers/mock_fetch.d.ts +0 -30
- package/dist/esm5/test/helpers/mock_fetch.test.d.ts +0 -17
- package/dist/esm5/test/helpers/mock_popup_redirect_resolver.d.ts +0 -24
- package/dist/esm5/test/helpers/redirect_persistence.d.ts +0 -24
- package/dist/esm5/test/helpers/timeout_stub.d.ts +0 -34
- package/dist/esm5/test/integration/flows/anonymous.test.d.ts +0 -17
- package/dist/esm5/test/integration/flows/custom.local.test.d.ts +0 -17
- package/dist/esm5/test/integration/flows/email.test.d.ts +0 -17
- package/dist/esm5/test/integration/flows/idp.local.test.d.ts +0 -17
- package/dist/esm5/test/integration/flows/middleware_test_generator.d.ts +0 -18
- package/dist/esm5/test/integration/flows/oob.local.test.d.ts +0 -17
- package/dist/esm5/test/integration/flows/password_policy.test.d.ts +0 -17
- package/dist/esm5/test/integration/flows/phone.test.d.ts +0 -17
- package/dist/esm5/test/integration/flows/totp.test.d.ts +0 -17
- package/dist/esm5/test/integration/webdriver/anonymous.test.d.ts +0 -17
- package/dist/esm5/test/integration/webdriver/compat/firebaseui.test.d.ts +0 -17
- package/dist/esm5/test/integration/webdriver/persistence.test.d.ts +0 -17
- package/dist/esm5/test/integration/webdriver/popup.test.d.ts +0 -17
- package/dist/esm5/test/integration/webdriver/redirect.test.d.ts +0 -17
- package/dist/esm5/test/integration/webdriver/util/auth_driver.d.ts +0 -46
- package/dist/esm5/test/integration/webdriver/util/functions.d.ts +0 -81
- package/dist/esm5/test/integration/webdriver/util/idp_page.d.ts +0 -31
- package/dist/esm5/test/integration/webdriver/util/js_load_condition.d.ts +0 -25
- package/dist/esm5/test/integration/webdriver/util/test_runner.d.ts +0 -19
- package/dist/esm5/test/integration/webdriver/util/test_server.d.ts +0 -27
- package/dist/esm5/test/integration/webdriver/util/ui_page.d.ts +0 -33
- package/dist/index.webworker.esm5.js +0 -9265
- package/dist/index.webworker.esm5.js.map +0 -1
- package/dist/node/totp-259483a2.js +0 -8762
- package/dist/node/totp-259483a2.js.map +0 -1
- package/dist/node-esm/totp-219bb96f.js.map +0 -1
- package/dist/rn/index-2f66320e.js +0 -9819
- package/dist/rn/index-2f66320e.js.map +0 -1
- package/dist/web-extension-cjs/register-674a8250.js.map +0 -1
- package/dist/web-extension-esm2017/register-428f8789.js.map +0 -1
- /package/dist/{esm5/test/integration/flows/firebaseserverapp.test.d.ts → browser-cjs/test/integration/flows/recaptcha_enterprise.test.d.ts} +0 -0
package/dist/rn/internal.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('./index-
|
|
6
|
-
var tslib = require('tslib');
|
|
7
|
-
var util = require('@firebase/util');
|
|
5
|
+
var index = require('./index-4d73adbf.js');
|
|
8
6
|
var app = require('@firebase/app');
|
|
7
|
+
var util = require('@firebase/util');
|
|
8
|
+
require('tslib');
|
|
9
9
|
require('@firebase/component');
|
|
10
10
|
require('@firebase/logger');
|
|
11
11
|
|
|
@@ -28,12 +28,12 @@ require('@firebase/logger');
|
|
|
28
28
|
// There are two different browser persistence types: local and session.
|
|
29
29
|
// Both have the same implementation but use a different underlying storage
|
|
30
30
|
// object.
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
class BrowserPersistenceClass {
|
|
32
|
+
constructor(storageRetriever, type) {
|
|
33
33
|
this.storageRetriever = storageRetriever;
|
|
34
34
|
this.type = type;
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
_isAvailable() {
|
|
37
37
|
try {
|
|
38
38
|
if (!this.storage) {
|
|
39
39
|
return Promise.resolve(false);
|
|
@@ -45,28 +45,23 @@ var BrowserPersistenceClass = /** @class */ (function () {
|
|
|
45
45
|
catch (_a) {
|
|
46
46
|
return Promise.resolve(false);
|
|
47
47
|
}
|
|
48
|
-
}
|
|
49
|
-
|
|
48
|
+
}
|
|
49
|
+
_set(key, value) {
|
|
50
50
|
this.storage.setItem(key, JSON.stringify(value));
|
|
51
51
|
return Promise.resolve();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
}
|
|
53
|
+
_get(key) {
|
|
54
|
+
const json = this.storage.getItem(key);
|
|
55
55
|
return Promise.resolve(json ? JSON.parse(json) : null);
|
|
56
|
-
}
|
|
57
|
-
|
|
56
|
+
}
|
|
57
|
+
_remove(key) {
|
|
58
58
|
this.storage.removeItem(key);
|
|
59
59
|
return Promise.resolve();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
enumerable: false,
|
|
66
|
-
configurable: true
|
|
67
|
-
});
|
|
68
|
-
return BrowserPersistenceClass;
|
|
69
|
-
}());
|
|
60
|
+
}
|
|
61
|
+
get storage() {
|
|
62
|
+
return this.storageRetriever();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
70
65
|
|
|
71
66
|
/**
|
|
72
67
|
* @license
|
|
@@ -85,49 +80,44 @@ var BrowserPersistenceClass = /** @class */ (function () {
|
|
|
85
80
|
* limitations under the License.
|
|
86
81
|
*/
|
|
87
82
|
// The polling period in case events are not supported
|
|
88
|
-
|
|
83
|
+
const _POLLING_INTERVAL_MS$1 = 1000;
|
|
89
84
|
// The IE 10 localStorage cross tab synchronization delay in milliseconds
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
_this.localCache = {};
|
|
85
|
+
const IE10_LOCAL_STORAGE_SYNC_DELAY = 10;
|
|
86
|
+
class BrowserLocalPersistence extends BrowserPersistenceClass {
|
|
87
|
+
constructor() {
|
|
88
|
+
super(() => window.localStorage, "LOCAL" /* PersistenceType.LOCAL */);
|
|
89
|
+
this.boundEventHandler = (event, poll) => this.onStorageEvent(event, poll);
|
|
90
|
+
this.listeners = {};
|
|
91
|
+
this.localCache = {};
|
|
98
92
|
// setTimeout return value is platform specific
|
|
99
93
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
100
|
-
|
|
94
|
+
this.pollTimer = null;
|
|
101
95
|
// Whether to use polling instead of depending on window events
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return _this;
|
|
96
|
+
this.fallbackToPolling = index._isMobileBrowser();
|
|
97
|
+
this._shouldAllowMigration = true;
|
|
105
98
|
}
|
|
106
|
-
|
|
99
|
+
forAllChangedKeys(cb) {
|
|
107
100
|
// Check all keys with listeners on them.
|
|
108
|
-
for (
|
|
109
|
-
var key = _a[_i];
|
|
101
|
+
for (const key of Object.keys(this.listeners)) {
|
|
110
102
|
// Get value from localStorage.
|
|
111
|
-
|
|
112
|
-
|
|
103
|
+
const newValue = this.storage.getItem(key);
|
|
104
|
+
const oldValue = this.localCache[key];
|
|
113
105
|
// If local map value does not match, trigger listener with storage event.
|
|
114
106
|
// Differentiate this simulated event from the real storage event.
|
|
115
107
|
if (newValue !== oldValue) {
|
|
116
108
|
cb(key, oldValue, newValue);
|
|
117
109
|
}
|
|
118
110
|
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
var _this = this;
|
|
122
|
-
if (poll === void 0) { poll = false; }
|
|
111
|
+
}
|
|
112
|
+
onStorageEvent(event, poll = false) {
|
|
123
113
|
// Key would be null in some situations, like when localStorage is cleared
|
|
124
114
|
if (!event.key) {
|
|
125
|
-
this.forAllChangedKeys(
|
|
126
|
-
|
|
115
|
+
this.forAllChangedKeys((key, _oldValue, newValue) => {
|
|
116
|
+
this.notifyListeners(key, newValue);
|
|
127
117
|
});
|
|
128
118
|
return;
|
|
129
119
|
}
|
|
130
|
-
|
|
120
|
+
const key = event.key;
|
|
131
121
|
// Check the mechanism how this event was detected.
|
|
132
122
|
// The first event will dictate the mechanism to be used.
|
|
133
123
|
if (poll) {
|
|
@@ -140,18 +130,18 @@ var BrowserLocalPersistence = /** @class */ (function (_super) {
|
|
|
140
130
|
// Remove polling listener to prevent possible event duplication.
|
|
141
131
|
this.stopPolling();
|
|
142
132
|
}
|
|
143
|
-
|
|
133
|
+
const triggerListeners = () => {
|
|
144
134
|
// Keep local map up to date in case storage event is triggered before
|
|
145
135
|
// poll.
|
|
146
|
-
|
|
147
|
-
if (!poll &&
|
|
136
|
+
const storedValue = this.storage.getItem(key);
|
|
137
|
+
if (!poll && this.localCache[key] === storedValue) {
|
|
148
138
|
// Real storage event which has already been detected, do nothing.
|
|
149
139
|
// This seems to trigger in some IE browsers for some reason.
|
|
150
140
|
return;
|
|
151
141
|
}
|
|
152
|
-
|
|
142
|
+
this.notifyListeners(key, storedValue);
|
|
153
143
|
};
|
|
154
|
-
|
|
144
|
+
const storedValue = this.storage.getItem(key);
|
|
155
145
|
if (index._isIE10() &&
|
|
156
146
|
storedValue !== event.newValue &&
|
|
157
147
|
event.newValue !== event.oldValue) {
|
|
@@ -164,44 +154,42 @@ var BrowserLocalPersistence = /** @class */ (function (_super) {
|
|
|
164
154
|
else {
|
|
165
155
|
triggerListeners();
|
|
166
156
|
}
|
|
167
|
-
}
|
|
168
|
-
|
|
157
|
+
}
|
|
158
|
+
notifyListeners(key, value) {
|
|
169
159
|
this.localCache[key] = value;
|
|
170
|
-
|
|
160
|
+
const listeners = this.listeners[key];
|
|
171
161
|
if (listeners) {
|
|
172
|
-
for (
|
|
173
|
-
var listener = _a[_i];
|
|
162
|
+
for (const listener of Array.from(listeners)) {
|
|
174
163
|
listener(value ? JSON.parse(value) : value);
|
|
175
164
|
}
|
|
176
165
|
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
var _this = this;
|
|
166
|
+
}
|
|
167
|
+
startPolling() {
|
|
180
168
|
this.stopPolling();
|
|
181
|
-
this.pollTimer = setInterval(
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
key
|
|
185
|
-
oldValue
|
|
186
|
-
newValue
|
|
169
|
+
this.pollTimer = setInterval(() => {
|
|
170
|
+
this.forAllChangedKeys((key, oldValue, newValue) => {
|
|
171
|
+
this.onStorageEvent(new StorageEvent('storage', {
|
|
172
|
+
key,
|
|
173
|
+
oldValue,
|
|
174
|
+
newValue
|
|
187
175
|
}),
|
|
188
176
|
/* poll */ true);
|
|
189
177
|
});
|
|
190
178
|
}, _POLLING_INTERVAL_MS$1);
|
|
191
|
-
}
|
|
192
|
-
|
|
179
|
+
}
|
|
180
|
+
stopPolling() {
|
|
193
181
|
if (this.pollTimer) {
|
|
194
182
|
clearInterval(this.pollTimer);
|
|
195
183
|
this.pollTimer = null;
|
|
196
184
|
}
|
|
197
|
-
}
|
|
198
|
-
|
|
185
|
+
}
|
|
186
|
+
attachListener() {
|
|
199
187
|
window.addEventListener('storage', this.boundEventHandler);
|
|
200
|
-
}
|
|
201
|
-
|
|
188
|
+
}
|
|
189
|
+
detachListener() {
|
|
202
190
|
window.removeEventListener('storage', this.boundEventHandler);
|
|
203
|
-
}
|
|
204
|
-
|
|
191
|
+
}
|
|
192
|
+
_addListener(key, listener) {
|
|
205
193
|
if (Object.keys(this.listeners).length === 0) {
|
|
206
194
|
// Whether browser can detect storage event when it had already been pushed to the background.
|
|
207
195
|
// This may happen in some mobile browsers. A localStorage change in the foreground window
|
|
@@ -220,8 +208,8 @@ var BrowserLocalPersistence = /** @class */ (function (_super) {
|
|
|
220
208
|
this.localCache[key] = this.storage.getItem(key);
|
|
221
209
|
}
|
|
222
210
|
this.listeners[key].add(listener);
|
|
223
|
-
}
|
|
224
|
-
|
|
211
|
+
}
|
|
212
|
+
_removeListener(key, listener) {
|
|
225
213
|
if (this.listeners[key]) {
|
|
226
214
|
this.listeners[key].delete(listener);
|
|
227
215
|
if (this.listeners[key].size === 0) {
|
|
@@ -232,58 +220,30 @@ var BrowserLocalPersistence = /** @class */ (function (_super) {
|
|
|
232
220
|
this.detachListener();
|
|
233
221
|
this.stopPolling();
|
|
234
222
|
}
|
|
235
|
-
}
|
|
223
|
+
}
|
|
236
224
|
// Update local cache on base operations:
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
var value;
|
|
253
|
-
return tslib.__generator(this, function (_a) {
|
|
254
|
-
switch (_a.label) {
|
|
255
|
-
case 0: return [4 /*yield*/, _super.prototype._get.call(this, key)];
|
|
256
|
-
case 1:
|
|
257
|
-
value = _a.sent();
|
|
258
|
-
this.localCache[key] = JSON.stringify(value);
|
|
259
|
-
return [2 /*return*/, value];
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
});
|
|
263
|
-
};
|
|
264
|
-
BrowserLocalPersistence.prototype._remove = function (key) {
|
|
265
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
266
|
-
return tslib.__generator(this, function (_a) {
|
|
267
|
-
switch (_a.label) {
|
|
268
|
-
case 0: return [4 /*yield*/, _super.prototype._remove.call(this, key)];
|
|
269
|
-
case 1:
|
|
270
|
-
_a.sent();
|
|
271
|
-
delete this.localCache[key];
|
|
272
|
-
return [2 /*return*/];
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
};
|
|
277
|
-
BrowserLocalPersistence.type = 'LOCAL';
|
|
278
|
-
return BrowserLocalPersistence;
|
|
279
|
-
}(BrowserPersistenceClass));
|
|
225
|
+
async _set(key, value) {
|
|
226
|
+
await super._set(key, value);
|
|
227
|
+
this.localCache[key] = JSON.stringify(value);
|
|
228
|
+
}
|
|
229
|
+
async _get(key) {
|
|
230
|
+
const value = await super._get(key);
|
|
231
|
+
this.localCache[key] = JSON.stringify(value);
|
|
232
|
+
return value;
|
|
233
|
+
}
|
|
234
|
+
async _remove(key) {
|
|
235
|
+
await super._remove(key);
|
|
236
|
+
delete this.localCache[key];
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
BrowserLocalPersistence.type = 'LOCAL';
|
|
280
240
|
/**
|
|
281
241
|
* An implementation of {@link Persistence} of type `LOCAL` using `localStorage`
|
|
282
242
|
* for the underlying storage.
|
|
283
243
|
*
|
|
284
244
|
* @public
|
|
285
245
|
*/
|
|
286
|
-
|
|
246
|
+
const browserLocalPersistence = BrowserLocalPersistence;
|
|
287
247
|
|
|
288
248
|
/**
|
|
289
249
|
* @license
|
|
@@ -301,29 +261,27 @@ var browserLocalPersistence = BrowserLocalPersistence;
|
|
|
301
261
|
* See the License for the specific language governing permissions and
|
|
302
262
|
* limitations under the License.
|
|
303
263
|
*/
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
return _super.call(this, function () { return window.sessionStorage; }, "SESSION" /* PersistenceType.SESSION */) || this;
|
|
264
|
+
class BrowserSessionPersistence extends BrowserPersistenceClass {
|
|
265
|
+
constructor() {
|
|
266
|
+
super(() => window.sessionStorage, "SESSION" /* PersistenceType.SESSION */);
|
|
308
267
|
}
|
|
309
|
-
|
|
268
|
+
_addListener(_key, _listener) {
|
|
310
269
|
// Listeners are not supported for session storage since it cannot be shared across windows
|
|
311
270
|
return;
|
|
312
|
-
}
|
|
313
|
-
|
|
271
|
+
}
|
|
272
|
+
_removeListener(_key, _listener) {
|
|
314
273
|
// Listeners are not supported for session storage since it cannot be shared across windows
|
|
315
274
|
return;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
}(BrowserPersistenceClass));
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
BrowserSessionPersistence.type = 'SESSION';
|
|
320
278
|
/**
|
|
321
279
|
* An implementation of {@link Persistence} of `SESSION` using `sessionStorage`
|
|
322
280
|
* for the underlying storage.
|
|
323
281
|
*
|
|
324
282
|
* @public
|
|
325
283
|
*/
|
|
326
|
-
|
|
284
|
+
const browserSessionPersistence = BrowserSessionPersistence;
|
|
327
285
|
|
|
328
286
|
/**
|
|
329
287
|
* @license
|
|
@@ -347,30 +305,21 @@ var browserSessionPersistence = BrowserSessionPersistence;
|
|
|
347
305
|
* @param promises - Array of promises to wait on.
|
|
348
306
|
*/
|
|
349
307
|
function _allSettled(promises) {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
reason_1 = _a.sent();
|
|
366
|
-
return [2 /*return*/, {
|
|
367
|
-
fulfilled: false,
|
|
368
|
-
reason: reason_1
|
|
369
|
-
}];
|
|
370
|
-
case 3: return [2 /*return*/];
|
|
371
|
-
}
|
|
372
|
-
});
|
|
373
|
-
}); }));
|
|
308
|
+
return Promise.all(promises.map(async (promise) => {
|
|
309
|
+
try {
|
|
310
|
+
const value = await promise;
|
|
311
|
+
return {
|
|
312
|
+
fulfilled: true,
|
|
313
|
+
value
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
catch (reason) {
|
|
317
|
+
return {
|
|
318
|
+
fulfilled: false,
|
|
319
|
+
reason
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
}));
|
|
374
323
|
}
|
|
375
324
|
|
|
376
325
|
/**
|
|
@@ -393,8 +342,8 @@ function _allSettled(promises) {
|
|
|
393
342
|
* Interface class for receiving messages.
|
|
394
343
|
*
|
|
395
344
|
*/
|
|
396
|
-
|
|
397
|
-
|
|
345
|
+
class Receiver {
|
|
346
|
+
constructor(eventTarget) {
|
|
398
347
|
this.eventTarget = eventTarget;
|
|
399
348
|
this.handlersMap = {};
|
|
400
349
|
this.boundEventHandler = this.handleEvent.bind(this);
|
|
@@ -405,23 +354,21 @@ var Receiver = /** @class */ (function () {
|
|
|
405
354
|
* @param eventTarget - An event target (such as window or self) through which the underlying
|
|
406
355
|
* messages will be received.
|
|
407
356
|
*/
|
|
408
|
-
|
|
357
|
+
static _getInstance(eventTarget) {
|
|
409
358
|
// The results are stored in an array since objects can't be keys for other
|
|
410
359
|
// objects. In addition, setting a unique property on an event target as a
|
|
411
360
|
// hash map key may not be allowed due to CORS restrictions.
|
|
412
|
-
|
|
413
|
-
return receiver.isListeningto(eventTarget);
|
|
414
|
-
});
|
|
361
|
+
const existingInstance = this.receivers.find(receiver => receiver.isListeningto(eventTarget));
|
|
415
362
|
if (existingInstance) {
|
|
416
363
|
return existingInstance;
|
|
417
364
|
}
|
|
418
|
-
|
|
365
|
+
const newInstance = new Receiver(eventTarget);
|
|
419
366
|
this.receivers.push(newInstance);
|
|
420
367
|
return newInstance;
|
|
421
|
-
}
|
|
422
|
-
|
|
368
|
+
}
|
|
369
|
+
isListeningto(eventTarget) {
|
|
423
370
|
return this.eventTarget === eventTarget;
|
|
424
|
-
}
|
|
371
|
+
}
|
|
425
372
|
/**
|
|
426
373
|
* Fans out a MessageEvent to the appropriate listeners.
|
|
427
374
|
*
|
|
@@ -432,41 +379,27 @@ var Receiver = /** @class */ (function () {
|
|
|
432
379
|
* @param event - The MessageEvent.
|
|
433
380
|
*
|
|
434
381
|
*/
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
return [2 /*return*/];
|
|
447
|
-
}
|
|
448
|
-
messageEvent.ports[0].postMessage({
|
|
449
|
-
status: "ack" /* _Status.ACK */,
|
|
450
|
-
eventId: eventId,
|
|
451
|
-
eventType: eventType
|
|
452
|
-
});
|
|
453
|
-
promises = Array.from(handlers).map(function (handler) { return tslib.__awaiter(_this, void 0, void 0, function () { return tslib.__generator(this, function (_a) {
|
|
454
|
-
return [2 /*return*/, handler(messageEvent.origin, data)];
|
|
455
|
-
}); }); });
|
|
456
|
-
return [4 /*yield*/, _allSettled(promises)];
|
|
457
|
-
case 1:
|
|
458
|
-
response = _b.sent();
|
|
459
|
-
messageEvent.ports[0].postMessage({
|
|
460
|
-
status: "done" /* _Status.DONE */,
|
|
461
|
-
eventId: eventId,
|
|
462
|
-
eventType: eventType,
|
|
463
|
-
response: response
|
|
464
|
-
});
|
|
465
|
-
return [2 /*return*/];
|
|
466
|
-
}
|
|
467
|
-
});
|
|
382
|
+
async handleEvent(event) {
|
|
383
|
+
const messageEvent = event;
|
|
384
|
+
const { eventId, eventType, data } = messageEvent.data;
|
|
385
|
+
const handlers = this.handlersMap[eventType];
|
|
386
|
+
if (!(handlers === null || handlers === void 0 ? void 0 : handlers.size)) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
messageEvent.ports[0].postMessage({
|
|
390
|
+
status: "ack" /* _Status.ACK */,
|
|
391
|
+
eventId,
|
|
392
|
+
eventType
|
|
468
393
|
});
|
|
469
|
-
|
|
394
|
+
const promises = Array.from(handlers).map(async (handler) => handler(messageEvent.origin, data));
|
|
395
|
+
const response = await _allSettled(promises);
|
|
396
|
+
messageEvent.ports[0].postMessage({
|
|
397
|
+
status: "done" /* _Status.DONE */,
|
|
398
|
+
eventId,
|
|
399
|
+
eventType,
|
|
400
|
+
response
|
|
401
|
+
});
|
|
402
|
+
}
|
|
470
403
|
/**
|
|
471
404
|
* Subscribe an event handler for a particular event.
|
|
472
405
|
*
|
|
@@ -474,7 +407,7 @@ var Receiver = /** @class */ (function () {
|
|
|
474
407
|
* @param eventHandler - The event handler which should receive the events.
|
|
475
408
|
*
|
|
476
409
|
*/
|
|
477
|
-
|
|
410
|
+
_subscribe(eventType, eventHandler) {
|
|
478
411
|
if (Object.keys(this.handlersMap).length === 0) {
|
|
479
412
|
this.eventTarget.addEventListener('message', this.boundEventHandler);
|
|
480
413
|
}
|
|
@@ -482,7 +415,7 @@ var Receiver = /** @class */ (function () {
|
|
|
482
415
|
this.handlersMap[eventType] = new Set();
|
|
483
416
|
}
|
|
484
417
|
this.handlersMap[eventType].add(eventHandler);
|
|
485
|
-
}
|
|
418
|
+
}
|
|
486
419
|
/**
|
|
487
420
|
* Unsubscribe an event handler from a particular event.
|
|
488
421
|
*
|
|
@@ -490,7 +423,7 @@ var Receiver = /** @class */ (function () {
|
|
|
490
423
|
* @param eventHandler - Optional event handler, if none provided, unsubscribe all handlers on this event.
|
|
491
424
|
*
|
|
492
425
|
*/
|
|
493
|
-
|
|
426
|
+
_unsubscribe(eventType, eventHandler) {
|
|
494
427
|
if (this.handlersMap[eventType] && eventHandler) {
|
|
495
428
|
this.handlersMap[eventType].delete(eventHandler);
|
|
496
429
|
}
|
|
@@ -500,10 +433,9 @@ var Receiver = /** @class */ (function () {
|
|
|
500
433
|
if (Object.keys(this.handlersMap).length === 0) {
|
|
501
434
|
this.eventTarget.removeEventListener('message', this.boundEventHandler);
|
|
502
435
|
}
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
}());
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
Receiver.receivers = [];
|
|
507
439
|
|
|
508
440
|
/**
|
|
509
441
|
* @license
|
|
@@ -521,11 +453,9 @@ var Receiver = /** @class */ (function () {
|
|
|
521
453
|
* See the License for the specific language governing permissions and
|
|
522
454
|
* limitations under the License.
|
|
523
455
|
*/
|
|
524
|
-
function _generateEventId(prefix, digits) {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
var random = '';
|
|
528
|
-
for (var i = 0; i < digits; i++) {
|
|
456
|
+
function _generateEventId(prefix = '', digits = 10) {
|
|
457
|
+
let random = '';
|
|
458
|
+
for (let i = 0; i < digits; i++) {
|
|
529
459
|
random += Math.floor(Math.random() * 10);
|
|
530
460
|
}
|
|
531
461
|
return prefix + random;
|
|
@@ -551,8 +481,8 @@ function _generateEventId(prefix, digits) {
|
|
|
551
481
|
* Interface for sending messages and waiting for a completion response.
|
|
552
482
|
*
|
|
553
483
|
*/
|
|
554
|
-
|
|
555
|
-
|
|
484
|
+
class Sender {
|
|
485
|
+
constructor(target) {
|
|
556
486
|
this.target = target;
|
|
557
487
|
this.handlers = new Set();
|
|
558
488
|
}
|
|
@@ -561,13 +491,13 @@ var Sender = /** @class */ (function () {
|
|
|
561
491
|
*
|
|
562
492
|
* @param handler - The handler to unsubscribe.
|
|
563
493
|
*/
|
|
564
|
-
|
|
494
|
+
removeMessageHandler(handler) {
|
|
565
495
|
if (handler.messageChannel) {
|
|
566
496
|
handler.messageChannel.port1.removeEventListener('message', handler.onMessage);
|
|
567
497
|
handler.messageChannel.port1.close();
|
|
568
498
|
}
|
|
569
499
|
this.handlers.delete(handler);
|
|
570
|
-
}
|
|
500
|
+
}
|
|
571
501
|
/**
|
|
572
502
|
* Send a message to the Receiver located at {@link target}.
|
|
573
503
|
*
|
|
@@ -581,67 +511,65 @@ var Sender = /** @class */ (function () {
|
|
|
581
511
|
*
|
|
582
512
|
* @returns An array of settled promises from all the handlers that were listening on the receiver.
|
|
583
513
|
*/
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
514
|
+
async _send(eventType, data, timeout = 50 /* _TimeoutDuration.ACK */) {
|
|
515
|
+
const messageChannel = typeof MessageChannel !== 'undefined' ? new MessageChannel() : null;
|
|
516
|
+
if (!messageChannel) {
|
|
517
|
+
throw new Error("connection_unavailable" /* _MessageError.CONNECTION_UNAVAILABLE */);
|
|
518
|
+
}
|
|
519
|
+
// Node timers and browser timers return fundamentally different types.
|
|
520
|
+
// We don't actually care what the value is but TS won't accept unknown and
|
|
521
|
+
// we can't cast properly in both environments.
|
|
522
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
523
|
+
let completionTimer;
|
|
524
|
+
let handler;
|
|
525
|
+
return new Promise((resolve, reject) => {
|
|
526
|
+
const eventId = _generateEventId('', 20);
|
|
527
|
+
messageChannel.port1.start();
|
|
528
|
+
const ackTimer = setTimeout(() => {
|
|
529
|
+
reject(new Error("unsupported_event" /* _MessageError.UNSUPPORTED_EVENT */));
|
|
530
|
+
}, timeout);
|
|
531
|
+
handler = {
|
|
532
|
+
messageChannel,
|
|
533
|
+
onMessage(event) {
|
|
534
|
+
const messageEvent = event;
|
|
535
|
+
if (messageEvent.data.eventId !== eventId) {
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
switch (messageEvent.data.status) {
|
|
539
|
+
case "ack" /* _Status.ACK */:
|
|
540
|
+
// The receiver should ACK first.
|
|
541
|
+
clearTimeout(ackTimer);
|
|
542
|
+
completionTimer = setTimeout(() => {
|
|
543
|
+
reject(new Error("timeout" /* _MessageError.TIMEOUT */));
|
|
544
|
+
}, 3000 /* _TimeoutDuration.COMPLETION */);
|
|
545
|
+
break;
|
|
546
|
+
case "done" /* _Status.DONE */:
|
|
547
|
+
// Once the receiver's handlers are finished we will get the results.
|
|
548
|
+
clearTimeout(completionTimer);
|
|
549
|
+
resolve(messageEvent.data.response);
|
|
550
|
+
break;
|
|
551
|
+
default:
|
|
552
|
+
clearTimeout(ackTimer);
|
|
553
|
+
clearTimeout(completionTimer);
|
|
554
|
+
reject(new Error("invalid_response" /* _MessageError.INVALID_RESPONSE */));
|
|
555
|
+
break;
|
|
556
|
+
}
|
|
593
557
|
}
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
}
|
|
607
|
-
switch (messageEvent.data.status) {
|
|
608
|
-
case "ack" /* _Status.ACK */:
|
|
609
|
-
// The receiver should ACK first.
|
|
610
|
-
clearTimeout(ackTimer);
|
|
611
|
-
completionTimer = setTimeout(function () {
|
|
612
|
-
reject(new Error("timeout" /* _MessageError.TIMEOUT */));
|
|
613
|
-
}, 3000 /* _TimeoutDuration.COMPLETION */);
|
|
614
|
-
break;
|
|
615
|
-
case "done" /* _Status.DONE */:
|
|
616
|
-
// Once the receiver's handlers are finished we will get the results.
|
|
617
|
-
clearTimeout(completionTimer);
|
|
618
|
-
resolve(messageEvent.data.response);
|
|
619
|
-
break;
|
|
620
|
-
default:
|
|
621
|
-
clearTimeout(ackTimer);
|
|
622
|
-
clearTimeout(completionTimer);
|
|
623
|
-
reject(new Error("invalid_response" /* _MessageError.INVALID_RESPONSE */));
|
|
624
|
-
break;
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
};
|
|
628
|
-
_this.handlers.add(handler);
|
|
629
|
-
messageChannel.port1.addEventListener('message', handler.onMessage);
|
|
630
|
-
_this.target.postMessage({
|
|
631
|
-
eventType: eventType,
|
|
632
|
-
eventId: eventId,
|
|
633
|
-
data: data
|
|
634
|
-
}, [messageChannel.port2]);
|
|
635
|
-
}).finally(function () {
|
|
636
|
-
if (handler) {
|
|
637
|
-
_this.removeMessageHandler(handler);
|
|
638
|
-
}
|
|
639
|
-
})];
|
|
640
|
-
});
|
|
558
|
+
};
|
|
559
|
+
this.handlers.add(handler);
|
|
560
|
+
messageChannel.port1.addEventListener('message', handler.onMessage);
|
|
561
|
+
this.target.postMessage({
|
|
562
|
+
eventType,
|
|
563
|
+
eventId,
|
|
564
|
+
data
|
|
565
|
+
}, [messageChannel.port2]);
|
|
566
|
+
}).finally(() => {
|
|
567
|
+
if (handler) {
|
|
568
|
+
this.removeMessageHandler(handler);
|
|
569
|
+
}
|
|
641
570
|
});
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
}());
|
|
571
|
+
}
|
|
572
|
+
}
|
|
645
573
|
|
|
646
574
|
/**
|
|
647
575
|
* @license
|
|
@@ -659,51 +587,48 @@ var Sender = /** @class */ (function () {
|
|
|
659
587
|
* See the License for the specific language governing permissions and
|
|
660
588
|
* limitations under the License.
|
|
661
589
|
*/
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
590
|
+
const DB_NAME = 'firebaseLocalStorageDb';
|
|
591
|
+
const DB_VERSION = 1;
|
|
592
|
+
const DB_OBJECTSTORE_NAME = 'firebaseLocalStorage';
|
|
593
|
+
const DB_DATA_KEYPATH = 'fbase_key';
|
|
666
594
|
/**
|
|
667
595
|
* Promise wrapper for IDBRequest
|
|
668
596
|
*
|
|
669
597
|
* Unfortunately we can't cleanly extend Promise<T> since promises are not callable in ES6
|
|
670
598
|
*
|
|
671
599
|
*/
|
|
672
|
-
|
|
673
|
-
|
|
600
|
+
class DBPromise {
|
|
601
|
+
constructor(request) {
|
|
674
602
|
this.request = request;
|
|
675
603
|
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
resolve(_this.request.result);
|
|
604
|
+
toPromise() {
|
|
605
|
+
return new Promise((resolve, reject) => {
|
|
606
|
+
this.request.addEventListener('success', () => {
|
|
607
|
+
resolve(this.request.result);
|
|
681
608
|
});
|
|
682
|
-
|
|
683
|
-
reject(
|
|
609
|
+
this.request.addEventListener('error', () => {
|
|
610
|
+
reject(this.request.error);
|
|
684
611
|
});
|
|
685
612
|
});
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
}());
|
|
613
|
+
}
|
|
614
|
+
}
|
|
689
615
|
function getObjectStore(db, isReadWrite) {
|
|
690
616
|
return db
|
|
691
617
|
.transaction([DB_OBJECTSTORE_NAME], isReadWrite ? 'readwrite' : 'readonly')
|
|
692
618
|
.objectStore(DB_OBJECTSTORE_NAME);
|
|
693
619
|
}
|
|
694
620
|
function _deleteDatabase() {
|
|
695
|
-
|
|
621
|
+
const request = indexedDB.deleteDatabase(DB_NAME);
|
|
696
622
|
return new DBPromise(request).toPromise();
|
|
697
623
|
}
|
|
698
624
|
function _openDatabase() {
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
request.addEventListener('error', function () {
|
|
625
|
+
const request = indexedDB.open(DB_NAME, DB_VERSION);
|
|
626
|
+
return new Promise((resolve, reject) => {
|
|
627
|
+
request.addEventListener('error', () => {
|
|
703
628
|
reject(request.error);
|
|
704
629
|
});
|
|
705
|
-
request.addEventListener('upgradeneeded',
|
|
706
|
-
|
|
630
|
+
request.addEventListener('upgradeneeded', () => {
|
|
631
|
+
const db = request.result;
|
|
707
632
|
try {
|
|
708
633
|
db.createObjectStore(DB_OBJECTSTORE_NAME, { keyPath: DB_DATA_KEYPATH });
|
|
709
634
|
}
|
|
@@ -711,68 +636,44 @@ function _openDatabase() {
|
|
|
711
636
|
reject(e);
|
|
712
637
|
}
|
|
713
638
|
});
|
|
714
|
-
request.addEventListener('success',
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
_a.apply(void 0, [_b.sent()]);
|
|
730
|
-
return [3 /*break*/, 4];
|
|
731
|
-
case 3:
|
|
732
|
-
resolve(db);
|
|
733
|
-
_b.label = 4;
|
|
734
|
-
case 4: return [2 /*return*/];
|
|
735
|
-
}
|
|
736
|
-
});
|
|
737
|
-
}); });
|
|
738
|
-
});
|
|
739
|
-
}
|
|
740
|
-
function _putObject(db, key, value) {
|
|
741
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
742
|
-
var request;
|
|
743
|
-
var _a;
|
|
744
|
-
return tslib.__generator(this, function (_b) {
|
|
745
|
-
request = getObjectStore(db, true).put((_a = {},
|
|
746
|
-
_a[DB_DATA_KEYPATH] = key,
|
|
747
|
-
_a.value = value,
|
|
748
|
-
_a));
|
|
749
|
-
return [2 /*return*/, new DBPromise(request).toPromise()];
|
|
639
|
+
request.addEventListener('success', async () => {
|
|
640
|
+
const db = request.result;
|
|
641
|
+
// Strange bug that occurs in Firefox when multiple tabs are opened at the
|
|
642
|
+
// same time. The only way to recover seems to be deleting the database
|
|
643
|
+
// and re-initializing it.
|
|
644
|
+
// https://github.com/firebase/firebase-js-sdk/issues/634
|
|
645
|
+
if (!db.objectStoreNames.contains(DB_OBJECTSTORE_NAME)) {
|
|
646
|
+
// Need to close the database or else you get a `blocked` event
|
|
647
|
+
db.close();
|
|
648
|
+
await _deleteDatabase();
|
|
649
|
+
resolve(await _openDatabase());
|
|
650
|
+
}
|
|
651
|
+
else {
|
|
652
|
+
resolve(db);
|
|
653
|
+
}
|
|
750
654
|
});
|
|
751
655
|
});
|
|
752
656
|
}
|
|
753
|
-
function
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
switch (_a.label) {
|
|
758
|
-
case 0:
|
|
759
|
-
request = getObjectStore(db, false).get(key);
|
|
760
|
-
return [4 /*yield*/, new DBPromise(request).toPromise()];
|
|
761
|
-
case 1:
|
|
762
|
-
data = _a.sent();
|
|
763
|
-
return [2 /*return*/, data === undefined ? null : data.value];
|
|
764
|
-
}
|
|
765
|
-
});
|
|
657
|
+
async function _putObject(db, key, value) {
|
|
658
|
+
const request = getObjectStore(db, true).put({
|
|
659
|
+
[DB_DATA_KEYPATH]: key,
|
|
660
|
+
value
|
|
766
661
|
});
|
|
662
|
+
return new DBPromise(request).toPromise();
|
|
663
|
+
}
|
|
664
|
+
async function getObject(db, key) {
|
|
665
|
+
const request = getObjectStore(db, false).get(key);
|
|
666
|
+
const data = await new DBPromise(request).toPromise();
|
|
667
|
+
return data === undefined ? null : data.value;
|
|
767
668
|
}
|
|
768
669
|
function _deleteObject(db, key) {
|
|
769
|
-
|
|
670
|
+
const request = getObjectStore(db, true).delete(key);
|
|
770
671
|
return new DBPromise(request).toPromise();
|
|
771
672
|
}
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
673
|
+
const _POLLING_INTERVAL_MS = 800;
|
|
674
|
+
const _TRANSACTION_RETRY_COUNT = 3;
|
|
675
|
+
class IndexedDBLocalPersistence {
|
|
676
|
+
constructor() {
|
|
776
677
|
this.type = "LOCAL" /* PersistenceType.LOCAL */;
|
|
777
678
|
this._shouldAllowMigration = true;
|
|
778
679
|
this.listeners = {};
|
|
@@ -787,102 +688,58 @@ var IndexedDBLocalPersistence = /** @class */ (function () {
|
|
|
787
688
|
this.activeServiceWorker = null;
|
|
788
689
|
// Fire & forget the service worker registration as it may never resolve
|
|
789
690
|
this._workerInitializationPromise =
|
|
790
|
-
this.initializeServiceWorkerMessaging().then(
|
|
691
|
+
this.initializeServiceWorkerMessaging().then(() => { }, () => { });
|
|
791
692
|
}
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
693
|
+
async _openDb() {
|
|
694
|
+
if (this.db) {
|
|
695
|
+
return this.db;
|
|
696
|
+
}
|
|
697
|
+
this.db = await _openDatabase();
|
|
698
|
+
return this.db;
|
|
699
|
+
}
|
|
700
|
+
async _withRetries(op) {
|
|
701
|
+
let numAttempts = 0;
|
|
702
|
+
while (true) {
|
|
703
|
+
try {
|
|
704
|
+
const db = await this._openDb();
|
|
705
|
+
return await op(db);
|
|
706
|
+
}
|
|
707
|
+
catch (e) {
|
|
708
|
+
if (numAttempts++ > _TRANSACTION_RETRY_COUNT) {
|
|
709
|
+
throw e;
|
|
806
710
|
}
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
IndexedDBLocalPersistence.prototype._withRetries = function (op) {
|
|
811
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
812
|
-
var numAttempts, db, e_1;
|
|
813
|
-
return tslib.__generator(this, function (_a) {
|
|
814
|
-
switch (_a.label) {
|
|
815
|
-
case 0:
|
|
816
|
-
numAttempts = 0;
|
|
817
|
-
_a.label = 1;
|
|
818
|
-
case 1:
|
|
819
|
-
_a.label = 2;
|
|
820
|
-
case 2:
|
|
821
|
-
_a.trys.push([2, 5, , 6]);
|
|
822
|
-
return [4 /*yield*/, this._openDb()];
|
|
823
|
-
case 3:
|
|
824
|
-
db = _a.sent();
|
|
825
|
-
return [4 /*yield*/, op(db)];
|
|
826
|
-
case 4: return [2 /*return*/, _a.sent()];
|
|
827
|
-
case 5:
|
|
828
|
-
e_1 = _a.sent();
|
|
829
|
-
if (numAttempts++ > _TRANSACTION_RETRY_COUNT) {
|
|
830
|
-
throw e_1;
|
|
831
|
-
}
|
|
832
|
-
if (this.db) {
|
|
833
|
-
this.db.close();
|
|
834
|
-
this.db = undefined;
|
|
835
|
-
}
|
|
836
|
-
return [3 /*break*/, 6];
|
|
837
|
-
case 6: return [3 /*break*/, 1];
|
|
838
|
-
case 7: return [2 /*return*/];
|
|
711
|
+
if (this.db) {
|
|
712
|
+
this.db.close();
|
|
713
|
+
this.db = undefined;
|
|
839
714
|
}
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
715
|
+
// TODO: consider adding exponential backoff
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
843
719
|
/**
|
|
844
720
|
* IndexedDB events do not propagate from the main window to the worker context. We rely on a
|
|
845
721
|
* postMessage interface to send these events to the worker ourselves.
|
|
846
722
|
*/
|
|
847
|
-
|
|
848
|
-
return
|
|
849
|
-
|
|
850
|
-
return [2 /*return*/, index._isWorker() ? this.initializeReceiver() : this.initializeSender()];
|
|
851
|
-
});
|
|
852
|
-
});
|
|
853
|
-
};
|
|
723
|
+
async initializeServiceWorkerMessaging() {
|
|
724
|
+
return index._isWorker() ? this.initializeReceiver() : this.initializeSender();
|
|
725
|
+
}
|
|
854
726
|
/**
|
|
855
727
|
* As the worker we should listen to events from the main window.
|
|
856
728
|
*/
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
return tslib.__generator(this, function (_a) {
|
|
866
|
-
switch (_a.label) {
|
|
867
|
-
case 0: return [4 /*yield*/, this._poll()];
|
|
868
|
-
case 1:
|
|
869
|
-
keys = _a.sent();
|
|
870
|
-
return [2 /*return*/, {
|
|
871
|
-
keyProcessed: keys.includes(data.key)
|
|
872
|
-
}];
|
|
873
|
-
}
|
|
874
|
-
});
|
|
875
|
-
}); });
|
|
876
|
-
// Let the sender know that we are listening so they give us more timeout.
|
|
877
|
-
this.receiver._subscribe("ping" /* _EventType.PING */, function (_origin, _data) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
878
|
-
return tslib.__generator(this, function (_a) {
|
|
879
|
-
return [2 /*return*/, ["keyChanged" /* _EventType.KEY_CHANGED */]];
|
|
880
|
-
});
|
|
881
|
-
}); });
|
|
882
|
-
return [2 /*return*/];
|
|
883
|
-
});
|
|
729
|
+
async initializeReceiver() {
|
|
730
|
+
this.receiver = Receiver._getInstance(index._getWorkerGlobalScope());
|
|
731
|
+
// Refresh from persistence if we receive a KeyChanged message.
|
|
732
|
+
this.receiver._subscribe("keyChanged" /* _EventType.KEY_CHANGED */, async (_origin, data) => {
|
|
733
|
+
const keys = await this._poll();
|
|
734
|
+
return {
|
|
735
|
+
keyProcessed: keys.includes(data.key)
|
|
736
|
+
};
|
|
884
737
|
});
|
|
885
|
-
|
|
738
|
+
// Let the sender know that we are listening so they give us more timeout.
|
|
739
|
+
this.receiver._subscribe("ping" /* _EventType.PING */, async (_origin, _data) => {
|
|
740
|
+
return ["keyChanged" /* _EventType.KEY_CHANGED */];
|
|
741
|
+
});
|
|
742
|
+
}
|
|
886
743
|
/**
|
|
887
744
|
* As the main window, we should let the worker know when keys change (set and remove).
|
|
888
745
|
*
|
|
@@ -890,38 +747,24 @@ var IndexedDBLocalPersistence = /** @class */ (function () {
|
|
|
890
747
|
* {@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/ready | ServiceWorkerContainer.ready}
|
|
891
748
|
* may not resolve.
|
|
892
749
|
*/
|
|
893
|
-
|
|
750
|
+
async initializeSender() {
|
|
894
751
|
var _a, _b;
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
case 2:
|
|
912
|
-
results = _d.sent();
|
|
913
|
-
if (!results) {
|
|
914
|
-
return [2 /*return*/];
|
|
915
|
-
}
|
|
916
|
-
if (((_a = results[0]) === null || _a === void 0 ? void 0 : _a.fulfilled) &&
|
|
917
|
-
((_b = results[0]) === null || _b === void 0 ? void 0 : _b.value.includes("keyChanged" /* _EventType.KEY_CHANGED */))) {
|
|
918
|
-
this.serviceWorkerReceiverAvailable = true;
|
|
919
|
-
}
|
|
920
|
-
return [2 /*return*/];
|
|
921
|
-
}
|
|
922
|
-
});
|
|
923
|
-
});
|
|
924
|
-
};
|
|
752
|
+
// Check to see if there's an active service worker.
|
|
753
|
+
this.activeServiceWorker = await index._getActiveServiceWorker();
|
|
754
|
+
if (!this.activeServiceWorker) {
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
this.sender = new Sender(this.activeServiceWorker);
|
|
758
|
+
// Ping the service worker to check what events they can handle.
|
|
759
|
+
const results = await this.sender._send("ping" /* _EventType.PING */, {}, 800 /* _TimeoutDuration.LONG_ACK */);
|
|
760
|
+
if (!results) {
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
if (((_a = results[0]) === null || _a === void 0 ? void 0 : _a.fulfilled) &&
|
|
764
|
+
((_b = results[0]) === null || _b === void 0 ? void 0 : _b.value.includes("keyChanged" /* _EventType.KEY_CHANGED */))) {
|
|
765
|
+
this.serviceWorkerReceiverAvailable = true;
|
|
766
|
+
}
|
|
767
|
+
}
|
|
925
768
|
/**
|
|
926
769
|
* Let the worker know about a changed key, the exact key doesn't technically matter since the
|
|
927
770
|
* worker will just trigger a full sync anyway.
|
|
@@ -931,203 +774,117 @@ var IndexedDBLocalPersistence = /** @class */ (function () {
|
|
|
931
774
|
*
|
|
932
775
|
* @param key - Storage key which changed.
|
|
933
776
|
*/
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
_b.sent();
|
|
979
|
-
return [4 /*yield*/, _deleteObject(db, index.STORAGE_AVAILABLE_KEY)];
|
|
980
|
-
case 3:
|
|
981
|
-
_b.sent();
|
|
982
|
-
return [2 /*return*/, true];
|
|
983
|
-
case 4:
|
|
984
|
-
_b.sent();
|
|
985
|
-
return [3 /*break*/, 5];
|
|
986
|
-
case 5: return [2 /*return*/, false];
|
|
987
|
-
}
|
|
988
|
-
});
|
|
989
|
-
});
|
|
990
|
-
};
|
|
991
|
-
IndexedDBLocalPersistence.prototype._withPendingWrite = function (write) {
|
|
992
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
993
|
-
return tslib.__generator(this, function (_a) {
|
|
994
|
-
switch (_a.label) {
|
|
995
|
-
case 0:
|
|
996
|
-
this.pendingWrites++;
|
|
997
|
-
_a.label = 1;
|
|
998
|
-
case 1:
|
|
999
|
-
_a.trys.push([1, , 3, 4]);
|
|
1000
|
-
return [4 /*yield*/, write()];
|
|
1001
|
-
case 2:
|
|
1002
|
-
_a.sent();
|
|
1003
|
-
return [3 /*break*/, 4];
|
|
1004
|
-
case 3:
|
|
1005
|
-
this.pendingWrites--;
|
|
1006
|
-
return [7 /*endfinally*/];
|
|
1007
|
-
case 4: return [2 /*return*/];
|
|
1008
|
-
}
|
|
1009
|
-
});
|
|
1010
|
-
});
|
|
1011
|
-
};
|
|
1012
|
-
IndexedDBLocalPersistence.prototype._set = function (key, value) {
|
|
1013
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
1014
|
-
var _this = this;
|
|
1015
|
-
return tslib.__generator(this, function (_a) {
|
|
1016
|
-
return [2 /*return*/, this._withPendingWrite(function () { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
1017
|
-
return tslib.__generator(this, function (_a) {
|
|
1018
|
-
switch (_a.label) {
|
|
1019
|
-
case 0: return [4 /*yield*/, this._withRetries(function (db) { return _putObject(db, key, value); })];
|
|
1020
|
-
case 1:
|
|
1021
|
-
_a.sent();
|
|
1022
|
-
this.localCache[key] = value;
|
|
1023
|
-
return [2 /*return*/, this.notifyServiceWorker(key)];
|
|
1024
|
-
}
|
|
1025
|
-
});
|
|
1026
|
-
}); })];
|
|
1027
|
-
});
|
|
777
|
+
async notifyServiceWorker(key) {
|
|
778
|
+
if (!this.sender ||
|
|
779
|
+
!this.activeServiceWorker ||
|
|
780
|
+
index._getServiceWorkerController() !== this.activeServiceWorker) {
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
try {
|
|
784
|
+
await this.sender._send("keyChanged" /* _EventType.KEY_CHANGED */, { key },
|
|
785
|
+
// Use long timeout if receiver has previously responded to a ping from us.
|
|
786
|
+
this.serviceWorkerReceiverAvailable
|
|
787
|
+
? 800 /* _TimeoutDuration.LONG_ACK */
|
|
788
|
+
: 50 /* _TimeoutDuration.ACK */);
|
|
789
|
+
}
|
|
790
|
+
catch (_a) {
|
|
791
|
+
// This is a best effort approach. Ignore errors.
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
async _isAvailable() {
|
|
795
|
+
try {
|
|
796
|
+
if (!indexedDB) {
|
|
797
|
+
return false;
|
|
798
|
+
}
|
|
799
|
+
const db = await _openDatabase();
|
|
800
|
+
await _putObject(db, index.STORAGE_AVAILABLE_KEY, '1');
|
|
801
|
+
await _deleteObject(db, index.STORAGE_AVAILABLE_KEY);
|
|
802
|
+
return true;
|
|
803
|
+
}
|
|
804
|
+
catch (_a) { }
|
|
805
|
+
return false;
|
|
806
|
+
}
|
|
807
|
+
async _withPendingWrite(write) {
|
|
808
|
+
this.pendingWrites++;
|
|
809
|
+
try {
|
|
810
|
+
await write();
|
|
811
|
+
}
|
|
812
|
+
finally {
|
|
813
|
+
this.pendingWrites--;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
async _set(key, value) {
|
|
817
|
+
return this._withPendingWrite(async () => {
|
|
818
|
+
await this._withRetries((db) => _putObject(db, key, value));
|
|
819
|
+
this.localCache[key] = value;
|
|
820
|
+
return this.notifyServiceWorker(key);
|
|
1028
821
|
});
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
this.localCache[key] = obj;
|
|
1041
|
-
return [2 /*return*/, obj];
|
|
1042
|
-
}
|
|
1043
|
-
});
|
|
822
|
+
}
|
|
823
|
+
async _get(key) {
|
|
824
|
+
const obj = (await this._withRetries((db) => getObject(db, key)));
|
|
825
|
+
this.localCache[key] = obj;
|
|
826
|
+
return obj;
|
|
827
|
+
}
|
|
828
|
+
async _remove(key) {
|
|
829
|
+
return this._withPendingWrite(async () => {
|
|
830
|
+
await this._withRetries((db) => _deleteObject(db, key));
|
|
831
|
+
delete this.localCache[key];
|
|
832
|
+
return this.notifyServiceWorker(key);
|
|
1044
833
|
});
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
return tslib.__generator(this, function (_a) {
|
|
1052
|
-
switch (_a.label) {
|
|
1053
|
-
case 0: return [4 /*yield*/, this._withRetries(function (db) { return _deleteObject(db, key); })];
|
|
1054
|
-
case 1:
|
|
1055
|
-
_a.sent();
|
|
1056
|
-
delete this.localCache[key];
|
|
1057
|
-
return [2 /*return*/, this.notifyServiceWorker(key)];
|
|
1058
|
-
}
|
|
1059
|
-
});
|
|
1060
|
-
}); })];
|
|
1061
|
-
});
|
|
834
|
+
}
|
|
835
|
+
async _poll() {
|
|
836
|
+
// TODO: check if we need to fallback if getAll is not supported
|
|
837
|
+
const result = await this._withRetries((db) => {
|
|
838
|
+
const getAllRequest = getObjectStore(db, false).getAll();
|
|
839
|
+
return new DBPromise(getAllRequest).toPromise();
|
|
1062
840
|
});
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
// If we have pending writes in progress abort, we'll get picked up on the next poll
|
|
1079
|
-
if (this.pendingWrites !== 0) {
|
|
1080
|
-
return [2 /*return*/, []];
|
|
1081
|
-
}
|
|
1082
|
-
keys = [];
|
|
1083
|
-
keysInResult = new Set();
|
|
1084
|
-
if (result.length !== 0) {
|
|
1085
|
-
for (_i = 0, result_1 = result; _i < result_1.length; _i++) {
|
|
1086
|
-
_a = result_1[_i], key = _a.fbase_key, value = _a.value;
|
|
1087
|
-
keysInResult.add(key);
|
|
1088
|
-
if (JSON.stringify(this.localCache[key]) !== JSON.stringify(value)) {
|
|
1089
|
-
this.notifyListeners(key, value);
|
|
1090
|
-
keys.push(key);
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
for (_b = 0, _c = Object.keys(this.localCache); _b < _c.length; _b++) {
|
|
1095
|
-
localKey = _c[_b];
|
|
1096
|
-
if (this.localCache[localKey] && !keysInResult.has(localKey)) {
|
|
1097
|
-
// Deleted
|
|
1098
|
-
this.notifyListeners(localKey, null);
|
|
1099
|
-
keys.push(localKey);
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
return [2 /*return*/, keys];
|
|
841
|
+
if (!result) {
|
|
842
|
+
return [];
|
|
843
|
+
}
|
|
844
|
+
// If we have pending writes in progress abort, we'll get picked up on the next poll
|
|
845
|
+
if (this.pendingWrites !== 0) {
|
|
846
|
+
return [];
|
|
847
|
+
}
|
|
848
|
+
const keys = [];
|
|
849
|
+
const keysInResult = new Set();
|
|
850
|
+
if (result.length !== 0) {
|
|
851
|
+
for (const { fbase_key: key, value } of result) {
|
|
852
|
+
keysInResult.add(key);
|
|
853
|
+
if (JSON.stringify(this.localCache[key]) !== JSON.stringify(value)) {
|
|
854
|
+
this.notifyListeners(key, value);
|
|
855
|
+
keys.push(key);
|
|
1103
856
|
}
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
|
|
1107
|
-
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
for (const localKey of Object.keys(this.localCache)) {
|
|
860
|
+
if (this.localCache[localKey] && !keysInResult.has(localKey)) {
|
|
861
|
+
// Deleted
|
|
862
|
+
this.notifyListeners(localKey, null);
|
|
863
|
+
keys.push(localKey);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
return keys;
|
|
867
|
+
}
|
|
868
|
+
notifyListeners(key, newValue) {
|
|
1108
869
|
this.localCache[key] = newValue;
|
|
1109
|
-
|
|
870
|
+
const listeners = this.listeners[key];
|
|
1110
871
|
if (listeners) {
|
|
1111
|
-
for (
|
|
1112
|
-
var listener = _a[_i];
|
|
872
|
+
for (const listener of Array.from(listeners)) {
|
|
1113
873
|
listener(newValue);
|
|
1114
874
|
}
|
|
1115
875
|
}
|
|
1116
|
-
}
|
|
1117
|
-
|
|
1118
|
-
var _this = this;
|
|
876
|
+
}
|
|
877
|
+
startPolling() {
|
|
1119
878
|
this.stopPolling();
|
|
1120
|
-
this.pollTimer = setInterval(
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
};
|
|
1124
|
-
IndexedDBLocalPersistence.prototype.stopPolling = function () {
|
|
879
|
+
this.pollTimer = setInterval(async () => this._poll(), _POLLING_INTERVAL_MS);
|
|
880
|
+
}
|
|
881
|
+
stopPolling() {
|
|
1125
882
|
if (this.pollTimer) {
|
|
1126
883
|
clearInterval(this.pollTimer);
|
|
1127
884
|
this.pollTimer = null;
|
|
1128
885
|
}
|
|
1129
|
-
}
|
|
1130
|
-
|
|
886
|
+
}
|
|
887
|
+
_addListener(key, listener) {
|
|
1131
888
|
if (Object.keys(this.listeners).length === 0) {
|
|
1132
889
|
this.startPolling();
|
|
1133
890
|
}
|
|
@@ -1137,8 +894,8 @@ var IndexedDBLocalPersistence = /** @class */ (function () {
|
|
|
1137
894
|
void this._get(key); // This can happen in the background async and we can return immediately.
|
|
1138
895
|
}
|
|
1139
896
|
this.listeners[key].add(listener);
|
|
1140
|
-
}
|
|
1141
|
-
|
|
897
|
+
}
|
|
898
|
+
_removeListener(key, listener) {
|
|
1142
899
|
if (this.listeners[key]) {
|
|
1143
900
|
this.listeners[key].delete(listener);
|
|
1144
901
|
if (this.listeners[key].size === 0) {
|
|
@@ -1148,17 +905,16 @@ var IndexedDBLocalPersistence = /** @class */ (function () {
|
|
|
1148
905
|
if (Object.keys(this.listeners).length === 0) {
|
|
1149
906
|
this.stopPolling();
|
|
1150
907
|
}
|
|
1151
|
-
}
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
}());
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
IndexedDBLocalPersistence.type = 'LOCAL';
|
|
1155
911
|
/**
|
|
1156
912
|
* An implementation of {@link Persistence} of type `LOCAL` using `indexedDB`
|
|
1157
913
|
* for the underlying storage.
|
|
1158
914
|
*
|
|
1159
915
|
* @public
|
|
1160
916
|
*/
|
|
1161
|
-
|
|
917
|
+
const indexedDBLocalPersistence = IndexedDBLocalPersistence;
|
|
1162
918
|
|
|
1163
919
|
/**
|
|
1164
920
|
* @license
|
|
@@ -1205,24 +961,22 @@ function _withDefaultResolver(auth, resolverOverride) {
|
|
|
1205
961
|
* See the License for the specific language governing permissions and
|
|
1206
962
|
* limitations under the License.
|
|
1207
963
|
*/
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
}
|
|
1215
|
-
IdpCredential.prototype._getIdTokenResponse = function (auth) {
|
|
964
|
+
class IdpCredential extends index.AuthCredential {
|
|
965
|
+
constructor(params) {
|
|
966
|
+
super("custom" /* ProviderId.CUSTOM */, "custom" /* ProviderId.CUSTOM */);
|
|
967
|
+
this.params = params;
|
|
968
|
+
}
|
|
969
|
+
_getIdTokenResponse(auth) {
|
|
1216
970
|
return index.signInWithIdp(auth, this._buildIdpRequest());
|
|
1217
|
-
}
|
|
1218
|
-
|
|
971
|
+
}
|
|
972
|
+
_linkToIdToken(auth, idToken) {
|
|
1219
973
|
return index.signInWithIdp(auth, this._buildIdpRequest(idToken));
|
|
1220
|
-
}
|
|
1221
|
-
|
|
974
|
+
}
|
|
975
|
+
_getReauthenticationResolver(auth) {
|
|
1222
976
|
return index.signInWithIdp(auth, this._buildIdpRequest());
|
|
1223
|
-
}
|
|
1224
|
-
|
|
1225
|
-
|
|
977
|
+
}
|
|
978
|
+
_buildIdpRequest(idToken) {
|
|
979
|
+
const request = {
|
|
1226
980
|
requestUri: this.params.requestUri,
|
|
1227
981
|
sessionId: this.params.sessionId,
|
|
1228
982
|
postBody: this.params.postBody,
|
|
@@ -1235,26 +989,20 @@ var IdpCredential = /** @class */ (function (_super) {
|
|
|
1235
989
|
request.idToken = idToken;
|
|
1236
990
|
}
|
|
1237
991
|
return request;
|
|
1238
|
-
}
|
|
1239
|
-
|
|
1240
|
-
}(index.AuthCredential));
|
|
992
|
+
}
|
|
993
|
+
}
|
|
1241
994
|
function _signIn(params) {
|
|
1242
995
|
return index._signInWithCredential(params.auth, new IdpCredential(params), params.bypassAuthState);
|
|
1243
996
|
}
|
|
1244
997
|
function _reauth(params) {
|
|
1245
|
-
|
|
998
|
+
const { auth, user } = params;
|
|
1246
999
|
index._assert(user, auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
|
|
1247
1000
|
return index._reauthenticate(user, new IdpCredential(params), params.bypassAuthState);
|
|
1248
1001
|
}
|
|
1249
|
-
function _link(params) {
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
auth = params.auth, user = params.user;
|
|
1254
|
-
index._assert(user, auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
|
|
1255
|
-
return [2 /*return*/, index._link(user, new IdpCredential(params), params.bypassAuthState)];
|
|
1256
|
-
});
|
|
1257
|
-
});
|
|
1002
|
+
async function _link(params) {
|
|
1003
|
+
const { auth, user } = params;
|
|
1004
|
+
index._assert(user, auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
|
|
1005
|
+
return index._link(user, new IdpCredential(params), params.bypassAuthState);
|
|
1258
1006
|
}
|
|
1259
1007
|
|
|
1260
1008
|
/**
|
|
@@ -1277,9 +1025,8 @@ function _link(params) {
|
|
|
1277
1025
|
* Popup event manager. Handles the popup's entire lifecycle; listens to auth
|
|
1278
1026
|
* events
|
|
1279
1027
|
*/
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
if (bypassAuthState === void 0) { bypassAuthState = false; }
|
|
1028
|
+
class AbstractPopupRedirectOperation {
|
|
1029
|
+
constructor(auth, filter, resolver, user, bypassAuthState = false) {
|
|
1283
1030
|
this.auth = auth;
|
|
1284
1031
|
this.resolver = resolver;
|
|
1285
1032
|
this.user = user;
|
|
@@ -1288,76 +1035,45 @@ var AbstractPopupRedirectOperation = /** @class */ (function () {
|
|
|
1288
1035
|
this.eventManager = null;
|
|
1289
1036
|
this.filter = Array.isArray(filter) ? filter : [filter];
|
|
1290
1037
|
}
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
_a = this;
|
|
1303
|
-
return [4 /*yield*/, this.resolver._initialize(this.auth)];
|
|
1304
|
-
case 2:
|
|
1305
|
-
_a.eventManager = _b.sent();
|
|
1306
|
-
return [4 /*yield*/, this.onExecution()];
|
|
1307
|
-
case 3:
|
|
1308
|
-
_b.sent();
|
|
1309
|
-
this.eventManager.registerConsumer(this);
|
|
1310
|
-
return [3 /*break*/, 5];
|
|
1311
|
-
case 4:
|
|
1312
|
-
e_1 = _b.sent();
|
|
1313
|
-
this.reject(e_1);
|
|
1314
|
-
return [3 /*break*/, 5];
|
|
1315
|
-
case 5: return [2 /*return*/];
|
|
1316
|
-
}
|
|
1317
|
-
});
|
|
1318
|
-
}); });
|
|
1319
|
-
};
|
|
1320
|
-
AbstractPopupRedirectOperation.prototype.onAuthEvent = function (event) {
|
|
1321
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
1322
|
-
var urlResponse, sessionId, postBody, tenantId, error, type, params, _a, e_2;
|
|
1323
|
-
return tslib.__generator(this, function (_b) {
|
|
1324
|
-
switch (_b.label) {
|
|
1325
|
-
case 0:
|
|
1326
|
-
urlResponse = event.urlResponse, sessionId = event.sessionId, postBody = event.postBody, tenantId = event.tenantId, error = event.error, type = event.type;
|
|
1327
|
-
if (error) {
|
|
1328
|
-
this.reject(error);
|
|
1329
|
-
return [2 /*return*/];
|
|
1330
|
-
}
|
|
1331
|
-
params = {
|
|
1332
|
-
auth: this.auth,
|
|
1333
|
-
requestUri: urlResponse,
|
|
1334
|
-
sessionId: sessionId,
|
|
1335
|
-
tenantId: tenantId || undefined,
|
|
1336
|
-
postBody: postBody || undefined,
|
|
1337
|
-
user: this.user,
|
|
1338
|
-
bypassAuthState: this.bypassAuthState
|
|
1339
|
-
};
|
|
1340
|
-
_b.label = 1;
|
|
1341
|
-
case 1:
|
|
1342
|
-
_b.trys.push([1, 3, , 4]);
|
|
1343
|
-
_a = this.resolve;
|
|
1344
|
-
return [4 /*yield*/, this.getIdpTask(type)(params)];
|
|
1345
|
-
case 2:
|
|
1346
|
-
_a.apply(this, [_b.sent()]);
|
|
1347
|
-
return [3 /*break*/, 4];
|
|
1348
|
-
case 3:
|
|
1349
|
-
e_2 = _b.sent();
|
|
1350
|
-
this.reject(e_2);
|
|
1351
|
-
return [3 /*break*/, 4];
|
|
1352
|
-
case 4: return [2 /*return*/];
|
|
1353
|
-
}
|
|
1354
|
-
});
|
|
1038
|
+
execute() {
|
|
1039
|
+
return new Promise(async (resolve, reject) => {
|
|
1040
|
+
this.pendingPromise = { resolve, reject };
|
|
1041
|
+
try {
|
|
1042
|
+
this.eventManager = await this.resolver._initialize(this.auth);
|
|
1043
|
+
await this.onExecution();
|
|
1044
|
+
this.eventManager.registerConsumer(this);
|
|
1045
|
+
}
|
|
1046
|
+
catch (e) {
|
|
1047
|
+
this.reject(e);
|
|
1048
|
+
}
|
|
1355
1049
|
});
|
|
1356
|
-
}
|
|
1357
|
-
|
|
1050
|
+
}
|
|
1051
|
+
async onAuthEvent(event) {
|
|
1052
|
+
const { urlResponse, sessionId, postBody, tenantId, error, type } = event;
|
|
1053
|
+
if (error) {
|
|
1054
|
+
this.reject(error);
|
|
1055
|
+
return;
|
|
1056
|
+
}
|
|
1057
|
+
const params = {
|
|
1058
|
+
auth: this.auth,
|
|
1059
|
+
requestUri: urlResponse,
|
|
1060
|
+
sessionId: sessionId,
|
|
1061
|
+
tenantId: tenantId || undefined,
|
|
1062
|
+
postBody: postBody || undefined,
|
|
1063
|
+
user: this.user,
|
|
1064
|
+
bypassAuthState: this.bypassAuthState
|
|
1065
|
+
};
|
|
1066
|
+
try {
|
|
1067
|
+
this.resolve(await this.getIdpTask(type)(params));
|
|
1068
|
+
}
|
|
1069
|
+
catch (e) {
|
|
1070
|
+
this.reject(e);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
onError(error) {
|
|
1358
1074
|
this.reject(error);
|
|
1359
|
-
}
|
|
1360
|
-
|
|
1075
|
+
}
|
|
1076
|
+
getIdpTask(type) {
|
|
1361
1077
|
switch (type) {
|
|
1362
1078
|
case "signInViaPopup" /* AuthEventType.SIGN_IN_VIA_POPUP */:
|
|
1363
1079
|
case "signInViaRedirect" /* AuthEventType.SIGN_IN_VIA_REDIRECT */:
|
|
@@ -1371,26 +1087,25 @@ var AbstractPopupRedirectOperation = /** @class */ (function () {
|
|
|
1371
1087
|
default:
|
|
1372
1088
|
index._fail(this.auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
|
|
1373
1089
|
}
|
|
1374
|
-
}
|
|
1375
|
-
|
|
1090
|
+
}
|
|
1091
|
+
resolve(cred) {
|
|
1376
1092
|
index.debugAssert(this.pendingPromise, 'Pending promise was never set');
|
|
1377
1093
|
this.pendingPromise.resolve(cred);
|
|
1378
1094
|
this.unregisterAndCleanUp();
|
|
1379
|
-
}
|
|
1380
|
-
|
|
1095
|
+
}
|
|
1096
|
+
reject(error) {
|
|
1381
1097
|
index.debugAssert(this.pendingPromise, 'Pending promise was never set');
|
|
1382
1098
|
this.pendingPromise.reject(error);
|
|
1383
1099
|
this.unregisterAndCleanUp();
|
|
1384
|
-
}
|
|
1385
|
-
|
|
1100
|
+
}
|
|
1101
|
+
unregisterAndCleanUp() {
|
|
1386
1102
|
if (this.eventManager) {
|
|
1387
1103
|
this.eventManager.unregisterConsumer(this);
|
|
1388
1104
|
}
|
|
1389
1105
|
this.pendingPromise = null;
|
|
1390
1106
|
this.cleanUp();
|
|
1391
|
-
}
|
|
1392
|
-
|
|
1393
|
-
}());
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1394
1109
|
|
|
1395
1110
|
/**
|
|
1396
1111
|
* @license
|
|
@@ -1408,7 +1123,7 @@ var AbstractPopupRedirectOperation = /** @class */ (function () {
|
|
|
1408
1123
|
* See the License for the specific language governing permissions and
|
|
1409
1124
|
* limitations under the License.
|
|
1410
1125
|
*/
|
|
1411
|
-
|
|
1126
|
+
const _POLL_WINDOW_CLOSE_TIMEOUT = new index.Delay(2000, 10000);
|
|
1412
1127
|
/**
|
|
1413
1128
|
* Authenticates a Firebase client using a popup-based OAuth authentication flow.
|
|
1414
1129
|
*
|
|
@@ -1440,20 +1155,15 @@ var _POLL_WINDOW_CLOSE_TIMEOUT = new index.Delay(2000, 10000);
|
|
|
1440
1155
|
*
|
|
1441
1156
|
* @public
|
|
1442
1157
|
*/
|
|
1443
|
-
function signInWithPopup(auth, provider, resolver) {
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
resolverInternal = _withDefaultResolver(authInternal, resolver);
|
|
1453
|
-
action = new PopupOperation(authInternal, "signInViaPopup" /* AuthEventType.SIGN_IN_VIA_POPUP */, provider, resolverInternal);
|
|
1454
|
-
return [2 /*return*/, action.executeNotNull()];
|
|
1455
|
-
});
|
|
1456
|
-
});
|
|
1158
|
+
async function signInWithPopup(auth, provider, resolver) {
|
|
1159
|
+
if (app._isFirebaseServerApp(auth.app)) {
|
|
1160
|
+
return Promise.reject(index._createError(auth, "operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */));
|
|
1161
|
+
}
|
|
1162
|
+
const authInternal = index._castAuth(auth);
|
|
1163
|
+
index._assertInstanceOf(auth, provider, index.FederatedAuthProvider);
|
|
1164
|
+
const resolverInternal = _withDefaultResolver(authInternal, resolver);
|
|
1165
|
+
const action = new PopupOperation(authInternal, "signInViaPopup" /* AuthEventType.SIGN_IN_VIA_POPUP */, provider, resolverInternal);
|
|
1166
|
+
return action.executeNotNull();
|
|
1457
1167
|
}
|
|
1458
1168
|
/**
|
|
1459
1169
|
* Reauthenticates the current user with the specified {@link OAuthProvider} using a pop-up based
|
|
@@ -1483,20 +1193,15 @@ function signInWithPopup(auth, provider, resolver) {
|
|
|
1483
1193
|
*
|
|
1484
1194
|
* @public
|
|
1485
1195
|
*/
|
|
1486
|
-
function reauthenticateWithPopup(user, provider, resolver) {
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
return
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
resolverInternal = _withDefaultResolver(userInternal.auth, resolver);
|
|
1496
|
-
action = new PopupOperation(userInternal.auth, "reauthViaPopup" /* AuthEventType.REAUTH_VIA_POPUP */, provider, resolverInternal, userInternal);
|
|
1497
|
-
return [2 /*return*/, action.executeNotNull()];
|
|
1498
|
-
});
|
|
1499
|
-
});
|
|
1196
|
+
async function reauthenticateWithPopup(user, provider, resolver) {
|
|
1197
|
+
const userInternal = util.getModularInstance(user);
|
|
1198
|
+
if (app._isFirebaseServerApp(userInternal.auth.app)) {
|
|
1199
|
+
return Promise.reject(index._createError(userInternal.auth, "operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */));
|
|
1200
|
+
}
|
|
1201
|
+
index._assertInstanceOf(userInternal.auth, provider, index.FederatedAuthProvider);
|
|
1202
|
+
const resolverInternal = _withDefaultResolver(userInternal.auth, resolver);
|
|
1203
|
+
const action = new PopupOperation(userInternal.auth, "reauthViaPopup" /* AuthEventType.REAUTH_VIA_POPUP */, provider, resolverInternal, userInternal);
|
|
1204
|
+
return action.executeNotNull();
|
|
1500
1205
|
}
|
|
1501
1206
|
/**
|
|
1502
1207
|
* Links the authenticated provider to the user account using a pop-up based OAuth flow.
|
|
@@ -1523,99 +1228,66 @@ function reauthenticateWithPopup(user, provider, resolver) {
|
|
|
1523
1228
|
*
|
|
1524
1229
|
* @public
|
|
1525
1230
|
*/
|
|
1526
|
-
function linkWithPopup(user, provider, resolver) {
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
resolverInternal = _withDefaultResolver(userInternal.auth, resolver);
|
|
1533
|
-
action = new PopupOperation(userInternal.auth, "linkViaPopup" /* AuthEventType.LINK_VIA_POPUP */, provider, resolverInternal, userInternal);
|
|
1534
|
-
return [2 /*return*/, action.executeNotNull()];
|
|
1535
|
-
});
|
|
1536
|
-
});
|
|
1231
|
+
async function linkWithPopup(user, provider, resolver) {
|
|
1232
|
+
const userInternal = util.getModularInstance(user);
|
|
1233
|
+
index._assertInstanceOf(userInternal.auth, provider, index.FederatedAuthProvider);
|
|
1234
|
+
const resolverInternal = _withDefaultResolver(userInternal.auth, resolver);
|
|
1235
|
+
const action = new PopupOperation(userInternal.auth, "linkViaPopup" /* AuthEventType.LINK_VIA_POPUP */, provider, resolverInternal, userInternal);
|
|
1236
|
+
return action.executeNotNull();
|
|
1537
1237
|
}
|
|
1538
1238
|
/**
|
|
1539
1239
|
* Popup event manager. Handles the popup's entire lifecycle; listens to auth
|
|
1540
1240
|
* events
|
|
1541
1241
|
*
|
|
1542
1242
|
*/
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
_this.pollId = null;
|
|
1243
|
+
class PopupOperation extends AbstractPopupRedirectOperation {
|
|
1244
|
+
constructor(auth, filter, provider, resolver, user) {
|
|
1245
|
+
super(auth, filter, resolver, user);
|
|
1246
|
+
this.provider = provider;
|
|
1247
|
+
this.authWindow = null;
|
|
1248
|
+
this.pollId = null;
|
|
1550
1249
|
if (PopupOperation.currentPopupAction) {
|
|
1551
1250
|
PopupOperation.currentPopupAction.cancel();
|
|
1552
1251
|
}
|
|
1553
|
-
PopupOperation.currentPopupAction =
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1252
|
+
PopupOperation.currentPopupAction = this;
|
|
1253
|
+
}
|
|
1254
|
+
async executeNotNull() {
|
|
1255
|
+
const result = await this.execute();
|
|
1256
|
+
index._assert(result, this.auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
|
|
1257
|
+
return result;
|
|
1258
|
+
}
|
|
1259
|
+
async onExecution() {
|
|
1260
|
+
index.debugAssert(this.filter.length === 1, 'Popup operations only handle one event');
|
|
1261
|
+
const eventId = _generateEventId();
|
|
1262
|
+
this.authWindow = await this.resolver._openPopup(this.auth, this.provider, this.filter[0], // There's always one, see constructor
|
|
1263
|
+
eventId);
|
|
1264
|
+
this.authWindow.associatedEvent = eventId;
|
|
1265
|
+
// Check for web storage support and origin validation _after_ the popup is
|
|
1266
|
+
// loaded. These operations are slow (~1 second or so) Rather than
|
|
1267
|
+
// waiting on them before opening the window, optimistically open the popup
|
|
1268
|
+
// and check for storage support at the same time. If storage support is
|
|
1269
|
+
// not available, this will cause the whole thing to reject properly. It
|
|
1270
|
+
// will also close the popup, but since the promise has already rejected,
|
|
1271
|
+
// the popup closed by user poll will reject into the void.
|
|
1272
|
+
this.resolver._originValidation(this.auth).catch(e => {
|
|
1273
|
+
this.reject(e);
|
|
1568
1274
|
});
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
var _this = this;
|
|
1574
|
-
return tslib.__generator(this, function (_b) {
|
|
1575
|
-
switch (_b.label) {
|
|
1576
|
-
case 0:
|
|
1577
|
-
index.debugAssert(this.filter.length === 1, 'Popup operations only handle one event');
|
|
1578
|
-
eventId = _generateEventId();
|
|
1579
|
-
_a = this;
|
|
1580
|
-
return [4 /*yield*/, this.resolver._openPopup(this.auth, this.provider, this.filter[0], // There's always one, see constructor
|
|
1581
|
-
eventId)];
|
|
1582
|
-
case 1:
|
|
1583
|
-
_a.authWindow = _b.sent();
|
|
1584
|
-
this.authWindow.associatedEvent = eventId;
|
|
1585
|
-
// Check for web storage support and origin validation _after_ the popup is
|
|
1586
|
-
// loaded. These operations are slow (~1 second or so) Rather than
|
|
1587
|
-
// waiting on them before opening the window, optimistically open the popup
|
|
1588
|
-
// and check for storage support at the same time. If storage support is
|
|
1589
|
-
// not available, this will cause the whole thing to reject properly. It
|
|
1590
|
-
// will also close the popup, but since the promise has already rejected,
|
|
1591
|
-
// the popup closed by user poll will reject into the void.
|
|
1592
|
-
this.resolver._originValidation(this.auth).catch(function (e) {
|
|
1593
|
-
_this.reject(e);
|
|
1594
|
-
});
|
|
1595
|
-
this.resolver._isIframeWebStorageSupported(this.auth, function (isSupported) {
|
|
1596
|
-
if (!isSupported) {
|
|
1597
|
-
_this.reject(index._createError(_this.auth, "web-storage-unsupported" /* AuthErrorCode.WEB_STORAGE_UNSUPPORTED */));
|
|
1598
|
-
}
|
|
1599
|
-
});
|
|
1600
|
-
// Handle user closure. Notice this does *not* use await
|
|
1601
|
-
this.pollUserCancellation();
|
|
1602
|
-
return [2 /*return*/];
|
|
1603
|
-
}
|
|
1604
|
-
});
|
|
1275
|
+
this.resolver._isIframeWebStorageSupported(this.auth, isSupported => {
|
|
1276
|
+
if (!isSupported) {
|
|
1277
|
+
this.reject(index._createError(this.auth, "web-storage-unsupported" /* AuthErrorCode.WEB_STORAGE_UNSUPPORTED */));
|
|
1278
|
+
}
|
|
1605
1279
|
});
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
});
|
|
1615
|
-
PopupOperation.prototype.cancel = function () {
|
|
1280
|
+
// Handle user closure. Notice this does *not* use await
|
|
1281
|
+
this.pollUserCancellation();
|
|
1282
|
+
}
|
|
1283
|
+
get eventId() {
|
|
1284
|
+
var _a;
|
|
1285
|
+
return ((_a = this.authWindow) === null || _a === void 0 ? void 0 : _a.associatedEvent) || null;
|
|
1286
|
+
}
|
|
1287
|
+
cancel() {
|
|
1616
1288
|
this.reject(index._createError(this.auth, "cancelled-popup-request" /* AuthErrorCode.EXPIRED_POPUP_REQUEST */));
|
|
1617
|
-
}
|
|
1618
|
-
|
|
1289
|
+
}
|
|
1290
|
+
cleanUp() {
|
|
1619
1291
|
if (this.authWindow) {
|
|
1620
1292
|
this.authWindow.close();
|
|
1621
1293
|
}
|
|
@@ -1625,32 +1297,30 @@ var PopupOperation = /** @class */ (function (_super) {
|
|
|
1625
1297
|
this.authWindow = null;
|
|
1626
1298
|
this.pollId = null;
|
|
1627
1299
|
PopupOperation.currentPopupAction = null;
|
|
1628
|
-
}
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
var poll = function () {
|
|
1300
|
+
}
|
|
1301
|
+
pollUserCancellation() {
|
|
1302
|
+
const poll = () => {
|
|
1632
1303
|
var _a, _b;
|
|
1633
|
-
if ((_b = (_a =
|
|
1304
|
+
if ((_b = (_a = this.authWindow) === null || _a === void 0 ? void 0 : _a.window) === null || _b === void 0 ? void 0 : _b.closed) {
|
|
1634
1305
|
// Make sure that there is sufficient time for whatever action to
|
|
1635
1306
|
// complete. The window could have closed but the sign in network
|
|
1636
1307
|
// call could still be in flight. This is specifically true for
|
|
1637
1308
|
// Firefox or if the opener is in an iframe, in which case the oauth
|
|
1638
1309
|
// helper closes the popup.
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1310
|
+
this.pollId = window.setTimeout(() => {
|
|
1311
|
+
this.pollId = null;
|
|
1312
|
+
this.reject(index._createError(this.auth, "popup-closed-by-user" /* AuthErrorCode.POPUP_CLOSED_BY_USER */));
|
|
1642
1313
|
}, 8000 /* _Timeout.AUTH_EVENT */);
|
|
1643
1314
|
return;
|
|
1644
1315
|
}
|
|
1645
|
-
|
|
1316
|
+
this.pollId = window.setTimeout(poll, _POLL_WINDOW_CLOSE_TIMEOUT.get());
|
|
1646
1317
|
};
|
|
1647
1318
|
poll();
|
|
1648
|
-
}
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
}(AbstractPopupRedirectOperation));
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
// Only one popup is ever shown at once. The lifecycle of the current popup
|
|
1322
|
+
// can be managed / cancelled by the constructor.
|
|
1323
|
+
PopupOperation.currentPopupAction = null;
|
|
1654
1324
|
|
|
1655
1325
|
/**
|
|
1656
1326
|
* @license
|
|
@@ -1668,140 +1338,79 @@ var PopupOperation = /** @class */ (function (_super) {
|
|
|
1668
1338
|
* See the License for the specific language governing permissions and
|
|
1669
1339
|
* limitations under the License.
|
|
1670
1340
|
*/
|
|
1671
|
-
|
|
1341
|
+
const PENDING_REDIRECT_KEY = 'pendingRedirect';
|
|
1672
1342
|
// We only get one redirect outcome for any one auth, so just store it
|
|
1673
1343
|
// in here.
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
if (bypassAuthState === void 0) { bypassAuthState = false; }
|
|
1679
|
-
var _this = _super.call(this, auth, [
|
|
1344
|
+
const redirectOutcomeMap = new Map();
|
|
1345
|
+
class RedirectAction extends AbstractPopupRedirectOperation {
|
|
1346
|
+
constructor(auth, resolver, bypassAuthState = false) {
|
|
1347
|
+
super(auth, [
|
|
1680
1348
|
"signInViaRedirect" /* AuthEventType.SIGN_IN_VIA_REDIRECT */,
|
|
1681
1349
|
"linkViaRedirect" /* AuthEventType.LINK_VIA_REDIRECT */,
|
|
1682
1350
|
"reauthViaRedirect" /* AuthEventType.REAUTH_VIA_REDIRECT */,
|
|
1683
1351
|
"unknown" /* AuthEventType.UNKNOWN */
|
|
1684
|
-
], resolver, undefined, bypassAuthState)
|
|
1685
|
-
|
|
1686
|
-
return _this;
|
|
1352
|
+
], resolver, undefined, bypassAuthState);
|
|
1353
|
+
this.eventId = null;
|
|
1687
1354
|
}
|
|
1688
1355
|
/**
|
|
1689
1356
|
* Override the execute function; if we already have a redirect result, then
|
|
1690
1357
|
* just return it.
|
|
1691
1358
|
*/
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
if (!!readyOutcome) return [3 /*break*/, 8];
|
|
1700
|
-
_b.label = 1;
|
|
1701
|
-
case 1:
|
|
1702
|
-
_b.trys.push([1, 6, , 7]);
|
|
1703
|
-
return [4 /*yield*/, _getAndClearPendingRedirectStatus(this.resolver, this.auth)];
|
|
1704
|
-
case 2:
|
|
1705
|
-
hasPendingRedirect = _b.sent();
|
|
1706
|
-
if (!hasPendingRedirect) return [3 /*break*/, 4];
|
|
1707
|
-
return [4 /*yield*/, _super.prototype.execute.call(this)];
|
|
1708
|
-
case 3:
|
|
1709
|
-
_a = _b.sent();
|
|
1710
|
-
return [3 /*break*/, 5];
|
|
1711
|
-
case 4:
|
|
1712
|
-
_a = null;
|
|
1713
|
-
_b.label = 5;
|
|
1714
|
-
case 5:
|
|
1715
|
-
result_1 = _a;
|
|
1716
|
-
readyOutcome = function () { return Promise.resolve(result_1); };
|
|
1717
|
-
return [3 /*break*/, 7];
|
|
1718
|
-
case 6:
|
|
1719
|
-
e_1 = _b.sent();
|
|
1720
|
-
readyOutcome = function () { return Promise.reject(e_1); };
|
|
1721
|
-
return [3 /*break*/, 7];
|
|
1722
|
-
case 7:
|
|
1723
|
-
redirectOutcomeMap.set(this.auth._key(), readyOutcome);
|
|
1724
|
-
_b.label = 8;
|
|
1725
|
-
case 8:
|
|
1726
|
-
// If we're not bypassing auth state, the ready outcome should be set to
|
|
1727
|
-
// null.
|
|
1728
|
-
if (!this.bypassAuthState) {
|
|
1729
|
-
redirectOutcomeMap.set(this.auth._key(), function () { return Promise.resolve(null); });
|
|
1730
|
-
}
|
|
1731
|
-
return [2 /*return*/, readyOutcome()];
|
|
1732
|
-
}
|
|
1733
|
-
});
|
|
1734
|
-
});
|
|
1735
|
-
};
|
|
1736
|
-
RedirectAction.prototype.onAuthEvent = function (event) {
|
|
1737
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
1738
|
-
var user;
|
|
1739
|
-
return tslib.__generator(this, function (_a) {
|
|
1740
|
-
switch (_a.label) {
|
|
1741
|
-
case 0:
|
|
1742
|
-
if (event.type === "signInViaRedirect" /* AuthEventType.SIGN_IN_VIA_REDIRECT */) {
|
|
1743
|
-
return [2 /*return*/, _super.prototype.onAuthEvent.call(this, event)];
|
|
1744
|
-
}
|
|
1745
|
-
else if (event.type === "unknown" /* AuthEventType.UNKNOWN */) {
|
|
1746
|
-
// This is a sentinel value indicating there's no pending redirect
|
|
1747
|
-
this.resolve(null);
|
|
1748
|
-
return [2 /*return*/];
|
|
1749
|
-
}
|
|
1750
|
-
if (!event.eventId) return [3 /*break*/, 2];
|
|
1751
|
-
return [4 /*yield*/, this.auth._redirectUserForId(event.eventId)];
|
|
1752
|
-
case 1:
|
|
1753
|
-
user = _a.sent();
|
|
1754
|
-
if (user) {
|
|
1755
|
-
this.user = user;
|
|
1756
|
-
return [2 /*return*/, _super.prototype.onAuthEvent.call(this, event)];
|
|
1757
|
-
}
|
|
1758
|
-
else {
|
|
1759
|
-
this.resolve(null);
|
|
1760
|
-
}
|
|
1761
|
-
_a.label = 2;
|
|
1762
|
-
case 2: return [2 /*return*/];
|
|
1763
|
-
}
|
|
1764
|
-
});
|
|
1765
|
-
});
|
|
1766
|
-
};
|
|
1767
|
-
RedirectAction.prototype.onExecution = function () {
|
|
1768
|
-
return tslib.__awaiter(this, void 0, void 0, function () { return tslib.__generator(this, function (_a) {
|
|
1769
|
-
return [2 /*return*/];
|
|
1770
|
-
}); });
|
|
1771
|
-
};
|
|
1772
|
-
RedirectAction.prototype.cleanUp = function () { };
|
|
1773
|
-
return RedirectAction;
|
|
1774
|
-
}(AbstractPopupRedirectOperation));
|
|
1775
|
-
function _getAndClearPendingRedirectStatus(resolver, auth) {
|
|
1776
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
1777
|
-
var key, persistence, hasPendingRedirect;
|
|
1778
|
-
return tslib.__generator(this, function (_a) {
|
|
1779
|
-
switch (_a.label) {
|
|
1780
|
-
case 0:
|
|
1781
|
-
key = pendingRedirectKey(auth);
|
|
1782
|
-
persistence = resolverPersistence(resolver);
|
|
1783
|
-
return [4 /*yield*/, persistence._isAvailable()];
|
|
1784
|
-
case 1:
|
|
1785
|
-
if (!(_a.sent())) {
|
|
1786
|
-
return [2 /*return*/, false];
|
|
1787
|
-
}
|
|
1788
|
-
return [4 /*yield*/, persistence._get(key)];
|
|
1789
|
-
case 2:
|
|
1790
|
-
hasPendingRedirect = (_a.sent()) === 'true';
|
|
1791
|
-
return [4 /*yield*/, persistence._remove(key)];
|
|
1792
|
-
case 3:
|
|
1793
|
-
_a.sent();
|
|
1794
|
-
return [2 /*return*/, hasPendingRedirect];
|
|
1359
|
+
async execute() {
|
|
1360
|
+
let readyOutcome = redirectOutcomeMap.get(this.auth._key());
|
|
1361
|
+
if (!readyOutcome) {
|
|
1362
|
+
try {
|
|
1363
|
+
const hasPendingRedirect = await _getAndClearPendingRedirectStatus(this.resolver, this.auth);
|
|
1364
|
+
const result = hasPendingRedirect ? await super.execute() : null;
|
|
1365
|
+
readyOutcome = () => Promise.resolve(result);
|
|
1795
1366
|
}
|
|
1796
|
-
|
|
1797
|
-
|
|
1367
|
+
catch (e) {
|
|
1368
|
+
readyOutcome = () => Promise.reject(e);
|
|
1369
|
+
}
|
|
1370
|
+
redirectOutcomeMap.set(this.auth._key(), readyOutcome);
|
|
1371
|
+
}
|
|
1372
|
+
// If we're not bypassing auth state, the ready outcome should be set to
|
|
1373
|
+
// null.
|
|
1374
|
+
if (!this.bypassAuthState) {
|
|
1375
|
+
redirectOutcomeMap.set(this.auth._key(), () => Promise.resolve(null));
|
|
1376
|
+
}
|
|
1377
|
+
return readyOutcome();
|
|
1378
|
+
}
|
|
1379
|
+
async onAuthEvent(event) {
|
|
1380
|
+
if (event.type === "signInViaRedirect" /* AuthEventType.SIGN_IN_VIA_REDIRECT */) {
|
|
1381
|
+
return super.onAuthEvent(event);
|
|
1382
|
+
}
|
|
1383
|
+
else if (event.type === "unknown" /* AuthEventType.UNKNOWN */) {
|
|
1384
|
+
// This is a sentinel value indicating there's no pending redirect
|
|
1385
|
+
this.resolve(null);
|
|
1386
|
+
return;
|
|
1387
|
+
}
|
|
1388
|
+
if (event.eventId) {
|
|
1389
|
+
const user = await this.auth._redirectUserForId(event.eventId);
|
|
1390
|
+
if (user) {
|
|
1391
|
+
this.user = user;
|
|
1392
|
+
return super.onAuthEvent(event);
|
|
1393
|
+
}
|
|
1394
|
+
else {
|
|
1395
|
+
this.resolve(null);
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
async onExecution() { }
|
|
1400
|
+
cleanUp() { }
|
|
1798
1401
|
}
|
|
1799
|
-
function
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
}
|
|
1402
|
+
async function _getAndClearPendingRedirectStatus(resolver, auth) {
|
|
1403
|
+
const key = pendingRedirectKey(auth);
|
|
1404
|
+
const persistence = resolverPersistence(resolver);
|
|
1405
|
+
if (!(await persistence._isAvailable())) {
|
|
1406
|
+
return false;
|
|
1407
|
+
}
|
|
1408
|
+
const hasPendingRedirect = (await persistence._get(key)) === 'true';
|
|
1409
|
+
await persistence._remove(key);
|
|
1410
|
+
return hasPendingRedirect;
|
|
1411
|
+
}
|
|
1412
|
+
async function _setPendingRedirectStatus(resolver, auth) {
|
|
1413
|
+
return resolverPersistence(resolver)._set(pendingRedirectKey(auth), 'true');
|
|
1805
1414
|
}
|
|
1806
1415
|
function _clearRedirectOutcomes() {
|
|
1807
1416
|
redirectOutcomeMap.clear();
|
|
@@ -1879,34 +1488,19 @@ function pendingRedirectKey(auth) {
|
|
|
1879
1488
|
function signInWithRedirect(auth, provider, resolver) {
|
|
1880
1489
|
return _signInWithRedirect(auth, provider, resolver);
|
|
1881
1490
|
}
|
|
1882
|
-
function _signInWithRedirect(auth, provider, resolver) {
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
// redirect and creating a PENDING_REDIRECT_KEY entry.
|
|
1896
|
-
return [4 /*yield*/, authInternal._initializationPromise];
|
|
1897
|
-
case 1:
|
|
1898
|
-
// Wait for auth initialization to complete, this will process pending redirects and clear the
|
|
1899
|
-
// PENDING_REDIRECT_KEY in persistence. This should be completed before starting a new
|
|
1900
|
-
// redirect and creating a PENDING_REDIRECT_KEY entry.
|
|
1901
|
-
_a.sent();
|
|
1902
|
-
resolverInternal = _withDefaultResolver(authInternal, resolver);
|
|
1903
|
-
return [4 /*yield*/, _setPendingRedirectStatus(resolverInternal, authInternal)];
|
|
1904
|
-
case 2:
|
|
1905
|
-
_a.sent();
|
|
1906
|
-
return [2 /*return*/, resolverInternal._openRedirect(authInternal, provider, "signInViaRedirect" /* AuthEventType.SIGN_IN_VIA_REDIRECT */)];
|
|
1907
|
-
}
|
|
1908
|
-
});
|
|
1909
|
-
});
|
|
1491
|
+
async function _signInWithRedirect(auth, provider, resolver) {
|
|
1492
|
+
if (app._isFirebaseServerApp(auth.app)) {
|
|
1493
|
+
return Promise.reject(index._serverAppCurrentUserOperationNotSupportedError(auth));
|
|
1494
|
+
}
|
|
1495
|
+
const authInternal = index._castAuth(auth);
|
|
1496
|
+
index._assertInstanceOf(auth, provider, index.FederatedAuthProvider);
|
|
1497
|
+
// Wait for auth initialization to complete, this will process pending redirects and clear the
|
|
1498
|
+
// PENDING_REDIRECT_KEY in persistence. This should be completed before starting a new
|
|
1499
|
+
// redirect and creating a PENDING_REDIRECT_KEY entry.
|
|
1500
|
+
await authInternal._initializationPromise;
|
|
1501
|
+
const resolverInternal = _withDefaultResolver(authInternal, resolver);
|
|
1502
|
+
await _setPendingRedirectStatus(resolverInternal, authInternal);
|
|
1503
|
+
return resolverInternal._openRedirect(authInternal, provider, "signInViaRedirect" /* AuthEventType.SIGN_IN_VIA_REDIRECT */);
|
|
1910
1504
|
}
|
|
1911
1505
|
/**
|
|
1912
1506
|
* Reauthenticates the current user with the specified {@link OAuthProvider} using a full-page redirect flow.
|
|
@@ -1946,37 +1540,21 @@ function _signInWithRedirect(auth, provider, resolver) {
|
|
|
1946
1540
|
function reauthenticateWithRedirect(user, provider, resolver) {
|
|
1947
1541
|
return _reauthenticateWithRedirect(user, provider, resolver);
|
|
1948
1542
|
}
|
|
1949
|
-
function _reauthenticateWithRedirect(user, provider, resolver) {
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
case 1:
|
|
1965
|
-
// Wait for auth initialization to complete, this will process pending redirects and clear the
|
|
1966
|
-
// PENDING_REDIRECT_KEY in persistence. This should be completed before starting a new
|
|
1967
|
-
// redirect and creating a PENDING_REDIRECT_KEY entry.
|
|
1968
|
-
_a.sent();
|
|
1969
|
-
resolverInternal = _withDefaultResolver(userInternal.auth, resolver);
|
|
1970
|
-
return [4 /*yield*/, _setPendingRedirectStatus(resolverInternal, userInternal.auth)];
|
|
1971
|
-
case 2:
|
|
1972
|
-
_a.sent();
|
|
1973
|
-
return [4 /*yield*/, prepareUserForRedirect(userInternal)];
|
|
1974
|
-
case 3:
|
|
1975
|
-
eventId = _a.sent();
|
|
1976
|
-
return [2 /*return*/, resolverInternal._openRedirect(userInternal.auth, provider, "reauthViaRedirect" /* AuthEventType.REAUTH_VIA_REDIRECT */, eventId)];
|
|
1977
|
-
}
|
|
1978
|
-
});
|
|
1979
|
-
});
|
|
1543
|
+
async function _reauthenticateWithRedirect(user, provider, resolver) {
|
|
1544
|
+
const userInternal = util.getModularInstance(user);
|
|
1545
|
+
index._assertInstanceOf(userInternal.auth, provider, index.FederatedAuthProvider);
|
|
1546
|
+
if (app._isFirebaseServerApp(userInternal.auth.app)) {
|
|
1547
|
+
return Promise.reject(index._serverAppCurrentUserOperationNotSupportedError(userInternal.auth));
|
|
1548
|
+
}
|
|
1549
|
+
// Wait for auth initialization to complete, this will process pending redirects and clear the
|
|
1550
|
+
// PENDING_REDIRECT_KEY in persistence. This should be completed before starting a new
|
|
1551
|
+
// redirect and creating a PENDING_REDIRECT_KEY entry.
|
|
1552
|
+
await userInternal.auth._initializationPromise;
|
|
1553
|
+
// Allow the resolver to error before persisting the redirect user
|
|
1554
|
+
const resolverInternal = _withDefaultResolver(userInternal.auth, resolver);
|
|
1555
|
+
await _setPendingRedirectStatus(resolverInternal, userInternal.auth);
|
|
1556
|
+
const eventId = await prepareUserForRedirect(userInternal);
|
|
1557
|
+
return resolverInternal._openRedirect(userInternal.auth, provider, "reauthViaRedirect" /* AuthEventType.REAUTH_VIA_REDIRECT */, eventId);
|
|
1980
1558
|
}
|
|
1981
1559
|
/**
|
|
1982
1560
|
* Links the {@link OAuthProvider} to the user account using a full-page redirect flow.
|
|
@@ -2012,37 +1590,19 @@ function _reauthenticateWithRedirect(user, provider, resolver) {
|
|
|
2012
1590
|
function linkWithRedirect(user, provider, resolver) {
|
|
2013
1591
|
return _linkWithRedirect(user, provider, resolver);
|
|
2014
1592
|
}
|
|
2015
|
-
function _linkWithRedirect(user, provider, resolver) {
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
// Wait for auth initialization to complete, this will process pending redirects and clear the
|
|
2029
|
-
// PENDING_REDIRECT_KEY in persistence. This should be completed before starting a new
|
|
2030
|
-
// redirect and creating a PENDING_REDIRECT_KEY entry.
|
|
2031
|
-
_a.sent();
|
|
2032
|
-
resolverInternal = _withDefaultResolver(userInternal.auth, resolver);
|
|
2033
|
-
return [4 /*yield*/, index._assertLinkedStatus(false, userInternal, provider.providerId)];
|
|
2034
|
-
case 2:
|
|
2035
|
-
_a.sent();
|
|
2036
|
-
return [4 /*yield*/, _setPendingRedirectStatus(resolverInternal, userInternal.auth)];
|
|
2037
|
-
case 3:
|
|
2038
|
-
_a.sent();
|
|
2039
|
-
return [4 /*yield*/, prepareUserForRedirect(userInternal)];
|
|
2040
|
-
case 4:
|
|
2041
|
-
eventId = _a.sent();
|
|
2042
|
-
return [2 /*return*/, resolverInternal._openRedirect(userInternal.auth, provider, "linkViaRedirect" /* AuthEventType.LINK_VIA_REDIRECT */, eventId)];
|
|
2043
|
-
}
|
|
2044
|
-
});
|
|
2045
|
-
});
|
|
1593
|
+
async function _linkWithRedirect(user, provider, resolver) {
|
|
1594
|
+
const userInternal = util.getModularInstance(user);
|
|
1595
|
+
index._assertInstanceOf(userInternal.auth, provider, index.FederatedAuthProvider);
|
|
1596
|
+
// Wait for auth initialization to complete, this will process pending redirects and clear the
|
|
1597
|
+
// PENDING_REDIRECT_KEY in persistence. This should be completed before starting a new
|
|
1598
|
+
// redirect and creating a PENDING_REDIRECT_KEY entry.
|
|
1599
|
+
await userInternal.auth._initializationPromise;
|
|
1600
|
+
// Allow the resolver to error before persisting the redirect user
|
|
1601
|
+
const resolverInternal = _withDefaultResolver(userInternal.auth, resolver);
|
|
1602
|
+
await index._assertLinkedStatus(false, userInternal, provider.providerId);
|
|
1603
|
+
await _setPendingRedirectStatus(resolverInternal, userInternal.auth);
|
|
1604
|
+
const eventId = await prepareUserForRedirect(userInternal);
|
|
1605
|
+
return resolverInternal._openRedirect(userInternal.auth, provider, "linkViaRedirect" /* AuthEventType.LINK_VIA_REDIRECT */, eventId);
|
|
2046
1606
|
}
|
|
2047
1607
|
/**
|
|
2048
1608
|
* Returns a {@link UserCredential} from the redirect-based sign-in flow.
|
|
@@ -2085,66 +1645,31 @@ function _linkWithRedirect(user, provider, resolver) {
|
|
|
2085
1645
|
*
|
|
2086
1646
|
* @public
|
|
2087
1647
|
*/
|
|
2088
|
-
function getRedirectResult(auth, resolver) {
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
switch (_a.label) {
|
|
2092
|
-
case 0: return [4 /*yield*/, index._castAuth(auth)._initializationPromise];
|
|
2093
|
-
case 1:
|
|
2094
|
-
_a.sent();
|
|
2095
|
-
return [2 /*return*/, _getRedirectResult(auth, resolver, false)];
|
|
2096
|
-
}
|
|
2097
|
-
});
|
|
2098
|
-
});
|
|
1648
|
+
async function getRedirectResult(auth, resolver) {
|
|
1649
|
+
await index._castAuth(auth)._initializationPromise;
|
|
1650
|
+
return _getRedirectResult(auth, resolver, false);
|
|
2099
1651
|
}
|
|
2100
|
-
function _getRedirectResult(auth, resolverExtern, bypassAuthState) {
|
|
2101
|
-
if (
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
case 1:
|
|
2115
|
-
result = _a.sent();
|
|
2116
|
-
if (!(result && !bypassAuthState)) return [3 /*break*/, 4];
|
|
2117
|
-
delete result.user._redirectEventId;
|
|
2118
|
-
return [4 /*yield*/, authInternal._persistUserIfCurrent(result.user)];
|
|
2119
|
-
case 2:
|
|
2120
|
-
_a.sent();
|
|
2121
|
-
return [4 /*yield*/, authInternal._setRedirectUser(null, resolverExtern)];
|
|
2122
|
-
case 3:
|
|
2123
|
-
_a.sent();
|
|
2124
|
-
_a.label = 4;
|
|
2125
|
-
case 4: return [2 /*return*/, result];
|
|
2126
|
-
}
|
|
2127
|
-
});
|
|
2128
|
-
});
|
|
1652
|
+
async function _getRedirectResult(auth, resolverExtern, bypassAuthState = false) {
|
|
1653
|
+
if (app._isFirebaseServerApp(auth.app)) {
|
|
1654
|
+
return Promise.reject(index._serverAppCurrentUserOperationNotSupportedError(auth));
|
|
1655
|
+
}
|
|
1656
|
+
const authInternal = index._castAuth(auth);
|
|
1657
|
+
const resolver = _withDefaultResolver(authInternal, resolverExtern);
|
|
1658
|
+
const action = new RedirectAction(authInternal, resolver, bypassAuthState);
|
|
1659
|
+
const result = await action.execute();
|
|
1660
|
+
if (result && !bypassAuthState) {
|
|
1661
|
+
delete result.user._redirectEventId;
|
|
1662
|
+
await authInternal._persistUserIfCurrent(result.user);
|
|
1663
|
+
await authInternal._setRedirectUser(null, resolverExtern);
|
|
1664
|
+
}
|
|
1665
|
+
return result;
|
|
2129
1666
|
}
|
|
2130
|
-
function prepareUserForRedirect(user) {
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
eventId = _generateEventId("".concat(user.uid, ":::"));
|
|
2137
|
-
user._redirectEventId = eventId;
|
|
2138
|
-
return [4 /*yield*/, user.auth._setRedirectUser(user)];
|
|
2139
|
-
case 1:
|
|
2140
|
-
_a.sent();
|
|
2141
|
-
return [4 /*yield*/, user.auth._persistUserIfCurrent(user)];
|
|
2142
|
-
case 2:
|
|
2143
|
-
_a.sent();
|
|
2144
|
-
return [2 /*return*/, eventId];
|
|
2145
|
-
}
|
|
2146
|
-
});
|
|
2147
|
-
});
|
|
1667
|
+
async function prepareUserForRedirect(user) {
|
|
1668
|
+
const eventId = _generateEventId(`${user.uid}:::`);
|
|
1669
|
+
user._redirectEventId = eventId;
|
|
1670
|
+
await user.auth._setRedirectUser(user);
|
|
1671
|
+
await user.auth._persistUserIfCurrent(user);
|
|
1672
|
+
return eventId;
|
|
2148
1673
|
}
|
|
2149
1674
|
|
|
2150
1675
|
/**
|
|
@@ -2165,9 +1690,9 @@ function prepareUserForRedirect(user) {
|
|
|
2165
1690
|
*/
|
|
2166
1691
|
// The amount of time to store the UIDs of seen events; this is
|
|
2167
1692
|
// set to 10 min by default
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
1693
|
+
const EVENT_DUPLICATION_CACHE_DURATION_MS = 10 * 60 * 1000;
|
|
1694
|
+
class AuthEventManager {
|
|
1695
|
+
constructor(auth) {
|
|
2171
1696
|
this.auth = auth;
|
|
2172
1697
|
this.cachedEventUids = new Set();
|
|
2173
1698
|
this.consumers = new Set();
|
|
@@ -2175,7 +1700,7 @@ var AuthEventManager = /** @class */ (function () {
|
|
|
2175
1700
|
this.hasHandledPotentialRedirect = false;
|
|
2176
1701
|
this.lastProcessedEventTime = Date.now();
|
|
2177
1702
|
}
|
|
2178
|
-
|
|
1703
|
+
registerConsumer(authEventConsumer) {
|
|
2179
1704
|
this.consumers.add(authEventConsumer);
|
|
2180
1705
|
if (this.queuedRedirectEvent &&
|
|
2181
1706
|
this.isEventForConsumer(this.queuedRedirectEvent, authEventConsumer)) {
|
|
@@ -2183,22 +1708,21 @@ var AuthEventManager = /** @class */ (function () {
|
|
|
2183
1708
|
this.saveEventToCache(this.queuedRedirectEvent);
|
|
2184
1709
|
this.queuedRedirectEvent = null;
|
|
2185
1710
|
}
|
|
2186
|
-
}
|
|
2187
|
-
|
|
1711
|
+
}
|
|
1712
|
+
unregisterConsumer(authEventConsumer) {
|
|
2188
1713
|
this.consumers.delete(authEventConsumer);
|
|
2189
|
-
}
|
|
2190
|
-
|
|
2191
|
-
var _this = this;
|
|
1714
|
+
}
|
|
1715
|
+
onEvent(event) {
|
|
2192
1716
|
// Check if the event has already been handled
|
|
2193
1717
|
if (this.hasEventBeenHandled(event)) {
|
|
2194
1718
|
return false;
|
|
2195
1719
|
}
|
|
2196
|
-
|
|
2197
|
-
this.consumers.forEach(
|
|
2198
|
-
if (
|
|
1720
|
+
let handled = false;
|
|
1721
|
+
this.consumers.forEach(consumer => {
|
|
1722
|
+
if (this.isEventForConsumer(event, consumer)) {
|
|
2199
1723
|
handled = true;
|
|
2200
|
-
|
|
2201
|
-
|
|
1724
|
+
this.sendToConsumer(event, consumer);
|
|
1725
|
+
this.saveEventToCache(event);
|
|
2202
1726
|
}
|
|
2203
1727
|
});
|
|
2204
1728
|
if (this.hasHandledPotentialRedirect || !isRedirectEvent(event)) {
|
|
@@ -2213,43 +1737,41 @@ var AuthEventManager = /** @class */ (function () {
|
|
|
2213
1737
|
handled = true;
|
|
2214
1738
|
}
|
|
2215
1739
|
return handled;
|
|
2216
|
-
}
|
|
2217
|
-
|
|
1740
|
+
}
|
|
1741
|
+
sendToConsumer(event, consumer) {
|
|
2218
1742
|
var _a;
|
|
2219
1743
|
if (event.error && !isNullRedirectEvent(event)) {
|
|
2220
|
-
|
|
1744
|
+
const code = ((_a = event.error.code) === null || _a === void 0 ? void 0 : _a.split('auth/')[1]) ||
|
|
2221
1745
|
"internal-error" /* AuthErrorCode.INTERNAL_ERROR */;
|
|
2222
1746
|
consumer.onError(index._createError(this.auth, code));
|
|
2223
1747
|
}
|
|
2224
1748
|
else {
|
|
2225
1749
|
consumer.onAuthEvent(event);
|
|
2226
1750
|
}
|
|
2227
|
-
}
|
|
2228
|
-
|
|
2229
|
-
|
|
1751
|
+
}
|
|
1752
|
+
isEventForConsumer(event, consumer) {
|
|
1753
|
+
const eventIdMatches = consumer.eventId === null ||
|
|
2230
1754
|
(!!event.eventId && event.eventId === consumer.eventId);
|
|
2231
1755
|
return consumer.filter.includes(event.type) && eventIdMatches;
|
|
2232
|
-
}
|
|
2233
|
-
|
|
1756
|
+
}
|
|
1757
|
+
hasEventBeenHandled(event) {
|
|
2234
1758
|
if (Date.now() - this.lastProcessedEventTime >=
|
|
2235
1759
|
EVENT_DUPLICATION_CACHE_DURATION_MS) {
|
|
2236
1760
|
this.cachedEventUids.clear();
|
|
2237
1761
|
}
|
|
2238
1762
|
return this.cachedEventUids.has(eventUid(event));
|
|
2239
|
-
}
|
|
2240
|
-
|
|
1763
|
+
}
|
|
1764
|
+
saveEventToCache(event) {
|
|
2241
1765
|
this.cachedEventUids.add(eventUid(event));
|
|
2242
1766
|
this.lastProcessedEventTime = Date.now();
|
|
2243
|
-
}
|
|
2244
|
-
|
|
2245
|
-
}());
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
2246
1769
|
function eventUid(e) {
|
|
2247
|
-
return [e.type, e.eventId, e.sessionId, e.tenantId].filter(
|
|
1770
|
+
return [e.type, e.eventId, e.sessionId, e.tenantId].filter(v => v).join('-');
|
|
2248
1771
|
}
|
|
2249
|
-
function isNullRedirectEvent(
|
|
2250
|
-
var type = _a.type, error = _a.error;
|
|
1772
|
+
function isNullRedirectEvent({ type, error }) {
|
|
2251
1773
|
return (type === "unknown" /* AuthEventType.UNKNOWN */ &&
|
|
2252
|
-
(error === null || error === void 0 ? void 0 : error.code) ===
|
|
1774
|
+
(error === null || error === void 0 ? void 0 : error.code) === `auth/${"no-auth-event" /* AuthErrorCode.NO_AUTH_EVENT */}`);
|
|
2253
1775
|
}
|
|
2254
1776
|
function isRedirectEvent(event) {
|
|
2255
1777
|
switch (event.type) {
|
|
@@ -2280,13 +1802,8 @@ function isRedirectEvent(event) {
|
|
|
2280
1802
|
* See the License for the specific language governing permissions and
|
|
2281
1803
|
* limitations under the License.
|
|
2282
1804
|
*/
|
|
2283
|
-
function _getProjectConfig(auth, request) {
|
|
2284
|
-
|
|
2285
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
2286
|
-
return tslib.__generator(this, function (_a) {
|
|
2287
|
-
return [2 /*return*/, index._performApiRequest(auth, "GET" /* HttpMethod.GET */, "/v1/projects" /* Endpoint.GET_PROJECT_CONFIG */, request)];
|
|
2288
|
-
});
|
|
2289
|
-
});
|
|
1805
|
+
async function _getProjectConfig(auth, request = {}) {
|
|
1806
|
+
return index._performApiRequest(auth, "GET" /* HttpMethod.GET */, "/v1/projects" /* Endpoint.GET_PROJECT_CONFIG */, request);
|
|
2290
1807
|
}
|
|
2291
1808
|
|
|
2292
1809
|
/**
|
|
@@ -2305,44 +1822,32 @@ function _getProjectConfig(auth, request) {
|
|
|
2305
1822
|
* See the License for the specific language governing permissions and
|
|
2306
1823
|
* limitations under the License.
|
|
2307
1824
|
*/
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
function _validateOrigin$1(auth) {
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
return
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
return [4 /*yield*/, _getProjectConfig(auth)];
|
|
2321
|
-
case 1:
|
|
2322
|
-
authorizedDomains = (_a.sent()).authorizedDomains;
|
|
2323
|
-
for (_i = 0, authorizedDomains_1 = authorizedDomains; _i < authorizedDomains_1.length; _i++) {
|
|
2324
|
-
domain = authorizedDomains_1[_i];
|
|
2325
|
-
try {
|
|
2326
|
-
if (matchDomain(domain)) {
|
|
2327
|
-
return [2 /*return*/];
|
|
2328
|
-
}
|
|
2329
|
-
}
|
|
2330
|
-
catch (_b) {
|
|
2331
|
-
// Do nothing if there's a URL error; just continue searching
|
|
2332
|
-
}
|
|
2333
|
-
}
|
|
2334
|
-
// In the old SDK, this error also provides helpful messages.
|
|
2335
|
-
index._fail(auth, "unauthorized-domain" /* AuthErrorCode.INVALID_ORIGIN */);
|
|
2336
|
-
return [2 /*return*/];
|
|
1825
|
+
const IP_ADDRESS_REGEX = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
|
|
1826
|
+
const HTTP_REGEX = /^https?/;
|
|
1827
|
+
async function _validateOrigin$1(auth) {
|
|
1828
|
+
// Skip origin validation if we are in an emulated environment
|
|
1829
|
+
if (auth.config.emulator) {
|
|
1830
|
+
return;
|
|
1831
|
+
}
|
|
1832
|
+
const { authorizedDomains } = await _getProjectConfig(auth);
|
|
1833
|
+
for (const domain of authorizedDomains) {
|
|
1834
|
+
try {
|
|
1835
|
+
if (matchDomain(domain)) {
|
|
1836
|
+
return;
|
|
2337
1837
|
}
|
|
2338
|
-
}
|
|
2339
|
-
|
|
1838
|
+
}
|
|
1839
|
+
catch (_a) {
|
|
1840
|
+
// Do nothing if there's a URL error; just continue searching
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
// In the old SDK, this error also provides helpful messages.
|
|
1844
|
+
index._fail(auth, "unauthorized-domain" /* AuthErrorCode.INVALID_ORIGIN */);
|
|
2340
1845
|
}
|
|
2341
1846
|
function matchDomain(expected) {
|
|
2342
|
-
|
|
2343
|
-
|
|
1847
|
+
const currentUrl = index._getCurrentUrl();
|
|
1848
|
+
const { protocol, hostname } = new URL(currentUrl);
|
|
2344
1849
|
if (expected.startsWith('chrome-extension://')) {
|
|
2345
|
-
|
|
1850
|
+
const ceUrl = new URL(expected);
|
|
2346
1851
|
if (ceUrl.hostname === '' && hostname === '') {
|
|
2347
1852
|
// For some reason we're not parsing chrome URLs properly
|
|
2348
1853
|
return (protocol === 'chrome-extension:' &&
|
|
@@ -2360,10 +1865,10 @@ function matchDomain(expected) {
|
|
|
2360
1865
|
return hostname === expected;
|
|
2361
1866
|
}
|
|
2362
1867
|
// Dots in pattern should be escaped.
|
|
2363
|
-
|
|
1868
|
+
const escapedDomainPattern = expected.replace(/\./g, '\\.');
|
|
2364
1869
|
// Non ip address domains.
|
|
2365
1870
|
// domain.com = *.domain.com OR domain.com
|
|
2366
|
-
|
|
1871
|
+
const re = new RegExp('^(.+\\.' + escapedDomainPattern + '|' + escapedDomainPattern + ')$', 'i');
|
|
2367
1872
|
return re.test(hostname);
|
|
2368
1873
|
}
|
|
2369
1874
|
|
|
@@ -2383,7 +1888,7 @@ function matchDomain(expected) {
|
|
|
2383
1888
|
* See the License for the specific language governing permissions and
|
|
2384
1889
|
* limitations under the License.
|
|
2385
1890
|
*/
|
|
2386
|
-
|
|
1891
|
+
const NETWORK_TIMEOUT = new index.Delay(30000, 60000);
|
|
2387
1892
|
/**
|
|
2388
1893
|
* Reset unloaded GApi modules. If gapi.load fails due to a network error,
|
|
2389
1894
|
* it will stop working after a retrial. This is a hack to fix this issue.
|
|
@@ -2392,21 +1897,20 @@ function resetUnloadedGapiModules() {
|
|
|
2392
1897
|
// Clear last failed gapi.load state to force next gapi.load to first
|
|
2393
1898
|
// load the failed gapi.iframes module.
|
|
2394
1899
|
// Get gapix.beacon context.
|
|
2395
|
-
|
|
1900
|
+
const beacon = index._window().___jsl;
|
|
2396
1901
|
// Get current hint.
|
|
2397
1902
|
if (beacon === null || beacon === void 0 ? void 0 : beacon.H) {
|
|
2398
1903
|
// Get gapi hint.
|
|
2399
|
-
for (
|
|
2400
|
-
var hint = _a[_i];
|
|
1904
|
+
for (const hint of Object.keys(beacon.H)) {
|
|
2401
1905
|
// Requested modules.
|
|
2402
1906
|
beacon.H[hint].r = beacon.H[hint].r || [];
|
|
2403
1907
|
// Loaded modules.
|
|
2404
1908
|
beacon.H[hint].L = beacon.H[hint].L || [];
|
|
2405
1909
|
// Set requested modules to a copy of the loaded modules.
|
|
2406
|
-
beacon.H[hint].r =
|
|
1910
|
+
beacon.H[hint].r = [...beacon.H[hint].L];
|
|
2407
1911
|
// Clear pending callbacks.
|
|
2408
1912
|
if (beacon.CP) {
|
|
2409
|
-
for (
|
|
1913
|
+
for (let i = 0; i < beacon.CP.length; i++) {
|
|
2410
1914
|
// Remove all failed pending callbacks.
|
|
2411
1915
|
beacon.CP[i] = null;
|
|
2412
1916
|
}
|
|
@@ -2415,7 +1919,7 @@ function resetUnloadedGapiModules() {
|
|
|
2415
1919
|
}
|
|
2416
1920
|
}
|
|
2417
1921
|
function loadGapi(auth) {
|
|
2418
|
-
return new Promise(
|
|
1922
|
+
return new Promise((resolve, reject) => {
|
|
2419
1923
|
var _a, _b, _c;
|
|
2420
1924
|
// Function to run when gapi.load is ready.
|
|
2421
1925
|
function loadGapiIframe() {
|
|
@@ -2423,10 +1927,10 @@ function loadGapi(auth) {
|
|
|
2423
1927
|
// Run this to fix that.
|
|
2424
1928
|
resetUnloadedGapiModules();
|
|
2425
1929
|
gapi.load('gapi.iframes', {
|
|
2426
|
-
callback:
|
|
1930
|
+
callback: () => {
|
|
2427
1931
|
resolve(gapi.iframes.getContext());
|
|
2428
1932
|
},
|
|
2429
|
-
ontimeout:
|
|
1933
|
+
ontimeout: () => {
|
|
2430
1934
|
// The above reset may be sufficient, but having this reset after
|
|
2431
1935
|
// failure ensures that if the developer calls gapi.load after the
|
|
2432
1936
|
// connection is re-established and before another attempt to embed
|
|
@@ -2453,9 +1957,9 @@ function loadGapi(auth) {
|
|
|
2453
1957
|
// multiple times in parallel and could result in the later callback
|
|
2454
1958
|
// overwriting the previous one. This would end up with a iframe
|
|
2455
1959
|
// timeout.
|
|
2456
|
-
|
|
1960
|
+
const cbName = index._generateCallbackName('iframefcb');
|
|
2457
1961
|
// GApi loader not available, dynamically load platform.js.
|
|
2458
|
-
index._window()[cbName] =
|
|
1962
|
+
index._window()[cbName] = () => {
|
|
2459
1963
|
// GApi loader should be ready.
|
|
2460
1964
|
if (!!gapi.load) {
|
|
2461
1965
|
loadGapiIframe();
|
|
@@ -2466,16 +1970,16 @@ function loadGapi(auth) {
|
|
|
2466
1970
|
}
|
|
2467
1971
|
};
|
|
2468
1972
|
// Load GApi loader.
|
|
2469
|
-
return index._loadJS(
|
|
2470
|
-
.catch(
|
|
1973
|
+
return index._loadJS(`${index._gapiScriptUrl()}?onload=${cbName}`)
|
|
1974
|
+
.catch(e => reject(e));
|
|
2471
1975
|
}
|
|
2472
|
-
}).catch(
|
|
1976
|
+
}).catch(error => {
|
|
2473
1977
|
// Reset cached promise to allow for retrial.
|
|
2474
1978
|
cachedGApiLoader = null;
|
|
2475
1979
|
throw error;
|
|
2476
1980
|
});
|
|
2477
1981
|
}
|
|
2478
|
-
|
|
1982
|
+
let cachedGApiLoader = null;
|
|
2479
1983
|
function _loadGapi(auth) {
|
|
2480
1984
|
cachedGApiLoader = cachedGApiLoader || loadGapi(auth);
|
|
2481
1985
|
return cachedGApiLoader;
|
|
@@ -2497,10 +2001,10 @@ function _loadGapi(auth) {
|
|
|
2497
2001
|
* See the License for the specific language governing permissions and
|
|
2498
2002
|
* limitations under the License.
|
|
2499
2003
|
*/
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2004
|
+
const PING_TIMEOUT = new index.Delay(5000, 15000);
|
|
2005
|
+
const IFRAME_PATH = '__/auth/iframe';
|
|
2006
|
+
const EMULATED_IFRAME_PATH = 'emulator/auth/iframe';
|
|
2007
|
+
const IFRAME_ATTRIBUTES = {
|
|
2504
2008
|
style: {
|
|
2505
2009
|
position: 'absolute',
|
|
2506
2010
|
top: '-100px',
|
|
@@ -2512,82 +2016,64 @@ var IFRAME_ATTRIBUTES = {
|
|
|
2512
2016
|
};
|
|
2513
2017
|
// Map from apiHost to endpoint ID for passing into iframe. In current SDK, apiHost can be set to
|
|
2514
2018
|
// anything (not from a list of endpoints with IDs as in legacy), so this is the closest we can get.
|
|
2515
|
-
|
|
2019
|
+
const EID_FROM_APIHOST = new Map([
|
|
2516
2020
|
["identitytoolkit.googleapis.com" /* DefaultConfig.API_HOST */, 'p'],
|
|
2517
2021
|
['staging-identitytoolkit.sandbox.googleapis.com', 's'],
|
|
2518
2022
|
['test-identitytoolkit.sandbox.googleapis.com', 't'] // test
|
|
2519
2023
|
]);
|
|
2520
2024
|
function getIframeUrl(auth) {
|
|
2521
|
-
|
|
2025
|
+
const config = auth.config;
|
|
2522
2026
|
index._assert(config.authDomain, auth, "auth-domain-config-required" /* AuthErrorCode.MISSING_AUTH_DOMAIN */);
|
|
2523
|
-
|
|
2027
|
+
const url = config.emulator
|
|
2524
2028
|
? index._emulatorUrl(config, EMULATED_IFRAME_PATH)
|
|
2525
|
-
:
|
|
2526
|
-
|
|
2029
|
+
: `https://${auth.config.authDomain}/${IFRAME_PATH}`;
|
|
2030
|
+
const params = {
|
|
2527
2031
|
apiKey: config.apiKey,
|
|
2528
2032
|
appName: auth.name,
|
|
2529
2033
|
v: app.SDK_VERSION
|
|
2530
2034
|
};
|
|
2531
|
-
|
|
2035
|
+
const eid = EID_FROM_APIHOST.get(auth.config.apiHost);
|
|
2532
2036
|
if (eid) {
|
|
2533
2037
|
params.eid = eid;
|
|
2534
2038
|
}
|
|
2535
|
-
|
|
2039
|
+
const frameworks = auth._getFrameworks();
|
|
2536
2040
|
if (frameworks.length) {
|
|
2537
2041
|
params.fw = frameworks.join(',');
|
|
2538
2042
|
}
|
|
2539
|
-
return
|
|
2043
|
+
return `${url}?${util.querystring(params).slice(1)}`;
|
|
2540
2044
|
}
|
|
2541
|
-
function _openIframe(auth) {
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
messageHandlersFilter: gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER,
|
|
2556
|
-
attributes: IFRAME_ATTRIBUTES,
|
|
2557
|
-
dontclear: true
|
|
2558
|
-
}, function (iframe) {
|
|
2559
|
-
return new Promise(function (resolve, reject) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
2560
|
-
// Clear timer and resolve pending iframe ready promise.
|
|
2561
|
-
function clearTimerAndResolve() {
|
|
2562
|
-
index._window().clearTimeout(networkErrorTimer);
|
|
2563
|
-
resolve(iframe);
|
|
2564
|
-
}
|
|
2565
|
-
var networkError, networkErrorTimer;
|
|
2566
|
-
return tslib.__generator(this, function (_a) {
|
|
2567
|
-
switch (_a.label) {
|
|
2568
|
-
case 0: return [4 /*yield*/, iframe.restyle({
|
|
2569
|
-
// Prevent iframe from closing on mouse out.
|
|
2570
|
-
setHideOnLeave: false
|
|
2571
|
-
})];
|
|
2572
|
-
case 1:
|
|
2573
|
-
_a.sent();
|
|
2574
|
-
networkError = index._createError(auth, "network-request-failed" /* AuthErrorCode.NETWORK_REQUEST_FAILED */);
|
|
2575
|
-
networkErrorTimer = index._window().setTimeout(function () {
|
|
2576
|
-
reject(networkError);
|
|
2577
|
-
}, PING_TIMEOUT.get());
|
|
2578
|
-
// This returns an IThenable. However the reject part does not call
|
|
2579
|
-
// when the iframe is not loaded.
|
|
2580
|
-
iframe.ping(clearTimerAndResolve).then(clearTimerAndResolve, function () {
|
|
2581
|
-
reject(networkError);
|
|
2582
|
-
});
|
|
2583
|
-
return [2 /*return*/];
|
|
2584
|
-
}
|
|
2585
|
-
});
|
|
2586
|
-
}); });
|
|
2587
|
-
})];
|
|
2588
|
-
}
|
|
2045
|
+
async function _openIframe(auth) {
|
|
2046
|
+
const context = await _loadGapi(auth);
|
|
2047
|
+
const gapi = index._window().gapi;
|
|
2048
|
+
index._assert(gapi, auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
|
|
2049
|
+
return context.open({
|
|
2050
|
+
where: document.body,
|
|
2051
|
+
url: getIframeUrl(auth),
|
|
2052
|
+
messageHandlersFilter: gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER,
|
|
2053
|
+
attributes: IFRAME_ATTRIBUTES,
|
|
2054
|
+
dontclear: true
|
|
2055
|
+
}, (iframe) => new Promise(async (resolve, reject) => {
|
|
2056
|
+
await iframe.restyle({
|
|
2057
|
+
// Prevent iframe from closing on mouse out.
|
|
2058
|
+
setHideOnLeave: false
|
|
2589
2059
|
});
|
|
2590
|
-
|
|
2060
|
+
const networkError = index._createError(auth, "network-request-failed" /* AuthErrorCode.NETWORK_REQUEST_FAILED */);
|
|
2061
|
+
// Confirm iframe is correctly loaded.
|
|
2062
|
+
// To fallback on failure, set a timeout.
|
|
2063
|
+
const networkErrorTimer = index._window().setTimeout(() => {
|
|
2064
|
+
reject(networkError);
|
|
2065
|
+
}, PING_TIMEOUT.get());
|
|
2066
|
+
// Clear timer and resolve pending iframe ready promise.
|
|
2067
|
+
function clearTimerAndResolve() {
|
|
2068
|
+
index._window().clearTimeout(networkErrorTimer);
|
|
2069
|
+
resolve(iframe);
|
|
2070
|
+
}
|
|
2071
|
+
// This returns an IThenable. However the reject part does not call
|
|
2072
|
+
// when the iframe is not loaded.
|
|
2073
|
+
iframe.ping(clearTimerAndResolve).then(clearTimerAndResolve, () => {
|
|
2074
|
+
reject(networkError);
|
|
2075
|
+
});
|
|
2076
|
+
}));
|
|
2591
2077
|
}
|
|
2592
2078
|
|
|
2593
2079
|
/**
|
|
@@ -2606,41 +2092,39 @@ function _openIframe(auth) {
|
|
|
2606
2092
|
* See the License for the specific language governing permissions and
|
|
2607
2093
|
* limitations under the License.
|
|
2608
2094
|
*/
|
|
2609
|
-
|
|
2095
|
+
const BASE_POPUP_OPTIONS = {
|
|
2610
2096
|
location: 'yes',
|
|
2611
2097
|
resizable: 'yes',
|
|
2612
2098
|
statusbar: 'yes',
|
|
2613
2099
|
toolbar: 'no'
|
|
2614
2100
|
};
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2101
|
+
const DEFAULT_WIDTH = 500;
|
|
2102
|
+
const DEFAULT_HEIGHT = 600;
|
|
2103
|
+
const TARGET_BLANK = '_blank';
|
|
2104
|
+
const FIREFOX_EMPTY_URL = 'http://localhost';
|
|
2105
|
+
class AuthPopup {
|
|
2106
|
+
constructor(window) {
|
|
2621
2107
|
this.window = window;
|
|
2622
2108
|
this.associatedEvent = null;
|
|
2623
2109
|
}
|
|
2624
|
-
|
|
2110
|
+
close() {
|
|
2625
2111
|
if (this.window) {
|
|
2626
2112
|
try {
|
|
2627
2113
|
this.window.close();
|
|
2628
2114
|
}
|
|
2629
2115
|
catch (e) { }
|
|
2630
2116
|
}
|
|
2631
|
-
}
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
var target = '';
|
|
2640
|
-
var options = tslib.__assign(tslib.__assign({}, BASE_POPUP_OPTIONS), { width: width.toString(), height: height.toString(), top: top, left: left });
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
function _open(auth, url, name, width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT) {
|
|
2120
|
+
const top = Math.max((window.screen.availHeight - height) / 2, 0).toString();
|
|
2121
|
+
const left = Math.max((window.screen.availWidth - width) / 2, 0).toString();
|
|
2122
|
+
let target = '';
|
|
2123
|
+
const options = Object.assign(Object.assign({}, BASE_POPUP_OPTIONS), { width: width.toString(), height: height.toString(), top,
|
|
2124
|
+
left });
|
|
2641
2125
|
// Chrome iOS 7 and 8 is returning an undefined popup win when target is
|
|
2642
2126
|
// specified, even though the popup is not necessarily blocked.
|
|
2643
|
-
|
|
2127
|
+
const ua = util.getUA().toLowerCase();
|
|
2644
2128
|
if (name) {
|
|
2645
2129
|
target = index._isChromeIOS(ua) ? TARGET_BLANK : name;
|
|
2646
2130
|
}
|
|
@@ -2651,17 +2135,14 @@ function _open(auth, url, name, width, height) {
|
|
|
2651
2135
|
// issues when the user has many Google accounts, for instance.
|
|
2652
2136
|
options.scrollbars = 'yes';
|
|
2653
2137
|
}
|
|
2654
|
-
|
|
2655
|
-
var key = _a[0], value = _a[1];
|
|
2656
|
-
return "".concat(accum).concat(key, "=").concat(value, ",");
|
|
2657
|
-
}, '');
|
|
2138
|
+
const optionsString = Object.entries(options).reduce((accum, [key, value]) => `${accum}${key}=${value},`, '');
|
|
2658
2139
|
if (index._isIOSStandalone(ua) && target !== '_self') {
|
|
2659
2140
|
openAsNewWindowIOS(url || '', target);
|
|
2660
2141
|
return new AuthPopup(null);
|
|
2661
2142
|
}
|
|
2662
2143
|
// about:blank getting sanitized causing browsers like IE/Edge to display
|
|
2663
2144
|
// brief error message before redirecting to handler.
|
|
2664
|
-
|
|
2145
|
+
const newWin = window.open(url || '', target, optionsString);
|
|
2665
2146
|
index._assert(newWin, auth, "popup-blocked" /* AuthErrorCode.POPUP_BLOCKED */);
|
|
2666
2147
|
// Flaky on IE edge, encapsulate with a try and catch.
|
|
2667
2148
|
try {
|
|
@@ -2671,10 +2152,10 @@ function _open(auth, url, name, width, height) {
|
|
|
2671
2152
|
return new AuthPopup(newWin);
|
|
2672
2153
|
}
|
|
2673
2154
|
function openAsNewWindowIOS(url, target) {
|
|
2674
|
-
|
|
2155
|
+
const el = document.createElement('a');
|
|
2675
2156
|
el.href = url;
|
|
2676
2157
|
el.target = target;
|
|
2677
|
-
|
|
2158
|
+
const click = document.createEvent('MouseEvent');
|
|
2678
2159
|
click.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 1, null);
|
|
2679
2160
|
el.dispatchEvent(click);
|
|
2680
2161
|
}
|
|
@@ -2700,79 +2181,69 @@ function openAsNewWindowIOS(url, target) {
|
|
|
2700
2181
|
*
|
|
2701
2182
|
* @internal
|
|
2702
2183
|
*/
|
|
2703
|
-
|
|
2184
|
+
const WIDGET_PATH = '__/auth/handler';
|
|
2704
2185
|
/**
|
|
2705
2186
|
* URL for emulated environment
|
|
2706
2187
|
*
|
|
2707
2188
|
* @internal
|
|
2708
2189
|
*/
|
|
2709
|
-
|
|
2190
|
+
const EMULATOR_WIDGET_PATH = 'emulator/auth/handler';
|
|
2710
2191
|
/**
|
|
2711
2192
|
* Fragment name for the App Check token that gets passed to the widget
|
|
2712
2193
|
*
|
|
2713
2194
|
* @internal
|
|
2714
2195
|
*/
|
|
2715
|
-
|
|
2716
|
-
function _getRedirectUrl(auth, provider, authType, redirectUrl, eventId, additionalParams) {
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
appCheckToken = _e.sent();
|
|
2763
|
-
appCheckTokenFragment = appCheckToken
|
|
2764
|
-
? "#".concat(FIREBASE_APP_CHECK_FRAGMENT_ID, "=").concat(encodeURIComponent(appCheckToken))
|
|
2765
|
-
: '';
|
|
2766
|
-
// Start at index 1 to skip the leading '&' in the query string
|
|
2767
|
-
return [2 /*return*/, "".concat(getHandlerBase(auth), "?").concat(util.querystring(paramsDict).slice(1)).concat(appCheckTokenFragment)];
|
|
2768
|
-
}
|
|
2769
|
-
});
|
|
2770
|
-
});
|
|
2196
|
+
const FIREBASE_APP_CHECK_FRAGMENT_ID = encodeURIComponent('fac');
|
|
2197
|
+
async function _getRedirectUrl(auth, provider, authType, redirectUrl, eventId, additionalParams) {
|
|
2198
|
+
index._assert(auth.config.authDomain, auth, "auth-domain-config-required" /* AuthErrorCode.MISSING_AUTH_DOMAIN */);
|
|
2199
|
+
index._assert(auth.config.apiKey, auth, "invalid-api-key" /* AuthErrorCode.INVALID_API_KEY */);
|
|
2200
|
+
const params = {
|
|
2201
|
+
apiKey: auth.config.apiKey,
|
|
2202
|
+
appName: auth.name,
|
|
2203
|
+
authType,
|
|
2204
|
+
redirectUrl,
|
|
2205
|
+
v: app.SDK_VERSION,
|
|
2206
|
+
eventId
|
|
2207
|
+
};
|
|
2208
|
+
if (provider instanceof index.FederatedAuthProvider) {
|
|
2209
|
+
provider.setDefaultLanguage(auth.languageCode);
|
|
2210
|
+
params.providerId = provider.providerId || '';
|
|
2211
|
+
if (!util.isEmpty(provider.getCustomParameters())) {
|
|
2212
|
+
params.customParameters = JSON.stringify(provider.getCustomParameters());
|
|
2213
|
+
}
|
|
2214
|
+
// TODO set additionalParams from the provider as well?
|
|
2215
|
+
for (const [key, value] of Object.entries(additionalParams || {})) {
|
|
2216
|
+
params[key] = value;
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
if (provider instanceof index.BaseOAuthProvider) {
|
|
2220
|
+
const scopes = provider.getScopes().filter(scope => scope !== '');
|
|
2221
|
+
if (scopes.length > 0) {
|
|
2222
|
+
params.scopes = scopes.join(',');
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
if (auth.tenantId) {
|
|
2226
|
+
params.tid = auth.tenantId;
|
|
2227
|
+
}
|
|
2228
|
+
// TODO: maybe set eid as endpointId
|
|
2229
|
+
// TODO: maybe set fw as Frameworks.join(",")
|
|
2230
|
+
const paramsDict = params;
|
|
2231
|
+
for (const key of Object.keys(paramsDict)) {
|
|
2232
|
+
if (paramsDict[key] === undefined) {
|
|
2233
|
+
delete paramsDict[key];
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2236
|
+
// Sets the App Check token to pass to the widget
|
|
2237
|
+
const appCheckToken = await auth._getAppCheckToken();
|
|
2238
|
+
const appCheckTokenFragment = appCheckToken
|
|
2239
|
+
? `#${FIREBASE_APP_CHECK_FRAGMENT_ID}=${encodeURIComponent(appCheckToken)}`
|
|
2240
|
+
: '';
|
|
2241
|
+
// Start at index 1 to skip the leading '&' in the query string
|
|
2242
|
+
return `${getHandlerBase(auth)}?${util.querystring(paramsDict).slice(1)}${appCheckTokenFragment}`;
|
|
2771
2243
|
}
|
|
2772
|
-
function getHandlerBase(
|
|
2773
|
-
var config = _a.config;
|
|
2244
|
+
function getHandlerBase({ config }) {
|
|
2774
2245
|
if (!config.emulator) {
|
|
2775
|
-
return
|
|
2246
|
+
return `https://${config.authDomain}/${WIDGET_PATH}`;
|
|
2776
2247
|
}
|
|
2777
2248
|
return index._emulatorUrl(config, EMULATOR_WIDGET_PATH);
|
|
2778
2249
|
}
|
|
@@ -2797,9 +2268,9 @@ function getHandlerBase(_a) {
|
|
|
2797
2268
|
* The special web storage event
|
|
2798
2269
|
*
|
|
2799
2270
|
*/
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2271
|
+
const WEB_STORAGE_SUPPORT_KEY = 'webStorageSupport';
|
|
2272
|
+
class BrowserPopupRedirectResolver {
|
|
2273
|
+
constructor() {
|
|
2803
2274
|
this.eventManagers = {};
|
|
2804
2275
|
this.iframes = {};
|
|
2805
2276
|
this.originValidationPromises = {};
|
|
@@ -2809,111 +2280,75 @@ var BrowserPopupRedirectResolver = /** @class */ (function () {
|
|
|
2809
2280
|
}
|
|
2810
2281
|
// Wrapping in async even though we don't await anywhere in order
|
|
2811
2282
|
// to make sure errors are raised as promise rejections
|
|
2812
|
-
|
|
2283
|
+
async _openPopup(auth, provider, authType, eventId) {
|
|
2813
2284
|
var _a;
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
});
|
|
2827
|
-
};
|
|
2828
|
-
BrowserPopupRedirectResolver.prototype._openRedirect = function (auth, provider, authType, eventId) {
|
|
2829
|
-
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
2830
|
-
var url;
|
|
2831
|
-
return tslib.__generator(this, function (_a) {
|
|
2832
|
-
switch (_a.label) {
|
|
2833
|
-
case 0: return [4 /*yield*/, this._originValidation(auth)];
|
|
2834
|
-
case 1:
|
|
2835
|
-
_a.sent();
|
|
2836
|
-
return [4 /*yield*/, _getRedirectUrl(auth, provider, authType, index._getCurrentUrl(), eventId)];
|
|
2837
|
-
case 2:
|
|
2838
|
-
url = _a.sent();
|
|
2839
|
-
index._setWindowLocation(url);
|
|
2840
|
-
return [2 /*return*/, new Promise(function () { })];
|
|
2841
|
-
}
|
|
2842
|
-
});
|
|
2843
|
-
});
|
|
2844
|
-
};
|
|
2845
|
-
BrowserPopupRedirectResolver.prototype._initialize = function (auth) {
|
|
2846
|
-
var _this = this;
|
|
2847
|
-
var key = auth._key();
|
|
2285
|
+
index.debugAssert((_a = this.eventManagers[auth._key()]) === null || _a === void 0 ? void 0 : _a.manager, '_initialize() not called before _openPopup()');
|
|
2286
|
+
const url = await _getRedirectUrl(auth, provider, authType, index._getCurrentUrl(), eventId);
|
|
2287
|
+
return _open(auth, url, _generateEventId());
|
|
2288
|
+
}
|
|
2289
|
+
async _openRedirect(auth, provider, authType, eventId) {
|
|
2290
|
+
await this._originValidation(auth);
|
|
2291
|
+
const url = await _getRedirectUrl(auth, provider, authType, index._getCurrentUrl(), eventId);
|
|
2292
|
+
index._setWindowLocation(url);
|
|
2293
|
+
return new Promise(() => { });
|
|
2294
|
+
}
|
|
2295
|
+
_initialize(auth) {
|
|
2296
|
+
const key = auth._key();
|
|
2848
2297
|
if (this.eventManagers[key]) {
|
|
2849
|
-
|
|
2298
|
+
const { manager, promise } = this.eventManagers[key];
|
|
2850
2299
|
if (manager) {
|
|
2851
2300
|
return Promise.resolve(manager);
|
|
2852
2301
|
}
|
|
2853
2302
|
else {
|
|
2854
|
-
index.debugAssert(
|
|
2855
|
-
return
|
|
2303
|
+
index.debugAssert(promise, 'If manager is not set, promise should be');
|
|
2304
|
+
return promise;
|
|
2856
2305
|
}
|
|
2857
2306
|
}
|
|
2858
|
-
|
|
2859
|
-
this.eventManagers[key] = { promise
|
|
2307
|
+
const promise = this.initAndGetManager(auth);
|
|
2308
|
+
this.eventManagers[key] = { promise };
|
|
2860
2309
|
// If the promise is rejected, the key should be removed so that the
|
|
2861
2310
|
// operation can be retried later.
|
|
2862
|
-
promise.catch(
|
|
2863
|
-
delete
|
|
2311
|
+
promise.catch(() => {
|
|
2312
|
+
delete this.eventManagers[key];
|
|
2864
2313
|
});
|
|
2865
2314
|
return promise;
|
|
2866
|
-
}
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
this.iframes[auth._key()] = iframe;
|
|
2884
|
-
return [2 /*return*/, manager];
|
|
2885
|
-
}
|
|
2886
|
-
});
|
|
2887
|
-
});
|
|
2888
|
-
};
|
|
2889
|
-
BrowserPopupRedirectResolver.prototype._isIframeWebStorageSupported = function (auth, cb) {
|
|
2890
|
-
var iframe = this.iframes[auth._key()];
|
|
2891
|
-
iframe.send(WEB_STORAGE_SUPPORT_KEY, { type: WEB_STORAGE_SUPPORT_KEY }, function (result) {
|
|
2315
|
+
}
|
|
2316
|
+
async initAndGetManager(auth) {
|
|
2317
|
+
const iframe = await _openIframe(auth);
|
|
2318
|
+
const manager = new AuthEventManager(auth);
|
|
2319
|
+
iframe.register('authEvent', (iframeEvent) => {
|
|
2320
|
+
index._assert(iframeEvent === null || iframeEvent === void 0 ? void 0 : iframeEvent.authEvent, auth, "invalid-auth-event" /* AuthErrorCode.INVALID_AUTH_EVENT */);
|
|
2321
|
+
// TODO: Consider splitting redirect and popup events earlier on
|
|
2322
|
+
const handled = manager.onEvent(iframeEvent.authEvent);
|
|
2323
|
+
return { status: handled ? "ACK" /* GapiOutcome.ACK */ : "ERROR" /* GapiOutcome.ERROR */ };
|
|
2324
|
+
}, gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER);
|
|
2325
|
+
this.eventManagers[auth._key()] = { manager };
|
|
2326
|
+
this.iframes[auth._key()] = iframe;
|
|
2327
|
+
return manager;
|
|
2328
|
+
}
|
|
2329
|
+
_isIframeWebStorageSupported(auth, cb) {
|
|
2330
|
+
const iframe = this.iframes[auth._key()];
|
|
2331
|
+
iframe.send(WEB_STORAGE_SUPPORT_KEY, { type: WEB_STORAGE_SUPPORT_KEY }, result => {
|
|
2892
2332
|
var _a;
|
|
2893
|
-
|
|
2333
|
+
const isSupported = (_a = result === null || result === void 0 ? void 0 : result[0]) === null || _a === void 0 ? void 0 : _a[WEB_STORAGE_SUPPORT_KEY];
|
|
2894
2334
|
if (isSupported !== undefined) {
|
|
2895
2335
|
cb(!!isSupported);
|
|
2896
2336
|
}
|
|
2897
2337
|
index._fail(auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
|
|
2898
2338
|
}, gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER);
|
|
2899
|
-
}
|
|
2900
|
-
|
|
2901
|
-
|
|
2339
|
+
}
|
|
2340
|
+
_originValidation(auth) {
|
|
2341
|
+
const key = auth._key();
|
|
2902
2342
|
if (!this.originValidationPromises[key]) {
|
|
2903
2343
|
this.originValidationPromises[key] = _validateOrigin$1(auth);
|
|
2904
2344
|
}
|
|
2905
2345
|
return this.originValidationPromises[key];
|
|
2906
|
-
}
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
enumerable: false,
|
|
2913
|
-
configurable: true
|
|
2914
|
-
});
|
|
2915
|
-
return BrowserPopupRedirectResolver;
|
|
2916
|
-
}());
|
|
2346
|
+
}
|
|
2347
|
+
get _shouldInitProactively() {
|
|
2348
|
+
// Mobile browsers and Safari need to optimistically initialize
|
|
2349
|
+
return index._isMobileBrowser() || index._isSafari() || index._isIOS();
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
2917
2352
|
/**
|
|
2918
2353
|
* An implementation of {@link PopupRedirectResolver} suitable for browser
|
|
2919
2354
|
* based applications.
|
|
@@ -2923,7 +2358,7 @@ var BrowserPopupRedirectResolver = /** @class */ (function () {
|
|
|
2923
2358
|
*
|
|
2924
2359
|
* @public
|
|
2925
2360
|
*/
|
|
2926
|
-
|
|
2361
|
+
const browserPopupRedirectResolver = BrowserPopupRedirectResolver;
|
|
2927
2362
|
|
|
2928
2363
|
/**
|
|
2929
2364
|
* @license
|
|
@@ -2941,46 +2376,31 @@ var browserPopupRedirectResolver = BrowserPopupRedirectResolver;
|
|
|
2941
2376
|
* See the License for the specific language governing permissions and
|
|
2942
2377
|
* limitations under the License.
|
|
2943
2378
|
*/
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
}
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
return [2 /*return*/];
|
|
2968
|
-
}
|
|
2969
|
-
lastPostedIdToken = idToken;
|
|
2970
|
-
return [4 /*yield*/, fetch(url, {
|
|
2971
|
-
method: idToken ? 'POST' : 'DELETE',
|
|
2972
|
-
headers: idToken
|
|
2973
|
-
? {
|
|
2974
|
-
'Authorization': "Bearer ".concat(idToken)
|
|
2975
|
-
}
|
|
2976
|
-
: {}
|
|
2977
|
-
})];
|
|
2978
|
-
case 3:
|
|
2979
|
-
_b.sent();
|
|
2980
|
-
return [2 /*return*/];
|
|
2981
|
-
}
|
|
2379
|
+
const DEFAULT_ID_TOKEN_MAX_AGE = 5 * 60;
|
|
2380
|
+
const authIdTokenMaxAge = util.getExperimentalSetting('authIdTokenMaxAge') || DEFAULT_ID_TOKEN_MAX_AGE;
|
|
2381
|
+
let lastPostedIdToken = null;
|
|
2382
|
+
const mintCookieFactory = (url) => async (user) => {
|
|
2383
|
+
const idTokenResult = user && (await user.getIdTokenResult());
|
|
2384
|
+
const idTokenAge = idTokenResult &&
|
|
2385
|
+
(new Date().getTime() - Date.parse(idTokenResult.issuedAtTime)) / 1000;
|
|
2386
|
+
if (idTokenAge && idTokenAge > authIdTokenMaxAge) {
|
|
2387
|
+
return;
|
|
2388
|
+
}
|
|
2389
|
+
// Specifically trip null => undefined when logged out, to delete any existing cookie
|
|
2390
|
+
const idToken = idTokenResult === null || idTokenResult === void 0 ? void 0 : idTokenResult.token;
|
|
2391
|
+
if (lastPostedIdToken === idToken) {
|
|
2392
|
+
return;
|
|
2393
|
+
}
|
|
2394
|
+
lastPostedIdToken = idToken;
|
|
2395
|
+
await fetch(url, {
|
|
2396
|
+
method: idToken ? 'POST' : 'DELETE',
|
|
2397
|
+
headers: idToken
|
|
2398
|
+
? {
|
|
2399
|
+
'Authorization': `Bearer ${idToken}`
|
|
2400
|
+
}
|
|
2401
|
+
: {}
|
|
2982
2402
|
});
|
|
2983
|
-
}
|
|
2403
|
+
};
|
|
2984
2404
|
/**
|
|
2985
2405
|
* Returns the Auth instance associated with the provided {@link @firebase/app#FirebaseApp}.
|
|
2986
2406
|
* If no instance exists, initializes an Auth instance with platform-specific default dependencies.
|
|
@@ -2989,13 +2409,12 @@ var mintCookieFactory = function (url) { return function (user) { return tslib._
|
|
|
2989
2409
|
*
|
|
2990
2410
|
* @public
|
|
2991
2411
|
*/
|
|
2992
|
-
function getAuth(app$1) {
|
|
2993
|
-
|
|
2994
|
-
var provider = app._getProvider(app$1, 'auth');
|
|
2412
|
+
function getAuth(app$1 = app.getApp()) {
|
|
2413
|
+
const provider = app._getProvider(app$1, 'auth');
|
|
2995
2414
|
if (provider.isInitialized()) {
|
|
2996
2415
|
return provider.getImmediate();
|
|
2997
2416
|
}
|
|
2998
|
-
|
|
2417
|
+
const auth = index.initializeAuth(app$1, {
|
|
2999
2418
|
popupRedirectResolver: browserPopupRedirectResolver,
|
|
3000
2419
|
persistence: [
|
|
3001
2420
|
indexedDBLocalPersistence,
|
|
@@ -3003,24 +2422,22 @@ function getAuth(app$1) {
|
|
|
3003
2422
|
browserSessionPersistence
|
|
3004
2423
|
]
|
|
3005
2424
|
});
|
|
3006
|
-
|
|
2425
|
+
const authTokenSyncPath = util.getExperimentalSetting('authTokenSyncURL');
|
|
3007
2426
|
// Only do the Cookie exchange in a secure context
|
|
3008
2427
|
if (authTokenSyncPath &&
|
|
3009
2428
|
typeof isSecureContext === 'boolean' &&
|
|
3010
2429
|
isSecureContext) {
|
|
3011
2430
|
// Don't allow urls (XSS possibility), only paths on the same domain
|
|
3012
|
-
|
|
2431
|
+
const authTokenSyncUrl = new URL(authTokenSyncPath, location.origin);
|
|
3013
2432
|
if (location.origin === authTokenSyncUrl.origin) {
|
|
3014
|
-
|
|
3015
|
-
index.beforeAuthStateChanged(auth,
|
|
3016
|
-
|
|
3017
|
-
});
|
|
3018
|
-
index.onIdTokenChanged(auth, function (user) { return mintCookie_1(user); });
|
|
2433
|
+
const mintCookie = mintCookieFactory(authTokenSyncUrl.toString());
|
|
2434
|
+
index.beforeAuthStateChanged(auth, mintCookie, () => mintCookie(auth.currentUser));
|
|
2435
|
+
index.onIdTokenChanged(auth, user => mintCookie(user));
|
|
3019
2436
|
}
|
|
3020
2437
|
}
|
|
3021
|
-
|
|
2438
|
+
const authEmulatorHost = util.getDefaultEmulatorHost('auth');
|
|
3022
2439
|
if (authEmulatorHost) {
|
|
3023
|
-
index.connectAuthEmulator(auth,
|
|
2440
|
+
index.connectAuthEmulator(auth, `http://${authEmulatorHost}`);
|
|
3024
2441
|
}
|
|
3025
2442
|
return auth;
|
|
3026
2443
|
}
|
|
@@ -3029,14 +2446,14 @@ function getScriptParentElement() {
|
|
|
3029
2446
|
return (_b = (_a = document.getElementsByTagName('head')) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : document;
|
|
3030
2447
|
}
|
|
3031
2448
|
index._setExternalJSProvider({
|
|
3032
|
-
loadJS
|
|
2449
|
+
loadJS(url) {
|
|
3033
2450
|
// TODO: consider adding timeout support & cancellation
|
|
3034
|
-
return new Promise(
|
|
3035
|
-
|
|
2451
|
+
return new Promise((resolve, reject) => {
|
|
2452
|
+
const el = document.createElement('script');
|
|
3036
2453
|
el.setAttribute('src', url);
|
|
3037
2454
|
el.onload = resolve;
|
|
3038
|
-
el.onerror =
|
|
3039
|
-
|
|
2455
|
+
el.onerror = e => {
|
|
2456
|
+
const error = index._createError("internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
|
|
3040
2457
|
error.customData = e;
|
|
3041
2458
|
reject(error);
|
|
3042
2459
|
};
|
|
@@ -3091,81 +2508,60 @@ function _cordovaWindow() {
|
|
|
3091
2508
|
* How long to wait after the app comes back into focus before concluding that
|
|
3092
2509
|
* the user closed the sign in tab.
|
|
3093
2510
|
*/
|
|
3094
|
-
|
|
2511
|
+
const REDIRECT_TIMEOUT_MS = 2000;
|
|
3095
2512
|
/**
|
|
3096
2513
|
* Generates the URL for the OAuth handler.
|
|
3097
2514
|
*/
|
|
3098
|
-
function _generateHandlerUrl(auth, event, provider) {
|
|
2515
|
+
async function _generateHandlerUrl(auth, event, provider) {
|
|
3099
2516
|
var _a;
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
if (BuildInfo.displayName) {
|
|
3124
|
-
additionalParams['appDisplayName'] = BuildInfo.displayName;
|
|
3125
|
-
}
|
|
3126
|
-
// Attached the hashed session ID
|
|
3127
|
-
additionalParams['sessionId'] = sessionDigest;
|
|
3128
|
-
return [2 /*return*/, _getRedirectUrl(auth, provider, event.type, undefined, (_a = event.eventId) !== null && _a !== void 0 ? _a : undefined, additionalParams)];
|
|
3129
|
-
}
|
|
3130
|
-
});
|
|
3131
|
-
});
|
|
2517
|
+
// Get the cordova plugins
|
|
2518
|
+
const { BuildInfo } = _cordovaWindow();
|
|
2519
|
+
index.debugAssert(event.sessionId, 'AuthEvent did not contain a session ID');
|
|
2520
|
+
const sessionDigest = await computeSha256(event.sessionId);
|
|
2521
|
+
const additionalParams = {};
|
|
2522
|
+
if (index._isIOS()) {
|
|
2523
|
+
// iOS app identifier
|
|
2524
|
+
additionalParams['ibi'] = BuildInfo.packageName;
|
|
2525
|
+
}
|
|
2526
|
+
else if (index._isAndroid()) {
|
|
2527
|
+
// Android app identifier
|
|
2528
|
+
additionalParams['apn'] = BuildInfo.packageName;
|
|
2529
|
+
}
|
|
2530
|
+
else {
|
|
2531
|
+
index._fail(auth, "operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */);
|
|
2532
|
+
}
|
|
2533
|
+
// Add the display name if available
|
|
2534
|
+
if (BuildInfo.displayName) {
|
|
2535
|
+
additionalParams['appDisplayName'] = BuildInfo.displayName;
|
|
2536
|
+
}
|
|
2537
|
+
// Attached the hashed session ID
|
|
2538
|
+
additionalParams['sessionId'] = sessionDigest;
|
|
2539
|
+
return _getRedirectUrl(auth, provider, event.type, undefined, (_a = event.eventId) !== null && _a !== void 0 ? _a : undefined, additionalParams);
|
|
3132
2540
|
}
|
|
3133
2541
|
/**
|
|
3134
2542
|
* Validates that this app is valid for this project configuration
|
|
3135
2543
|
*/
|
|
3136
|
-
function _validateOrigin(auth) {
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
else {
|
|
3151
|
-
index._fail(auth, "operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */);
|
|
3152
|
-
}
|
|
3153
|
-
// Will fail automatically if package name is not authorized
|
|
3154
|
-
return [4 /*yield*/, _getProjectConfig(auth, request)];
|
|
3155
|
-
case 1:
|
|
3156
|
-
// Will fail automatically if package name is not authorized
|
|
3157
|
-
_a.sent();
|
|
3158
|
-
return [2 /*return*/];
|
|
3159
|
-
}
|
|
3160
|
-
});
|
|
3161
|
-
});
|
|
2544
|
+
async function _validateOrigin(auth) {
|
|
2545
|
+
const { BuildInfo } = _cordovaWindow();
|
|
2546
|
+
const request = {};
|
|
2547
|
+
if (index._isIOS()) {
|
|
2548
|
+
request.iosBundleId = BuildInfo.packageName;
|
|
2549
|
+
}
|
|
2550
|
+
else if (index._isAndroid()) {
|
|
2551
|
+
request.androidPackageName = BuildInfo.packageName;
|
|
2552
|
+
}
|
|
2553
|
+
else {
|
|
2554
|
+
index._fail(auth, "operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */);
|
|
2555
|
+
}
|
|
2556
|
+
// Will fail automatically if package name is not authorized
|
|
2557
|
+
await _getProjectConfig(auth, request);
|
|
3162
2558
|
}
|
|
3163
2559
|
function _performRedirect(handlerUrl) {
|
|
3164
2560
|
// Get the cordova plugins
|
|
3165
|
-
|
|
3166
|
-
return new Promise(
|
|
3167
|
-
cordova.plugins.browsertab.isAvailable(
|
|
3168
|
-
|
|
2561
|
+
const { cordova } = _cordovaWindow();
|
|
2562
|
+
return new Promise(resolve => {
|
|
2563
|
+
cordova.plugins.browsertab.isAvailable(browserTabIsAvailable => {
|
|
2564
|
+
let iabRef = null;
|
|
3169
2565
|
if (browserTabIsAvailable) {
|
|
3170
2566
|
cordova.plugins.browsertab.openUrl(handlerUrl);
|
|
3171
2567
|
}
|
|
@@ -3183,78 +2579,66 @@ function _performRedirect(handlerUrl) {
|
|
|
3183
2579
|
* to be visible, this promise resolves. AFTER that resolution, the listeners
|
|
3184
2580
|
* are detached and any browser tabs left open will be closed.
|
|
3185
2581
|
*/
|
|
3186
|
-
function _waitForAppResume(auth, eventListener, iabRef) {
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
// Listen for the auth event
|
|
3232
|
-
eventListener.addPassiveListener(authEventSeen);
|
|
3233
|
-
// Listen for resume and visibility events
|
|
3234
|
-
document.addEventListener('resume', resumed, false);
|
|
3235
|
-
if (index._isAndroid()) {
|
|
3236
|
-
document.addEventListener('visibilitychange', visibilityChanged, false);
|
|
3237
|
-
}
|
|
3238
|
-
// SETUP THE CLEANUP FUNCTION =====
|
|
3239
|
-
cleanup = function () {
|
|
3240
|
-
eventListener.removePassiveListener(authEventSeen);
|
|
3241
|
-
document.removeEventListener('resume', resumed, false);
|
|
3242
|
-
document.removeEventListener('visibilitychange', visibilityChanged, false);
|
|
3243
|
-
if (onCloseTimer) {
|
|
3244
|
-
window.clearTimeout(onCloseTimer);
|
|
3245
|
-
}
|
|
3246
|
-
};
|
|
3247
|
-
})];
|
|
3248
|
-
case 2:
|
|
3249
|
-
_a.sent();
|
|
3250
|
-
return [3 /*break*/, 4];
|
|
3251
|
-
case 3:
|
|
3252
|
-
cleanup();
|
|
3253
|
-
return [7 /*endfinally*/];
|
|
3254
|
-
case 4: return [2 /*return*/];
|
|
2582
|
+
async function _waitForAppResume(auth, eventListener, iabRef) {
|
|
2583
|
+
// Get the cordova plugins
|
|
2584
|
+
const { cordova } = _cordovaWindow();
|
|
2585
|
+
let cleanup = () => { };
|
|
2586
|
+
try {
|
|
2587
|
+
await new Promise((resolve, reject) => {
|
|
2588
|
+
let onCloseTimer = null;
|
|
2589
|
+
// DEFINE ALL THE CALLBACKS =====
|
|
2590
|
+
function authEventSeen() {
|
|
2591
|
+
var _a;
|
|
2592
|
+
// Auth event was detected. Resolve this promise and close the extra
|
|
2593
|
+
// window if it's still open.
|
|
2594
|
+
resolve();
|
|
2595
|
+
const closeBrowserTab = (_a = cordova.plugins.browsertab) === null || _a === void 0 ? void 0 : _a.close;
|
|
2596
|
+
if (typeof closeBrowserTab === 'function') {
|
|
2597
|
+
closeBrowserTab();
|
|
2598
|
+
}
|
|
2599
|
+
// Close inappbrowser embedded webview in iOS7 and 8 case if still
|
|
2600
|
+
// open.
|
|
2601
|
+
if (typeof (iabRef === null || iabRef === void 0 ? void 0 : iabRef.close) === 'function') {
|
|
2602
|
+
iabRef.close();
|
|
2603
|
+
}
|
|
2604
|
+
}
|
|
2605
|
+
function resumed() {
|
|
2606
|
+
if (onCloseTimer) {
|
|
2607
|
+
// This code already ran; do not rerun.
|
|
2608
|
+
return;
|
|
2609
|
+
}
|
|
2610
|
+
onCloseTimer = window.setTimeout(() => {
|
|
2611
|
+
// Wait two seconds after resume then reject.
|
|
2612
|
+
reject(index._createError(auth, "redirect-cancelled-by-user" /* AuthErrorCode.REDIRECT_CANCELLED_BY_USER */));
|
|
2613
|
+
}, REDIRECT_TIMEOUT_MS);
|
|
2614
|
+
}
|
|
2615
|
+
function visibilityChanged() {
|
|
2616
|
+
if ((document === null || document === void 0 ? void 0 : document.visibilityState) === 'visible') {
|
|
2617
|
+
resumed();
|
|
2618
|
+
}
|
|
2619
|
+
}
|
|
2620
|
+
// ATTACH ALL THE LISTENERS =====
|
|
2621
|
+
// Listen for the auth event
|
|
2622
|
+
eventListener.addPassiveListener(authEventSeen);
|
|
2623
|
+
// Listen for resume and visibility events
|
|
2624
|
+
document.addEventListener('resume', resumed, false);
|
|
2625
|
+
if (index._isAndroid()) {
|
|
2626
|
+
document.addEventListener('visibilitychange', visibilityChanged, false);
|
|
3255
2627
|
}
|
|
2628
|
+
// SETUP THE CLEANUP FUNCTION =====
|
|
2629
|
+
cleanup = () => {
|
|
2630
|
+
eventListener.removePassiveListener(authEventSeen);
|
|
2631
|
+
document.removeEventListener('resume', resumed, false);
|
|
2632
|
+
document.removeEventListener('visibilitychange', visibilityChanged, false);
|
|
2633
|
+
if (onCloseTimer) {
|
|
2634
|
+
window.clearTimeout(onCloseTimer);
|
|
2635
|
+
}
|
|
2636
|
+
};
|
|
3256
2637
|
});
|
|
3257
|
-
}
|
|
2638
|
+
}
|
|
2639
|
+
finally {
|
|
2640
|
+
cleanup();
|
|
2641
|
+
}
|
|
3258
2642
|
}
|
|
3259
2643
|
/**
|
|
3260
2644
|
* Checks the configuration of the Cordova environment. This has no side effect
|
|
@@ -3263,7 +2647,7 @@ function _waitForAppResume(auth, eventListener, iabRef) {
|
|
|
3263
2647
|
*/
|
|
3264
2648
|
function _checkCordovaConfiguration(auth) {
|
|
3265
2649
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
3266
|
-
|
|
2650
|
+
const win = _cordovaWindow();
|
|
3267
2651
|
// Check all dependencies installed.
|
|
3268
2652
|
// https://github.com/nordnet/cordova-universal-links-plugin
|
|
3269
2653
|
// Note that cordova-universal-links-plugin has been abandoned.
|
|
@@ -3293,21 +2677,15 @@ function _checkCordovaConfiguration(auth) {
|
|
|
3293
2677
|
* available in "secure" contexts, which covers Cordova (which is served on a file
|
|
3294
2678
|
* protocol).
|
|
3295
2679
|
*/
|
|
3296
|
-
function computeSha256(sessionId) {
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
buf = _a.sent();
|
|
3306
|
-
arr = Array.from(new Uint8Array(buf));
|
|
3307
|
-
return [2 /*return*/, arr.map(function (num) { return num.toString(16).padStart(2, '0'); }).join('')];
|
|
3308
|
-
}
|
|
3309
|
-
});
|
|
3310
|
-
});
|
|
2680
|
+
async function computeSha256(sessionId) {
|
|
2681
|
+
const bytes = stringToArrayBuffer(sessionId);
|
|
2682
|
+
// TODO: For IE11 crypto has a different name and this operation comes back
|
|
2683
|
+
// as an object, not a promise. This is the old proposed standard that
|
|
2684
|
+
// is used by IE11:
|
|
2685
|
+
// https://www.w3.org/TR/2013/WD-WebCryptoAPI-20130108/#cryptooperation-interface
|
|
2686
|
+
const buf = await crypto.subtle.digest('SHA-256', bytes);
|
|
2687
|
+
const arr = Array.from(new Uint8Array(buf));
|
|
2688
|
+
return arr.map(num => num.toString(16).padStart(2, '0')).join('');
|
|
3311
2689
|
}
|
|
3312
2690
|
function stringToArrayBuffer(str) {
|
|
3313
2691
|
// This function is only meant to deal with an ASCII charset and makes
|
|
@@ -3316,9 +2694,9 @@ function stringToArrayBuffer(str) {
|
|
|
3316
2694
|
if (typeof TextEncoder !== 'undefined') {
|
|
3317
2695
|
return new TextEncoder().encode(str);
|
|
3318
2696
|
}
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
for (
|
|
2697
|
+
const buff = new ArrayBuffer(str.length);
|
|
2698
|
+
const view = new Uint8Array(buff);
|
|
2699
|
+
for (let i = 0; i < str.length; i++) {
|
|
3322
2700
|
view[i] = str.charCodeAt(i);
|
|
3323
2701
|
}
|
|
3324
2702
|
return view;
|
|
@@ -3340,58 +2718,45 @@ function stringToArrayBuffer(str) {
|
|
|
3340
2718
|
* See the License for the specific language governing permissions and
|
|
3341
2719
|
* limitations under the License.
|
|
3342
2720
|
*/
|
|
3343
|
-
|
|
2721
|
+
const SESSION_ID_LENGTH = 20;
|
|
3344
2722
|
/** Custom AuthEventManager that adds passive listeners to events */
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
_this.resolveInitialized = resolve;
|
|
2723
|
+
class CordovaAuthEventManager extends AuthEventManager {
|
|
2724
|
+
constructor() {
|
|
2725
|
+
super(...arguments);
|
|
2726
|
+
this.passiveListeners = new Set();
|
|
2727
|
+
this.initPromise = new Promise(resolve => {
|
|
2728
|
+
this.resolveInitialized = resolve;
|
|
3352
2729
|
});
|
|
3353
|
-
return _this;
|
|
3354
2730
|
}
|
|
3355
|
-
|
|
2731
|
+
addPassiveListener(cb) {
|
|
3356
2732
|
this.passiveListeners.add(cb);
|
|
3357
|
-
}
|
|
3358
|
-
|
|
2733
|
+
}
|
|
2734
|
+
removePassiveListener(cb) {
|
|
3359
2735
|
this.passiveListeners.delete(cb);
|
|
3360
|
-
}
|
|
2736
|
+
}
|
|
3361
2737
|
// In a Cordova environment, this manager can live through multiple redirect
|
|
3362
2738
|
// operations
|
|
3363
|
-
|
|
2739
|
+
resetRedirect() {
|
|
3364
2740
|
this.queuedRedirectEvent = null;
|
|
3365
2741
|
this.hasHandledPotentialRedirect = false;
|
|
3366
|
-
}
|
|
2742
|
+
}
|
|
3367
2743
|
/** Override the onEvent method */
|
|
3368
|
-
|
|
2744
|
+
onEvent(event) {
|
|
3369
2745
|
this.resolveInitialized();
|
|
3370
|
-
this.passiveListeners.forEach(
|
|
3371
|
-
return
|
|
3372
|
-
}
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
case 0: return [4 /*yield*/, this.initPromise];
|
|
3378
|
-
case 1:
|
|
3379
|
-
_a.sent();
|
|
3380
|
-
return [2 /*return*/];
|
|
3381
|
-
}
|
|
3382
|
-
});
|
|
3383
|
-
});
|
|
3384
|
-
};
|
|
3385
|
-
return CordovaAuthEventManager;
|
|
3386
|
-
}(AuthEventManager));
|
|
2746
|
+
this.passiveListeners.forEach(cb => cb(event));
|
|
2747
|
+
return super.onEvent(event);
|
|
2748
|
+
}
|
|
2749
|
+
async initialized() {
|
|
2750
|
+
await this.initPromise;
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
3387
2753
|
/**
|
|
3388
2754
|
* Generates a (partial) {@link AuthEvent}.
|
|
3389
2755
|
*/
|
|
3390
|
-
function _generateNewEvent(auth, type, eventId) {
|
|
3391
|
-
if (eventId === void 0) { eventId = null; }
|
|
2756
|
+
function _generateNewEvent(auth, type, eventId = null) {
|
|
3392
2757
|
return {
|
|
3393
|
-
type
|
|
3394
|
-
eventId
|
|
2758
|
+
type,
|
|
2759
|
+
eventId,
|
|
3395
2760
|
urlResponse: null,
|
|
3396
2761
|
sessionId: generateSessionId(),
|
|
3397
2762
|
postBody: null,
|
|
@@ -3402,28 +2767,17 @@ function _generateNewEvent(auth, type, eventId) {
|
|
|
3402
2767
|
function _savePartialEvent(auth, event) {
|
|
3403
2768
|
return storage()._set(persistenceKey(auth), event);
|
|
3404
2769
|
}
|
|
3405
|
-
function _getAndRemoveEvent(auth) {
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
case 1:
|
|
3412
|
-
event = (_a.sent());
|
|
3413
|
-
if (!event) return [3 /*break*/, 3];
|
|
3414
|
-
return [4 /*yield*/, storage()._remove(persistenceKey(auth))];
|
|
3415
|
-
case 2:
|
|
3416
|
-
_a.sent();
|
|
3417
|
-
_a.label = 3;
|
|
3418
|
-
case 3: return [2 /*return*/, event];
|
|
3419
|
-
}
|
|
3420
|
-
});
|
|
3421
|
-
});
|
|
2770
|
+
async function _getAndRemoveEvent(auth) {
|
|
2771
|
+
const event = (await storage()._get(persistenceKey(auth)));
|
|
2772
|
+
if (event) {
|
|
2773
|
+
await storage()._remove(persistenceKey(auth));
|
|
2774
|
+
}
|
|
2775
|
+
return event;
|
|
3422
2776
|
}
|
|
3423
2777
|
function _eventFromPartialAndUrl(partialEvent, url) {
|
|
3424
2778
|
var _a, _b;
|
|
3425
2779
|
// Parse the deep link within the dynamic link URL.
|
|
3426
|
-
|
|
2780
|
+
const callbackUrl = _getDeepLinkFromCallback(url);
|
|
3427
2781
|
// Confirm it is actually a callback URL.
|
|
3428
2782
|
// Currently the universal link will be of this format:
|
|
3429
2783
|
// https://<AUTH_DOMAIN>/__/auth/callback<OAUTH_RESPONSE>
|
|
@@ -3433,19 +2787,19 @@ function _eventFromPartialAndUrl(partialEvent, url) {
|
|
|
3433
2787
|
// Check if there is an error in the URL.
|
|
3434
2788
|
// This mechanism is also used to pass errors back to the app:
|
|
3435
2789
|
// https://<AUTH_DOMAIN>/__/auth/callback?firebaseError=<STRINGIFIED_ERROR>
|
|
3436
|
-
|
|
2790
|
+
const params = searchParamsOrEmpty(callbackUrl);
|
|
3437
2791
|
// Get the error object corresponding to the stringified error if found.
|
|
3438
|
-
|
|
2792
|
+
const errorObject = params['firebaseError']
|
|
3439
2793
|
? parseJsonOrNull(decodeURIComponent(params['firebaseError']))
|
|
3440
2794
|
: null;
|
|
3441
|
-
|
|
3442
|
-
|
|
2795
|
+
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];
|
|
2796
|
+
const error = code ? index._createError(code) : null;
|
|
3443
2797
|
if (error) {
|
|
3444
2798
|
return {
|
|
3445
2799
|
type: partialEvent.type,
|
|
3446
2800
|
eventId: partialEvent.eventId,
|
|
3447
2801
|
tenantId: partialEvent.tenantId,
|
|
3448
|
-
error
|
|
2802
|
+
error,
|
|
3449
2803
|
urlResponse: null,
|
|
3450
2804
|
sessionId: null,
|
|
3451
2805
|
postBody: null
|
|
@@ -3465,10 +2819,10 @@ function _eventFromPartialAndUrl(partialEvent, url) {
|
|
|
3465
2819
|
return null;
|
|
3466
2820
|
}
|
|
3467
2821
|
function generateSessionId() {
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
for (
|
|
3471
|
-
|
|
2822
|
+
const chars = [];
|
|
2823
|
+
const allowedChars = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
2824
|
+
for (let i = 0; i < SESSION_ID_LENGTH; i++) {
|
|
2825
|
+
const idx = Math.floor(Math.random() * allowedChars.length);
|
|
3472
2826
|
chars.push(allowedChars.charAt(idx));
|
|
3473
2827
|
}
|
|
3474
2828
|
return chars.join('');
|
|
@@ -3489,15 +2843,15 @@ function parseJsonOrNull(json) {
|
|
|
3489
2843
|
}
|
|
3490
2844
|
// Exported for testing
|
|
3491
2845
|
function _getDeepLinkFromCallback(url) {
|
|
3492
|
-
|
|
3493
|
-
|
|
2846
|
+
const params = searchParamsOrEmpty(url);
|
|
2847
|
+
const link = params['link'] ? decodeURIComponent(params['link']) : undefined;
|
|
3494
2848
|
// Double link case (automatic redirect)
|
|
3495
|
-
|
|
2849
|
+
const doubleDeepLink = searchParamsOrEmpty(link)['link'];
|
|
3496
2850
|
// iOS custom scheme links.
|
|
3497
|
-
|
|
2851
|
+
const iOSDeepLink = params['deep_link_id']
|
|
3498
2852
|
? decodeURIComponent(params['deep_link_id'])
|
|
3499
2853
|
: undefined;
|
|
3500
|
-
|
|
2854
|
+
const iOSDoubleDeepLink = searchParamsOrEmpty(iOSDeepLink)['link'];
|
|
3501
2855
|
return iOSDoubleDeepLink || iOSDeepLink || doubleDeepLink || link || url;
|
|
3502
2856
|
}
|
|
3503
2857
|
/**
|
|
@@ -3508,7 +2862,7 @@ function searchParamsOrEmpty(url) {
|
|
|
3508
2862
|
if (!(url === null || url === void 0 ? void 0 : url.includes('?'))) {
|
|
3509
2863
|
return {};
|
|
3510
2864
|
}
|
|
3511
|
-
|
|
2865
|
+
const [_, ...rest] = url.split('?');
|
|
3512
2866
|
return util.querystringDecode(rest.join('?'));
|
|
3513
2867
|
}
|
|
3514
2868
|
|
|
@@ -3532,9 +2886,9 @@ function searchParamsOrEmpty(url) {
|
|
|
3532
2886
|
* How long to wait for the initial auth event before concluding no
|
|
3533
2887
|
* redirect pending
|
|
3534
2888
|
*/
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
2889
|
+
const INITIAL_EVENT_TIMEOUT_MS = 500;
|
|
2890
|
+
class CordovaPopupRedirectResolver {
|
|
2891
|
+
constructor() {
|
|
3538
2892
|
this._redirectPersistence = browserSessionPersistence;
|
|
3539
2893
|
this._shouldInitProactively = true; // This is lightweight for Cordova
|
|
3540
2894
|
this.eventManagers = new Map();
|
|
@@ -3542,110 +2896,65 @@ var CordovaPopupRedirectResolver = /** @class */ (function () {
|
|
|
3542
2896
|
this._completeRedirectFn = _getRedirectResult;
|
|
3543
2897
|
this._overrideRedirectResult = _overrideRedirectResult;
|
|
3544
2898
|
}
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
return [2 /*return*/, manager];
|
|
3557
|
-
});
|
|
3558
|
-
});
|
|
3559
|
-
};
|
|
3560
|
-
CordovaPopupRedirectResolver.prototype._openPopup = function (auth) {
|
|
2899
|
+
async _initialize(auth) {
|
|
2900
|
+
const key = auth._key();
|
|
2901
|
+
let manager = this.eventManagers.get(key);
|
|
2902
|
+
if (!manager) {
|
|
2903
|
+
manager = new CordovaAuthEventManager(auth);
|
|
2904
|
+
this.eventManagers.set(key, manager);
|
|
2905
|
+
this.attachCallbackListeners(auth, manager);
|
|
2906
|
+
}
|
|
2907
|
+
return manager;
|
|
2908
|
+
}
|
|
2909
|
+
_openPopup(auth) {
|
|
3561
2910
|
index._fail(auth, "operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */);
|
|
3562
|
-
}
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
_clearRedirectOutcomes();
|
|
3581
|
-
return [4 /*yield*/, this._originValidation(auth)];
|
|
3582
|
-
case 3:
|
|
3583
|
-
_a.sent();
|
|
3584
|
-
event = _generateNewEvent(auth, authType, eventId);
|
|
3585
|
-
return [4 /*yield*/, _savePartialEvent(auth, event)];
|
|
3586
|
-
case 4:
|
|
3587
|
-
_a.sent();
|
|
3588
|
-
return [4 /*yield*/, _generateHandlerUrl(auth, event, provider)];
|
|
3589
|
-
case 5:
|
|
3590
|
-
url = _a.sent();
|
|
3591
|
-
return [4 /*yield*/, _performRedirect(url)];
|
|
3592
|
-
case 6:
|
|
3593
|
-
iabRef = _a.sent();
|
|
3594
|
-
return [2 /*return*/, _waitForAppResume(auth, manager, iabRef)];
|
|
3595
|
-
}
|
|
3596
|
-
});
|
|
3597
|
-
});
|
|
3598
|
-
};
|
|
3599
|
-
CordovaPopupRedirectResolver.prototype._isIframeWebStorageSupported = function (_auth, _cb) {
|
|
2911
|
+
}
|
|
2912
|
+
async _openRedirect(auth, provider, authType, eventId) {
|
|
2913
|
+
_checkCordovaConfiguration(auth);
|
|
2914
|
+
const manager = await this._initialize(auth);
|
|
2915
|
+
await manager.initialized();
|
|
2916
|
+
// Reset the persisted redirect states. This does not matter on Web where
|
|
2917
|
+
// the redirect always blows away application state entirely. On Cordova,
|
|
2918
|
+
// the app maintains control flow through the redirect.
|
|
2919
|
+
manager.resetRedirect();
|
|
2920
|
+
_clearRedirectOutcomes();
|
|
2921
|
+
await this._originValidation(auth);
|
|
2922
|
+
const event = _generateNewEvent(auth, authType, eventId);
|
|
2923
|
+
await _savePartialEvent(auth, event);
|
|
2924
|
+
const url = await _generateHandlerUrl(auth, event, provider);
|
|
2925
|
+
const iabRef = await _performRedirect(url);
|
|
2926
|
+
return _waitForAppResume(auth, manager, iabRef);
|
|
2927
|
+
}
|
|
2928
|
+
_isIframeWebStorageSupported(_auth, _cb) {
|
|
3600
2929
|
throw new Error('Method not implemented.');
|
|
3601
|
-
}
|
|
3602
|
-
|
|
3603
|
-
|
|
2930
|
+
}
|
|
2931
|
+
_originValidation(auth) {
|
|
2932
|
+
const key = auth._key();
|
|
3604
2933
|
if (!this.originValidationPromises[key]) {
|
|
3605
2934
|
this.originValidationPromises[key] = _validateOrigin(auth);
|
|
3606
2935
|
}
|
|
3607
2936
|
return this.originValidationPromises[key];
|
|
3608
|
-
}
|
|
3609
|
-
|
|
3610
|
-
var _this = this;
|
|
2937
|
+
}
|
|
2938
|
+
attachCallbackListeners(auth, manager) {
|
|
3611
2939
|
// Get the global plugins
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
var partialEvent, finalEvent;
|
|
3631
|
-
return tslib.__generator(this, function (_a) {
|
|
3632
|
-
switch (_a.label) {
|
|
3633
|
-
case 0:
|
|
3634
|
-
// We have an event so we can clear the no event timeout
|
|
3635
|
-
clearTimeout(noEventTimeout);
|
|
3636
|
-
return [4 /*yield*/, _getAndRemoveEvent(auth)];
|
|
3637
|
-
case 1:
|
|
3638
|
-
partialEvent = _a.sent();
|
|
3639
|
-
finalEvent = null;
|
|
3640
|
-
if (partialEvent && (eventData === null || eventData === void 0 ? void 0 : eventData['url'])) {
|
|
3641
|
-
finalEvent = _eventFromPartialAndUrl(partialEvent, eventData['url']);
|
|
3642
|
-
}
|
|
3643
|
-
// If finalEvent is never filled, trigger with no event
|
|
3644
|
-
manager.onEvent(finalEvent || generateNoEvent());
|
|
3645
|
-
return [2 /*return*/];
|
|
3646
|
-
}
|
|
3647
|
-
});
|
|
3648
|
-
}); };
|
|
2940
|
+
const { universalLinks, handleOpenURL, BuildInfo } = _cordovaWindow();
|
|
2941
|
+
const noEventTimeout = setTimeout(async () => {
|
|
2942
|
+
// We didn't see that initial event. Clear any pending object and
|
|
2943
|
+
// dispatch no event
|
|
2944
|
+
await _getAndRemoveEvent(auth);
|
|
2945
|
+
manager.onEvent(generateNoEvent());
|
|
2946
|
+
}, INITIAL_EVENT_TIMEOUT_MS);
|
|
2947
|
+
const universalLinksCb = async (eventData) => {
|
|
2948
|
+
// We have an event so we can clear the no event timeout
|
|
2949
|
+
clearTimeout(noEventTimeout);
|
|
2950
|
+
const partialEvent = await _getAndRemoveEvent(auth);
|
|
2951
|
+
let finalEvent = null;
|
|
2952
|
+
if (partialEvent && (eventData === null || eventData === void 0 ? void 0 : eventData['url'])) {
|
|
2953
|
+
finalEvent = _eventFromPartialAndUrl(partialEvent, eventData['url']);
|
|
2954
|
+
}
|
|
2955
|
+
// If finalEvent is never filled, trigger with no event
|
|
2956
|
+
manager.onEvent(finalEvent || generateNoEvent());
|
|
2957
|
+
};
|
|
3649
2958
|
// Universal links subscriber doesn't exist for iOS, so we need to check
|
|
3650
2959
|
if (typeof universalLinks !== 'undefined' &&
|
|
3651
2960
|
typeof universalLinks.subscribe === 'function') {
|
|
@@ -3656,38 +2965,34 @@ var CordovaPopupRedirectResolver = /** @class */ (function () {
|
|
|
3656
2965
|
// For this to work, cordova-plugin-customurlscheme needs to be installed.
|
|
3657
2966
|
// https://github.com/EddyVerbruggen/Custom-URL-scheme
|
|
3658
2967
|
// Do not overwrite the existing developer's URL handler.
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
_cordovaWindow().handleOpenURL =
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
2968
|
+
const existingHandleOpenURL = handleOpenURL;
|
|
2969
|
+
const packagePrefix = `${BuildInfo.packageName.toLowerCase()}://`;
|
|
2970
|
+
_cordovaWindow().handleOpenURL = async (url) => {
|
|
2971
|
+
if (url.toLowerCase().startsWith(packagePrefix)) {
|
|
2972
|
+
// We want this intentionally to float
|
|
2973
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
2974
|
+
universalLinksCb({ url });
|
|
2975
|
+
}
|
|
2976
|
+
// Call the developer's handler if it is present.
|
|
2977
|
+
if (typeof existingHandleOpenURL === 'function') {
|
|
2978
|
+
try {
|
|
2979
|
+
existingHandleOpenURL(url);
|
|
3667
2980
|
}
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
existingHandleOpenURL(url);
|
|
3672
|
-
}
|
|
3673
|
-
catch (e) {
|
|
3674
|
-
// This is a developer error. Don't stop the flow of the SDK.
|
|
3675
|
-
console.error(e);
|
|
3676
|
-
}
|
|
2981
|
+
catch (e) {
|
|
2982
|
+
// This is a developer error. Don't stop the flow of the SDK.
|
|
2983
|
+
console.error(e);
|
|
3677
2984
|
}
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
return CordovaPopupRedirectResolver;
|
|
3683
|
-
}());
|
|
2985
|
+
}
|
|
2986
|
+
};
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
3684
2989
|
/**
|
|
3685
2990
|
* An implementation of {@link PopupRedirectResolver} suitable for Cordova
|
|
3686
2991
|
* based applications.
|
|
3687
2992
|
*
|
|
3688
2993
|
* @public
|
|
3689
2994
|
*/
|
|
3690
|
-
|
|
2995
|
+
const cordovaPopupRedirectResolver = CordovaPopupRedirectResolver;
|
|
3691
2996
|
function generateNoEvent() {
|
|
3692
2997
|
return {
|
|
3693
2998
|
type: "unknown" /* AuthEventType.UNKNOWN */,
|