@firebase/auth 1.5.1 → 1.6.0-20240131233318

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.
Files changed (657) hide show
  1. package/dist/auth-public.d.ts +1 -1
  2. package/dist/auth.d.ts +3 -2
  3. package/dist/browser-cjs/{index-21814063.js → index-ef98d5d0.js} +57 -25
  4. package/dist/browser-cjs/index-ef98d5d0.js.map +1 -0
  5. package/dist/browser-cjs/index.js +1 -1
  6. package/dist/browser-cjs/index.web-extension.d.ts +31 -0
  7. package/dist/browser-cjs/internal.js +1 -1
  8. package/dist/browser-cjs/src/core/providers/google.d.ts +1 -1
  9. package/dist/browser-cjs/src/core/util/version.d.ts +2 -1
  10. package/dist/browser-cjs/src/platform_browser/load_js.d.ts +11 -0
  11. package/dist/cordova/index.js +2 -2
  12. package/dist/cordova/index.web-extension.d.ts +31 -0
  13. package/dist/cordova/internal.js +29 -5
  14. package/dist/cordova/internal.js.map +1 -1
  15. package/dist/cordova/{popup_redirect-106f885f.js → popup_redirect-35ee3740.js} +35 -23
  16. package/dist/cordova/popup_redirect-35ee3740.js.map +1 -0
  17. package/dist/cordova/src/core/providers/google.d.ts +1 -1
  18. package/dist/cordova/src/core/util/version.d.ts +2 -1
  19. package/dist/cordova/src/platform_browser/load_js.d.ts +11 -0
  20. package/dist/esm2017/{index-dd468b12.js → index-a8a90353.js} +57 -25
  21. package/dist/esm2017/index-a8a90353.js.map +1 -0
  22. package/dist/esm2017/index.js +1 -1
  23. package/dist/esm2017/index.web-extension.d.ts +31 -0
  24. package/dist/esm2017/internal.js +2 -2
  25. package/dist/esm2017/src/core/providers/google.d.ts +1 -1
  26. package/dist/esm2017/src/core/util/version.d.ts +2 -1
  27. package/dist/esm2017/src/platform_browser/load_js.d.ts +11 -0
  28. package/dist/esm5/{index-dd399a6e.js → index-a5faf903.js} +61 -25
  29. package/dist/esm5/index-a5faf903.js.map +1 -0
  30. package/dist/esm5/index.js +1 -1
  31. package/dist/esm5/index.web-extension.d.ts +31 -0
  32. package/dist/esm5/internal.js +2 -2
  33. package/dist/esm5/src/core/providers/google.d.ts +1 -1
  34. package/dist/esm5/src/core/util/version.d.ts +2 -1
  35. package/dist/esm5/src/platform_browser/load_js.d.ts +11 -0
  36. package/dist/index.web-extension.d.ts +31 -0
  37. package/dist/index.webworker.esm5.js +25 -22
  38. package/dist/index.webworker.esm5.js.map +1 -1
  39. package/dist/node/index.js +1 -1
  40. package/dist/node/index.web-extension.d.ts +31 -0
  41. package/dist/node/internal.js +1 -1
  42. package/dist/node/src/core/providers/google.d.ts +1 -1
  43. package/dist/node/src/core/util/version.d.ts +2 -1
  44. package/dist/node/src/platform_browser/load_js.d.ts +11 -0
  45. package/dist/node/{totp-fe65684a.js → totp-eef93749.js} +26 -23
  46. package/dist/node/totp-eef93749.js.map +1 -0
  47. package/dist/node-esm/index.js +1 -1
  48. package/dist/node-esm/index.web-extension.d.ts +31 -0
  49. package/dist/node-esm/internal.js +2 -2
  50. package/dist/node-esm/src/core/providers/google.d.ts +1 -1
  51. package/dist/node-esm/src/core/util/version.d.ts +2 -1
  52. package/dist/node-esm/src/platform_browser/load_js.d.ts +11 -0
  53. package/dist/node-esm/{totp-4c2d4e67.js → totp-fae228ad.js} +22 -23
  54. package/dist/node-esm/totp-fae228ad.js.map +1 -0
  55. package/dist/rn/{index-96ab5fb1.js → index-d81c94f1.js} +37 -24
  56. package/dist/rn/index-d81c94f1.js.map +1 -0
  57. package/dist/rn/index.js +1 -1
  58. package/dist/rn/index.web-extension.d.ts +31 -0
  59. package/dist/rn/internal.js +27 -2
  60. package/dist/rn/internal.js.map +1 -1
  61. package/dist/rn/src/core/providers/google.d.ts +1 -1
  62. package/dist/rn/src/core/util/version.d.ts +2 -1
  63. package/dist/rn/src/platform_browser/load_js.d.ts +11 -0
  64. package/dist/src/core/providers/google.d.ts +1 -1
  65. package/dist/src/core/util/version.d.ts +2 -1
  66. package/dist/src/platform_browser/load_js.d.ts +11 -0
  67. package/dist/web-extension-cjs/index.cordova.d.ts +32 -0
  68. package/dist/web-extension-cjs/index.d.ts +37 -0
  69. package/dist/web-extension-cjs/index.doc.d.ts +24 -0
  70. package/dist/web-extension-cjs/index.js +114 -0
  71. package/dist/web-extension-cjs/index.js.map +1 -0
  72. package/dist/web-extension-cjs/index.node.d.ts +17 -0
  73. package/dist/web-extension-cjs/index.rn.d.ts +40 -0
  74. package/dist/web-extension-cjs/index.shared.d.ts +19 -0
  75. package/dist/web-extension-cjs/index.web-extension.d.ts +31 -0
  76. package/dist/web-extension-cjs/index.webworker.d.ts +21 -0
  77. package/dist/web-extension-cjs/internal/index.d.ts +42 -0
  78. package/dist/web-extension-cjs/internal.js +3452 -0
  79. package/dist/web-extension-cjs/internal.js.map +1 -0
  80. package/dist/web-extension-cjs/register-0d3d4fea.js +7874 -0
  81. package/dist/web-extension-cjs/register-0d3d4fea.js.map +1 -0
  82. package/dist/web-extension-cjs/scripts/run_node_tests.d.ts +17 -0
  83. package/dist/web-extension-cjs/src/api/account_management/account.d.ts +59 -0
  84. package/dist/web-extension-cjs/src/api/account_management/account.test.d.ts +17 -0
  85. package/dist/web-extension-cjs/src/api/account_management/email_and_password.d.ts +49 -0
  86. package/dist/web-extension-cjs/src/api/account_management/email_and_password.test.d.ts +17 -0
  87. package/dist/web-extension-cjs/src/api/account_management/mfa.d.ts +103 -0
  88. package/dist/web-extension-cjs/src/api/account_management/mfa.test.d.ts +17 -0
  89. package/dist/web-extension-cjs/src/api/account_management/profile.d.ts +29 -0
  90. package/dist/web-extension-cjs/src/api/account_management/profile.test.d.ts +17 -0
  91. package/dist/web-extension-cjs/src/api/authentication/create_auth_uri.d.ts +26 -0
  92. package/dist/web-extension-cjs/src/api/authentication/create_auth_uri.test.d.ts +17 -0
  93. package/dist/web-extension-cjs/src/api/authentication/custom_token.d.ts +26 -0
  94. package/dist/web-extension-cjs/src/api/authentication/custom_token.test.d.ts +17 -0
  95. package/dist/web-extension-cjs/src/api/authentication/email_and_password.d.ts +85 -0
  96. package/dist/web-extension-cjs/src/api/authentication/email_and_password.test.d.ts +17 -0
  97. package/dist/web-extension-cjs/src/api/authentication/email_link.d.ts +32 -0
  98. package/dist/web-extension-cjs/src/api/authentication/email_link.test.d.ts +17 -0
  99. package/dist/web-extension-cjs/src/api/authentication/idp.d.ts +40 -0
  100. package/dist/web-extension-cjs/src/api/authentication/idp.test.d.ts +17 -0
  101. package/dist/web-extension-cjs/src/api/authentication/mfa.d.ts +69 -0
  102. package/dist/web-extension-cjs/src/api/authentication/mfa.test.d.ts +17 -0
  103. package/dist/web-extension-cjs/src/api/authentication/recaptcha.d.ts +34 -0
  104. package/dist/web-extension-cjs/src/api/authentication/recaptcha.test.d.ts +17 -0
  105. package/dist/web-extension-cjs/src/api/authentication/sign_up.d.ts +34 -0
  106. package/dist/web-extension-cjs/src/api/authentication/sign_up.test.d.ts +17 -0
  107. package/dist/web-extension-cjs/src/api/authentication/sms.d.ts +50 -0
  108. package/dist/web-extension-cjs/src/api/authentication/sms.test.d.ts +17 -0
  109. package/dist/web-extension-cjs/src/api/authentication/token.d.ts +37 -0
  110. package/dist/web-extension-cjs/src/api/authentication/token.test.d.ts +17 -0
  111. package/dist/web-extension-cjs/src/api/errors.d.ts +128 -0
  112. package/dist/web-extension-cjs/src/api/index.d.ts +97 -0
  113. package/dist/web-extension-cjs/src/api/index.test.d.ts +17 -0
  114. package/dist/web-extension-cjs/src/api/password_policy/get_password_policy.d.ts +48 -0
  115. package/dist/web-extension-cjs/src/api/password_policy/get_password_policy.test.d.ts +17 -0
  116. package/dist/web-extension-cjs/src/api/project_config/get_project_config.d.ts +25 -0
  117. package/dist/web-extension-cjs/src/api/project_config/get_project_config.test.d.ts +17 -0
  118. package/dist/web-extension-cjs/src/core/action_code_url.d.ts +73 -0
  119. package/dist/web-extension-cjs/src/core/action_code_url.test.d.ts +17 -0
  120. package/dist/web-extension-cjs/src/core/auth/auth_event_manager.d.ts +34 -0
  121. package/dist/web-extension-cjs/src/core/auth/auth_event_manager.test.d.ts +17 -0
  122. package/dist/web-extension-cjs/src/core/auth/auth_impl.d.ts +129 -0
  123. package/dist/web-extension-cjs/src/core/auth/auth_impl.test.d.ts +17 -0
  124. package/dist/web-extension-cjs/src/core/auth/emulator.d.ts +42 -0
  125. package/dist/web-extension-cjs/src/core/auth/emulator.test.d.ts +17 -0
  126. package/dist/web-extension-cjs/src/core/auth/firebase_internal.d.ts +35 -0
  127. package/dist/web-extension-cjs/src/core/auth/firebase_internal.test.d.ts +17 -0
  128. package/dist/web-extension-cjs/src/core/auth/initialize.d.ts +46 -0
  129. package/dist/web-extension-cjs/src/core/auth/initialize.test.d.ts +17 -0
  130. package/dist/web-extension-cjs/src/core/auth/middleware.d.ts +25 -0
  131. package/dist/web-extension-cjs/src/core/auth/middleware.test.d.ts +17 -0
  132. package/dist/web-extension-cjs/src/core/auth/password_policy_impl.d.ts +59 -0
  133. package/dist/web-extension-cjs/src/core/auth/password_policy_impl.test.d.ts +17 -0
  134. package/dist/web-extension-cjs/src/core/auth/register.d.ts +23 -0
  135. package/dist/web-extension-cjs/src/core/credentials/auth_credential.d.ts +75 -0
  136. package/dist/web-extension-cjs/src/core/credentials/email.d.ts +60 -0
  137. package/dist/web-extension-cjs/src/core/credentials/email.test.d.ts +17 -0
  138. package/dist/web-extension-cjs/src/core/credentials/index.d.ts +23 -0
  139. package/dist/web-extension-cjs/src/core/credentials/oauth.d.ts +81 -0
  140. package/dist/web-extension-cjs/src/core/credentials/oauth.test.d.ts +17 -0
  141. package/dist/web-extension-cjs/src/core/credentials/phone.d.ts +52 -0
  142. package/dist/web-extension-cjs/src/core/credentials/phone.test.d.ts +17 -0
  143. package/dist/web-extension-cjs/src/core/credentials/saml.d.ts +52 -0
  144. package/dist/web-extension-cjs/src/core/credentials/saml.test.d.ts +17 -0
  145. package/dist/web-extension-cjs/src/core/errors.d.ts +325 -0
  146. package/dist/web-extension-cjs/src/core/errors.test.d.ts +17 -0
  147. package/dist/web-extension-cjs/src/core/index.d.ts +222 -0
  148. package/dist/web-extension-cjs/src/core/persistence/in_memory.d.ts +35 -0
  149. package/dist/web-extension-cjs/src/core/persistence/in_memory.test.d.ts +17 -0
  150. package/dist/web-extension-cjs/src/core/persistence/index.d.ts +41 -0
  151. package/dist/web-extension-cjs/src/core/persistence/persistence_user_manager.d.ts +45 -0
  152. package/dist/web-extension-cjs/src/core/persistence/persistence_user_manager.test.d.ts +17 -0
  153. package/dist/web-extension-cjs/src/core/providers/email.d.ts +83 -0
  154. package/dist/web-extension-cjs/src/core/providers/email.test.d.ts +17 -0
  155. package/dist/web-extension-cjs/src/core/providers/facebook.d.ts +93 -0
  156. package/dist/web-extension-cjs/src/core/providers/facebook.test.d.ts +17 -0
  157. package/dist/web-extension-cjs/src/core/providers/federated.d.ts +64 -0
  158. package/dist/web-extension-cjs/src/core/providers/federated.test.d.ts +17 -0
  159. package/dist/web-extension-cjs/src/core/providers/github.d.ts +89 -0
  160. package/dist/web-extension-cjs/src/core/providers/github.test.d.ts +17 -0
  161. package/dist/web-extension-cjs/src/core/providers/google.d.ts +96 -0
  162. package/dist/web-extension-cjs/src/core/providers/google.test.d.ts +17 -0
  163. package/dist/web-extension-cjs/src/core/providers/oauth.d.ts +151 -0
  164. package/dist/web-extension-cjs/src/core/providers/oauth.test.d.ts +17 -0
  165. package/dist/web-extension-cjs/src/core/providers/saml.d.ts +62 -0
  166. package/dist/web-extension-cjs/src/core/providers/saml.test.d.ts +17 -0
  167. package/dist/web-extension-cjs/src/core/providers/twitter.d.ts +103 -0
  168. package/dist/web-extension-cjs/src/core/providers/twitter.test.d.ts +17 -0
  169. package/dist/web-extension-cjs/src/core/strategies/abstract_popup_redirect_operation.d.ts +44 -0
  170. package/dist/web-extension-cjs/src/core/strategies/abstract_popup_redirect_operation.test.d.ts +17 -0
  171. package/dist/web-extension-cjs/src/core/strategies/action_code_settings.d.ts +19 -0
  172. package/dist/web-extension-cjs/src/core/strategies/action_code_settings.test.d.ts +17 -0
  173. package/dist/web-extension-cjs/src/core/strategies/anonymous.d.ts +29 -0
  174. package/dist/web-extension-cjs/src/core/strategies/anonymous.test.d.ts +17 -0
  175. package/dist/web-extension-cjs/src/core/strategies/credential.d.ts +58 -0
  176. package/dist/web-extension-cjs/src/core/strategies/credential.test.d.ts +17 -0
  177. package/dist/web-extension-cjs/src/core/strategies/custom_token.d.ts +34 -0
  178. package/dist/web-extension-cjs/src/core/strategies/custom_token.test.d.ts +17 -0
  179. package/dist/web-extension-cjs/src/core/strategies/email.d.ts +102 -0
  180. package/dist/web-extension-cjs/src/core/strategies/email.test.d.ts +17 -0
  181. package/dist/web-extension-cjs/src/core/strategies/email_and_password.d.ts +130 -0
  182. package/dist/web-extension-cjs/src/core/strategies/email_and_password.test.d.ts +17 -0
  183. package/dist/web-extension-cjs/src/core/strategies/email_link.d.ts +103 -0
  184. package/dist/web-extension-cjs/src/core/strategies/email_link.test.d.ts +17 -0
  185. package/dist/web-extension-cjs/src/core/strategies/idp.d.ts +32 -0
  186. package/dist/web-extension-cjs/src/core/strategies/idp.test.d.ts +17 -0
  187. package/dist/web-extension-cjs/src/core/strategies/redirect.d.ts +36 -0
  188. package/dist/web-extension-cjs/src/core/strategies/redirect.test.d.ts +17 -0
  189. package/dist/web-extension-cjs/src/core/user/account_info.d.ts +63 -0
  190. package/dist/web-extension-cjs/src/core/user/account_info.test.d.ts +17 -0
  191. package/dist/web-extension-cjs/src/core/user/additional_user_info.d.ts +31 -0
  192. package/dist/web-extension-cjs/src/core/user/additional_user_info.test.d.ts +17 -0
  193. package/dist/web-extension-cjs/src/core/user/id_token_result.d.ts +48 -0
  194. package/dist/web-extension-cjs/src/core/user/id_token_result.test.d.ts +17 -0
  195. package/dist/web-extension-cjs/src/core/user/invalidation.d.ts +18 -0
  196. package/dist/web-extension-cjs/src/core/user/invalidation.test.d.ts +17 -0
  197. package/dist/web-extension-cjs/src/core/user/link_unlink.d.ts +30 -0
  198. package/dist/web-extension-cjs/src/core/user/link_unlink.test.d.ts +17 -0
  199. package/dist/web-extension-cjs/src/core/user/proactive_refresh.d.ts +34 -0
  200. package/dist/web-extension-cjs/src/core/user/proactive_refresh.test.d.ts +17 -0
  201. package/dist/web-extension-cjs/src/core/user/reauthenticate.d.ts +20 -0
  202. package/dist/web-extension-cjs/src/core/user/reauthenticate.test.d.ts +17 -0
  203. package/dist/web-extension-cjs/src/core/user/reload.d.ts +27 -0
  204. package/dist/web-extension-cjs/src/core/user/reload.test.d.ts +17 -0
  205. package/dist/web-extension-cjs/src/core/user/token_manager.d.ts +49 -0
  206. package/dist/web-extension-cjs/src/core/user/token_manager.test.d.ts +17 -0
  207. package/dist/web-extension-cjs/src/core/user/user_credential_impl.d.ts +37 -0
  208. package/dist/web-extension-cjs/src/core/user/user_credential_impl.test.d.ts +17 -0
  209. package/dist/web-extension-cjs/src/core/user/user_impl.d.ts +68 -0
  210. package/dist/web-extension-cjs/src/core/user/user_impl.test.d.ts +17 -0
  211. package/dist/web-extension-cjs/src/core/user/user_metadata.d.ts +27 -0
  212. package/dist/web-extension-cjs/src/core/util/assert.d.ts +93 -0
  213. package/dist/web-extension-cjs/src/core/util/assert.test.d.ts +17 -0
  214. package/dist/web-extension-cjs/src/core/util/browser.d.ts +50 -0
  215. package/dist/web-extension-cjs/src/core/util/browser.test.d.ts +17 -0
  216. package/dist/web-extension-cjs/src/core/util/delay.d.ts +31 -0
  217. package/dist/web-extension-cjs/src/core/util/delay.test.d.ts +17 -0
  218. package/dist/web-extension-cjs/src/core/util/emulator.d.ts +18 -0
  219. package/dist/web-extension-cjs/src/core/util/emulator.test.d.ts +17 -0
  220. package/dist/web-extension-cjs/src/core/util/event_id.d.ts +17 -0
  221. package/dist/web-extension-cjs/src/core/util/event_id.test.d.ts +17 -0
  222. package/dist/web-extension-cjs/src/core/util/fetch_provider.d.ts +25 -0
  223. package/dist/web-extension-cjs/src/core/util/handler.d.ts +20 -0
  224. package/dist/web-extension-cjs/src/core/util/instantiator.d.ts +28 -0
  225. package/dist/web-extension-cjs/src/core/util/instantiator.test.d.ts +17 -0
  226. package/dist/web-extension-cjs/src/core/util/location.d.ts +19 -0
  227. package/dist/web-extension-cjs/src/core/util/log.d.ts +23 -0
  228. package/dist/web-extension-cjs/src/core/util/navigator.d.ts +21 -0
  229. package/dist/web-extension-cjs/src/core/util/providers.d.ts +23 -0
  230. package/dist/web-extension-cjs/src/core/util/resolver.d.ts +25 -0
  231. package/dist/web-extension-cjs/src/core/util/time.d.ts +17 -0
  232. package/dist/web-extension-cjs/src/core/util/validate_origin.d.ts +18 -0
  233. package/dist/web-extension-cjs/src/core/util/validate_origin.test.d.ts +17 -0
  234. package/dist/web-extension-cjs/src/core/util/version.d.ts +31 -0
  235. package/dist/web-extension-cjs/src/core/util/version.test.d.ts +17 -0
  236. package/dist/web-extension-cjs/src/index.d.ts +18 -0
  237. package/dist/web-extension-cjs/src/mfa/assertions/totp.d.ts +124 -0
  238. package/dist/web-extension-cjs/src/mfa/assertions/totp.test.d.ts +17 -0
  239. package/dist/web-extension-cjs/src/mfa/index.d.ts +18 -0
  240. package/dist/web-extension-cjs/src/mfa/mfa_assertion.d.ts +27 -0
  241. package/dist/web-extension-cjs/src/mfa/mfa_error.d.ts +35 -0
  242. package/dist/web-extension-cjs/src/mfa/mfa_info.d.ts +36 -0
  243. package/dist/web-extension-cjs/src/mfa/mfa_info.test.d.ts +17 -0
  244. package/dist/web-extension-cjs/src/mfa/mfa_resolver.d.ts +41 -0
  245. package/dist/web-extension-cjs/src/mfa/mfa_resolver.test.d.ts +17 -0
  246. package/dist/web-extension-cjs/src/mfa/mfa_session.d.ts +39 -0
  247. package/dist/web-extension-cjs/src/mfa/mfa_session.test.d.ts +17 -0
  248. package/dist/web-extension-cjs/src/mfa/mfa_user.d.ts +38 -0
  249. package/dist/web-extension-cjs/src/mfa/mfa_user.test.d.ts +17 -0
  250. package/dist/web-extension-cjs/src/model/application_verifier.d.ts +23 -0
  251. package/dist/web-extension-cjs/src/model/auth.d.ts +87 -0
  252. package/dist/web-extension-cjs/src/model/enum_maps.d.ts +98 -0
  253. package/dist/web-extension-cjs/src/model/enums.d.ts +74 -0
  254. package/dist/web-extension-cjs/src/model/id_token.d.ts +87 -0
  255. package/dist/web-extension-cjs/src/model/password_policy.d.ts +111 -0
  256. package/dist/web-extension-cjs/src/model/popup_redirect.d.ts +94 -0
  257. package/dist/web-extension-cjs/src/model/public_types.d.ts +1278 -0
  258. package/dist/web-extension-cjs/src/model/user.d.ts +83 -0
  259. package/dist/web-extension-cjs/src/platform_browser/auth.test.d.ts +17 -0
  260. package/dist/web-extension-cjs/src/platform_browser/auth_window.d.ts +37 -0
  261. package/dist/web-extension-cjs/src/platform_browser/iframe/gapi.d.ts +19 -0
  262. package/dist/web-extension-cjs/src/platform_browser/iframe/gapi.iframes.d.ts +47 -0
  263. package/dist/web-extension-cjs/src/platform_browser/iframe/gapi.test.d.ts +17 -0
  264. package/dist/web-extension-cjs/src/platform_browser/iframe/iframe.d.ts +18 -0
  265. package/dist/web-extension-cjs/src/platform_browser/iframe/iframe.test.d.ts +17 -0
  266. package/dist/web-extension-cjs/src/platform_browser/index.d.ts +27 -0
  267. package/dist/web-extension-cjs/src/platform_browser/load_js.d.ts +29 -0
  268. package/dist/web-extension-cjs/src/platform_browser/load_js.test.d.ts +17 -0
  269. package/dist/web-extension-cjs/src/platform_browser/messagechannel/index.d.ts +87 -0
  270. package/dist/web-extension-cjs/src/platform_browser/messagechannel/promise.d.ts +33 -0
  271. package/dist/web-extension-cjs/src/platform_browser/messagechannel/promise.test.d.ts +17 -0
  272. package/dist/web-extension-cjs/src/platform_browser/messagechannel/receiver.d.ts +63 -0
  273. package/dist/web-extension-cjs/src/platform_browser/messagechannel/receiver.test.d.ts +17 -0
  274. package/dist/web-extension-cjs/src/platform_browser/messagechannel/sender.d.ts +46 -0
  275. package/dist/web-extension-cjs/src/platform_browser/messagechannel/sender.test.d.ts +17 -0
  276. package/dist/web-extension-cjs/src/platform_browser/mfa/assertions/phone.d.ts +59 -0
  277. package/dist/web-extension-cjs/src/platform_browser/mfa/assertions/phone.test.d.ts +17 -0
  278. package/dist/web-extension-cjs/src/platform_browser/persistence/browser.d.ts +27 -0
  279. package/dist/web-extension-cjs/src/platform_browser/persistence/browser.test.d.ts +17 -0
  280. package/dist/web-extension-cjs/src/platform_browser/persistence/indexed_db.d.ts +33 -0
  281. package/dist/web-extension-cjs/src/platform_browser/persistence/indexed_db.test.d.ts +17 -0
  282. package/dist/web-extension-cjs/src/platform_browser/persistence/local_storage.d.ts +25 -0
  283. package/dist/web-extension-cjs/src/platform_browser/persistence/local_storage.test.d.ts +17 -0
  284. package/dist/web-extension-cjs/src/platform_browser/persistence/session_storage.d.ts +24 -0
  285. package/dist/web-extension-cjs/src/platform_browser/persistence/session_storage.test.d.ts +17 -0
  286. package/dist/web-extension-cjs/src/platform_browser/popup_redirect.d.ts +27 -0
  287. package/dist/web-extension-cjs/src/platform_browser/popup_redirect.test.d.ts +17 -0
  288. package/dist/web-extension-cjs/src/platform_browser/providers/phone.d.ts +152 -0
  289. package/dist/web-extension-cjs/src/platform_browser/providers/phone.test.d.ts +17 -0
  290. package/dist/web-extension-cjs/src/platform_browser/recaptcha/recaptcha.d.ts +71 -0
  291. package/dist/web-extension-cjs/src/platform_browser/recaptcha/recaptcha.test.d.ts +17 -0
  292. package/dist/web-extension-cjs/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +45 -0
  293. package/dist/web-extension-cjs/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.test.d.ts +17 -0
  294. package/dist/web-extension-cjs/src/platform_browser/recaptcha/recaptcha_loader.d.ts +49 -0
  295. package/dist/web-extension-cjs/src/platform_browser/recaptcha/recaptcha_loader.test.d.ts +17 -0
  296. package/dist/web-extension-cjs/src/platform_browser/recaptcha/recaptcha_mock.d.ts +66 -0
  297. package/dist/web-extension-cjs/src/platform_browser/recaptcha/recaptcha_mock.test.d.ts +17 -0
  298. package/dist/web-extension-cjs/src/platform_browser/recaptcha/recaptcha_verifier.d.ts +92 -0
  299. package/dist/web-extension-cjs/src/platform_browser/recaptcha/recaptcha_verifier.test.d.ts +17 -0
  300. package/dist/web-extension-cjs/src/platform_browser/strategies/phone.d.ts +109 -0
  301. package/dist/web-extension-cjs/src/platform_browser/strategies/phone.test.d.ts +17 -0
  302. package/dist/web-extension-cjs/src/platform_browser/strategies/popup.d.ts +107 -0
  303. package/dist/web-extension-cjs/src/platform_browser/strategies/popup.test.d.ts +17 -0
  304. package/dist/web-extension-cjs/src/platform_browser/strategies/redirect.d.ts +172 -0
  305. package/dist/web-extension-cjs/src/platform_browser/strategies/redirect.test.d.ts +17 -0
  306. package/dist/web-extension-cjs/src/platform_browser/util/popup.d.ts +24 -0
  307. package/dist/web-extension-cjs/src/platform_browser/util/popup.test.d.ts +17 -0
  308. package/dist/web-extension-cjs/src/platform_browser/util/worker.d.ts +20 -0
  309. package/dist/web-extension-cjs/src/platform_cordova/plugins.d.ts +42 -0
  310. package/dist/web-extension-cjs/src/platform_cordova/popup_redirect/events.d.ts +39 -0
  311. package/dist/web-extension-cjs/src/platform_cordova/popup_redirect/events.test.d.ts +17 -0
  312. package/dist/web-extension-cjs/src/platform_cordova/popup_redirect/popup_redirect.d.ts +24 -0
  313. package/dist/web-extension-cjs/src/platform_cordova/popup_redirect/popup_redirect.test.d.ts +17 -0
  314. package/dist/web-extension-cjs/src/platform_cordova/popup_redirect/utils.d.ts +47 -0
  315. package/dist/web-extension-cjs/src/platform_cordova/popup_redirect/utils.test.d.ts +17 -0
  316. package/dist/web-extension-cjs/src/platform_cordova/strategies/redirect.d.ts +20 -0
  317. package/dist/web-extension-cjs/src/platform_node/index.d.ts +50 -0
  318. package/dist/web-extension-cjs/src/platform_react_native/persistence/react_native.d.ts +25 -0
  319. package/dist/web-extension-cjs/src/platform_react_native/persistence/react_native.test.d.ts +17 -0
  320. package/dist/web-extension-cjs/test/helpers/api/helper.d.ts +22 -0
  321. package/dist/web-extension-cjs/test/helpers/delay.d.ts +20 -0
  322. package/dist/web-extension-cjs/test/helpers/erroring_unavailable_persistence.d.ts +36 -0
  323. package/dist/web-extension-cjs/test/helpers/fake_service_worker.d.ts +22 -0
  324. package/dist/web-extension-cjs/test/helpers/id_token_response.d.ts +18 -0
  325. package/dist/web-extension-cjs/test/helpers/iframe_event.d.ts +19 -0
  326. package/dist/web-extension-cjs/test/helpers/integration/emulator_rest_helpers.d.ts +35 -0
  327. package/dist/web-extension-cjs/test/helpers/integration/helpers.d.ts +30 -0
  328. package/dist/web-extension-cjs/test/helpers/integration/settings.d.ts +23 -0
  329. package/dist/web-extension-cjs/test/helpers/jwt.d.ts +17 -0
  330. package/dist/web-extension-cjs/test/helpers/mock_auth.d.ts +47 -0
  331. package/dist/web-extension-cjs/test/helpers/mock_auth_credential.d.ts +31 -0
  332. package/dist/web-extension-cjs/test/helpers/mock_fetch.d.ts +30 -0
  333. package/dist/web-extension-cjs/test/helpers/mock_fetch.test.d.ts +17 -0
  334. package/dist/web-extension-cjs/test/helpers/mock_popup_redirect_resolver.d.ts +24 -0
  335. package/dist/web-extension-cjs/test/helpers/redirect_persistence.d.ts +24 -0
  336. package/dist/web-extension-cjs/test/helpers/timeout_stub.d.ts +34 -0
  337. package/dist/web-extension-cjs/test/integration/flows/anonymous.test.d.ts +17 -0
  338. package/dist/web-extension-cjs/test/integration/flows/custom.local.test.d.ts +17 -0
  339. package/dist/web-extension-cjs/test/integration/flows/email.test.d.ts +17 -0
  340. package/dist/web-extension-cjs/test/integration/flows/idp.local.test.d.ts +17 -0
  341. package/dist/web-extension-cjs/test/integration/flows/middleware_test_generator.d.ts +18 -0
  342. package/dist/web-extension-cjs/test/integration/flows/oob.local.test.d.ts +17 -0
  343. package/dist/web-extension-cjs/test/integration/flows/password_policy.test.d.ts +17 -0
  344. package/dist/web-extension-cjs/test/integration/flows/phone.test.d.ts +17 -0
  345. package/dist/web-extension-cjs/test/integration/flows/totp.test.d.ts +17 -0
  346. package/dist/web-extension-cjs/test/integration/webdriver/anonymous.test.d.ts +17 -0
  347. package/dist/web-extension-cjs/test/integration/webdriver/compat/firebaseui.test.d.ts +17 -0
  348. package/dist/web-extension-cjs/test/integration/webdriver/persistence.test.d.ts +17 -0
  349. package/dist/web-extension-cjs/test/integration/webdriver/popup.test.d.ts +17 -0
  350. package/dist/web-extension-cjs/test/integration/webdriver/redirect.test.d.ts +17 -0
  351. package/dist/web-extension-cjs/test/integration/webdriver/util/auth_driver.d.ts +46 -0
  352. package/dist/web-extension-cjs/test/integration/webdriver/util/functions.d.ts +81 -0
  353. package/dist/web-extension-cjs/test/integration/webdriver/util/idp_page.d.ts +31 -0
  354. package/dist/web-extension-cjs/test/integration/webdriver/util/js_load_condition.d.ts +25 -0
  355. package/dist/web-extension-cjs/test/integration/webdriver/util/test_runner.d.ts +19 -0
  356. package/dist/web-extension-cjs/test/integration/webdriver/util/test_server.d.ts +27 -0
  357. package/dist/web-extension-cjs/test/integration/webdriver/util/ui_page.d.ts +33 -0
  358. package/dist/web-extension-esm2017/index.cordova.d.ts +32 -0
  359. package/dist/web-extension-esm2017/index.d.ts +37 -0
  360. package/dist/web-extension-esm2017/index.doc.d.ts +24 -0
  361. package/dist/web-extension-esm2017/index.js +50 -0
  362. package/dist/web-extension-esm2017/index.js.map +1 -0
  363. package/dist/web-extension-esm2017/index.node.d.ts +17 -0
  364. package/dist/web-extension-esm2017/index.rn.d.ts +40 -0
  365. package/dist/web-extension-esm2017/index.shared.d.ts +19 -0
  366. package/dist/web-extension-esm2017/index.web-extension.d.ts +31 -0
  367. package/dist/web-extension-esm2017/index.webworker.d.ts +21 -0
  368. package/dist/web-extension-esm2017/internal/index.d.ts +42 -0
  369. package/dist/web-extension-esm2017/internal.js +3350 -0
  370. package/dist/web-extension-esm2017/internal.js.map +1 -0
  371. package/dist/web-extension-esm2017/register-ec86a01e.js +7758 -0
  372. package/dist/web-extension-esm2017/register-ec86a01e.js.map +1 -0
  373. package/dist/web-extension-esm2017/scripts/run_node_tests.d.ts +17 -0
  374. package/dist/web-extension-esm2017/src/api/account_management/account.d.ts +59 -0
  375. package/dist/web-extension-esm2017/src/api/account_management/account.test.d.ts +17 -0
  376. package/dist/web-extension-esm2017/src/api/account_management/email_and_password.d.ts +49 -0
  377. package/dist/web-extension-esm2017/src/api/account_management/email_and_password.test.d.ts +17 -0
  378. package/dist/web-extension-esm2017/src/api/account_management/mfa.d.ts +103 -0
  379. package/dist/web-extension-esm2017/src/api/account_management/mfa.test.d.ts +17 -0
  380. package/dist/web-extension-esm2017/src/api/account_management/profile.d.ts +29 -0
  381. package/dist/web-extension-esm2017/src/api/account_management/profile.test.d.ts +17 -0
  382. package/dist/web-extension-esm2017/src/api/authentication/create_auth_uri.d.ts +26 -0
  383. package/dist/web-extension-esm2017/src/api/authentication/create_auth_uri.test.d.ts +17 -0
  384. package/dist/web-extension-esm2017/src/api/authentication/custom_token.d.ts +26 -0
  385. package/dist/web-extension-esm2017/src/api/authentication/custom_token.test.d.ts +17 -0
  386. package/dist/web-extension-esm2017/src/api/authentication/email_and_password.d.ts +85 -0
  387. package/dist/web-extension-esm2017/src/api/authentication/email_and_password.test.d.ts +17 -0
  388. package/dist/web-extension-esm2017/src/api/authentication/email_link.d.ts +32 -0
  389. package/dist/web-extension-esm2017/src/api/authentication/email_link.test.d.ts +17 -0
  390. package/dist/web-extension-esm2017/src/api/authentication/idp.d.ts +40 -0
  391. package/dist/web-extension-esm2017/src/api/authentication/idp.test.d.ts +17 -0
  392. package/dist/web-extension-esm2017/src/api/authentication/mfa.d.ts +69 -0
  393. package/dist/web-extension-esm2017/src/api/authentication/mfa.test.d.ts +17 -0
  394. package/dist/web-extension-esm2017/src/api/authentication/recaptcha.d.ts +34 -0
  395. package/dist/web-extension-esm2017/src/api/authentication/recaptcha.test.d.ts +17 -0
  396. package/dist/web-extension-esm2017/src/api/authentication/sign_up.d.ts +34 -0
  397. package/dist/web-extension-esm2017/src/api/authentication/sign_up.test.d.ts +17 -0
  398. package/dist/web-extension-esm2017/src/api/authentication/sms.d.ts +50 -0
  399. package/dist/web-extension-esm2017/src/api/authentication/sms.test.d.ts +17 -0
  400. package/dist/web-extension-esm2017/src/api/authentication/token.d.ts +37 -0
  401. package/dist/web-extension-esm2017/src/api/authentication/token.test.d.ts +17 -0
  402. package/dist/web-extension-esm2017/src/api/errors.d.ts +128 -0
  403. package/dist/web-extension-esm2017/src/api/index.d.ts +97 -0
  404. package/dist/web-extension-esm2017/src/api/index.test.d.ts +17 -0
  405. package/dist/web-extension-esm2017/src/api/password_policy/get_password_policy.d.ts +48 -0
  406. package/dist/web-extension-esm2017/src/api/password_policy/get_password_policy.test.d.ts +17 -0
  407. package/dist/web-extension-esm2017/src/api/project_config/get_project_config.d.ts +25 -0
  408. package/dist/web-extension-esm2017/src/api/project_config/get_project_config.test.d.ts +17 -0
  409. package/dist/web-extension-esm2017/src/core/action_code_url.d.ts +73 -0
  410. package/dist/web-extension-esm2017/src/core/action_code_url.test.d.ts +17 -0
  411. package/dist/web-extension-esm2017/src/core/auth/auth_event_manager.d.ts +34 -0
  412. package/dist/web-extension-esm2017/src/core/auth/auth_event_manager.test.d.ts +17 -0
  413. package/dist/web-extension-esm2017/src/core/auth/auth_impl.d.ts +129 -0
  414. package/dist/web-extension-esm2017/src/core/auth/auth_impl.test.d.ts +17 -0
  415. package/dist/web-extension-esm2017/src/core/auth/emulator.d.ts +42 -0
  416. package/dist/web-extension-esm2017/src/core/auth/emulator.test.d.ts +17 -0
  417. package/dist/web-extension-esm2017/src/core/auth/firebase_internal.d.ts +35 -0
  418. package/dist/web-extension-esm2017/src/core/auth/firebase_internal.test.d.ts +17 -0
  419. package/dist/web-extension-esm2017/src/core/auth/initialize.d.ts +46 -0
  420. package/dist/web-extension-esm2017/src/core/auth/initialize.test.d.ts +17 -0
  421. package/dist/web-extension-esm2017/src/core/auth/middleware.d.ts +25 -0
  422. package/dist/web-extension-esm2017/src/core/auth/middleware.test.d.ts +17 -0
  423. package/dist/web-extension-esm2017/src/core/auth/password_policy_impl.d.ts +59 -0
  424. package/dist/web-extension-esm2017/src/core/auth/password_policy_impl.test.d.ts +17 -0
  425. package/dist/web-extension-esm2017/src/core/auth/register.d.ts +23 -0
  426. package/dist/web-extension-esm2017/src/core/credentials/auth_credential.d.ts +75 -0
  427. package/dist/web-extension-esm2017/src/core/credentials/email.d.ts +60 -0
  428. package/dist/web-extension-esm2017/src/core/credentials/email.test.d.ts +17 -0
  429. package/dist/web-extension-esm2017/src/core/credentials/index.d.ts +23 -0
  430. package/dist/web-extension-esm2017/src/core/credentials/oauth.d.ts +81 -0
  431. package/dist/web-extension-esm2017/src/core/credentials/oauth.test.d.ts +17 -0
  432. package/dist/web-extension-esm2017/src/core/credentials/phone.d.ts +52 -0
  433. package/dist/web-extension-esm2017/src/core/credentials/phone.test.d.ts +17 -0
  434. package/dist/web-extension-esm2017/src/core/credentials/saml.d.ts +52 -0
  435. package/dist/web-extension-esm2017/src/core/credentials/saml.test.d.ts +17 -0
  436. package/dist/web-extension-esm2017/src/core/errors.d.ts +325 -0
  437. package/dist/web-extension-esm2017/src/core/errors.test.d.ts +17 -0
  438. package/dist/web-extension-esm2017/src/core/index.d.ts +222 -0
  439. package/dist/web-extension-esm2017/src/core/persistence/in_memory.d.ts +35 -0
  440. package/dist/web-extension-esm2017/src/core/persistence/in_memory.test.d.ts +17 -0
  441. package/dist/web-extension-esm2017/src/core/persistence/index.d.ts +41 -0
  442. package/dist/web-extension-esm2017/src/core/persistence/persistence_user_manager.d.ts +45 -0
  443. package/dist/web-extension-esm2017/src/core/persistence/persistence_user_manager.test.d.ts +17 -0
  444. package/dist/web-extension-esm2017/src/core/providers/email.d.ts +83 -0
  445. package/dist/web-extension-esm2017/src/core/providers/email.test.d.ts +17 -0
  446. package/dist/web-extension-esm2017/src/core/providers/facebook.d.ts +93 -0
  447. package/dist/web-extension-esm2017/src/core/providers/facebook.test.d.ts +17 -0
  448. package/dist/web-extension-esm2017/src/core/providers/federated.d.ts +64 -0
  449. package/dist/web-extension-esm2017/src/core/providers/federated.test.d.ts +17 -0
  450. package/dist/web-extension-esm2017/src/core/providers/github.d.ts +89 -0
  451. package/dist/web-extension-esm2017/src/core/providers/github.test.d.ts +17 -0
  452. package/dist/web-extension-esm2017/src/core/providers/google.d.ts +96 -0
  453. package/dist/web-extension-esm2017/src/core/providers/google.test.d.ts +17 -0
  454. package/dist/web-extension-esm2017/src/core/providers/oauth.d.ts +151 -0
  455. package/dist/web-extension-esm2017/src/core/providers/oauth.test.d.ts +17 -0
  456. package/dist/web-extension-esm2017/src/core/providers/saml.d.ts +62 -0
  457. package/dist/web-extension-esm2017/src/core/providers/saml.test.d.ts +17 -0
  458. package/dist/web-extension-esm2017/src/core/providers/twitter.d.ts +103 -0
  459. package/dist/web-extension-esm2017/src/core/providers/twitter.test.d.ts +17 -0
  460. package/dist/web-extension-esm2017/src/core/strategies/abstract_popup_redirect_operation.d.ts +44 -0
  461. package/dist/web-extension-esm2017/src/core/strategies/abstract_popup_redirect_operation.test.d.ts +17 -0
  462. package/dist/web-extension-esm2017/src/core/strategies/action_code_settings.d.ts +19 -0
  463. package/dist/web-extension-esm2017/src/core/strategies/action_code_settings.test.d.ts +17 -0
  464. package/dist/web-extension-esm2017/src/core/strategies/anonymous.d.ts +29 -0
  465. package/dist/web-extension-esm2017/src/core/strategies/anonymous.test.d.ts +17 -0
  466. package/dist/web-extension-esm2017/src/core/strategies/credential.d.ts +58 -0
  467. package/dist/web-extension-esm2017/src/core/strategies/credential.test.d.ts +17 -0
  468. package/dist/web-extension-esm2017/src/core/strategies/custom_token.d.ts +34 -0
  469. package/dist/web-extension-esm2017/src/core/strategies/custom_token.test.d.ts +17 -0
  470. package/dist/web-extension-esm2017/src/core/strategies/email.d.ts +102 -0
  471. package/dist/web-extension-esm2017/src/core/strategies/email.test.d.ts +17 -0
  472. package/dist/web-extension-esm2017/src/core/strategies/email_and_password.d.ts +130 -0
  473. package/dist/web-extension-esm2017/src/core/strategies/email_and_password.test.d.ts +17 -0
  474. package/dist/web-extension-esm2017/src/core/strategies/email_link.d.ts +103 -0
  475. package/dist/web-extension-esm2017/src/core/strategies/email_link.test.d.ts +17 -0
  476. package/dist/web-extension-esm2017/src/core/strategies/idp.d.ts +32 -0
  477. package/dist/web-extension-esm2017/src/core/strategies/idp.test.d.ts +17 -0
  478. package/dist/web-extension-esm2017/src/core/strategies/redirect.d.ts +36 -0
  479. package/dist/web-extension-esm2017/src/core/strategies/redirect.test.d.ts +17 -0
  480. package/dist/web-extension-esm2017/src/core/user/account_info.d.ts +63 -0
  481. package/dist/web-extension-esm2017/src/core/user/account_info.test.d.ts +17 -0
  482. package/dist/web-extension-esm2017/src/core/user/additional_user_info.d.ts +31 -0
  483. package/dist/web-extension-esm2017/src/core/user/additional_user_info.test.d.ts +17 -0
  484. package/dist/web-extension-esm2017/src/core/user/id_token_result.d.ts +48 -0
  485. package/dist/web-extension-esm2017/src/core/user/id_token_result.test.d.ts +17 -0
  486. package/dist/web-extension-esm2017/src/core/user/invalidation.d.ts +18 -0
  487. package/dist/web-extension-esm2017/src/core/user/invalidation.test.d.ts +17 -0
  488. package/dist/web-extension-esm2017/src/core/user/link_unlink.d.ts +30 -0
  489. package/dist/web-extension-esm2017/src/core/user/link_unlink.test.d.ts +17 -0
  490. package/dist/web-extension-esm2017/src/core/user/proactive_refresh.d.ts +34 -0
  491. package/dist/web-extension-esm2017/src/core/user/proactive_refresh.test.d.ts +17 -0
  492. package/dist/web-extension-esm2017/src/core/user/reauthenticate.d.ts +20 -0
  493. package/dist/web-extension-esm2017/src/core/user/reauthenticate.test.d.ts +17 -0
  494. package/dist/web-extension-esm2017/src/core/user/reload.d.ts +27 -0
  495. package/dist/web-extension-esm2017/src/core/user/reload.test.d.ts +17 -0
  496. package/dist/web-extension-esm2017/src/core/user/token_manager.d.ts +49 -0
  497. package/dist/web-extension-esm2017/src/core/user/token_manager.test.d.ts +17 -0
  498. package/dist/web-extension-esm2017/src/core/user/user_credential_impl.d.ts +37 -0
  499. package/dist/web-extension-esm2017/src/core/user/user_credential_impl.test.d.ts +17 -0
  500. package/dist/web-extension-esm2017/src/core/user/user_impl.d.ts +68 -0
  501. package/dist/web-extension-esm2017/src/core/user/user_impl.test.d.ts +17 -0
  502. package/dist/web-extension-esm2017/src/core/user/user_metadata.d.ts +27 -0
  503. package/dist/web-extension-esm2017/src/core/util/assert.d.ts +93 -0
  504. package/dist/web-extension-esm2017/src/core/util/assert.test.d.ts +17 -0
  505. package/dist/web-extension-esm2017/src/core/util/browser.d.ts +50 -0
  506. package/dist/web-extension-esm2017/src/core/util/browser.test.d.ts +17 -0
  507. package/dist/web-extension-esm2017/src/core/util/delay.d.ts +31 -0
  508. package/dist/web-extension-esm2017/src/core/util/delay.test.d.ts +17 -0
  509. package/dist/web-extension-esm2017/src/core/util/emulator.d.ts +18 -0
  510. package/dist/web-extension-esm2017/src/core/util/emulator.test.d.ts +17 -0
  511. package/dist/web-extension-esm2017/src/core/util/event_id.d.ts +17 -0
  512. package/dist/web-extension-esm2017/src/core/util/event_id.test.d.ts +17 -0
  513. package/dist/web-extension-esm2017/src/core/util/fetch_provider.d.ts +25 -0
  514. package/dist/web-extension-esm2017/src/core/util/handler.d.ts +20 -0
  515. package/dist/web-extension-esm2017/src/core/util/instantiator.d.ts +28 -0
  516. package/dist/web-extension-esm2017/src/core/util/instantiator.test.d.ts +17 -0
  517. package/dist/web-extension-esm2017/src/core/util/location.d.ts +19 -0
  518. package/dist/web-extension-esm2017/src/core/util/log.d.ts +23 -0
  519. package/dist/web-extension-esm2017/src/core/util/navigator.d.ts +21 -0
  520. package/dist/web-extension-esm2017/src/core/util/providers.d.ts +23 -0
  521. package/dist/web-extension-esm2017/src/core/util/resolver.d.ts +25 -0
  522. package/dist/web-extension-esm2017/src/core/util/time.d.ts +17 -0
  523. package/dist/web-extension-esm2017/src/core/util/validate_origin.d.ts +18 -0
  524. package/dist/web-extension-esm2017/src/core/util/validate_origin.test.d.ts +17 -0
  525. package/dist/web-extension-esm2017/src/core/util/version.d.ts +31 -0
  526. package/dist/web-extension-esm2017/src/core/util/version.test.d.ts +17 -0
  527. package/dist/web-extension-esm2017/src/index.d.ts +18 -0
  528. package/dist/web-extension-esm2017/src/mfa/assertions/totp.d.ts +124 -0
  529. package/dist/web-extension-esm2017/src/mfa/assertions/totp.test.d.ts +17 -0
  530. package/dist/web-extension-esm2017/src/mfa/index.d.ts +18 -0
  531. package/dist/web-extension-esm2017/src/mfa/mfa_assertion.d.ts +27 -0
  532. package/dist/web-extension-esm2017/src/mfa/mfa_error.d.ts +35 -0
  533. package/dist/web-extension-esm2017/src/mfa/mfa_info.d.ts +36 -0
  534. package/dist/web-extension-esm2017/src/mfa/mfa_info.test.d.ts +17 -0
  535. package/dist/web-extension-esm2017/src/mfa/mfa_resolver.d.ts +41 -0
  536. package/dist/web-extension-esm2017/src/mfa/mfa_resolver.test.d.ts +17 -0
  537. package/dist/web-extension-esm2017/src/mfa/mfa_session.d.ts +39 -0
  538. package/dist/web-extension-esm2017/src/mfa/mfa_session.test.d.ts +17 -0
  539. package/dist/web-extension-esm2017/src/mfa/mfa_user.d.ts +38 -0
  540. package/dist/web-extension-esm2017/src/mfa/mfa_user.test.d.ts +17 -0
  541. package/dist/web-extension-esm2017/src/model/application_verifier.d.ts +23 -0
  542. package/dist/web-extension-esm2017/src/model/auth.d.ts +87 -0
  543. package/dist/web-extension-esm2017/src/model/enum_maps.d.ts +98 -0
  544. package/dist/web-extension-esm2017/src/model/enums.d.ts +74 -0
  545. package/dist/web-extension-esm2017/src/model/id_token.d.ts +87 -0
  546. package/dist/web-extension-esm2017/src/model/password_policy.d.ts +111 -0
  547. package/dist/web-extension-esm2017/src/model/popup_redirect.d.ts +94 -0
  548. package/dist/web-extension-esm2017/src/model/public_types.d.ts +1278 -0
  549. package/dist/web-extension-esm2017/src/model/user.d.ts +83 -0
  550. package/dist/web-extension-esm2017/src/platform_browser/auth.test.d.ts +17 -0
  551. package/dist/web-extension-esm2017/src/platform_browser/auth_window.d.ts +37 -0
  552. package/dist/web-extension-esm2017/src/platform_browser/iframe/gapi.d.ts +19 -0
  553. package/dist/web-extension-esm2017/src/platform_browser/iframe/gapi.iframes.d.ts +47 -0
  554. package/dist/web-extension-esm2017/src/platform_browser/iframe/gapi.test.d.ts +17 -0
  555. package/dist/web-extension-esm2017/src/platform_browser/iframe/iframe.d.ts +18 -0
  556. package/dist/web-extension-esm2017/src/platform_browser/iframe/iframe.test.d.ts +17 -0
  557. package/dist/web-extension-esm2017/src/platform_browser/index.d.ts +27 -0
  558. package/dist/web-extension-esm2017/src/platform_browser/load_js.d.ts +29 -0
  559. package/dist/web-extension-esm2017/src/platform_browser/load_js.test.d.ts +17 -0
  560. package/dist/web-extension-esm2017/src/platform_browser/messagechannel/index.d.ts +87 -0
  561. package/dist/web-extension-esm2017/src/platform_browser/messagechannel/promise.d.ts +33 -0
  562. package/dist/web-extension-esm2017/src/platform_browser/messagechannel/promise.test.d.ts +17 -0
  563. package/dist/web-extension-esm2017/src/platform_browser/messagechannel/receiver.d.ts +63 -0
  564. package/dist/web-extension-esm2017/src/platform_browser/messagechannel/receiver.test.d.ts +17 -0
  565. package/dist/web-extension-esm2017/src/platform_browser/messagechannel/sender.d.ts +46 -0
  566. package/dist/web-extension-esm2017/src/platform_browser/messagechannel/sender.test.d.ts +17 -0
  567. package/dist/web-extension-esm2017/src/platform_browser/mfa/assertions/phone.d.ts +59 -0
  568. package/dist/web-extension-esm2017/src/platform_browser/mfa/assertions/phone.test.d.ts +17 -0
  569. package/dist/web-extension-esm2017/src/platform_browser/persistence/browser.d.ts +27 -0
  570. package/dist/web-extension-esm2017/src/platform_browser/persistence/browser.test.d.ts +17 -0
  571. package/dist/web-extension-esm2017/src/platform_browser/persistence/indexed_db.d.ts +33 -0
  572. package/dist/web-extension-esm2017/src/platform_browser/persistence/indexed_db.test.d.ts +17 -0
  573. package/dist/web-extension-esm2017/src/platform_browser/persistence/local_storage.d.ts +25 -0
  574. package/dist/web-extension-esm2017/src/platform_browser/persistence/local_storage.test.d.ts +17 -0
  575. package/dist/web-extension-esm2017/src/platform_browser/persistence/session_storage.d.ts +24 -0
  576. package/dist/web-extension-esm2017/src/platform_browser/persistence/session_storage.test.d.ts +17 -0
  577. package/dist/web-extension-esm2017/src/platform_browser/popup_redirect.d.ts +27 -0
  578. package/dist/web-extension-esm2017/src/platform_browser/popup_redirect.test.d.ts +17 -0
  579. package/dist/web-extension-esm2017/src/platform_browser/providers/phone.d.ts +152 -0
  580. package/dist/web-extension-esm2017/src/platform_browser/providers/phone.test.d.ts +17 -0
  581. package/dist/web-extension-esm2017/src/platform_browser/recaptcha/recaptcha.d.ts +71 -0
  582. package/dist/web-extension-esm2017/src/platform_browser/recaptcha/recaptcha.test.d.ts +17 -0
  583. package/dist/web-extension-esm2017/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.d.ts +45 -0
  584. package/dist/web-extension-esm2017/src/platform_browser/recaptcha/recaptcha_enterprise_verifier.test.d.ts +17 -0
  585. package/dist/web-extension-esm2017/src/platform_browser/recaptcha/recaptcha_loader.d.ts +49 -0
  586. package/dist/web-extension-esm2017/src/platform_browser/recaptcha/recaptcha_loader.test.d.ts +17 -0
  587. package/dist/web-extension-esm2017/src/platform_browser/recaptcha/recaptcha_mock.d.ts +66 -0
  588. package/dist/web-extension-esm2017/src/platform_browser/recaptcha/recaptcha_mock.test.d.ts +17 -0
  589. package/dist/web-extension-esm2017/src/platform_browser/recaptcha/recaptcha_verifier.d.ts +92 -0
  590. package/dist/web-extension-esm2017/src/platform_browser/recaptcha/recaptcha_verifier.test.d.ts +17 -0
  591. package/dist/web-extension-esm2017/src/platform_browser/strategies/phone.d.ts +109 -0
  592. package/dist/web-extension-esm2017/src/platform_browser/strategies/phone.test.d.ts +17 -0
  593. package/dist/web-extension-esm2017/src/platform_browser/strategies/popup.d.ts +107 -0
  594. package/dist/web-extension-esm2017/src/platform_browser/strategies/popup.test.d.ts +17 -0
  595. package/dist/web-extension-esm2017/src/platform_browser/strategies/redirect.d.ts +172 -0
  596. package/dist/web-extension-esm2017/src/platform_browser/strategies/redirect.test.d.ts +17 -0
  597. package/dist/web-extension-esm2017/src/platform_browser/util/popup.d.ts +24 -0
  598. package/dist/web-extension-esm2017/src/platform_browser/util/popup.test.d.ts +17 -0
  599. package/dist/web-extension-esm2017/src/platform_browser/util/worker.d.ts +20 -0
  600. package/dist/web-extension-esm2017/src/platform_cordova/plugins.d.ts +42 -0
  601. package/dist/web-extension-esm2017/src/platform_cordova/popup_redirect/events.d.ts +39 -0
  602. package/dist/web-extension-esm2017/src/platform_cordova/popup_redirect/events.test.d.ts +17 -0
  603. package/dist/web-extension-esm2017/src/platform_cordova/popup_redirect/popup_redirect.d.ts +24 -0
  604. package/dist/web-extension-esm2017/src/platform_cordova/popup_redirect/popup_redirect.test.d.ts +17 -0
  605. package/dist/web-extension-esm2017/src/platform_cordova/popup_redirect/utils.d.ts +47 -0
  606. package/dist/web-extension-esm2017/src/platform_cordova/popup_redirect/utils.test.d.ts +17 -0
  607. package/dist/web-extension-esm2017/src/platform_cordova/strategies/redirect.d.ts +20 -0
  608. package/dist/web-extension-esm2017/src/platform_node/index.d.ts +50 -0
  609. package/dist/web-extension-esm2017/src/platform_react_native/persistence/react_native.d.ts +25 -0
  610. package/dist/web-extension-esm2017/src/platform_react_native/persistence/react_native.test.d.ts +17 -0
  611. package/dist/web-extension-esm2017/test/helpers/api/helper.d.ts +22 -0
  612. package/dist/web-extension-esm2017/test/helpers/delay.d.ts +20 -0
  613. package/dist/web-extension-esm2017/test/helpers/erroring_unavailable_persistence.d.ts +36 -0
  614. package/dist/web-extension-esm2017/test/helpers/fake_service_worker.d.ts +22 -0
  615. package/dist/web-extension-esm2017/test/helpers/id_token_response.d.ts +18 -0
  616. package/dist/web-extension-esm2017/test/helpers/iframe_event.d.ts +19 -0
  617. package/dist/web-extension-esm2017/test/helpers/integration/emulator_rest_helpers.d.ts +35 -0
  618. package/dist/web-extension-esm2017/test/helpers/integration/helpers.d.ts +30 -0
  619. package/dist/web-extension-esm2017/test/helpers/integration/settings.d.ts +23 -0
  620. package/dist/web-extension-esm2017/test/helpers/jwt.d.ts +17 -0
  621. package/dist/web-extension-esm2017/test/helpers/mock_auth.d.ts +47 -0
  622. package/dist/web-extension-esm2017/test/helpers/mock_auth_credential.d.ts +31 -0
  623. package/dist/web-extension-esm2017/test/helpers/mock_fetch.d.ts +30 -0
  624. package/dist/web-extension-esm2017/test/helpers/mock_fetch.test.d.ts +17 -0
  625. package/dist/web-extension-esm2017/test/helpers/mock_popup_redirect_resolver.d.ts +24 -0
  626. package/dist/web-extension-esm2017/test/helpers/redirect_persistence.d.ts +24 -0
  627. package/dist/web-extension-esm2017/test/helpers/timeout_stub.d.ts +34 -0
  628. package/dist/web-extension-esm2017/test/integration/flows/anonymous.test.d.ts +17 -0
  629. package/dist/web-extension-esm2017/test/integration/flows/custom.local.test.d.ts +17 -0
  630. package/dist/web-extension-esm2017/test/integration/flows/email.test.d.ts +17 -0
  631. package/dist/web-extension-esm2017/test/integration/flows/idp.local.test.d.ts +17 -0
  632. package/dist/web-extension-esm2017/test/integration/flows/middleware_test_generator.d.ts +18 -0
  633. package/dist/web-extension-esm2017/test/integration/flows/oob.local.test.d.ts +17 -0
  634. package/dist/web-extension-esm2017/test/integration/flows/password_policy.test.d.ts +17 -0
  635. package/dist/web-extension-esm2017/test/integration/flows/phone.test.d.ts +17 -0
  636. package/dist/web-extension-esm2017/test/integration/flows/totp.test.d.ts +17 -0
  637. package/dist/web-extension-esm2017/test/integration/webdriver/anonymous.test.d.ts +17 -0
  638. package/dist/web-extension-esm2017/test/integration/webdriver/compat/firebaseui.test.d.ts +17 -0
  639. package/dist/web-extension-esm2017/test/integration/webdriver/persistence.test.d.ts +17 -0
  640. package/dist/web-extension-esm2017/test/integration/webdriver/popup.test.d.ts +17 -0
  641. package/dist/web-extension-esm2017/test/integration/webdriver/redirect.test.d.ts +17 -0
  642. package/dist/web-extension-esm2017/test/integration/webdriver/util/auth_driver.d.ts +46 -0
  643. package/dist/web-extension-esm2017/test/integration/webdriver/util/functions.d.ts +81 -0
  644. package/dist/web-extension-esm2017/test/integration/webdriver/util/idp_page.d.ts +31 -0
  645. package/dist/web-extension-esm2017/test/integration/webdriver/util/js_load_condition.d.ts +25 -0
  646. package/dist/web-extension-esm2017/test/integration/webdriver/util/test_runner.d.ts +19 -0
  647. package/dist/web-extension-esm2017/test/integration/webdriver/util/test_server.d.ts +27 -0
  648. package/dist/web-extension-esm2017/test/integration/webdriver/util/ui_page.d.ts +33 -0
  649. package/package.json +20 -6
  650. package/web-extension/package.json +8 -0
  651. package/dist/browser-cjs/index-21814063.js.map +0 -1
  652. package/dist/cordova/popup_redirect-106f885f.js.map +0 -1
  653. package/dist/esm2017/index-dd468b12.js.map +0 -1
  654. package/dist/esm5/index-dd399a6e.js.map +0 -1
  655. package/dist/node/totp-fe65684a.js.map +0 -1
  656. package/dist/node-esm/totp-4c2d4e67.js.map +0 -1
  657. package/dist/rn/index-96ab5fb1.js.map +0 -1
@@ -0,0 +1,3350 @@
1
+ import { a8 as STORAGE_AVAILABLE_KEY, a9 as _isIframe, aa as _isMobileBrowser, ab as _isIE10, ac as _isSafari, ad as _isIOS, ae as _assert, af as Delay, ag as _window, ah as isV2, ai as _createError, aj as _recaptchaV2ScriptUrl, ak as _loadJS, al as _generateCallbackName, am as _castAuth, an as _isHttpOrHttps, ao as _isWorker, ap as getRecaptchaParams, z as signInWithCredential, aq as _assertLinkedStatus, B as linkWithCredential, C as reauthenticateWithCredential, ar as startEnrollPhoneMfa, as as startSignInPhoneMfa, at as sendPhoneVerificationCode, au as _link$1, P as PhoneAuthCredential, av as _getInstance, aw as _signInWithCredential, ax as _reauthenticate, m as AuthCredential, ay as signInWithIdp, az as _fail, aA as debugAssert, aB as _assertInstanceOf, aC as _generateEventId, aD as FederatedAuthProvider, aE as _persistenceKeyName, aF as _performApiRequest, aG as _getCurrentUrl, aH as _gapiScriptUrl, aI as _emulatorUrl, aJ as _isChromeIOS, aK as _isFirefox, aL as _isIOSStandalone, aM as BaseOAuthProvider, aN as _setWindowLocation, aO as MultiFactorAssertionImpl, aP as finalizeEnrollPhoneMfa, aQ as finalizeSignInPhoneMfa, r as registerAuth, i as initializeAuth, a as indexedDBLocalPersistence, e as beforeAuthStateChanged, o as onIdTokenChanged, c as connectAuthEmulator, aR as _setExternalJSProvider, aS as _isAndroid, aT as _isIOS7Or8 } from './register-ec86a01e.js';
2
+ export { Y as ActionCodeURL, m as AuthCredential, A as AuthErrorCodes, aV as AuthImpl, E as EmailAuthCredential, q as EmailAuthProvider, F as FacebookAuthProvider, aX as FetchProvider, t as GithubAuthProvider, G as GoogleAuthProvider, O as OAuthCredential, w as OAuthProvider, P as PhoneAuthCredential, aY as SAMLAuthCredential, S as SAMLAuthProvider, T as TotpMultiFactorGenerator, b as TotpSecret, x as TwitterAuthProvider, aU as UserImpl, ae as _assert, am as _castAuth, az as _fail, aC as _generateEventId, aW as _getClientVersion, av as _getInstance, aE as _persistenceKeyName, J as applyActionCode, e as beforeAuthStateChanged, K as checkActionCode, I as confirmPasswordReset, c as connectAuthEmulator, M as createUserWithEmailAndPassword, l as debugErrorMap, k as deleteUser, V as fetchSignInMethodsForEmail, a4 as getAdditionalUserInfo, a1 as getIdToken, a2 as getIdTokenResult, a6 as getMultiFactorResolver, n as inMemoryPersistence, a as indexedDBLocalPersistence, i as initializeAuth, d as initializeRecaptchaConfig, R as isSignInWithEmailLink, B as linkWithCredential, a7 as multiFactor, f as onAuthStateChanged, o as onIdTokenChanged, Z as parseActionCodeURL, p as prodErrorMap, C as reauthenticateWithCredential, a5 as reload, j as revokeAccessToken, W as sendEmailVerification, H as sendPasswordResetEmail, Q as sendSignInLinkToEmail, s as setPersistence, y as signInAnonymously, z as signInWithCredential, D as signInWithCustomToken, N as signInWithEmailAndPassword, U as signInWithEmailLink, h as signOut, a3 as unlink, g as updateCurrentUser, $ as updateEmail, a0 as updatePassword, _ as updateProfile, u as useDeviceLanguage, v as validatePassword, X as verifyBeforeUpdateEmail, L as verifyPasswordResetCode } from './register-ec86a01e.js';
3
+ import { getUA, querystring, getModularInstance, isEmpty, getExperimentalSetting, getDefaultEmulatorHost, querystringDecode } from '@firebase/util';
4
+ import 'tslib';
5
+ import { SDK_VERSION, _getProvider, getApp } from '@firebase/app';
6
+ import '@firebase/component';
7
+ import '@firebase/logger';
8
+
9
+ /**
10
+ * @license
11
+ * Copyright 2021 Google LLC
12
+ *
13
+ * Licensed under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License.
15
+ * You may obtain a copy of the License at
16
+ *
17
+ * http://www.apache.org/licenses/LICENSE-2.0
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software
20
+ * distributed under the License is distributed on an "AS IS" BASIS,
21
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ * See the License for the specific language governing permissions and
23
+ * limitations under the License.
24
+ */
25
+ /**
26
+ * An enum of factors that may be used for multifactor authentication.
27
+ *
28
+ * @public
29
+ */
30
+ const FactorId = {
31
+ /** Phone as second factor */
32
+ PHONE: 'phone',
33
+ TOTP: 'totp'
34
+ };
35
+ /**
36
+ * Enumeration of supported providers.
37
+ *
38
+ * @public
39
+ */
40
+ const ProviderId = {
41
+ /** Facebook provider ID */
42
+ FACEBOOK: 'facebook.com',
43
+ /** GitHub provider ID */
44
+ GITHUB: 'github.com',
45
+ /** Google provider ID */
46
+ GOOGLE: 'google.com',
47
+ /** Password provider */
48
+ PASSWORD: 'password',
49
+ /** Phone provider */
50
+ PHONE: 'phone',
51
+ /** Twitter provider ID */
52
+ TWITTER: 'twitter.com'
53
+ };
54
+ /**
55
+ * Enumeration of supported sign-in methods.
56
+ *
57
+ * @public
58
+ */
59
+ const SignInMethod = {
60
+ /** Email link sign in method */
61
+ EMAIL_LINK: 'emailLink',
62
+ /** Email/password sign in method */
63
+ EMAIL_PASSWORD: 'password',
64
+ /** Facebook sign in method */
65
+ FACEBOOK: 'facebook.com',
66
+ /** GitHub sign in method */
67
+ GITHUB: 'github.com',
68
+ /** Google sign in method */
69
+ GOOGLE: 'google.com',
70
+ /** Phone sign in method */
71
+ PHONE: 'phone',
72
+ /** Twitter sign in method */
73
+ TWITTER: 'twitter.com'
74
+ };
75
+ /**
76
+ * Enumeration of supported operation types.
77
+ *
78
+ * @public
79
+ */
80
+ const OperationType = {
81
+ /** Operation involving linking an additional provider to an already signed-in user. */
82
+ LINK: 'link',
83
+ /** Operation involving using a provider to reauthenticate an already signed-in user. */
84
+ REAUTHENTICATE: 'reauthenticate',
85
+ /** Operation involving signing in a user. */
86
+ SIGN_IN: 'signIn'
87
+ };
88
+ /**
89
+ * An enumeration of the possible email action types.
90
+ *
91
+ * @public
92
+ */
93
+ const ActionCodeOperation = {
94
+ /** The email link sign-in action. */
95
+ EMAIL_SIGNIN: 'EMAIL_SIGNIN',
96
+ /** The password reset action. */
97
+ PASSWORD_RESET: 'PASSWORD_RESET',
98
+ /** The email revocation action. */
99
+ RECOVER_EMAIL: 'RECOVER_EMAIL',
100
+ /** The revert second factor addition email action. */
101
+ REVERT_SECOND_FACTOR_ADDITION: 'REVERT_SECOND_FACTOR_ADDITION',
102
+ /** The revert second factor addition email action. */
103
+ VERIFY_AND_CHANGE_EMAIL: 'VERIFY_AND_CHANGE_EMAIL',
104
+ /** The email verification action. */
105
+ VERIFY_EMAIL: 'VERIFY_EMAIL'
106
+ };
107
+
108
+ /**
109
+ * @license
110
+ * Copyright 2019 Google LLC
111
+ *
112
+ * Licensed under the Apache License, Version 2.0 (the "License");
113
+ * you may not use this file except in compliance with the License.
114
+ * You may obtain a copy of the License at
115
+ *
116
+ * http://www.apache.org/licenses/LICENSE-2.0
117
+ *
118
+ * Unless required by applicable law or agreed to in writing, software
119
+ * distributed under the License is distributed on an "AS IS" BASIS,
120
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
121
+ * See the License for the specific language governing permissions and
122
+ * limitations under the License.
123
+ */
124
+ // There are two different browser persistence types: local and session.
125
+ // Both have the same implementation but use a different underlying storage
126
+ // object.
127
+ class BrowserPersistenceClass {
128
+ constructor(storageRetriever, type) {
129
+ this.storageRetriever = storageRetriever;
130
+ this.type = type;
131
+ }
132
+ _isAvailable() {
133
+ try {
134
+ if (!this.storage) {
135
+ return Promise.resolve(false);
136
+ }
137
+ this.storage.setItem(STORAGE_AVAILABLE_KEY, '1');
138
+ this.storage.removeItem(STORAGE_AVAILABLE_KEY);
139
+ return Promise.resolve(true);
140
+ }
141
+ catch (_a) {
142
+ return Promise.resolve(false);
143
+ }
144
+ }
145
+ _set(key, value) {
146
+ this.storage.setItem(key, JSON.stringify(value));
147
+ return Promise.resolve();
148
+ }
149
+ _get(key) {
150
+ const json = this.storage.getItem(key);
151
+ return Promise.resolve(json ? JSON.parse(json) : null);
152
+ }
153
+ _remove(key) {
154
+ this.storage.removeItem(key);
155
+ return Promise.resolve();
156
+ }
157
+ get storage() {
158
+ return this.storageRetriever();
159
+ }
160
+ }
161
+
162
+ /**
163
+ * @license
164
+ * Copyright 2020 Google LLC
165
+ *
166
+ * Licensed under the Apache License, Version 2.0 (the "License");
167
+ * you may not use this file except in compliance with the License.
168
+ * You may obtain a copy of the License at
169
+ *
170
+ * http://www.apache.org/licenses/LICENSE-2.0
171
+ *
172
+ * Unless required by applicable law or agreed to in writing, software
173
+ * distributed under the License is distributed on an "AS IS" BASIS,
174
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
175
+ * See the License for the specific language governing permissions and
176
+ * limitations under the License.
177
+ */
178
+ function _iframeCannotSyncWebStorage() {
179
+ const ua = getUA();
180
+ return _isSafari(ua) || _isIOS(ua);
181
+ }
182
+ // The polling period in case events are not supported
183
+ const _POLLING_INTERVAL_MS = 1000;
184
+ // The IE 10 localStorage cross tab synchronization delay in milliseconds
185
+ const IE10_LOCAL_STORAGE_SYNC_DELAY = 10;
186
+ class BrowserLocalPersistence extends BrowserPersistenceClass {
187
+ constructor() {
188
+ super(() => window.localStorage, "LOCAL" /* PersistenceType.LOCAL */);
189
+ this.boundEventHandler = (event, poll) => this.onStorageEvent(event, poll);
190
+ this.listeners = {};
191
+ this.localCache = {};
192
+ // setTimeout return value is platform specific
193
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
194
+ this.pollTimer = null;
195
+ // Safari or iOS browser and embedded in an iframe.
196
+ this.safariLocalStorageNotSynced = _iframeCannotSyncWebStorage() && _isIframe();
197
+ // Whether to use polling instead of depending on window events
198
+ this.fallbackToPolling = _isMobileBrowser();
199
+ this._shouldAllowMigration = true;
200
+ }
201
+ forAllChangedKeys(cb) {
202
+ // Check all keys with listeners on them.
203
+ for (const key of Object.keys(this.listeners)) {
204
+ // Get value from localStorage.
205
+ const newValue = this.storage.getItem(key);
206
+ const oldValue = this.localCache[key];
207
+ // If local map value does not match, trigger listener with storage event.
208
+ // Differentiate this simulated event from the real storage event.
209
+ if (newValue !== oldValue) {
210
+ cb(key, oldValue, newValue);
211
+ }
212
+ }
213
+ }
214
+ onStorageEvent(event, poll = false) {
215
+ // Key would be null in some situations, like when localStorage is cleared
216
+ if (!event.key) {
217
+ this.forAllChangedKeys((key, _oldValue, newValue) => {
218
+ this.notifyListeners(key, newValue);
219
+ });
220
+ return;
221
+ }
222
+ const key = event.key;
223
+ // Check the mechanism how this event was detected.
224
+ // The first event will dictate the mechanism to be used.
225
+ if (poll) {
226
+ // Environment detects storage changes via polling.
227
+ // Remove storage event listener to prevent possible event duplication.
228
+ this.detachListener();
229
+ }
230
+ else {
231
+ // Environment detects storage changes via storage event listener.
232
+ // Remove polling listener to prevent possible event duplication.
233
+ this.stopPolling();
234
+ }
235
+ // Safari embedded iframe. Storage event will trigger with the delta
236
+ // changes but no changes will be applied to the iframe localStorage.
237
+ if (this.safariLocalStorageNotSynced) {
238
+ // Get current iframe page value.
239
+ const storedValue = this.storage.getItem(key);
240
+ // Value not synchronized, synchronize manually.
241
+ if (event.newValue !== storedValue) {
242
+ if (event.newValue !== null) {
243
+ // Value changed from current value.
244
+ this.storage.setItem(key, event.newValue);
245
+ }
246
+ else {
247
+ // Current value deleted.
248
+ this.storage.removeItem(key);
249
+ }
250
+ }
251
+ else if (this.localCache[key] === event.newValue && !poll) {
252
+ // Already detected and processed, do not trigger listeners again.
253
+ return;
254
+ }
255
+ }
256
+ const triggerListeners = () => {
257
+ // Keep local map up to date in case storage event is triggered before
258
+ // poll.
259
+ const storedValue = this.storage.getItem(key);
260
+ if (!poll && this.localCache[key] === storedValue) {
261
+ // Real storage event which has already been detected, do nothing.
262
+ // This seems to trigger in some IE browsers for some reason.
263
+ return;
264
+ }
265
+ this.notifyListeners(key, storedValue);
266
+ };
267
+ const storedValue = this.storage.getItem(key);
268
+ if (_isIE10() &&
269
+ storedValue !== event.newValue &&
270
+ event.newValue !== event.oldValue) {
271
+ // IE 10 has this weird bug where a storage event would trigger with the
272
+ // correct key, oldValue and newValue but localStorage.getItem(key) does
273
+ // not yield the updated value until a few milliseconds. This ensures
274
+ // this recovers from that situation.
275
+ setTimeout(triggerListeners, IE10_LOCAL_STORAGE_SYNC_DELAY);
276
+ }
277
+ else {
278
+ triggerListeners();
279
+ }
280
+ }
281
+ notifyListeners(key, value) {
282
+ this.localCache[key] = value;
283
+ const listeners = this.listeners[key];
284
+ if (listeners) {
285
+ for (const listener of Array.from(listeners)) {
286
+ listener(value ? JSON.parse(value) : value);
287
+ }
288
+ }
289
+ }
290
+ startPolling() {
291
+ this.stopPolling();
292
+ this.pollTimer = setInterval(() => {
293
+ this.forAllChangedKeys((key, oldValue, newValue) => {
294
+ this.onStorageEvent(new StorageEvent('storage', {
295
+ key,
296
+ oldValue,
297
+ newValue
298
+ }),
299
+ /* poll */ true);
300
+ });
301
+ }, _POLLING_INTERVAL_MS);
302
+ }
303
+ stopPolling() {
304
+ if (this.pollTimer) {
305
+ clearInterval(this.pollTimer);
306
+ this.pollTimer = null;
307
+ }
308
+ }
309
+ attachListener() {
310
+ window.addEventListener('storage', this.boundEventHandler);
311
+ }
312
+ detachListener() {
313
+ window.removeEventListener('storage', this.boundEventHandler);
314
+ }
315
+ _addListener(key, listener) {
316
+ if (Object.keys(this.listeners).length === 0) {
317
+ // Whether browser can detect storage event when it had already been pushed to the background.
318
+ // This may happen in some mobile browsers. A localStorage change in the foreground window
319
+ // will not be detected in the background window via the storage event.
320
+ // This was detected in iOS 7.x mobile browsers
321
+ if (this.fallbackToPolling) {
322
+ this.startPolling();
323
+ }
324
+ else {
325
+ this.attachListener();
326
+ }
327
+ }
328
+ if (!this.listeners[key]) {
329
+ this.listeners[key] = new Set();
330
+ // Populate the cache to avoid spuriously triggering on first poll.
331
+ this.localCache[key] = this.storage.getItem(key);
332
+ }
333
+ this.listeners[key].add(listener);
334
+ }
335
+ _removeListener(key, listener) {
336
+ if (this.listeners[key]) {
337
+ this.listeners[key].delete(listener);
338
+ if (this.listeners[key].size === 0) {
339
+ delete this.listeners[key];
340
+ }
341
+ }
342
+ if (Object.keys(this.listeners).length === 0) {
343
+ this.detachListener();
344
+ this.stopPolling();
345
+ }
346
+ }
347
+ // Update local cache on base operations:
348
+ async _set(key, value) {
349
+ await super._set(key, value);
350
+ this.localCache[key] = JSON.stringify(value);
351
+ }
352
+ async _get(key) {
353
+ const value = await super._get(key);
354
+ this.localCache[key] = JSON.stringify(value);
355
+ return value;
356
+ }
357
+ async _remove(key) {
358
+ await super._remove(key);
359
+ delete this.localCache[key];
360
+ }
361
+ }
362
+ BrowserLocalPersistence.type = 'LOCAL';
363
+ /**
364
+ * An implementation of {@link Persistence} of type `LOCAL` using `localStorage`
365
+ * for the underlying storage.
366
+ *
367
+ * @public
368
+ */
369
+ const browserLocalPersistence = BrowserLocalPersistence;
370
+
371
+ /**
372
+ * @license
373
+ * Copyright 2020 Google LLC
374
+ *
375
+ * Licensed under the Apache License, Version 2.0 (the "License");
376
+ * you may not use this file except in compliance with the License.
377
+ * You may obtain a copy of the License at
378
+ *
379
+ * http://www.apache.org/licenses/LICENSE-2.0
380
+ *
381
+ * Unless required by applicable law or agreed to in writing, software
382
+ * distributed under the License is distributed on an "AS IS" BASIS,
383
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
384
+ * See the License for the specific language governing permissions and
385
+ * limitations under the License.
386
+ */
387
+ class BrowserSessionPersistence extends BrowserPersistenceClass {
388
+ constructor() {
389
+ super(() => window.sessionStorage, "SESSION" /* PersistenceType.SESSION */);
390
+ }
391
+ _addListener(_key, _listener) {
392
+ // Listeners are not supported for session storage since it cannot be shared across windows
393
+ return;
394
+ }
395
+ _removeListener(_key, _listener) {
396
+ // Listeners are not supported for session storage since it cannot be shared across windows
397
+ return;
398
+ }
399
+ }
400
+ BrowserSessionPersistence.type = 'SESSION';
401
+ /**
402
+ * An implementation of {@link Persistence} of `SESSION` using `sessionStorage`
403
+ * for the underlying storage.
404
+ *
405
+ * @public
406
+ */
407
+ const browserSessionPersistence = BrowserSessionPersistence;
408
+
409
+ /**
410
+ * @license
411
+ * Copyright 2020 Google LLC
412
+ *
413
+ * Licensed under the Apache License, Version 2.0 (the "License");
414
+ * you may not use this file except in compliance with the License.
415
+ * You may obtain a copy of the License at
416
+ *
417
+ * http://www.apache.org/licenses/LICENSE-2.0
418
+ *
419
+ * Unless required by applicable law or agreed to in writing, software
420
+ * distributed under the License is distributed on an "AS IS" BASIS,
421
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
422
+ * See the License for the specific language governing permissions and
423
+ * limitations under the License.
424
+ */
425
+ const _SOLVE_TIME_MS = 500;
426
+ const _EXPIRATION_TIME_MS = 60000;
427
+ const _WIDGET_ID_START = 1000000000000;
428
+ class MockReCaptcha {
429
+ constructor(auth) {
430
+ this.auth = auth;
431
+ this.counter = _WIDGET_ID_START;
432
+ this._widgets = new Map();
433
+ }
434
+ render(container, parameters) {
435
+ const id = this.counter;
436
+ this._widgets.set(id, new MockWidget(container, this.auth.name, parameters || {}));
437
+ this.counter++;
438
+ return id;
439
+ }
440
+ reset(optWidgetId) {
441
+ var _a;
442
+ const id = optWidgetId || _WIDGET_ID_START;
443
+ void ((_a = this._widgets.get(id)) === null || _a === void 0 ? void 0 : _a.delete());
444
+ this._widgets.delete(id);
445
+ }
446
+ getResponse(optWidgetId) {
447
+ var _a;
448
+ const id = optWidgetId || _WIDGET_ID_START;
449
+ return ((_a = this._widgets.get(id)) === null || _a === void 0 ? void 0 : _a.getResponse()) || '';
450
+ }
451
+ async execute(optWidgetId) {
452
+ var _a;
453
+ const id = optWidgetId || _WIDGET_ID_START;
454
+ void ((_a = this._widgets.get(id)) === null || _a === void 0 ? void 0 : _a.execute());
455
+ return '';
456
+ }
457
+ }
458
+ class MockWidget {
459
+ constructor(containerOrId, appName, params) {
460
+ this.params = params;
461
+ this.timerId = null;
462
+ this.deleted = false;
463
+ this.responseToken = null;
464
+ this.clickHandler = () => {
465
+ this.execute();
466
+ };
467
+ const container = typeof containerOrId === 'string'
468
+ ? document.getElementById(containerOrId)
469
+ : containerOrId;
470
+ _assert(container, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */, { appName });
471
+ this.container = container;
472
+ this.isVisible = this.params.size !== 'invisible';
473
+ if (this.isVisible) {
474
+ this.execute();
475
+ }
476
+ else {
477
+ this.container.addEventListener('click', this.clickHandler);
478
+ }
479
+ }
480
+ getResponse() {
481
+ this.checkIfDeleted();
482
+ return this.responseToken;
483
+ }
484
+ delete() {
485
+ this.checkIfDeleted();
486
+ this.deleted = true;
487
+ if (this.timerId) {
488
+ clearTimeout(this.timerId);
489
+ this.timerId = null;
490
+ }
491
+ this.container.removeEventListener('click', this.clickHandler);
492
+ }
493
+ execute() {
494
+ this.checkIfDeleted();
495
+ if (this.timerId) {
496
+ return;
497
+ }
498
+ this.timerId = window.setTimeout(() => {
499
+ this.responseToken = generateRandomAlphaNumericString(50);
500
+ const { callback, 'expired-callback': expiredCallback } = this.params;
501
+ if (callback) {
502
+ try {
503
+ callback(this.responseToken);
504
+ }
505
+ catch (e) { }
506
+ }
507
+ this.timerId = window.setTimeout(() => {
508
+ this.timerId = null;
509
+ this.responseToken = null;
510
+ if (expiredCallback) {
511
+ try {
512
+ expiredCallback();
513
+ }
514
+ catch (e) { }
515
+ }
516
+ if (this.isVisible) {
517
+ this.execute();
518
+ }
519
+ }, _EXPIRATION_TIME_MS);
520
+ }, _SOLVE_TIME_MS);
521
+ }
522
+ checkIfDeleted() {
523
+ if (this.deleted) {
524
+ throw new Error('reCAPTCHA mock was already deleted!');
525
+ }
526
+ }
527
+ }
528
+ function generateRandomAlphaNumericString(len) {
529
+ const chars = [];
530
+ const allowedChars = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
531
+ for (let i = 0; i < len; i++) {
532
+ chars.push(allowedChars.charAt(Math.floor(Math.random() * allowedChars.length)));
533
+ }
534
+ return chars.join('');
535
+ }
536
+
537
+ /**
538
+ * @license
539
+ * Copyright 2020 Google LLC
540
+ *
541
+ * Licensed under the Apache License, Version 2.0 (the "License");
542
+ * you may not use this file except in compliance with the License.
543
+ * You may obtain a copy of the License at
544
+ *
545
+ * http://www.apache.org/licenses/LICENSE-2.0
546
+ *
547
+ * Unless required by applicable law or agreed to in writing, software
548
+ * distributed under the License is distributed on an "AS IS" BASIS,
549
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
550
+ * See the License for the specific language governing permissions and
551
+ * limitations under the License.
552
+ */
553
+ // ReCaptcha will load using the same callback, so the callback function needs
554
+ // to be kept around
555
+ const _JSLOAD_CALLBACK = _generateCallbackName('rcb');
556
+ const NETWORK_TIMEOUT_DELAY = new Delay(30000, 60000);
557
+ /**
558
+ * Loader for the GReCaptcha library. There should only ever be one of this.
559
+ */
560
+ class ReCaptchaLoaderImpl {
561
+ constructor() {
562
+ var _a;
563
+ this.hostLanguage = '';
564
+ this.counter = 0;
565
+ /**
566
+ * Check for `render()` method. `window.grecaptcha` will exist if the Enterprise
567
+ * version of the ReCAPTCHA script was loaded by someone else (e.g. App Check) but
568
+ * `window.grecaptcha.render()` will not. Another load will add it.
569
+ */
570
+ this.librarySeparatelyLoaded = !!((_a = _window().grecaptcha) === null || _a === void 0 ? void 0 : _a.render);
571
+ }
572
+ load(auth, hl = '') {
573
+ _assert(isHostLanguageValid(hl), auth, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
574
+ if (this.shouldResolveImmediately(hl) && isV2(_window().grecaptcha)) {
575
+ return Promise.resolve(_window().grecaptcha);
576
+ }
577
+ return new Promise((resolve, reject) => {
578
+ const networkTimeout = _window().setTimeout(() => {
579
+ reject(_createError(auth, "network-request-failed" /* AuthErrorCode.NETWORK_REQUEST_FAILED */));
580
+ }, NETWORK_TIMEOUT_DELAY.get());
581
+ _window()[_JSLOAD_CALLBACK] = () => {
582
+ _window().clearTimeout(networkTimeout);
583
+ delete _window()[_JSLOAD_CALLBACK];
584
+ const recaptcha = _window().grecaptcha;
585
+ if (!recaptcha || !isV2(recaptcha)) {
586
+ reject(_createError(auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */));
587
+ return;
588
+ }
589
+ // Wrap the greptcha render function so that we know if the developer has
590
+ // called it separately
591
+ const render = recaptcha.render;
592
+ recaptcha.render = (container, params) => {
593
+ const widgetId = render(container, params);
594
+ this.counter++;
595
+ return widgetId;
596
+ };
597
+ this.hostLanguage = hl;
598
+ resolve(recaptcha);
599
+ };
600
+ const url = `${_recaptchaV2ScriptUrl()}?${querystring({
601
+ onload: _JSLOAD_CALLBACK,
602
+ render: 'explicit',
603
+ hl
604
+ })}`;
605
+ _loadJS(url).catch(() => {
606
+ clearTimeout(networkTimeout);
607
+ reject(_createError(auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */));
608
+ });
609
+ });
610
+ }
611
+ clearedOneInstance() {
612
+ this.counter--;
613
+ }
614
+ shouldResolveImmediately(hl) {
615
+ var _a;
616
+ // We can resolve immediately if:
617
+ // • grecaptcha is already defined AND (
618
+ // 1. the requested language codes are the same OR
619
+ // 2. there exists already a ReCaptcha on the page
620
+ // 3. the library was already loaded by the app
621
+ // In cases (2) and (3), we _can't_ reload as it would break the recaptchas
622
+ // that are already in the page
623
+ return (!!((_a = _window().grecaptcha) === null || _a === void 0 ? void 0 : _a.render) &&
624
+ (hl === this.hostLanguage ||
625
+ this.counter > 0 ||
626
+ this.librarySeparatelyLoaded));
627
+ }
628
+ }
629
+ function isHostLanguageValid(hl) {
630
+ return hl.length <= 6 && /^\s*[a-zA-Z0-9\-]*\s*$/.test(hl);
631
+ }
632
+ class MockReCaptchaLoaderImpl {
633
+ async load(auth) {
634
+ return new MockReCaptcha(auth);
635
+ }
636
+ clearedOneInstance() { }
637
+ }
638
+
639
+ /**
640
+ * @license
641
+ * Copyright 2020 Google LLC
642
+ *
643
+ * Licensed under the Apache License, Version 2.0 (the "License");
644
+ * you may not use this file except in compliance with the License.
645
+ * You may obtain a copy of the License at
646
+ *
647
+ * http://www.apache.org/licenses/LICENSE-2.0
648
+ *
649
+ * Unless required by applicable law or agreed to in writing, software
650
+ * distributed under the License is distributed on an "AS IS" BASIS,
651
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
652
+ * See the License for the specific language governing permissions and
653
+ * limitations under the License.
654
+ */
655
+ const RECAPTCHA_VERIFIER_TYPE = 'recaptcha';
656
+ const DEFAULT_PARAMS = {
657
+ theme: 'light',
658
+ type: 'image'
659
+ };
660
+ /**
661
+ * An {@link https://www.google.com/recaptcha/ | reCAPTCHA}-based application verifier.
662
+ *
663
+ * @remarks
664
+ * `RecaptchaVerifier` does not work in a Node.js environment.
665
+ *
666
+ * @public
667
+ */
668
+ class RecaptchaVerifier {
669
+ /**
670
+ * @param authExtern - The corresponding Firebase {@link Auth} instance.
671
+ *
672
+ * @param containerOrId - The reCAPTCHA container parameter.
673
+ *
674
+ * @remarks
675
+ * This has different meaning depending on whether the reCAPTCHA is hidden or visible. For a
676
+ * visible reCAPTCHA the container must be empty. If a string is used, it has to correspond to
677
+ * an element ID. The corresponding element must also must be in the DOM at the time of
678
+ * initialization.
679
+ *
680
+ * @param parameters - The optional reCAPTCHA parameters.
681
+ *
682
+ * @remarks
683
+ * Check the reCAPTCHA docs for a comprehensive list. All parameters are accepted except for
684
+ * the sitekey. Firebase Auth backend provisions a reCAPTCHA for each project and will
685
+ * configure this upon rendering. For an invisible reCAPTCHA, a size key must have the value
686
+ * 'invisible'.
687
+ */
688
+ constructor(authExtern, containerOrId, parameters = Object.assign({}, DEFAULT_PARAMS)) {
689
+ this.parameters = parameters;
690
+ /**
691
+ * The application verifier type.
692
+ *
693
+ * @remarks
694
+ * For a reCAPTCHA verifier, this is 'recaptcha'.
695
+ */
696
+ this.type = RECAPTCHA_VERIFIER_TYPE;
697
+ this.destroyed = false;
698
+ this.widgetId = null;
699
+ this.tokenChangeListeners = new Set();
700
+ this.renderPromise = null;
701
+ this.recaptcha = null;
702
+ this.auth = _castAuth(authExtern);
703
+ this.isInvisible = this.parameters.size === 'invisible';
704
+ _assert(typeof document !== 'undefined', this.auth, "operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */);
705
+ const container = typeof containerOrId === 'string'
706
+ ? document.getElementById(containerOrId)
707
+ : containerOrId;
708
+ _assert(container, this.auth, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
709
+ this.container = container;
710
+ this.parameters.callback = this.makeTokenCallback(this.parameters.callback);
711
+ this._recaptchaLoader = this.auth.settings.appVerificationDisabledForTesting
712
+ ? new MockReCaptchaLoaderImpl()
713
+ : new ReCaptchaLoaderImpl();
714
+ this.validateStartingState();
715
+ // TODO: Figure out if sdk version is needed
716
+ }
717
+ /**
718
+ * Waits for the user to solve the reCAPTCHA and resolves with the reCAPTCHA token.
719
+ *
720
+ * @returns A Promise for the reCAPTCHA token.
721
+ */
722
+ async verify() {
723
+ this.assertNotDestroyed();
724
+ const id = await this.render();
725
+ const recaptcha = this.getAssertedRecaptcha();
726
+ const response = recaptcha.getResponse(id);
727
+ if (response) {
728
+ return response;
729
+ }
730
+ return new Promise(resolve => {
731
+ const tokenChange = (token) => {
732
+ if (!token) {
733
+ return; // Ignore token expirations.
734
+ }
735
+ this.tokenChangeListeners.delete(tokenChange);
736
+ resolve(token);
737
+ };
738
+ this.tokenChangeListeners.add(tokenChange);
739
+ if (this.isInvisible) {
740
+ recaptcha.execute(id);
741
+ }
742
+ });
743
+ }
744
+ /**
745
+ * Renders the reCAPTCHA widget on the page.
746
+ *
747
+ * @returns A Promise that resolves with the reCAPTCHA widget ID.
748
+ */
749
+ render() {
750
+ try {
751
+ this.assertNotDestroyed();
752
+ }
753
+ catch (e) {
754
+ // This method returns a promise. Since it's not async (we want to return the
755
+ // _same_ promise if rendering is still occurring), the API surface should
756
+ // reject with the error rather than just throw
757
+ return Promise.reject(e);
758
+ }
759
+ if (this.renderPromise) {
760
+ return this.renderPromise;
761
+ }
762
+ this.renderPromise = this.makeRenderPromise().catch(e => {
763
+ this.renderPromise = null;
764
+ throw e;
765
+ });
766
+ return this.renderPromise;
767
+ }
768
+ /** @internal */
769
+ _reset() {
770
+ this.assertNotDestroyed();
771
+ if (this.widgetId !== null) {
772
+ this.getAssertedRecaptcha().reset(this.widgetId);
773
+ }
774
+ }
775
+ /**
776
+ * Clears the reCAPTCHA widget from the page and destroys the instance.
777
+ */
778
+ clear() {
779
+ this.assertNotDestroyed();
780
+ this.destroyed = true;
781
+ this._recaptchaLoader.clearedOneInstance();
782
+ if (!this.isInvisible) {
783
+ this.container.childNodes.forEach(node => {
784
+ this.container.removeChild(node);
785
+ });
786
+ }
787
+ }
788
+ validateStartingState() {
789
+ _assert(!this.parameters.sitekey, this.auth, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
790
+ _assert(this.isInvisible || !this.container.hasChildNodes(), this.auth, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
791
+ _assert(typeof document !== 'undefined', this.auth, "operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */);
792
+ }
793
+ makeTokenCallback(existing) {
794
+ return token => {
795
+ this.tokenChangeListeners.forEach(listener => listener(token));
796
+ if (typeof existing === 'function') {
797
+ existing(token);
798
+ }
799
+ else if (typeof existing === 'string') {
800
+ const globalFunc = _window()[existing];
801
+ if (typeof globalFunc === 'function') {
802
+ globalFunc(token);
803
+ }
804
+ }
805
+ };
806
+ }
807
+ assertNotDestroyed() {
808
+ _assert(!this.destroyed, this.auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
809
+ }
810
+ async makeRenderPromise() {
811
+ await this.init();
812
+ if (!this.widgetId) {
813
+ let container = this.container;
814
+ if (!this.isInvisible) {
815
+ const guaranteedEmpty = document.createElement('div');
816
+ container.appendChild(guaranteedEmpty);
817
+ container = guaranteedEmpty;
818
+ }
819
+ this.widgetId = this.getAssertedRecaptcha().render(container, this.parameters);
820
+ }
821
+ return this.widgetId;
822
+ }
823
+ async init() {
824
+ _assert(_isHttpOrHttps() && !_isWorker(), this.auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
825
+ await domReady();
826
+ this.recaptcha = await this._recaptchaLoader.load(this.auth, this.auth.languageCode || undefined);
827
+ const siteKey = await getRecaptchaParams(this.auth);
828
+ _assert(siteKey, this.auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
829
+ this.parameters.sitekey = siteKey;
830
+ }
831
+ getAssertedRecaptcha() {
832
+ _assert(this.recaptcha, this.auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
833
+ return this.recaptcha;
834
+ }
835
+ }
836
+ function domReady() {
837
+ let resolver = null;
838
+ return new Promise(resolve => {
839
+ if (document.readyState === 'complete') {
840
+ resolve();
841
+ return;
842
+ }
843
+ // Document not ready, wait for load before resolving.
844
+ // Save resolver, so we can remove listener in case it was externally
845
+ // cancelled.
846
+ resolver = () => resolve();
847
+ window.addEventListener('load', resolver);
848
+ }).catch(e => {
849
+ if (resolver) {
850
+ window.removeEventListener('load', resolver);
851
+ }
852
+ throw e;
853
+ });
854
+ }
855
+
856
+ /**
857
+ * @license
858
+ * Copyright 2020 Google LLC
859
+ *
860
+ * Licensed under the Apache License, Version 2.0 (the "License");
861
+ * you may not use this file except in compliance with the License.
862
+ * You may obtain a copy of the License at
863
+ *
864
+ * http://www.apache.org/licenses/LICENSE-2.0
865
+ *
866
+ * Unless required by applicable law or agreed to in writing, software
867
+ * distributed under the License is distributed on an "AS IS" BASIS,
868
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
869
+ * See the License for the specific language governing permissions and
870
+ * limitations under the License.
871
+ */
872
+ class ConfirmationResultImpl {
873
+ constructor(verificationId, onConfirmation) {
874
+ this.verificationId = verificationId;
875
+ this.onConfirmation = onConfirmation;
876
+ }
877
+ confirm(verificationCode) {
878
+ const authCredential = PhoneAuthCredential._fromVerification(this.verificationId, verificationCode);
879
+ return this.onConfirmation(authCredential);
880
+ }
881
+ }
882
+ /**
883
+ * Asynchronously signs in using a phone number.
884
+ *
885
+ * @remarks
886
+ * This method sends a code via SMS to the given
887
+ * phone number, and returns a {@link ConfirmationResult}. After the user
888
+ * provides the code sent to their phone, call {@link ConfirmationResult.confirm}
889
+ * with the code to sign the user in.
890
+ *
891
+ * For abuse prevention, this method also requires a {@link ApplicationVerifier}.
892
+ * This SDK includes a reCAPTCHA-based implementation, {@link RecaptchaVerifier}.
893
+ * This function can work on other platforms that do not support the
894
+ * {@link RecaptchaVerifier} (like React Native), but you need to use a
895
+ * third-party {@link ApplicationVerifier} implementation.
896
+ *
897
+ * This method does not work in a Node.js environment.
898
+ *
899
+ * @example
900
+ * ```javascript
901
+ * // 'recaptcha-container' is the ID of an element in the DOM.
902
+ * const applicationVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container');
903
+ * const confirmationResult = await signInWithPhoneNumber(auth, phoneNumber, applicationVerifier);
904
+ * // Obtain a verificationCode from the user.
905
+ * const credential = await confirmationResult.confirm(verificationCode);
906
+ * ```
907
+ *
908
+ * @param auth - The {@link Auth} instance.
909
+ * @param phoneNumber - The user's phone number in E.164 format (e.g. +16505550101).
910
+ * @param appVerifier - The {@link ApplicationVerifier}.
911
+ *
912
+ * @public
913
+ */
914
+ async function signInWithPhoneNumber(auth, phoneNumber, appVerifier) {
915
+ const authInternal = _castAuth(auth);
916
+ const verificationId = await _verifyPhoneNumber(authInternal, phoneNumber, getModularInstance(appVerifier));
917
+ return new ConfirmationResultImpl(verificationId, cred => signInWithCredential(authInternal, cred));
918
+ }
919
+ /**
920
+ * Links the user account with the given phone number.
921
+ *
922
+ * @remarks
923
+ * This method does not work in a Node.js environment.
924
+ *
925
+ * @param user - The user.
926
+ * @param phoneNumber - The user's phone number in E.164 format (e.g. +16505550101).
927
+ * @param appVerifier - The {@link ApplicationVerifier}.
928
+ *
929
+ * @public
930
+ */
931
+ async function linkWithPhoneNumber(user, phoneNumber, appVerifier) {
932
+ const userInternal = getModularInstance(user);
933
+ await _assertLinkedStatus(false, userInternal, "phone" /* ProviderId.PHONE */);
934
+ const verificationId = await _verifyPhoneNumber(userInternal.auth, phoneNumber, getModularInstance(appVerifier));
935
+ return new ConfirmationResultImpl(verificationId, cred => linkWithCredential(userInternal, cred));
936
+ }
937
+ /**
938
+ * Re-authenticates a user using a fresh phone credential.
939
+ *
940
+ * @remarks
941
+ * Use before operations such as {@link updatePassword} that require tokens from recent sign-in attempts.
942
+ *
943
+ * This method does not work in a Node.js environment.
944
+ *
945
+ * @param user - The user.
946
+ * @param phoneNumber - The user's phone number in E.164 format (e.g. +16505550101).
947
+ * @param appVerifier - The {@link ApplicationVerifier}.
948
+ *
949
+ * @public
950
+ */
951
+ async function reauthenticateWithPhoneNumber(user, phoneNumber, appVerifier) {
952
+ const userInternal = getModularInstance(user);
953
+ const verificationId = await _verifyPhoneNumber(userInternal.auth, phoneNumber, getModularInstance(appVerifier));
954
+ return new ConfirmationResultImpl(verificationId, cred => reauthenticateWithCredential(userInternal, cred));
955
+ }
956
+ /**
957
+ * Returns a verification ID to be used in conjunction with the SMS code that is sent.
958
+ *
959
+ */
960
+ async function _verifyPhoneNumber(auth, options, verifier) {
961
+ var _a;
962
+ const recaptchaToken = await verifier.verify();
963
+ try {
964
+ _assert(typeof recaptchaToken === 'string', auth, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
965
+ _assert(verifier.type === RECAPTCHA_VERIFIER_TYPE, auth, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
966
+ let phoneInfoOptions;
967
+ if (typeof options === 'string') {
968
+ phoneInfoOptions = {
969
+ phoneNumber: options
970
+ };
971
+ }
972
+ else {
973
+ phoneInfoOptions = options;
974
+ }
975
+ if ('session' in phoneInfoOptions) {
976
+ const session = phoneInfoOptions.session;
977
+ if ('phoneNumber' in phoneInfoOptions) {
978
+ _assert(session.type === "enroll" /* MultiFactorSessionType.ENROLL */, auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
979
+ const response = await startEnrollPhoneMfa(auth, {
980
+ idToken: session.credential,
981
+ phoneEnrollmentInfo: {
982
+ phoneNumber: phoneInfoOptions.phoneNumber,
983
+ recaptchaToken
984
+ }
985
+ });
986
+ return response.phoneSessionInfo.sessionInfo;
987
+ }
988
+ else {
989
+ _assert(session.type === "signin" /* MultiFactorSessionType.SIGN_IN */, auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
990
+ const mfaEnrollmentId = ((_a = phoneInfoOptions.multiFactorHint) === null || _a === void 0 ? void 0 : _a.uid) ||
991
+ phoneInfoOptions.multiFactorUid;
992
+ _assert(mfaEnrollmentId, auth, "missing-multi-factor-info" /* AuthErrorCode.MISSING_MFA_INFO */);
993
+ const response = await startSignInPhoneMfa(auth, {
994
+ mfaPendingCredential: session.credential,
995
+ mfaEnrollmentId,
996
+ phoneSignInInfo: {
997
+ recaptchaToken
998
+ }
999
+ });
1000
+ return response.phoneResponseInfo.sessionInfo;
1001
+ }
1002
+ }
1003
+ else {
1004
+ const { sessionInfo } = await sendPhoneVerificationCode(auth, {
1005
+ phoneNumber: phoneInfoOptions.phoneNumber,
1006
+ recaptchaToken
1007
+ });
1008
+ return sessionInfo;
1009
+ }
1010
+ }
1011
+ finally {
1012
+ verifier._reset();
1013
+ }
1014
+ }
1015
+ /**
1016
+ * Updates the user's phone number.
1017
+ *
1018
+ * @remarks
1019
+ * This method does not work in a Node.js environment.
1020
+ *
1021
+ * @example
1022
+ * ```
1023
+ * // 'recaptcha-container' is the ID of an element in the DOM.
1024
+ * const applicationVerifier = new RecaptchaVerifier('recaptcha-container');
1025
+ * const provider = new PhoneAuthProvider(auth);
1026
+ * const verificationId = await provider.verifyPhoneNumber('+16505550101', applicationVerifier);
1027
+ * // Obtain the verificationCode from the user.
1028
+ * const phoneCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
1029
+ * await updatePhoneNumber(user, phoneCredential);
1030
+ * ```
1031
+ *
1032
+ * @param user - The user.
1033
+ * @param credential - A credential authenticating the new phone number.
1034
+ *
1035
+ * @public
1036
+ */
1037
+ async function updatePhoneNumber(user, credential) {
1038
+ await _link$1(getModularInstance(user), credential);
1039
+ }
1040
+
1041
+ /**
1042
+ * @license
1043
+ * Copyright 2020 Google LLC
1044
+ *
1045
+ * Licensed under the Apache License, Version 2.0 (the "License");
1046
+ * you may not use this file except in compliance with the License.
1047
+ * You may obtain a copy of the License at
1048
+ *
1049
+ * http://www.apache.org/licenses/LICENSE-2.0
1050
+ *
1051
+ * Unless required by applicable law or agreed to in writing, software
1052
+ * distributed under the License is distributed on an "AS IS" BASIS,
1053
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1054
+ * See the License for the specific language governing permissions and
1055
+ * limitations under the License.
1056
+ */
1057
+ /**
1058
+ * Provider for generating an {@link PhoneAuthCredential}.
1059
+ *
1060
+ * @remarks
1061
+ * `PhoneAuthProvider` does not work in a Node.js environment.
1062
+ *
1063
+ * @example
1064
+ * ```javascript
1065
+ * // 'recaptcha-container' is the ID of an element in the DOM.
1066
+ * const applicationVerifier = new RecaptchaVerifier('recaptcha-container');
1067
+ * const provider = new PhoneAuthProvider(auth);
1068
+ * const verificationId = await provider.verifyPhoneNumber('+16505550101', applicationVerifier);
1069
+ * // Obtain the verificationCode from the user.
1070
+ * const phoneCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
1071
+ * const userCredential = await signInWithCredential(auth, phoneCredential);
1072
+ * ```
1073
+ *
1074
+ * @public
1075
+ */
1076
+ class PhoneAuthProvider {
1077
+ /**
1078
+ * @param auth - The Firebase {@link Auth} instance in which sign-ins should occur.
1079
+ *
1080
+ */
1081
+ constructor(auth) {
1082
+ /** Always set to {@link ProviderId}.PHONE. */
1083
+ this.providerId = PhoneAuthProvider.PROVIDER_ID;
1084
+ this.auth = _castAuth(auth);
1085
+ }
1086
+ /**
1087
+ *
1088
+ * Starts a phone number authentication flow by sending a verification code to the given phone
1089
+ * number.
1090
+ *
1091
+ * @example
1092
+ * ```javascript
1093
+ * const provider = new PhoneAuthProvider(auth);
1094
+ * const verificationId = await provider.verifyPhoneNumber(phoneNumber, applicationVerifier);
1095
+ * // Obtain verificationCode from the user.
1096
+ * const authCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
1097
+ * const userCredential = await signInWithCredential(auth, authCredential);
1098
+ * ```
1099
+ *
1100
+ * @example
1101
+ * An alternative flow is provided using the `signInWithPhoneNumber` method.
1102
+ * ```javascript
1103
+ * const confirmationResult = signInWithPhoneNumber(auth, phoneNumber, applicationVerifier);
1104
+ * // Obtain verificationCode from the user.
1105
+ * const userCredential = confirmationResult.confirm(verificationCode);
1106
+ * ```
1107
+ *
1108
+ * @param phoneInfoOptions - The user's {@link PhoneInfoOptions}. The phone number should be in
1109
+ * E.164 format (e.g. +16505550101).
1110
+ * @param applicationVerifier - For abuse prevention, this method also requires a
1111
+ * {@link ApplicationVerifier}. This SDK includes a reCAPTCHA-based implementation,
1112
+ * {@link RecaptchaVerifier}.
1113
+ *
1114
+ * @returns A Promise for a verification ID that can be passed to
1115
+ * {@link PhoneAuthProvider.credential} to identify this flow..
1116
+ */
1117
+ verifyPhoneNumber(phoneOptions, applicationVerifier) {
1118
+ return _verifyPhoneNumber(this.auth, phoneOptions, getModularInstance(applicationVerifier));
1119
+ }
1120
+ /**
1121
+ * Creates a phone auth credential, given the verification ID from
1122
+ * {@link PhoneAuthProvider.verifyPhoneNumber} and the code that was sent to the user's
1123
+ * mobile device.
1124
+ *
1125
+ * @example
1126
+ * ```javascript
1127
+ * const provider = new PhoneAuthProvider(auth);
1128
+ * const verificationId = provider.verifyPhoneNumber(phoneNumber, applicationVerifier);
1129
+ * // Obtain verificationCode from the user.
1130
+ * const authCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
1131
+ * const userCredential = signInWithCredential(auth, authCredential);
1132
+ * ```
1133
+ *
1134
+ * @example
1135
+ * An alternative flow is provided using the `signInWithPhoneNumber` method.
1136
+ * ```javascript
1137
+ * const confirmationResult = await signInWithPhoneNumber(auth, phoneNumber, applicationVerifier);
1138
+ * // Obtain verificationCode from the user.
1139
+ * const userCredential = await confirmationResult.confirm(verificationCode);
1140
+ * ```
1141
+ *
1142
+ * @param verificationId - The verification ID returned from {@link PhoneAuthProvider.verifyPhoneNumber}.
1143
+ * @param verificationCode - The verification code sent to the user's mobile device.
1144
+ *
1145
+ * @returns The auth provider credential.
1146
+ */
1147
+ static credential(verificationId, verificationCode) {
1148
+ return PhoneAuthCredential._fromVerification(verificationId, verificationCode);
1149
+ }
1150
+ /**
1151
+ * Generates an {@link AuthCredential} from a {@link UserCredential}.
1152
+ * @param userCredential - The user credential.
1153
+ */
1154
+ static credentialFromResult(userCredential) {
1155
+ const credential = userCredential;
1156
+ return PhoneAuthProvider.credentialFromTaggedObject(credential);
1157
+ }
1158
+ /**
1159
+ * Returns an {@link AuthCredential} when passed an error.
1160
+ *
1161
+ * @remarks
1162
+ *
1163
+ * This method works for errors like
1164
+ * `auth/account-exists-with-different-credentials`. This is useful for
1165
+ * recovering when attempting to set a user's phone number but the number
1166
+ * in question is already tied to another account. For example, the following
1167
+ * code tries to update the current user's phone number, and if that
1168
+ * fails, links the user with the account associated with that number:
1169
+ *
1170
+ * ```js
1171
+ * const provider = new PhoneAuthProvider(auth);
1172
+ * const verificationId = await provider.verifyPhoneNumber(number, verifier);
1173
+ * try {
1174
+ * const code = ''; // Prompt the user for the verification code
1175
+ * await updatePhoneNumber(
1176
+ * auth.currentUser,
1177
+ * PhoneAuthProvider.credential(verificationId, code));
1178
+ * } catch (e) {
1179
+ * if ((e as FirebaseError)?.code === 'auth/account-exists-with-different-credential') {
1180
+ * const cred = PhoneAuthProvider.credentialFromError(e);
1181
+ * await linkWithCredential(auth.currentUser, cred);
1182
+ * }
1183
+ * }
1184
+ *
1185
+ * // At this point, auth.currentUser.phoneNumber === number.
1186
+ * ```
1187
+ *
1188
+ * @param error - The error to generate a credential from.
1189
+ */
1190
+ static credentialFromError(error) {
1191
+ return PhoneAuthProvider.credentialFromTaggedObject((error.customData || {}));
1192
+ }
1193
+ static credentialFromTaggedObject({ _tokenResponse: tokenResponse }) {
1194
+ if (!tokenResponse) {
1195
+ return null;
1196
+ }
1197
+ const { phoneNumber, temporaryProof } = tokenResponse;
1198
+ if (phoneNumber && temporaryProof) {
1199
+ return PhoneAuthCredential._fromTokenResponse(phoneNumber, temporaryProof);
1200
+ }
1201
+ return null;
1202
+ }
1203
+ }
1204
+ /** Always set to {@link ProviderId}.PHONE. */
1205
+ PhoneAuthProvider.PROVIDER_ID = "phone" /* ProviderId.PHONE */;
1206
+ /** Always set to {@link SignInMethod}.PHONE. */
1207
+ PhoneAuthProvider.PHONE_SIGN_IN_METHOD = "phone" /* SignInMethod.PHONE */;
1208
+
1209
+ /**
1210
+ * @license
1211
+ * Copyright 2021 Google LLC
1212
+ *
1213
+ * Licensed under the Apache License, Version 2.0 (the "License");
1214
+ * you may not use this file except in compliance with the License.
1215
+ * You may obtain a copy of the License at
1216
+ *
1217
+ * http://www.apache.org/licenses/LICENSE-2.0
1218
+ *
1219
+ * Unless required by applicable law or agreed to in writing, software
1220
+ * distributed under the License is distributed on an "AS IS" BASIS,
1221
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1222
+ * See the License for the specific language governing permissions and
1223
+ * limitations under the License.
1224
+ */
1225
+ /**
1226
+ * Chooses a popup/redirect resolver to use. This prefers the override (which
1227
+ * is directly passed in), and falls back to the property set on the auth
1228
+ * object. If neither are available, this function errors w/ an argument error.
1229
+ */
1230
+ function _withDefaultResolver(auth, resolverOverride) {
1231
+ if (resolverOverride) {
1232
+ return _getInstance(resolverOverride);
1233
+ }
1234
+ _assert(auth._popupRedirectResolver, auth, "argument-error" /* AuthErrorCode.ARGUMENT_ERROR */);
1235
+ return auth._popupRedirectResolver;
1236
+ }
1237
+
1238
+ /**
1239
+ * @license
1240
+ * Copyright 2019 Google LLC
1241
+ *
1242
+ * Licensed under the Apache License, Version 2.0 (the "License");
1243
+ * you may not use this file except in compliance with the License.
1244
+ * You may obtain a copy of the License at
1245
+ *
1246
+ * http://www.apache.org/licenses/LICENSE-2.0
1247
+ *
1248
+ * Unless required by applicable law or agreed to in writing, software
1249
+ * distributed under the License is distributed on an "AS IS" BASIS,
1250
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1251
+ * See the License for the specific language governing permissions and
1252
+ * limitations under the License.
1253
+ */
1254
+ class IdpCredential extends AuthCredential {
1255
+ constructor(params) {
1256
+ super("custom" /* ProviderId.CUSTOM */, "custom" /* ProviderId.CUSTOM */);
1257
+ this.params = params;
1258
+ }
1259
+ _getIdTokenResponse(auth) {
1260
+ return signInWithIdp(auth, this._buildIdpRequest());
1261
+ }
1262
+ _linkToIdToken(auth, idToken) {
1263
+ return signInWithIdp(auth, this._buildIdpRequest(idToken));
1264
+ }
1265
+ _getReauthenticationResolver(auth) {
1266
+ return signInWithIdp(auth, this._buildIdpRequest());
1267
+ }
1268
+ _buildIdpRequest(idToken) {
1269
+ const request = {
1270
+ requestUri: this.params.requestUri,
1271
+ sessionId: this.params.sessionId,
1272
+ postBody: this.params.postBody,
1273
+ tenantId: this.params.tenantId,
1274
+ pendingToken: this.params.pendingToken,
1275
+ returnSecureToken: true,
1276
+ returnIdpCredential: true
1277
+ };
1278
+ if (idToken) {
1279
+ request.idToken = idToken;
1280
+ }
1281
+ return request;
1282
+ }
1283
+ }
1284
+ function _signIn(params) {
1285
+ return _signInWithCredential(params.auth, new IdpCredential(params), params.bypassAuthState);
1286
+ }
1287
+ function _reauth(params) {
1288
+ const { auth, user } = params;
1289
+ _assert(user, auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
1290
+ return _reauthenticate(user, new IdpCredential(params), params.bypassAuthState);
1291
+ }
1292
+ async function _link(params) {
1293
+ const { auth, user } = params;
1294
+ _assert(user, auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
1295
+ return _link$1(user, new IdpCredential(params), params.bypassAuthState);
1296
+ }
1297
+
1298
+ /**
1299
+ * @license
1300
+ * Copyright 2020 Google LLC
1301
+ *
1302
+ * Licensed under the Apache License, Version 2.0 (the "License");
1303
+ * you may not use this file except in compliance with the License.
1304
+ * You may obtain a copy of the License at
1305
+ *
1306
+ * http://www.apache.org/licenses/LICENSE-2.0
1307
+ *
1308
+ * Unless required by applicable law or agreed to in writing, software
1309
+ * distributed under the License is distributed on an "AS IS" BASIS,
1310
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1311
+ * See the License for the specific language governing permissions and
1312
+ * limitations under the License.
1313
+ */
1314
+ /**
1315
+ * Popup event manager. Handles the popup's entire lifecycle; listens to auth
1316
+ * events
1317
+ */
1318
+ class AbstractPopupRedirectOperation {
1319
+ constructor(auth, filter, resolver, user, bypassAuthState = false) {
1320
+ this.auth = auth;
1321
+ this.resolver = resolver;
1322
+ this.user = user;
1323
+ this.bypassAuthState = bypassAuthState;
1324
+ this.pendingPromise = null;
1325
+ this.eventManager = null;
1326
+ this.filter = Array.isArray(filter) ? filter : [filter];
1327
+ }
1328
+ execute() {
1329
+ return new Promise(async (resolve, reject) => {
1330
+ this.pendingPromise = { resolve, reject };
1331
+ try {
1332
+ this.eventManager = await this.resolver._initialize(this.auth);
1333
+ await this.onExecution();
1334
+ this.eventManager.registerConsumer(this);
1335
+ }
1336
+ catch (e) {
1337
+ this.reject(e);
1338
+ }
1339
+ });
1340
+ }
1341
+ async onAuthEvent(event) {
1342
+ const { urlResponse, sessionId, postBody, tenantId, error, type } = event;
1343
+ if (error) {
1344
+ this.reject(error);
1345
+ return;
1346
+ }
1347
+ const params = {
1348
+ auth: this.auth,
1349
+ requestUri: urlResponse,
1350
+ sessionId: sessionId,
1351
+ tenantId: tenantId || undefined,
1352
+ postBody: postBody || undefined,
1353
+ user: this.user,
1354
+ bypassAuthState: this.bypassAuthState
1355
+ };
1356
+ try {
1357
+ this.resolve(await this.getIdpTask(type)(params));
1358
+ }
1359
+ catch (e) {
1360
+ this.reject(e);
1361
+ }
1362
+ }
1363
+ onError(error) {
1364
+ this.reject(error);
1365
+ }
1366
+ getIdpTask(type) {
1367
+ switch (type) {
1368
+ case "signInViaPopup" /* AuthEventType.SIGN_IN_VIA_POPUP */:
1369
+ case "signInViaRedirect" /* AuthEventType.SIGN_IN_VIA_REDIRECT */:
1370
+ return _signIn;
1371
+ case "linkViaPopup" /* AuthEventType.LINK_VIA_POPUP */:
1372
+ case "linkViaRedirect" /* AuthEventType.LINK_VIA_REDIRECT */:
1373
+ return _link;
1374
+ case "reauthViaPopup" /* AuthEventType.REAUTH_VIA_POPUP */:
1375
+ case "reauthViaRedirect" /* AuthEventType.REAUTH_VIA_REDIRECT */:
1376
+ return _reauth;
1377
+ default:
1378
+ _fail(this.auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
1379
+ }
1380
+ }
1381
+ resolve(cred) {
1382
+ debugAssert(this.pendingPromise, 'Pending promise was never set');
1383
+ this.pendingPromise.resolve(cred);
1384
+ this.unregisterAndCleanUp();
1385
+ }
1386
+ reject(error) {
1387
+ debugAssert(this.pendingPromise, 'Pending promise was never set');
1388
+ this.pendingPromise.reject(error);
1389
+ this.unregisterAndCleanUp();
1390
+ }
1391
+ unregisterAndCleanUp() {
1392
+ if (this.eventManager) {
1393
+ this.eventManager.unregisterConsumer(this);
1394
+ }
1395
+ this.pendingPromise = null;
1396
+ this.cleanUp();
1397
+ }
1398
+ }
1399
+
1400
+ /**
1401
+ * @license
1402
+ * Copyright 2020 Google LLC
1403
+ *
1404
+ * Licensed under the Apache License, Version 2.0 (the "License");
1405
+ * you may not use this file except in compliance with the License.
1406
+ * You may obtain a copy of the License at
1407
+ *
1408
+ * http://www.apache.org/licenses/LICENSE-2.0
1409
+ *
1410
+ * Unless required by applicable law or agreed to in writing, software
1411
+ * distributed under the License is distributed on an "AS IS" BASIS,
1412
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1413
+ * See the License for the specific language governing permissions and
1414
+ * limitations under the License.
1415
+ */
1416
+ const _POLL_WINDOW_CLOSE_TIMEOUT = new Delay(2000, 10000);
1417
+ /**
1418
+ * Authenticates a Firebase client using a popup-based OAuth authentication flow.
1419
+ *
1420
+ * @remarks
1421
+ * If succeeds, returns the signed in user along with the provider's credential. If sign in was
1422
+ * unsuccessful, returns an error object containing additional information about the error.
1423
+ *
1424
+ * This method does not work in a Node.js environment.
1425
+ *
1426
+ * @example
1427
+ * ```javascript
1428
+ * // Sign in using a popup.
1429
+ * const provider = new FacebookAuthProvider();
1430
+ * const result = await signInWithPopup(auth, provider);
1431
+ *
1432
+ * // The signed-in user info.
1433
+ * const user = result.user;
1434
+ * // This gives you a Facebook Access Token.
1435
+ * const credential = provider.credentialFromResult(auth, result);
1436
+ * const token = credential.accessToken;
1437
+ * ```
1438
+ *
1439
+ * @param auth - The {@link Auth} instance.
1440
+ * @param provider - The provider to authenticate. The provider has to be an {@link OAuthProvider}.
1441
+ * Non-OAuth providers like {@link EmailAuthProvider} will throw an error.
1442
+ * @param resolver - An instance of {@link PopupRedirectResolver}, optional
1443
+ * if already supplied to {@link initializeAuth} or provided by {@link getAuth}.
1444
+ *
1445
+ * @public
1446
+ */
1447
+ async function signInWithPopup(auth, provider, resolver) {
1448
+ const authInternal = _castAuth(auth);
1449
+ _assertInstanceOf(auth, provider, FederatedAuthProvider);
1450
+ const resolverInternal = _withDefaultResolver(authInternal, resolver);
1451
+ const action = new PopupOperation(authInternal, "signInViaPopup" /* AuthEventType.SIGN_IN_VIA_POPUP */, provider, resolverInternal);
1452
+ return action.executeNotNull();
1453
+ }
1454
+ /**
1455
+ * Reauthenticates the current user with the specified {@link OAuthProvider} using a pop-up based
1456
+ * OAuth flow.
1457
+ *
1458
+ * @remarks
1459
+ * If the reauthentication is successful, the returned result will contain the user and the
1460
+ * provider's credential.
1461
+ *
1462
+ * This method does not work in a Node.js environment.
1463
+ *
1464
+ * @example
1465
+ * ```javascript
1466
+ * // Sign in using a popup.
1467
+ * const provider = new FacebookAuthProvider();
1468
+ * const result = await signInWithPopup(auth, provider);
1469
+ * // Reauthenticate using a popup.
1470
+ * await reauthenticateWithPopup(result.user, provider);
1471
+ * ```
1472
+ *
1473
+ * @param user - The user.
1474
+ * @param provider - The provider to authenticate. The provider has to be an {@link OAuthProvider}.
1475
+ * Non-OAuth providers like {@link EmailAuthProvider} will throw an error.
1476
+ * @param resolver - An instance of {@link PopupRedirectResolver}, optional
1477
+ * if already supplied to {@link initializeAuth} or provided by {@link getAuth}.
1478
+ *
1479
+ * @public
1480
+ */
1481
+ async function reauthenticateWithPopup(user, provider, resolver) {
1482
+ const userInternal = getModularInstance(user);
1483
+ _assertInstanceOf(userInternal.auth, provider, FederatedAuthProvider);
1484
+ const resolverInternal = _withDefaultResolver(userInternal.auth, resolver);
1485
+ const action = new PopupOperation(userInternal.auth, "reauthViaPopup" /* AuthEventType.REAUTH_VIA_POPUP */, provider, resolverInternal, userInternal);
1486
+ return action.executeNotNull();
1487
+ }
1488
+ /**
1489
+ * Links the authenticated provider to the user account using a pop-up based OAuth flow.
1490
+ *
1491
+ * @remarks
1492
+ * If the linking is successful, the returned result will contain the user and the provider's credential.
1493
+ *
1494
+ * This method does not work in a Node.js environment.
1495
+ *
1496
+ * @example
1497
+ * ```javascript
1498
+ * // Sign in using some other provider.
1499
+ * const result = await signInWithEmailAndPassword(auth, email, password);
1500
+ * // Link using a popup.
1501
+ * const provider = new FacebookAuthProvider();
1502
+ * await linkWithPopup(result.user, provider);
1503
+ * ```
1504
+ *
1505
+ * @param user - The user.
1506
+ * @param provider - The provider to authenticate. The provider has to be an {@link OAuthProvider}.
1507
+ * Non-OAuth providers like {@link EmailAuthProvider} will throw an error.
1508
+ * @param resolver - An instance of {@link PopupRedirectResolver}, optional
1509
+ * if already supplied to {@link initializeAuth} or provided by {@link getAuth}.
1510
+ *
1511
+ * @public
1512
+ */
1513
+ async function linkWithPopup(user, provider, resolver) {
1514
+ const userInternal = getModularInstance(user);
1515
+ _assertInstanceOf(userInternal.auth, provider, FederatedAuthProvider);
1516
+ const resolverInternal = _withDefaultResolver(userInternal.auth, resolver);
1517
+ const action = new PopupOperation(userInternal.auth, "linkViaPopup" /* AuthEventType.LINK_VIA_POPUP */, provider, resolverInternal, userInternal);
1518
+ return action.executeNotNull();
1519
+ }
1520
+ /**
1521
+ * Popup event manager. Handles the popup's entire lifecycle; listens to auth
1522
+ * events
1523
+ *
1524
+ */
1525
+ class PopupOperation extends AbstractPopupRedirectOperation {
1526
+ constructor(auth, filter, provider, resolver, user) {
1527
+ super(auth, filter, resolver, user);
1528
+ this.provider = provider;
1529
+ this.authWindow = null;
1530
+ this.pollId = null;
1531
+ if (PopupOperation.currentPopupAction) {
1532
+ PopupOperation.currentPopupAction.cancel();
1533
+ }
1534
+ PopupOperation.currentPopupAction = this;
1535
+ }
1536
+ async executeNotNull() {
1537
+ const result = await this.execute();
1538
+ _assert(result, this.auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
1539
+ return result;
1540
+ }
1541
+ async onExecution() {
1542
+ debugAssert(this.filter.length === 1, 'Popup operations only handle one event');
1543
+ const eventId = _generateEventId();
1544
+ this.authWindow = await this.resolver._openPopup(this.auth, this.provider, this.filter[0], // There's always one, see constructor
1545
+ eventId);
1546
+ this.authWindow.associatedEvent = eventId;
1547
+ // Check for web storage support and origin validation _after_ the popup is
1548
+ // loaded. These operations are slow (~1 second or so) Rather than
1549
+ // waiting on them before opening the window, optimistically open the popup
1550
+ // and check for storage support at the same time. If storage support is
1551
+ // not available, this will cause the whole thing to reject properly. It
1552
+ // will also close the popup, but since the promise has already rejected,
1553
+ // the popup closed by user poll will reject into the void.
1554
+ this.resolver._originValidation(this.auth).catch(e => {
1555
+ this.reject(e);
1556
+ });
1557
+ this.resolver._isIframeWebStorageSupported(this.auth, isSupported => {
1558
+ if (!isSupported) {
1559
+ this.reject(_createError(this.auth, "web-storage-unsupported" /* AuthErrorCode.WEB_STORAGE_UNSUPPORTED */));
1560
+ }
1561
+ });
1562
+ // Handle user closure. Notice this does *not* use await
1563
+ this.pollUserCancellation();
1564
+ }
1565
+ get eventId() {
1566
+ var _a;
1567
+ return ((_a = this.authWindow) === null || _a === void 0 ? void 0 : _a.associatedEvent) || null;
1568
+ }
1569
+ cancel() {
1570
+ this.reject(_createError(this.auth, "cancelled-popup-request" /* AuthErrorCode.EXPIRED_POPUP_REQUEST */));
1571
+ }
1572
+ cleanUp() {
1573
+ if (this.authWindow) {
1574
+ this.authWindow.close();
1575
+ }
1576
+ if (this.pollId) {
1577
+ window.clearTimeout(this.pollId);
1578
+ }
1579
+ this.authWindow = null;
1580
+ this.pollId = null;
1581
+ PopupOperation.currentPopupAction = null;
1582
+ }
1583
+ pollUserCancellation() {
1584
+ const poll = () => {
1585
+ var _a, _b;
1586
+ if ((_b = (_a = this.authWindow) === null || _a === void 0 ? void 0 : _a.window) === null || _b === void 0 ? void 0 : _b.closed) {
1587
+ // Make sure that there is sufficient time for whatever action to
1588
+ // complete. The window could have closed but the sign in network
1589
+ // call could still be in flight. This is specifically true for
1590
+ // Firefox or if the opener is in an iframe, in which case the oauth
1591
+ // helper closes the popup.
1592
+ this.pollId = window.setTimeout(() => {
1593
+ this.pollId = null;
1594
+ this.reject(_createError(this.auth, "popup-closed-by-user" /* AuthErrorCode.POPUP_CLOSED_BY_USER */));
1595
+ }, 8000 /* _Timeout.AUTH_EVENT */);
1596
+ return;
1597
+ }
1598
+ this.pollId = window.setTimeout(poll, _POLL_WINDOW_CLOSE_TIMEOUT.get());
1599
+ };
1600
+ poll();
1601
+ }
1602
+ }
1603
+ // Only one popup is ever shown at once. The lifecycle of the current popup
1604
+ // can be managed / cancelled by the constructor.
1605
+ PopupOperation.currentPopupAction = null;
1606
+
1607
+ /**
1608
+ * @license
1609
+ * Copyright 2020 Google LLC
1610
+ *
1611
+ * Licensed under the Apache License, Version 2.0 (the "License");
1612
+ * you may not use this file except in compliance with the License.
1613
+ * You may obtain a copy of the License at
1614
+ *
1615
+ * http://www.apache.org/licenses/LICENSE-2.0
1616
+ *
1617
+ * Unless required by applicable law or agreed to in writing, software
1618
+ * distributed under the License is distributed on an "AS IS" BASIS,
1619
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1620
+ * See the License for the specific language governing permissions and
1621
+ * limitations under the License.
1622
+ */
1623
+ const PENDING_REDIRECT_KEY = 'pendingRedirect';
1624
+ // We only get one redirect outcome for any one auth, so just store it
1625
+ // in here.
1626
+ const redirectOutcomeMap = new Map();
1627
+ class RedirectAction extends AbstractPopupRedirectOperation {
1628
+ constructor(auth, resolver, bypassAuthState = false) {
1629
+ super(auth, [
1630
+ "signInViaRedirect" /* AuthEventType.SIGN_IN_VIA_REDIRECT */,
1631
+ "linkViaRedirect" /* AuthEventType.LINK_VIA_REDIRECT */,
1632
+ "reauthViaRedirect" /* AuthEventType.REAUTH_VIA_REDIRECT */,
1633
+ "unknown" /* AuthEventType.UNKNOWN */
1634
+ ], resolver, undefined, bypassAuthState);
1635
+ this.eventId = null;
1636
+ }
1637
+ /**
1638
+ * Override the execute function; if we already have a redirect result, then
1639
+ * just return it.
1640
+ */
1641
+ async execute() {
1642
+ let readyOutcome = redirectOutcomeMap.get(this.auth._key());
1643
+ if (!readyOutcome) {
1644
+ try {
1645
+ const hasPendingRedirect = await _getAndClearPendingRedirectStatus(this.resolver, this.auth);
1646
+ const result = hasPendingRedirect ? await super.execute() : null;
1647
+ readyOutcome = () => Promise.resolve(result);
1648
+ }
1649
+ catch (e) {
1650
+ readyOutcome = () => Promise.reject(e);
1651
+ }
1652
+ redirectOutcomeMap.set(this.auth._key(), readyOutcome);
1653
+ }
1654
+ // If we're not bypassing auth state, the ready outcome should be set to
1655
+ // null.
1656
+ if (!this.bypassAuthState) {
1657
+ redirectOutcomeMap.set(this.auth._key(), () => Promise.resolve(null));
1658
+ }
1659
+ return readyOutcome();
1660
+ }
1661
+ async onAuthEvent(event) {
1662
+ if (event.type === "signInViaRedirect" /* AuthEventType.SIGN_IN_VIA_REDIRECT */) {
1663
+ return super.onAuthEvent(event);
1664
+ }
1665
+ else if (event.type === "unknown" /* AuthEventType.UNKNOWN */) {
1666
+ // This is a sentinel value indicating there's no pending redirect
1667
+ this.resolve(null);
1668
+ return;
1669
+ }
1670
+ if (event.eventId) {
1671
+ const user = await this.auth._redirectUserForId(event.eventId);
1672
+ if (user) {
1673
+ this.user = user;
1674
+ return super.onAuthEvent(event);
1675
+ }
1676
+ else {
1677
+ this.resolve(null);
1678
+ }
1679
+ }
1680
+ }
1681
+ async onExecution() { }
1682
+ cleanUp() { }
1683
+ }
1684
+ async function _getAndClearPendingRedirectStatus(resolver, auth) {
1685
+ const key = pendingRedirectKey(auth);
1686
+ const persistence = resolverPersistence(resolver);
1687
+ if (!(await persistence._isAvailable())) {
1688
+ return false;
1689
+ }
1690
+ const hasPendingRedirect = (await persistence._get(key)) === 'true';
1691
+ await persistence._remove(key);
1692
+ return hasPendingRedirect;
1693
+ }
1694
+ async function _setPendingRedirectStatus(resolver, auth) {
1695
+ return resolverPersistence(resolver)._set(pendingRedirectKey(auth), 'true');
1696
+ }
1697
+ function _clearRedirectOutcomes() {
1698
+ redirectOutcomeMap.clear();
1699
+ }
1700
+ function _overrideRedirectResult(auth, result) {
1701
+ redirectOutcomeMap.set(auth._key(), result);
1702
+ }
1703
+ function resolverPersistence(resolver) {
1704
+ return _getInstance(resolver._redirectPersistence);
1705
+ }
1706
+ function pendingRedirectKey(auth) {
1707
+ return _persistenceKeyName(PENDING_REDIRECT_KEY, auth.config.apiKey, auth.name);
1708
+ }
1709
+
1710
+ /**
1711
+ * @license
1712
+ * Copyright 2020 Google LLC
1713
+ *
1714
+ * Licensed under the Apache License, Version 2.0 (the "License");
1715
+ * you may not use this file except in compliance with the License.
1716
+ * You may obtain a copy of the License at
1717
+ *
1718
+ * http://www.apache.org/licenses/LICENSE-2.0
1719
+ *
1720
+ * Unless required by applicable law or agreed to in writing, software
1721
+ * distributed under the License is distributed on an "AS IS" BASIS,
1722
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1723
+ * See the License for the specific language governing permissions and
1724
+ * limitations under the License.
1725
+ */
1726
+ /**
1727
+ * Authenticates a Firebase client using a full-page redirect flow.
1728
+ *
1729
+ * @remarks
1730
+ * To handle the results and errors for this operation, refer to {@link getRedirectResult}.
1731
+ * Follow the {@link https://firebase.google.com/docs/auth/web/redirect-best-practices
1732
+ * | best practices} when using {@link signInWithRedirect}.
1733
+ *
1734
+ * This method does not work in a Node.js environment.
1735
+ *
1736
+ * @example
1737
+ * ```javascript
1738
+ * // Sign in using a redirect.
1739
+ * const provider = new FacebookAuthProvider();
1740
+ * // You can add additional scopes to the provider:
1741
+ * provider.addScope('user_birthday');
1742
+ * // Start a sign in process for an unauthenticated user.
1743
+ * await signInWithRedirect(auth, provider);
1744
+ * // This will trigger a full page redirect away from your app
1745
+ *
1746
+ * // After returning from the redirect when your app initializes you can obtain the result
1747
+ * const result = await getRedirectResult(auth);
1748
+ * if (result) {
1749
+ * // This is the signed-in user
1750
+ * const user = result.user;
1751
+ * // This gives you a Facebook Access Token.
1752
+ * const credential = provider.credentialFromResult(auth, result);
1753
+ * const token = credential.accessToken;
1754
+ * }
1755
+ * // As this API can be used for sign-in, linking and reauthentication,
1756
+ * // check the operationType to determine what triggered this redirect
1757
+ * // operation.
1758
+ * const operationType = result.operationType;
1759
+ * ```
1760
+ *
1761
+ * @param auth - The {@link Auth} instance.
1762
+ * @param provider - The provider to authenticate. The provider has to be an {@link OAuthProvider}.
1763
+ * Non-OAuth providers like {@link EmailAuthProvider} will throw an error.
1764
+ * @param resolver - An instance of {@link PopupRedirectResolver}, optional
1765
+ * if already supplied to {@link initializeAuth} or provided by {@link getAuth}.
1766
+ *
1767
+ * @public
1768
+ */
1769
+ function signInWithRedirect(auth, provider, resolver) {
1770
+ return _signInWithRedirect(auth, provider, resolver);
1771
+ }
1772
+ async function _signInWithRedirect(auth, provider, resolver) {
1773
+ const authInternal = _castAuth(auth);
1774
+ _assertInstanceOf(auth, provider, FederatedAuthProvider);
1775
+ // Wait for auth initialization to complete, this will process pending redirects and clear the
1776
+ // PENDING_REDIRECT_KEY in persistence. This should be completed before starting a new
1777
+ // redirect and creating a PENDING_REDIRECT_KEY entry.
1778
+ await authInternal._initializationPromise;
1779
+ const resolverInternal = _withDefaultResolver(authInternal, resolver);
1780
+ await _setPendingRedirectStatus(resolverInternal, authInternal);
1781
+ return resolverInternal._openRedirect(authInternal, provider, "signInViaRedirect" /* AuthEventType.SIGN_IN_VIA_REDIRECT */);
1782
+ }
1783
+ /**
1784
+ * Reauthenticates the current user with the specified {@link OAuthProvider} using a full-page redirect flow.
1785
+ * @remarks
1786
+ * To handle the results and errors for this operation, refer to {@link getRedirectResult}.
1787
+ * Follow the {@link https://firebase.google.com/docs/auth/web/redirect-best-practices
1788
+ * | best practices} when using {@link reauthenticateWithRedirect}.
1789
+ *
1790
+ * This method does not work in a Node.js environment.
1791
+ *
1792
+ * @example
1793
+ * ```javascript
1794
+ * // Sign in using a redirect.
1795
+ * const provider = new FacebookAuthProvider();
1796
+ * const result = await signInWithRedirect(auth, provider);
1797
+ * // This will trigger a full page redirect away from your app
1798
+ *
1799
+ * // After returning from the redirect when your app initializes you can obtain the result
1800
+ * const result = await getRedirectResult(auth);
1801
+ * // Reauthenticate using a redirect.
1802
+ * await reauthenticateWithRedirect(result.user, provider);
1803
+ * // This will again trigger a full page redirect away from your app
1804
+ *
1805
+ * // After returning from the redirect when your app initializes you can obtain the result
1806
+ * const result = await getRedirectResult(auth);
1807
+ * ```
1808
+ *
1809
+ * @param user - The user.
1810
+ * @param provider - The provider to authenticate. The provider has to be an {@link OAuthProvider}.
1811
+ * Non-OAuth providers like {@link EmailAuthProvider} will throw an error.
1812
+ * @param resolver - An instance of {@link PopupRedirectResolver}, optional
1813
+ * if already supplied to {@link initializeAuth} or provided by {@link getAuth}.
1814
+ *
1815
+ * @public
1816
+ */
1817
+ function reauthenticateWithRedirect(user, provider, resolver) {
1818
+ return _reauthenticateWithRedirect(user, provider, resolver);
1819
+ }
1820
+ async function _reauthenticateWithRedirect(user, provider, resolver) {
1821
+ const userInternal = getModularInstance(user);
1822
+ _assertInstanceOf(userInternal.auth, provider, FederatedAuthProvider);
1823
+ // Wait for auth initialization to complete, this will process pending redirects and clear the
1824
+ // PENDING_REDIRECT_KEY in persistence. This should be completed before starting a new
1825
+ // redirect and creating a PENDING_REDIRECT_KEY entry.
1826
+ await userInternal.auth._initializationPromise;
1827
+ // Allow the resolver to error before persisting the redirect user
1828
+ const resolverInternal = _withDefaultResolver(userInternal.auth, resolver);
1829
+ await _setPendingRedirectStatus(resolverInternal, userInternal.auth);
1830
+ const eventId = await prepareUserForRedirect(userInternal);
1831
+ return resolverInternal._openRedirect(userInternal.auth, provider, "reauthViaRedirect" /* AuthEventType.REAUTH_VIA_REDIRECT */, eventId);
1832
+ }
1833
+ /**
1834
+ * Links the {@link OAuthProvider} to the user account using a full-page redirect flow.
1835
+ * @remarks
1836
+ * To handle the results and errors for this operation, refer to {@link getRedirectResult}.
1837
+ * Follow the {@link https://firebase.google.com/docs/auth/web/redirect-best-practices
1838
+ * | best practices} when using {@link linkWithRedirect}.
1839
+ *
1840
+ * This method does not work in a Node.js environment.
1841
+ *
1842
+ * @example
1843
+ * ```javascript
1844
+ * // Sign in using some other provider.
1845
+ * const result = await signInWithEmailAndPassword(auth, email, password);
1846
+ * // Link using a redirect.
1847
+ * const provider = new FacebookAuthProvider();
1848
+ * await linkWithRedirect(result.user, provider);
1849
+ * // This will trigger a full page redirect away from your app
1850
+ *
1851
+ * // After returning from the redirect when your app initializes you can obtain the result
1852
+ * const result = await getRedirectResult(auth);
1853
+ * ```
1854
+ *
1855
+ * @param user - The user.
1856
+ * @param provider - The provider to authenticate. The provider has to be an {@link OAuthProvider}.
1857
+ * Non-OAuth providers like {@link EmailAuthProvider} will throw an error.
1858
+ * @param resolver - An instance of {@link PopupRedirectResolver}, optional
1859
+ * if already supplied to {@link initializeAuth} or provided by {@link getAuth}.
1860
+ *
1861
+ * @public
1862
+ */
1863
+ function linkWithRedirect(user, provider, resolver) {
1864
+ return _linkWithRedirect(user, provider, resolver);
1865
+ }
1866
+ async function _linkWithRedirect(user, provider, resolver) {
1867
+ const userInternal = getModularInstance(user);
1868
+ _assertInstanceOf(userInternal.auth, provider, FederatedAuthProvider);
1869
+ // Wait for auth initialization to complete, this will process pending redirects and clear the
1870
+ // PENDING_REDIRECT_KEY in persistence. This should be completed before starting a new
1871
+ // redirect and creating a PENDING_REDIRECT_KEY entry.
1872
+ await userInternal.auth._initializationPromise;
1873
+ // Allow the resolver to error before persisting the redirect user
1874
+ const resolverInternal = _withDefaultResolver(userInternal.auth, resolver);
1875
+ await _assertLinkedStatus(false, userInternal, provider.providerId);
1876
+ await _setPendingRedirectStatus(resolverInternal, userInternal.auth);
1877
+ const eventId = await prepareUserForRedirect(userInternal);
1878
+ return resolverInternal._openRedirect(userInternal.auth, provider, "linkViaRedirect" /* AuthEventType.LINK_VIA_REDIRECT */, eventId);
1879
+ }
1880
+ /**
1881
+ * Returns a {@link UserCredential} from the redirect-based sign-in flow.
1882
+ *
1883
+ * @remarks
1884
+ * If sign-in succeeded, returns the signed in user. If sign-in was unsuccessful, fails with an
1885
+ * error. If no redirect operation was called, returns `null`.
1886
+ *
1887
+ * This method does not work in a Node.js environment.
1888
+ *
1889
+ * @example
1890
+ * ```javascript
1891
+ * // Sign in using a redirect.
1892
+ * const provider = new FacebookAuthProvider();
1893
+ * // You can add additional scopes to the provider:
1894
+ * provider.addScope('user_birthday');
1895
+ * // Start a sign in process for an unauthenticated user.
1896
+ * await signInWithRedirect(auth, provider);
1897
+ * // This will trigger a full page redirect away from your app
1898
+ *
1899
+ * // After returning from the redirect when your app initializes you can obtain the result
1900
+ * const result = await getRedirectResult(auth);
1901
+ * if (result) {
1902
+ * // This is the signed-in user
1903
+ * const user = result.user;
1904
+ * // This gives you a Facebook Access Token.
1905
+ * const credential = provider.credentialFromResult(auth, result);
1906
+ * const token = credential.accessToken;
1907
+ * }
1908
+ * // As this API can be used for sign-in, linking and reauthentication,
1909
+ * // check the operationType to determine what triggered this redirect
1910
+ * // operation.
1911
+ * const operationType = result.operationType;
1912
+ * ```
1913
+ *
1914
+ * @param auth - The {@link Auth} instance.
1915
+ * @param resolver - An instance of {@link PopupRedirectResolver}, optional
1916
+ * if already supplied to {@link initializeAuth} or provided by {@link getAuth}.
1917
+ *
1918
+ * @public
1919
+ */
1920
+ async function getRedirectResult(auth, resolver) {
1921
+ await _castAuth(auth)._initializationPromise;
1922
+ return _getRedirectResult(auth, resolver, false);
1923
+ }
1924
+ async function _getRedirectResult(auth, resolverExtern, bypassAuthState = false) {
1925
+ const authInternal = _castAuth(auth);
1926
+ const resolver = _withDefaultResolver(authInternal, resolverExtern);
1927
+ const action = new RedirectAction(authInternal, resolver, bypassAuthState);
1928
+ const result = await action.execute();
1929
+ if (result && !bypassAuthState) {
1930
+ delete result.user._redirectEventId;
1931
+ await authInternal._persistUserIfCurrent(result.user);
1932
+ await authInternal._setRedirectUser(null, resolverExtern);
1933
+ }
1934
+ return result;
1935
+ }
1936
+ async function prepareUserForRedirect(user) {
1937
+ const eventId = _generateEventId(`${user.uid}:::`);
1938
+ user._redirectEventId = eventId;
1939
+ await user.auth._setRedirectUser(user);
1940
+ await user.auth._persistUserIfCurrent(user);
1941
+ return eventId;
1942
+ }
1943
+
1944
+ /**
1945
+ * @license
1946
+ * Copyright 2020 Google LLC
1947
+ *
1948
+ * Licensed under the Apache License, Version 2.0 (the "License");
1949
+ * you may not use this file except in compliance with the License.
1950
+ * You may obtain a copy of the License at
1951
+ *
1952
+ * http://www.apache.org/licenses/LICENSE-2.0
1953
+ *
1954
+ * Unless required by applicable law or agreed to in writing, software
1955
+ * distributed under the License is distributed on an "AS IS" BASIS,
1956
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1957
+ * See the License for the specific language governing permissions and
1958
+ * limitations under the License.
1959
+ */
1960
+ // The amount of time to store the UIDs of seen events; this is
1961
+ // set to 10 min by default
1962
+ const EVENT_DUPLICATION_CACHE_DURATION_MS = 10 * 60 * 1000;
1963
+ class AuthEventManager {
1964
+ constructor(auth) {
1965
+ this.auth = auth;
1966
+ this.cachedEventUids = new Set();
1967
+ this.consumers = new Set();
1968
+ this.queuedRedirectEvent = null;
1969
+ this.hasHandledPotentialRedirect = false;
1970
+ this.lastProcessedEventTime = Date.now();
1971
+ }
1972
+ registerConsumer(authEventConsumer) {
1973
+ this.consumers.add(authEventConsumer);
1974
+ if (this.queuedRedirectEvent &&
1975
+ this.isEventForConsumer(this.queuedRedirectEvent, authEventConsumer)) {
1976
+ this.sendToConsumer(this.queuedRedirectEvent, authEventConsumer);
1977
+ this.saveEventToCache(this.queuedRedirectEvent);
1978
+ this.queuedRedirectEvent = null;
1979
+ }
1980
+ }
1981
+ unregisterConsumer(authEventConsumer) {
1982
+ this.consumers.delete(authEventConsumer);
1983
+ }
1984
+ onEvent(event) {
1985
+ // Check if the event has already been handled
1986
+ if (this.hasEventBeenHandled(event)) {
1987
+ return false;
1988
+ }
1989
+ let handled = false;
1990
+ this.consumers.forEach(consumer => {
1991
+ if (this.isEventForConsumer(event, consumer)) {
1992
+ handled = true;
1993
+ this.sendToConsumer(event, consumer);
1994
+ this.saveEventToCache(event);
1995
+ }
1996
+ });
1997
+ if (this.hasHandledPotentialRedirect || !isRedirectEvent(event)) {
1998
+ // If we've already seen a redirect before, or this is a popup event,
1999
+ // bail now
2000
+ return handled;
2001
+ }
2002
+ this.hasHandledPotentialRedirect = true;
2003
+ // If the redirect wasn't handled, hang on to it
2004
+ if (!handled) {
2005
+ this.queuedRedirectEvent = event;
2006
+ handled = true;
2007
+ }
2008
+ return handled;
2009
+ }
2010
+ sendToConsumer(event, consumer) {
2011
+ var _a;
2012
+ if (event.error && !isNullRedirectEvent(event)) {
2013
+ const code = ((_a = event.error.code) === null || _a === void 0 ? void 0 : _a.split('auth/')[1]) ||
2014
+ "internal-error" /* AuthErrorCode.INTERNAL_ERROR */;
2015
+ consumer.onError(_createError(this.auth, code));
2016
+ }
2017
+ else {
2018
+ consumer.onAuthEvent(event);
2019
+ }
2020
+ }
2021
+ isEventForConsumer(event, consumer) {
2022
+ const eventIdMatches = consumer.eventId === null ||
2023
+ (!!event.eventId && event.eventId === consumer.eventId);
2024
+ return consumer.filter.includes(event.type) && eventIdMatches;
2025
+ }
2026
+ hasEventBeenHandled(event) {
2027
+ if (Date.now() - this.lastProcessedEventTime >=
2028
+ EVENT_DUPLICATION_CACHE_DURATION_MS) {
2029
+ this.cachedEventUids.clear();
2030
+ }
2031
+ return this.cachedEventUids.has(eventUid(event));
2032
+ }
2033
+ saveEventToCache(event) {
2034
+ this.cachedEventUids.add(eventUid(event));
2035
+ this.lastProcessedEventTime = Date.now();
2036
+ }
2037
+ }
2038
+ function eventUid(e) {
2039
+ return [e.type, e.eventId, e.sessionId, e.tenantId].filter(v => v).join('-');
2040
+ }
2041
+ function isNullRedirectEvent({ type, error }) {
2042
+ return (type === "unknown" /* AuthEventType.UNKNOWN */ &&
2043
+ (error === null || error === void 0 ? void 0 : error.code) === `auth/${"no-auth-event" /* AuthErrorCode.NO_AUTH_EVENT */}`);
2044
+ }
2045
+ function isRedirectEvent(event) {
2046
+ switch (event.type) {
2047
+ case "signInViaRedirect" /* AuthEventType.SIGN_IN_VIA_REDIRECT */:
2048
+ case "linkViaRedirect" /* AuthEventType.LINK_VIA_REDIRECT */:
2049
+ case "reauthViaRedirect" /* AuthEventType.REAUTH_VIA_REDIRECT */:
2050
+ return true;
2051
+ case "unknown" /* AuthEventType.UNKNOWN */:
2052
+ return isNullRedirectEvent(event);
2053
+ default:
2054
+ return false;
2055
+ }
2056
+ }
2057
+
2058
+ /**
2059
+ * @license
2060
+ * Copyright 2020 Google LLC
2061
+ *
2062
+ * Licensed under the Apache License, Version 2.0 (the "License");
2063
+ * you may not use this file except in compliance with the License.
2064
+ * You may obtain a copy of the License at
2065
+ *
2066
+ * http://www.apache.org/licenses/LICENSE-2.0
2067
+ *
2068
+ * Unless required by applicable law or agreed to in writing, software
2069
+ * distributed under the License is distributed on an "AS IS" BASIS,
2070
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2071
+ * See the License for the specific language governing permissions and
2072
+ * limitations under the License.
2073
+ */
2074
+ async function _getProjectConfig(auth, request = {}) {
2075
+ return _performApiRequest(auth, "GET" /* HttpMethod.GET */, "/v1/projects" /* Endpoint.GET_PROJECT_CONFIG */, request);
2076
+ }
2077
+
2078
+ /**
2079
+ * @license
2080
+ * Copyright 2020 Google LLC
2081
+ *
2082
+ * Licensed under the Apache License, Version 2.0 (the "License");
2083
+ * you may not use this file except in compliance with the License.
2084
+ * You may obtain a copy of the License at
2085
+ *
2086
+ * http://www.apache.org/licenses/LICENSE-2.0
2087
+ *
2088
+ * Unless required by applicable law or agreed to in writing, software
2089
+ * distributed under the License is distributed on an "AS IS" BASIS,
2090
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2091
+ * See the License for the specific language governing permissions and
2092
+ * limitations under the License.
2093
+ */
2094
+ const IP_ADDRESS_REGEX = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
2095
+ const HTTP_REGEX = /^https?/;
2096
+ async function _validateOrigin$1(auth) {
2097
+ // Skip origin validation if we are in an emulated environment
2098
+ if (auth.config.emulator) {
2099
+ return;
2100
+ }
2101
+ const { authorizedDomains } = await _getProjectConfig(auth);
2102
+ for (const domain of authorizedDomains) {
2103
+ try {
2104
+ if (matchDomain(domain)) {
2105
+ return;
2106
+ }
2107
+ }
2108
+ catch (_a) {
2109
+ // Do nothing if there's a URL error; just continue searching
2110
+ }
2111
+ }
2112
+ // In the old SDK, this error also provides helpful messages.
2113
+ _fail(auth, "unauthorized-domain" /* AuthErrorCode.INVALID_ORIGIN */);
2114
+ }
2115
+ function matchDomain(expected) {
2116
+ const currentUrl = _getCurrentUrl();
2117
+ const { protocol, hostname } = new URL(currentUrl);
2118
+ if (expected.startsWith('chrome-extension://')) {
2119
+ const ceUrl = new URL(expected);
2120
+ if (ceUrl.hostname === '' && hostname === '') {
2121
+ // For some reason we're not parsing chrome URLs properly
2122
+ return (protocol === 'chrome-extension:' &&
2123
+ expected.replace('chrome-extension://', '') ===
2124
+ currentUrl.replace('chrome-extension://', ''));
2125
+ }
2126
+ return protocol === 'chrome-extension:' && ceUrl.hostname === hostname;
2127
+ }
2128
+ if (!HTTP_REGEX.test(protocol)) {
2129
+ return false;
2130
+ }
2131
+ if (IP_ADDRESS_REGEX.test(expected)) {
2132
+ // The domain has to be exactly equal to the pattern, as an IP domain will
2133
+ // only contain the IP, no extra character.
2134
+ return hostname === expected;
2135
+ }
2136
+ // Dots in pattern should be escaped.
2137
+ const escapedDomainPattern = expected.replace(/\./g, '\\.');
2138
+ // Non ip address domains.
2139
+ // domain.com = *.domain.com OR domain.com
2140
+ const re = new RegExp('^(.+\\.' + escapedDomainPattern + '|' + escapedDomainPattern + ')$', 'i');
2141
+ return re.test(hostname);
2142
+ }
2143
+
2144
+ /**
2145
+ * @license
2146
+ * Copyright 2020 Google LLC.
2147
+ *
2148
+ * Licensed under the Apache License, Version 2.0 (the "License");
2149
+ * you may not use this file except in compliance with the License.
2150
+ * You may obtain a copy of the License at
2151
+ *
2152
+ * http://www.apache.org/licenses/LICENSE-2.0
2153
+ *
2154
+ * Unless required by applicable law or agreed to in writing, software
2155
+ * distributed under the License is distributed on an "AS IS" BASIS,
2156
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2157
+ * See the License for the specific language governing permissions and
2158
+ * limitations under the License.
2159
+ */
2160
+ const NETWORK_TIMEOUT = new Delay(30000, 60000);
2161
+ /**
2162
+ * Reset unlaoded GApi modules. If gapi.load fails due to a network error,
2163
+ * it will stop working after a retrial. This is a hack to fix this issue.
2164
+ */
2165
+ function resetUnloadedGapiModules() {
2166
+ // Clear last failed gapi.load state to force next gapi.load to first
2167
+ // load the failed gapi.iframes module.
2168
+ // Get gapix.beacon context.
2169
+ const beacon = _window().___jsl;
2170
+ // Get current hint.
2171
+ if (beacon === null || beacon === void 0 ? void 0 : beacon.H) {
2172
+ // Get gapi hint.
2173
+ for (const hint of Object.keys(beacon.H)) {
2174
+ // Requested modules.
2175
+ beacon.H[hint].r = beacon.H[hint].r || [];
2176
+ // Loaded modules.
2177
+ beacon.H[hint].L = beacon.H[hint].L || [];
2178
+ // Set requested modules to a copy of the loaded modules.
2179
+ beacon.H[hint].r = [...beacon.H[hint].L];
2180
+ // Clear pending callbacks.
2181
+ if (beacon.CP) {
2182
+ for (let i = 0; i < beacon.CP.length; i++) {
2183
+ // Remove all failed pending callbacks.
2184
+ beacon.CP[i] = null;
2185
+ }
2186
+ }
2187
+ }
2188
+ }
2189
+ }
2190
+ function loadGapi(auth) {
2191
+ return new Promise((resolve, reject) => {
2192
+ var _a, _b, _c;
2193
+ // Function to run when gapi.load is ready.
2194
+ function loadGapiIframe() {
2195
+ // The developer may have tried to previously run gapi.load and failed.
2196
+ // Run this to fix that.
2197
+ resetUnloadedGapiModules();
2198
+ gapi.load('gapi.iframes', {
2199
+ callback: () => {
2200
+ resolve(gapi.iframes.getContext());
2201
+ },
2202
+ ontimeout: () => {
2203
+ // The above reset may be sufficient, but having this reset after
2204
+ // failure ensures that if the developer calls gapi.load after the
2205
+ // connection is re-established and before another attempt to embed
2206
+ // the iframe, it would work and would not be broken because of our
2207
+ // failed attempt.
2208
+ // Timeout when gapi.iframes.Iframe not loaded.
2209
+ resetUnloadedGapiModules();
2210
+ reject(_createError(auth, "network-request-failed" /* AuthErrorCode.NETWORK_REQUEST_FAILED */));
2211
+ },
2212
+ timeout: NETWORK_TIMEOUT.get()
2213
+ });
2214
+ }
2215
+ if ((_b = (_a = _window().gapi) === null || _a === void 0 ? void 0 : _a.iframes) === null || _b === void 0 ? void 0 : _b.Iframe) {
2216
+ // If gapi.iframes.Iframe available, resolve.
2217
+ resolve(gapi.iframes.getContext());
2218
+ }
2219
+ else if (!!((_c = _window().gapi) === null || _c === void 0 ? void 0 : _c.load)) {
2220
+ // Gapi loader ready, load gapi.iframes.
2221
+ loadGapiIframe();
2222
+ }
2223
+ else {
2224
+ // Create a new iframe callback when this is called so as not to overwrite
2225
+ // any previous defined callback. This happens if this method is called
2226
+ // multiple times in parallel and could result in the later callback
2227
+ // overwriting the previous one. This would end up with a iframe
2228
+ // timeout.
2229
+ const cbName = _generateCallbackName('iframefcb');
2230
+ // GApi loader not available, dynamically load platform.js.
2231
+ _window()[cbName] = () => {
2232
+ // GApi loader should be ready.
2233
+ if (!!gapi.load) {
2234
+ loadGapiIframe();
2235
+ }
2236
+ else {
2237
+ // Gapi loader failed, throw error.
2238
+ reject(_createError(auth, "network-request-failed" /* AuthErrorCode.NETWORK_REQUEST_FAILED */));
2239
+ }
2240
+ };
2241
+ // Load GApi loader.
2242
+ return _loadJS(`${_gapiScriptUrl()}?onload=${cbName}`)
2243
+ .catch(e => reject(e));
2244
+ }
2245
+ }).catch(error => {
2246
+ // Reset cached promise to allow for retrial.
2247
+ cachedGApiLoader = null;
2248
+ throw error;
2249
+ });
2250
+ }
2251
+ let cachedGApiLoader = null;
2252
+ function _loadGapi(auth) {
2253
+ cachedGApiLoader = cachedGApiLoader || loadGapi(auth);
2254
+ return cachedGApiLoader;
2255
+ }
2256
+
2257
+ /**
2258
+ * @license
2259
+ * Copyright 2020 Google LLC.
2260
+ *
2261
+ * Licensed under the Apache License, Version 2.0 (the "License");
2262
+ * you may not use this file except in compliance with the License.
2263
+ * You may obtain a copy of the License at
2264
+ *
2265
+ * http://www.apache.org/licenses/LICENSE-2.0
2266
+ *
2267
+ * Unless required by applicable law or agreed to in writing, software
2268
+ * distributed under the License is distributed on an "AS IS" BASIS,
2269
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2270
+ * See the License for the specific language governing permissions and
2271
+ * limitations under the License.
2272
+ */
2273
+ const PING_TIMEOUT = new Delay(5000, 15000);
2274
+ const IFRAME_PATH = '__/auth/iframe';
2275
+ const EMULATED_IFRAME_PATH = 'emulator/auth/iframe';
2276
+ const IFRAME_ATTRIBUTES = {
2277
+ style: {
2278
+ position: 'absolute',
2279
+ top: '-100px',
2280
+ width: '1px',
2281
+ height: '1px'
2282
+ },
2283
+ 'aria-hidden': 'true',
2284
+ tabindex: '-1'
2285
+ };
2286
+ // Map from apiHost to endpoint ID for passing into iframe. In current SDK, apiHost can be set to
2287
+ // anything (not from a list of endpoints with IDs as in legacy), so this is the closest we can get.
2288
+ const EID_FROM_APIHOST = new Map([
2289
+ ["identitytoolkit.googleapis.com" /* DefaultConfig.API_HOST */, 'p'],
2290
+ ['staging-identitytoolkit.sandbox.googleapis.com', 's'],
2291
+ ['test-identitytoolkit.sandbox.googleapis.com', 't'] // test
2292
+ ]);
2293
+ function getIframeUrl(auth) {
2294
+ const config = auth.config;
2295
+ _assert(config.authDomain, auth, "auth-domain-config-required" /* AuthErrorCode.MISSING_AUTH_DOMAIN */);
2296
+ const url = config.emulator
2297
+ ? _emulatorUrl(config, EMULATED_IFRAME_PATH)
2298
+ : `https://${auth.config.authDomain}/${IFRAME_PATH}`;
2299
+ const params = {
2300
+ apiKey: config.apiKey,
2301
+ appName: auth.name,
2302
+ v: SDK_VERSION
2303
+ };
2304
+ const eid = EID_FROM_APIHOST.get(auth.config.apiHost);
2305
+ if (eid) {
2306
+ params.eid = eid;
2307
+ }
2308
+ const frameworks = auth._getFrameworks();
2309
+ if (frameworks.length) {
2310
+ params.fw = frameworks.join(',');
2311
+ }
2312
+ return `${url}?${querystring(params).slice(1)}`;
2313
+ }
2314
+ async function _openIframe(auth) {
2315
+ const context = await _loadGapi(auth);
2316
+ const gapi = _window().gapi;
2317
+ _assert(gapi, auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
2318
+ return context.open({
2319
+ where: document.body,
2320
+ url: getIframeUrl(auth),
2321
+ messageHandlersFilter: gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER,
2322
+ attributes: IFRAME_ATTRIBUTES,
2323
+ dontclear: true
2324
+ }, (iframe) => new Promise(async (resolve, reject) => {
2325
+ await iframe.restyle({
2326
+ // Prevent iframe from closing on mouse out.
2327
+ setHideOnLeave: false
2328
+ });
2329
+ const networkError = _createError(auth, "network-request-failed" /* AuthErrorCode.NETWORK_REQUEST_FAILED */);
2330
+ // Confirm iframe is correctly loaded.
2331
+ // To fallback on failure, set a timeout.
2332
+ const networkErrorTimer = _window().setTimeout(() => {
2333
+ reject(networkError);
2334
+ }, PING_TIMEOUT.get());
2335
+ // Clear timer and resolve pending iframe ready promise.
2336
+ function clearTimerAndResolve() {
2337
+ _window().clearTimeout(networkErrorTimer);
2338
+ resolve(iframe);
2339
+ }
2340
+ // This returns an IThenable. However the reject part does not call
2341
+ // when the iframe is not loaded.
2342
+ iframe.ping(clearTimerAndResolve).then(clearTimerAndResolve, () => {
2343
+ reject(networkError);
2344
+ });
2345
+ }));
2346
+ }
2347
+
2348
+ /**
2349
+ * @license
2350
+ * Copyright 2020 Google LLC.
2351
+ *
2352
+ * Licensed under the Apache License, Version 2.0 (the "License");
2353
+ * you may not use this file except in compliance with the License.
2354
+ * You may obtain a copy of the License at
2355
+ *
2356
+ * http://www.apache.org/licenses/LICENSE-2.0
2357
+ *
2358
+ * Unless required by applicable law or agreed to in writing, software
2359
+ * distributed under the License is distributed on an "AS IS" BASIS,
2360
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2361
+ * See the License for the specific language governing permissions and
2362
+ * limitations under the License.
2363
+ */
2364
+ const BASE_POPUP_OPTIONS = {
2365
+ location: 'yes',
2366
+ resizable: 'yes',
2367
+ statusbar: 'yes',
2368
+ toolbar: 'no'
2369
+ };
2370
+ const DEFAULT_WIDTH = 500;
2371
+ const DEFAULT_HEIGHT = 600;
2372
+ const TARGET_BLANK = '_blank';
2373
+ const FIREFOX_EMPTY_URL = 'http://localhost';
2374
+ class AuthPopup {
2375
+ constructor(window) {
2376
+ this.window = window;
2377
+ this.associatedEvent = null;
2378
+ }
2379
+ close() {
2380
+ if (this.window) {
2381
+ try {
2382
+ this.window.close();
2383
+ }
2384
+ catch (e) { }
2385
+ }
2386
+ }
2387
+ }
2388
+ function _open(auth, url, name, width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT) {
2389
+ const top = Math.max((window.screen.availHeight - height) / 2, 0).toString();
2390
+ const left = Math.max((window.screen.availWidth - width) / 2, 0).toString();
2391
+ let target = '';
2392
+ const options = Object.assign(Object.assign({}, BASE_POPUP_OPTIONS), { width: width.toString(), height: height.toString(), top,
2393
+ left });
2394
+ // Chrome iOS 7 and 8 is returning an undefined popup win when target is
2395
+ // specified, even though the popup is not necessarily blocked.
2396
+ const ua = getUA().toLowerCase();
2397
+ if (name) {
2398
+ target = _isChromeIOS(ua) ? TARGET_BLANK : name;
2399
+ }
2400
+ if (_isFirefox(ua)) {
2401
+ // Firefox complains when invalid URLs are popped out. Hacky way to bypass.
2402
+ url = url || FIREFOX_EMPTY_URL;
2403
+ // Firefox disables by default scrolling on popup windows, which can create
2404
+ // issues when the user has many Google accounts, for instance.
2405
+ options.scrollbars = 'yes';
2406
+ }
2407
+ const optionsString = Object.entries(options).reduce((accum, [key, value]) => `${accum}${key}=${value},`, '');
2408
+ if (_isIOSStandalone(ua) && target !== '_self') {
2409
+ openAsNewWindowIOS(url || '', target);
2410
+ return new AuthPopup(null);
2411
+ }
2412
+ // about:blank getting sanitized causing browsers like IE/Edge to display
2413
+ // brief error message before redirecting to handler.
2414
+ const newWin = window.open(url || '', target, optionsString);
2415
+ _assert(newWin, auth, "popup-blocked" /* AuthErrorCode.POPUP_BLOCKED */);
2416
+ // Flaky on IE edge, encapsulate with a try and catch.
2417
+ try {
2418
+ newWin.focus();
2419
+ }
2420
+ catch (e) { }
2421
+ return new AuthPopup(newWin);
2422
+ }
2423
+ function openAsNewWindowIOS(url, target) {
2424
+ const el = document.createElement('a');
2425
+ el.href = url;
2426
+ el.target = target;
2427
+ const click = document.createEvent('MouseEvent');
2428
+ click.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 1, null);
2429
+ el.dispatchEvent(click);
2430
+ }
2431
+
2432
+ /**
2433
+ * @license
2434
+ * Copyright 2021 Google LLC
2435
+ *
2436
+ * Licensed under the Apache License, Version 2.0 (the "License");
2437
+ * you may not use this file except in compliance with the License.
2438
+ * You may obtain a copy of the License at
2439
+ *
2440
+ * http://www.apache.org/licenses/LICENSE-2.0
2441
+ *
2442
+ * Unless required by applicable law or agreed to in writing, software
2443
+ * distributed under the License is distributed on an "AS IS" BASIS,
2444
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2445
+ * See the License for the specific language governing permissions and
2446
+ * limitations under the License.
2447
+ */
2448
+ /**
2449
+ * URL for Authentication widget which will initiate the OAuth handshake
2450
+ *
2451
+ * @internal
2452
+ */
2453
+ const WIDGET_PATH = '__/auth/handler';
2454
+ /**
2455
+ * URL for emulated environment
2456
+ *
2457
+ * @internal
2458
+ */
2459
+ const EMULATOR_WIDGET_PATH = 'emulator/auth/handler';
2460
+ /**
2461
+ * Fragment name for the App Check token that gets passed to the widget
2462
+ *
2463
+ * @internal
2464
+ */
2465
+ const FIREBASE_APP_CHECK_FRAGMENT_ID = encodeURIComponent('fac');
2466
+ async function _getRedirectUrl(auth, provider, authType, redirectUrl, eventId, additionalParams) {
2467
+ _assert(auth.config.authDomain, auth, "auth-domain-config-required" /* AuthErrorCode.MISSING_AUTH_DOMAIN */);
2468
+ _assert(auth.config.apiKey, auth, "invalid-api-key" /* AuthErrorCode.INVALID_API_KEY */);
2469
+ const params = {
2470
+ apiKey: auth.config.apiKey,
2471
+ appName: auth.name,
2472
+ authType,
2473
+ redirectUrl,
2474
+ v: SDK_VERSION,
2475
+ eventId
2476
+ };
2477
+ if (provider instanceof FederatedAuthProvider) {
2478
+ provider.setDefaultLanguage(auth.languageCode);
2479
+ params.providerId = provider.providerId || '';
2480
+ if (!isEmpty(provider.getCustomParameters())) {
2481
+ params.customParameters = JSON.stringify(provider.getCustomParameters());
2482
+ }
2483
+ // TODO set additionalParams from the provider as well?
2484
+ for (const [key, value] of Object.entries(additionalParams || {})) {
2485
+ params[key] = value;
2486
+ }
2487
+ }
2488
+ if (provider instanceof BaseOAuthProvider) {
2489
+ const scopes = provider.getScopes().filter(scope => scope !== '');
2490
+ if (scopes.length > 0) {
2491
+ params.scopes = scopes.join(',');
2492
+ }
2493
+ }
2494
+ if (auth.tenantId) {
2495
+ params.tid = auth.tenantId;
2496
+ }
2497
+ // TODO: maybe set eid as endipointId
2498
+ // TODO: maybe set fw as Frameworks.join(",")
2499
+ const paramsDict = params;
2500
+ for (const key of Object.keys(paramsDict)) {
2501
+ if (paramsDict[key] === undefined) {
2502
+ delete paramsDict[key];
2503
+ }
2504
+ }
2505
+ // Sets the App Check token to pass to the widget
2506
+ const appCheckToken = await auth._getAppCheckToken();
2507
+ const appCheckTokenFragment = appCheckToken
2508
+ ? `#${FIREBASE_APP_CHECK_FRAGMENT_ID}=${encodeURIComponent(appCheckToken)}`
2509
+ : '';
2510
+ // Start at index 1 to skip the leading '&' in the query string
2511
+ return `${getHandlerBase(auth)}?${querystring(paramsDict).slice(1)}${appCheckTokenFragment}`;
2512
+ }
2513
+ function getHandlerBase({ config }) {
2514
+ if (!config.emulator) {
2515
+ return `https://${config.authDomain}/${WIDGET_PATH}`;
2516
+ }
2517
+ return _emulatorUrl(config, EMULATOR_WIDGET_PATH);
2518
+ }
2519
+
2520
+ /**
2521
+ * @license
2522
+ * Copyright 2020 Google LLC
2523
+ *
2524
+ * Licensed under the Apache License, Version 2.0 (the "License");
2525
+ * you may not use this file except in compliance with the License.
2526
+ * You may obtain a copy of the License at
2527
+ *
2528
+ * http://www.apache.org/licenses/LICENSE-2.0
2529
+ *
2530
+ * Unless required by applicable law or agreed to in writing, software
2531
+ * distributed under the License is distributed on an "AS IS" BASIS,
2532
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2533
+ * See the License for the specific language governing permissions and
2534
+ * limitations under the License.
2535
+ */
2536
+ /**
2537
+ * The special web storage event
2538
+ *
2539
+ */
2540
+ const WEB_STORAGE_SUPPORT_KEY = 'webStorageSupport';
2541
+ class BrowserPopupRedirectResolver {
2542
+ constructor() {
2543
+ this.eventManagers = {};
2544
+ this.iframes = {};
2545
+ this.originValidationPromises = {};
2546
+ this._redirectPersistence = browserSessionPersistence;
2547
+ this._completeRedirectFn = _getRedirectResult;
2548
+ this._overrideRedirectResult = _overrideRedirectResult;
2549
+ }
2550
+ // Wrapping in async even though we don't await anywhere in order
2551
+ // to make sure errors are raised as promise rejections
2552
+ async _openPopup(auth, provider, authType, eventId) {
2553
+ var _a;
2554
+ debugAssert((_a = this.eventManagers[auth._key()]) === null || _a === void 0 ? void 0 : _a.manager, '_initialize() not called before _openPopup()');
2555
+ const url = await _getRedirectUrl(auth, provider, authType, _getCurrentUrl(), eventId);
2556
+ return _open(auth, url, _generateEventId());
2557
+ }
2558
+ async _openRedirect(auth, provider, authType, eventId) {
2559
+ await this._originValidation(auth);
2560
+ const url = await _getRedirectUrl(auth, provider, authType, _getCurrentUrl(), eventId);
2561
+ _setWindowLocation(url);
2562
+ return new Promise(() => { });
2563
+ }
2564
+ _initialize(auth) {
2565
+ const key = auth._key();
2566
+ if (this.eventManagers[key]) {
2567
+ const { manager, promise } = this.eventManagers[key];
2568
+ if (manager) {
2569
+ return Promise.resolve(manager);
2570
+ }
2571
+ else {
2572
+ debugAssert(promise, 'If manager is not set, promise should be');
2573
+ return promise;
2574
+ }
2575
+ }
2576
+ const promise = this.initAndGetManager(auth);
2577
+ this.eventManagers[key] = { promise };
2578
+ // If the promise is rejected, the key should be removed so that the
2579
+ // operation can be retried later.
2580
+ promise.catch(() => {
2581
+ delete this.eventManagers[key];
2582
+ });
2583
+ return promise;
2584
+ }
2585
+ async initAndGetManager(auth) {
2586
+ const iframe = await _openIframe(auth);
2587
+ const manager = new AuthEventManager(auth);
2588
+ iframe.register('authEvent', (iframeEvent) => {
2589
+ _assert(iframeEvent === null || iframeEvent === void 0 ? void 0 : iframeEvent.authEvent, auth, "invalid-auth-event" /* AuthErrorCode.INVALID_AUTH_EVENT */);
2590
+ // TODO: Consider splitting redirect and popup events earlier on
2591
+ const handled = manager.onEvent(iframeEvent.authEvent);
2592
+ return { status: handled ? "ACK" /* GapiOutcome.ACK */ : "ERROR" /* GapiOutcome.ERROR */ };
2593
+ }, gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER);
2594
+ this.eventManagers[auth._key()] = { manager };
2595
+ this.iframes[auth._key()] = iframe;
2596
+ return manager;
2597
+ }
2598
+ _isIframeWebStorageSupported(auth, cb) {
2599
+ const iframe = this.iframes[auth._key()];
2600
+ iframe.send(WEB_STORAGE_SUPPORT_KEY, { type: WEB_STORAGE_SUPPORT_KEY }, result => {
2601
+ var _a;
2602
+ const isSupported = (_a = result === null || result === void 0 ? void 0 : result[0]) === null || _a === void 0 ? void 0 : _a[WEB_STORAGE_SUPPORT_KEY];
2603
+ if (isSupported !== undefined) {
2604
+ cb(!!isSupported);
2605
+ }
2606
+ _fail(auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
2607
+ }, gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER);
2608
+ }
2609
+ _originValidation(auth) {
2610
+ const key = auth._key();
2611
+ if (!this.originValidationPromises[key]) {
2612
+ this.originValidationPromises[key] = _validateOrigin$1(auth);
2613
+ }
2614
+ return this.originValidationPromises[key];
2615
+ }
2616
+ get _shouldInitProactively() {
2617
+ // Mobile browsers and Safari need to optimistically initialize
2618
+ return _isMobileBrowser() || _isSafari() || _isIOS();
2619
+ }
2620
+ }
2621
+ /**
2622
+ * An implementation of {@link PopupRedirectResolver} suitable for browser
2623
+ * based applications.
2624
+ *
2625
+ * @remarks
2626
+ * This method does not work in a Node.js environment.
2627
+ *
2628
+ * @public
2629
+ */
2630
+ const browserPopupRedirectResolver = BrowserPopupRedirectResolver;
2631
+
2632
+ /**
2633
+ * {@inheritdoc PhoneMultiFactorAssertion}
2634
+ *
2635
+ * @public
2636
+ */
2637
+ class PhoneMultiFactorAssertionImpl extends MultiFactorAssertionImpl {
2638
+ constructor(credential) {
2639
+ super("phone" /* FactorId.PHONE */);
2640
+ this.credential = credential;
2641
+ }
2642
+ /** @internal */
2643
+ static _fromCredential(credential) {
2644
+ return new PhoneMultiFactorAssertionImpl(credential);
2645
+ }
2646
+ /** @internal */
2647
+ _finalizeEnroll(auth, idToken, displayName) {
2648
+ return finalizeEnrollPhoneMfa(auth, {
2649
+ idToken,
2650
+ displayName,
2651
+ phoneVerificationInfo: this.credential._makeVerificationRequest()
2652
+ });
2653
+ }
2654
+ /** @internal */
2655
+ _finalizeSignIn(auth, mfaPendingCredential) {
2656
+ return finalizeSignInPhoneMfa(auth, {
2657
+ mfaPendingCredential,
2658
+ phoneVerificationInfo: this.credential._makeVerificationRequest()
2659
+ });
2660
+ }
2661
+ }
2662
+ /**
2663
+ * Provider for generating a {@link PhoneMultiFactorAssertion}.
2664
+ *
2665
+ * @public
2666
+ */
2667
+ class PhoneMultiFactorGenerator {
2668
+ constructor() { }
2669
+ /**
2670
+ * Provides a {@link PhoneMultiFactorAssertion} to confirm ownership of the phone second factor.
2671
+ *
2672
+ * @remarks
2673
+ * This method does not work in a Node.js environment.
2674
+ *
2675
+ * @param phoneAuthCredential - A credential provided by {@link PhoneAuthProvider.credential}.
2676
+ * @returns A {@link PhoneMultiFactorAssertion} which can be used with
2677
+ * {@link MultiFactorResolver.resolveSignIn}
2678
+ */
2679
+ static assertion(credential) {
2680
+ return PhoneMultiFactorAssertionImpl._fromCredential(credential);
2681
+ }
2682
+ }
2683
+ /**
2684
+ * The identifier of the phone second factor: `phone`.
2685
+ */
2686
+ PhoneMultiFactorGenerator.FACTOR_ID = 'phone';
2687
+
2688
+ /**
2689
+ * @license
2690
+ * Copyright 2021 Google LLC
2691
+ *
2692
+ * Licensed under the Apache License, Version 2.0 (the "License");
2693
+ * you may not use this file except in compliance with the License.
2694
+ * You may obtain a copy of the License at
2695
+ *
2696
+ * http://www.apache.org/licenses/LICENSE-2.0
2697
+ *
2698
+ * Unless required by applicable law or agreed to in writing, software
2699
+ * distributed under the License is distributed on an "AS IS" BASIS,
2700
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2701
+ * See the License for the specific language governing permissions and
2702
+ * limitations under the License.
2703
+ */
2704
+ const DEFAULT_ID_TOKEN_MAX_AGE = 5 * 60;
2705
+ const authIdTokenMaxAge = getExperimentalSetting('authIdTokenMaxAge') || DEFAULT_ID_TOKEN_MAX_AGE;
2706
+ let lastPostedIdToken = null;
2707
+ const mintCookieFactory = (url) => async (user) => {
2708
+ const idTokenResult = user && (await user.getIdTokenResult());
2709
+ const idTokenAge = idTokenResult &&
2710
+ (new Date().getTime() - Date.parse(idTokenResult.issuedAtTime)) / 1000;
2711
+ if (idTokenAge && idTokenAge > authIdTokenMaxAge) {
2712
+ return;
2713
+ }
2714
+ // Specifically trip null => undefined when logged out, to delete any existing cookie
2715
+ const idToken = idTokenResult === null || idTokenResult === void 0 ? void 0 : idTokenResult.token;
2716
+ if (lastPostedIdToken === idToken) {
2717
+ return;
2718
+ }
2719
+ lastPostedIdToken = idToken;
2720
+ await fetch(url, {
2721
+ method: idToken ? 'POST' : 'DELETE',
2722
+ headers: idToken
2723
+ ? {
2724
+ 'Authorization': `Bearer ${idToken}`
2725
+ }
2726
+ : {}
2727
+ });
2728
+ };
2729
+ /**
2730
+ * Returns the Auth instance associated with the provided {@link @firebase/app#FirebaseApp}.
2731
+ * If no instance exists, initializes an Auth instance with platform-specific default dependencies.
2732
+ *
2733
+ * @param app - The Firebase App.
2734
+ *
2735
+ * @public
2736
+ */
2737
+ function getAuth(app = getApp()) {
2738
+ const provider = _getProvider(app, 'auth');
2739
+ if (provider.isInitialized()) {
2740
+ return provider.getImmediate();
2741
+ }
2742
+ const auth = initializeAuth(app, {
2743
+ popupRedirectResolver: browserPopupRedirectResolver,
2744
+ persistence: [
2745
+ indexedDBLocalPersistence,
2746
+ browserLocalPersistence,
2747
+ browserSessionPersistence
2748
+ ]
2749
+ });
2750
+ const authTokenSyncUrl = getExperimentalSetting('authTokenSyncURL');
2751
+ if (authTokenSyncUrl) {
2752
+ const mintCookie = mintCookieFactory(authTokenSyncUrl);
2753
+ beforeAuthStateChanged(auth, mintCookie, () => mintCookie(auth.currentUser));
2754
+ onIdTokenChanged(auth, user => mintCookie(user));
2755
+ }
2756
+ const authEmulatorHost = getDefaultEmulatorHost('auth');
2757
+ if (authEmulatorHost) {
2758
+ connectAuthEmulator(auth, `http://${authEmulatorHost}`);
2759
+ }
2760
+ return auth;
2761
+ }
2762
+ function getScriptParentElement() {
2763
+ var _a, _b;
2764
+ return (_b = (_a = document.getElementsByTagName('head')) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : document;
2765
+ }
2766
+ _setExternalJSProvider({
2767
+ loadJS(url) {
2768
+ // TODO: consider adding timeout support & cancellation
2769
+ return new Promise((resolve, reject) => {
2770
+ const el = document.createElement('script');
2771
+ el.setAttribute('src', url);
2772
+ el.onload = resolve;
2773
+ el.onerror = e => {
2774
+ const error = _createError("internal-error" /* AuthErrorCode.INTERNAL_ERROR */);
2775
+ error.customData = e;
2776
+ reject(error);
2777
+ };
2778
+ el.type = 'text/javascript';
2779
+ el.charset = 'UTF-8';
2780
+ getScriptParentElement().appendChild(el);
2781
+ });
2782
+ },
2783
+ gapiScript: 'https://apis.google.com/js/api.js',
2784
+ recaptchaV2Script: 'https://www.google.com/recaptcha/api.js',
2785
+ recaptchaEnterpriseScript: 'https://www.google.com/recaptcha/enterprise.js?render='
2786
+ });
2787
+ registerAuth("Browser" /* ClientPlatform.BROWSER */);
2788
+
2789
+ /**
2790
+ * @license
2791
+ * Copyright 2021 Google LLC
2792
+ *
2793
+ * Licensed under the Apache License, Version 2.0 (the "License");
2794
+ * you may not use this file except in compliance with the License.
2795
+ * You may obtain a copy of the License at
2796
+ *
2797
+ * http://www.apache.org/licenses/LICENSE-2.0
2798
+ *
2799
+ * Unless required by applicable law or agreed to in writing, software
2800
+ * distributed under the License is distributed on an "AS IS" BASIS,
2801
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2802
+ * See the License for the specific language governing permissions and
2803
+ * limitations under the License.
2804
+ */
2805
+ function _cordovaWindow() {
2806
+ return window;
2807
+ }
2808
+
2809
+ /**
2810
+ * @license
2811
+ * Copyright 2020 Google LLC
2812
+ *
2813
+ * Licensed under the Apache License, Version 2.0 (the "License");
2814
+ * you may not use this file except in compliance with the License.
2815
+ * You may obtain a copy of the License at
2816
+ *
2817
+ * http://www.apache.org/licenses/LICENSE-2.0
2818
+ *
2819
+ * Unless required by applicable law or agreed to in writing, software
2820
+ * distributed under the License is distributed on an "AS IS" BASIS,
2821
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2822
+ * See the License for the specific language governing permissions and
2823
+ * limitations under the License.
2824
+ */
2825
+ /**
2826
+ * How long to wait after the app comes back into focus before concluding that
2827
+ * the user closed the sign in tab.
2828
+ */
2829
+ const REDIRECT_TIMEOUT_MS = 2000;
2830
+ /**
2831
+ * Generates the URL for the OAuth handler.
2832
+ */
2833
+ async function _generateHandlerUrl(auth, event, provider) {
2834
+ var _a;
2835
+ // Get the cordova plugins
2836
+ const { BuildInfo } = _cordovaWindow();
2837
+ debugAssert(event.sessionId, 'AuthEvent did not contain a session ID');
2838
+ const sessionDigest = await computeSha256(event.sessionId);
2839
+ const additionalParams = {};
2840
+ if (_isIOS()) {
2841
+ // iOS app identifier
2842
+ additionalParams['ibi'] = BuildInfo.packageName;
2843
+ }
2844
+ else if (_isAndroid()) {
2845
+ // Android app identifier
2846
+ additionalParams['apn'] = BuildInfo.packageName;
2847
+ }
2848
+ else {
2849
+ _fail(auth, "operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */);
2850
+ }
2851
+ // Add the display name if available
2852
+ if (BuildInfo.displayName) {
2853
+ additionalParams['appDisplayName'] = BuildInfo.displayName;
2854
+ }
2855
+ // Attached the hashed session ID
2856
+ additionalParams['sessionId'] = sessionDigest;
2857
+ return _getRedirectUrl(auth, provider, event.type, undefined, (_a = event.eventId) !== null && _a !== void 0 ? _a : undefined, additionalParams);
2858
+ }
2859
+ /**
2860
+ * Validates that this app is valid for this project configuration
2861
+ */
2862
+ async function _validateOrigin(auth) {
2863
+ const { BuildInfo } = _cordovaWindow();
2864
+ const request = {};
2865
+ if (_isIOS()) {
2866
+ request.iosBundleId = BuildInfo.packageName;
2867
+ }
2868
+ else if (_isAndroid()) {
2869
+ request.androidPackageName = BuildInfo.packageName;
2870
+ }
2871
+ else {
2872
+ _fail(auth, "operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */);
2873
+ }
2874
+ // Will fail automatically if package name is not authorized
2875
+ await _getProjectConfig(auth, request);
2876
+ }
2877
+ function _performRedirect(handlerUrl) {
2878
+ // Get the cordova plugins
2879
+ const { cordova } = _cordovaWindow();
2880
+ return new Promise(resolve => {
2881
+ cordova.plugins.browsertab.isAvailable(browserTabIsAvailable => {
2882
+ let iabRef = null;
2883
+ if (browserTabIsAvailable) {
2884
+ cordova.plugins.browsertab.openUrl(handlerUrl);
2885
+ }
2886
+ else {
2887
+ // TODO: Return the inappbrowser ref that's returned from the open call
2888
+ iabRef = cordova.InAppBrowser.open(handlerUrl, _isIOS7Or8() ? '_blank' : '_system', 'location=yes');
2889
+ }
2890
+ resolve(iabRef);
2891
+ });
2892
+ });
2893
+ }
2894
+ /**
2895
+ * This function waits for app activity to be seen before resolving. It does
2896
+ * this by attaching listeners to various dom events. Once the app is determined
2897
+ * to be visible, this promise resolves. AFTER that resolution, the listeners
2898
+ * are detached and any browser tabs left open will be closed.
2899
+ */
2900
+ async function _waitForAppResume(auth, eventListener, iabRef) {
2901
+ // Get the cordova plugins
2902
+ const { cordova } = _cordovaWindow();
2903
+ let cleanup = () => { };
2904
+ try {
2905
+ await new Promise((resolve, reject) => {
2906
+ let onCloseTimer = null;
2907
+ // DEFINE ALL THE CALLBACKS =====
2908
+ function authEventSeen() {
2909
+ var _a;
2910
+ // Auth event was detected. Resolve this promise and close the extra
2911
+ // window if it's still open.
2912
+ resolve();
2913
+ const closeBrowserTab = (_a = cordova.plugins.browsertab) === null || _a === void 0 ? void 0 : _a.close;
2914
+ if (typeof closeBrowserTab === 'function') {
2915
+ closeBrowserTab();
2916
+ }
2917
+ // Close inappbrowser emebedded webview in iOS7 and 8 case if still
2918
+ // open.
2919
+ if (typeof (iabRef === null || iabRef === void 0 ? void 0 : iabRef.close) === 'function') {
2920
+ iabRef.close();
2921
+ }
2922
+ }
2923
+ function resumed() {
2924
+ if (onCloseTimer) {
2925
+ // This code already ran; do not rerun.
2926
+ return;
2927
+ }
2928
+ onCloseTimer = window.setTimeout(() => {
2929
+ // Wait two seeconds after resume then reject.
2930
+ reject(_createError(auth, "redirect-cancelled-by-user" /* AuthErrorCode.REDIRECT_CANCELLED_BY_USER */));
2931
+ }, REDIRECT_TIMEOUT_MS);
2932
+ }
2933
+ function visibilityChanged() {
2934
+ if ((document === null || document === void 0 ? void 0 : document.visibilityState) === 'visible') {
2935
+ resumed();
2936
+ }
2937
+ }
2938
+ // ATTACH ALL THE LISTENERS =====
2939
+ // Listen for the auth event
2940
+ eventListener.addPassiveListener(authEventSeen);
2941
+ // Listen for resume and visibility events
2942
+ document.addEventListener('resume', resumed, false);
2943
+ if (_isAndroid()) {
2944
+ document.addEventListener('visibilitychange', visibilityChanged, false);
2945
+ }
2946
+ // SETUP THE CLEANUP FUNCTION =====
2947
+ cleanup = () => {
2948
+ eventListener.removePassiveListener(authEventSeen);
2949
+ document.removeEventListener('resume', resumed, false);
2950
+ document.removeEventListener('visibilitychange', visibilityChanged, false);
2951
+ if (onCloseTimer) {
2952
+ window.clearTimeout(onCloseTimer);
2953
+ }
2954
+ };
2955
+ });
2956
+ }
2957
+ finally {
2958
+ cleanup();
2959
+ }
2960
+ }
2961
+ /**
2962
+ * Checks the configuration of the Cordova environment. This has no side effect
2963
+ * if the configuration is correct; otherwise it throws an error with the
2964
+ * missing plugin.
2965
+ */
2966
+ function _checkCordovaConfiguration(auth) {
2967
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
2968
+ const win = _cordovaWindow();
2969
+ // Check all dependencies installed.
2970
+ // https://github.com/nordnet/cordova-universal-links-plugin
2971
+ // Note that cordova-universal-links-plugin has been abandoned.
2972
+ // A fork with latest fixes is available at:
2973
+ // https://www.npmjs.com/package/cordova-universal-links-plugin-fix
2974
+ _assert(typeof ((_a = win === null || win === void 0 ? void 0 : win.universalLinks) === null || _a === void 0 ? void 0 : _a.subscribe) === 'function', auth, "invalid-cordova-configuration" /* AuthErrorCode.INVALID_CORDOVA_CONFIGURATION */, {
2975
+ missingPlugin: 'cordova-universal-links-plugin-fix'
2976
+ });
2977
+ // https://www.npmjs.com/package/cordova-plugin-buildinfo
2978
+ _assert(typeof ((_b = win === null || win === void 0 ? void 0 : win.BuildInfo) === null || _b === void 0 ? void 0 : _b.packageName) !== 'undefined', auth, "invalid-cordova-configuration" /* AuthErrorCode.INVALID_CORDOVA_CONFIGURATION */, {
2979
+ missingPlugin: 'cordova-plugin-buildInfo'
2980
+ });
2981
+ // https://github.com/google/cordova-plugin-browsertab
2982
+ _assert(typeof ((_e = (_d = (_c = win === null || win === void 0 ? void 0 : win.cordova) === null || _c === void 0 ? void 0 : _c.plugins) === null || _d === void 0 ? void 0 : _d.browsertab) === null || _e === void 0 ? void 0 : _e.openUrl) === 'function', auth, "invalid-cordova-configuration" /* AuthErrorCode.INVALID_CORDOVA_CONFIGURATION */, {
2983
+ missingPlugin: 'cordova-plugin-browsertab'
2984
+ });
2985
+ _assert(typeof ((_h = (_g = (_f = win === null || win === void 0 ? void 0 : win.cordova) === null || _f === void 0 ? void 0 : _f.plugins) === null || _g === void 0 ? void 0 : _g.browsertab) === null || _h === void 0 ? void 0 : _h.isAvailable) === 'function', auth, "invalid-cordova-configuration" /* AuthErrorCode.INVALID_CORDOVA_CONFIGURATION */, {
2986
+ missingPlugin: 'cordova-plugin-browsertab'
2987
+ });
2988
+ // https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-inappbrowser/
2989
+ _assert(typeof ((_k = (_j = win === null || win === void 0 ? void 0 : win.cordova) === null || _j === void 0 ? void 0 : _j.InAppBrowser) === null || _k === void 0 ? void 0 : _k.open) === 'function', auth, "invalid-cordova-configuration" /* AuthErrorCode.INVALID_CORDOVA_CONFIGURATION */, {
2990
+ missingPlugin: 'cordova-plugin-inappbrowser'
2991
+ });
2992
+ }
2993
+ /**
2994
+ * Computes the SHA-256 of a session ID. The SubtleCrypto interface is only
2995
+ * available in "secure" contexts, which covers Cordova (which is served on a file
2996
+ * protocol).
2997
+ */
2998
+ async function computeSha256(sessionId) {
2999
+ const bytes = stringToArrayBuffer(sessionId);
3000
+ // TODO: For IE11 crypto has a different name and this operation comes back
3001
+ // as an object, not a promise. This is the old proposed standard that
3002
+ // is used by IE11:
3003
+ // https://www.w3.org/TR/2013/WD-WebCryptoAPI-20130108/#cryptooperation-interface
3004
+ const buf = await crypto.subtle.digest('SHA-256', bytes);
3005
+ const arr = Array.from(new Uint8Array(buf));
3006
+ return arr.map(num => num.toString(16).padStart(2, '0')).join('');
3007
+ }
3008
+ function stringToArrayBuffer(str) {
3009
+ // This function is only meant to deal with an ASCII charset and makes
3010
+ // certain simplifying assumptions.
3011
+ debugAssert(/[0-9a-zA-Z]+/.test(str), 'Can only convert alpha-numeric strings');
3012
+ if (typeof TextEncoder !== 'undefined') {
3013
+ return new TextEncoder().encode(str);
3014
+ }
3015
+ const buff = new ArrayBuffer(str.length);
3016
+ const view = new Uint8Array(buff);
3017
+ for (let i = 0; i < str.length; i++) {
3018
+ view[i] = str.charCodeAt(i);
3019
+ }
3020
+ return view;
3021
+ }
3022
+
3023
+ /**
3024
+ * @license
3025
+ * Copyright 2020 Google LLC
3026
+ *
3027
+ * Licensed under the Apache License, Version 2.0 (the "License");
3028
+ * you may not use this file except in compliance with the License.
3029
+ * You may obtain a copy of the License at
3030
+ *
3031
+ * http://www.apache.org/licenses/LICENSE-2.0
3032
+ *
3033
+ * Unless required by applicable law or agreed to in writing, software
3034
+ * distributed under the License is distributed on an "AS IS" BASIS,
3035
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3036
+ * See the License for the specific language governing permissions and
3037
+ * limitations under the License.
3038
+ */
3039
+ const SESSION_ID_LENGTH = 20;
3040
+ /** Custom AuthEventManager that adds passive listeners to events */
3041
+ class CordovaAuthEventManager extends AuthEventManager {
3042
+ constructor() {
3043
+ super(...arguments);
3044
+ this.passiveListeners = new Set();
3045
+ this.initPromise = new Promise(resolve => {
3046
+ this.resolveInialized = resolve;
3047
+ });
3048
+ }
3049
+ addPassiveListener(cb) {
3050
+ this.passiveListeners.add(cb);
3051
+ }
3052
+ removePassiveListener(cb) {
3053
+ this.passiveListeners.delete(cb);
3054
+ }
3055
+ // In a Cordova environment, this manager can live through multiple redirect
3056
+ // operations
3057
+ resetRedirect() {
3058
+ this.queuedRedirectEvent = null;
3059
+ this.hasHandledPotentialRedirect = false;
3060
+ }
3061
+ /** Override the onEvent method */
3062
+ onEvent(event) {
3063
+ this.resolveInialized();
3064
+ this.passiveListeners.forEach(cb => cb(event));
3065
+ return super.onEvent(event);
3066
+ }
3067
+ async initialized() {
3068
+ await this.initPromise;
3069
+ }
3070
+ }
3071
+ /**
3072
+ * Generates a (partial) {@link AuthEvent}.
3073
+ */
3074
+ function _generateNewEvent(auth, type, eventId = null) {
3075
+ return {
3076
+ type,
3077
+ eventId,
3078
+ urlResponse: null,
3079
+ sessionId: generateSessionId(),
3080
+ postBody: null,
3081
+ tenantId: auth.tenantId,
3082
+ error: _createError(auth, "no-auth-event" /* AuthErrorCode.NO_AUTH_EVENT */)
3083
+ };
3084
+ }
3085
+ function _savePartialEvent(auth, event) {
3086
+ return storage()._set(persistenceKey(auth), event);
3087
+ }
3088
+ async function _getAndRemoveEvent(auth) {
3089
+ const event = (await storage()._get(persistenceKey(auth)));
3090
+ if (event) {
3091
+ await storage()._remove(persistenceKey(auth));
3092
+ }
3093
+ return event;
3094
+ }
3095
+ function _eventFromPartialAndUrl(partialEvent, url) {
3096
+ var _a, _b;
3097
+ // Parse the deep link within the dynamic link URL.
3098
+ const callbackUrl = _getDeepLinkFromCallback(url);
3099
+ // Confirm it is actually a callback URL.
3100
+ // Currently the universal link will be of this format:
3101
+ // https://<AUTH_DOMAIN>/__/auth/callback<OAUTH_RESPONSE>
3102
+ // This is a fake URL but is not intended to take the user anywhere
3103
+ // and just redirect to the app.
3104
+ if (callbackUrl.includes('/__/auth/callback')) {
3105
+ // Check if there is an error in the URL.
3106
+ // This mechanism is also used to pass errors back to the app:
3107
+ // https://<AUTH_DOMAIN>/__/auth/callback?firebaseError=<STRINGIFIED_ERROR>
3108
+ const params = searchParamsOrEmpty(callbackUrl);
3109
+ // Get the error object corresponding to the stringified error if found.
3110
+ const errorObject = params['firebaseError']
3111
+ ? parseJsonOrNull(decodeURIComponent(params['firebaseError']))
3112
+ : null;
3113
+ 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];
3114
+ const error = code ? _createError(code) : null;
3115
+ if (error) {
3116
+ return {
3117
+ type: partialEvent.type,
3118
+ eventId: partialEvent.eventId,
3119
+ tenantId: partialEvent.tenantId,
3120
+ error,
3121
+ urlResponse: null,
3122
+ sessionId: null,
3123
+ postBody: null
3124
+ };
3125
+ }
3126
+ else {
3127
+ return {
3128
+ type: partialEvent.type,
3129
+ eventId: partialEvent.eventId,
3130
+ tenantId: partialEvent.tenantId,
3131
+ sessionId: partialEvent.sessionId,
3132
+ urlResponse: callbackUrl,
3133
+ postBody: null
3134
+ };
3135
+ }
3136
+ }
3137
+ return null;
3138
+ }
3139
+ function generateSessionId() {
3140
+ const chars = [];
3141
+ const allowedChars = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
3142
+ for (let i = 0; i < SESSION_ID_LENGTH; i++) {
3143
+ const idx = Math.floor(Math.random() * allowedChars.length);
3144
+ chars.push(allowedChars.charAt(idx));
3145
+ }
3146
+ return chars.join('');
3147
+ }
3148
+ function storage() {
3149
+ return _getInstance(browserLocalPersistence);
3150
+ }
3151
+ function persistenceKey(auth) {
3152
+ return _persistenceKeyName("authEvent" /* KeyName.AUTH_EVENT */, auth.config.apiKey, auth.name);
3153
+ }
3154
+ function parseJsonOrNull(json) {
3155
+ try {
3156
+ return JSON.parse(json);
3157
+ }
3158
+ catch (e) {
3159
+ return null;
3160
+ }
3161
+ }
3162
+ // Exported for testing
3163
+ function _getDeepLinkFromCallback(url) {
3164
+ const params = searchParamsOrEmpty(url);
3165
+ const link = params['link'] ? decodeURIComponent(params['link']) : undefined;
3166
+ // Double link case (automatic redirect)
3167
+ const doubleDeepLink = searchParamsOrEmpty(link)['link'];
3168
+ // iOS custom scheme links.
3169
+ const iOSDeepLink = params['deep_link_id']
3170
+ ? decodeURIComponent(params['deep_link_id'])
3171
+ : undefined;
3172
+ const iOSDoubleDeepLink = searchParamsOrEmpty(iOSDeepLink)['link'];
3173
+ return iOSDoubleDeepLink || iOSDeepLink || doubleDeepLink || link || url;
3174
+ }
3175
+ /**
3176
+ * Optimistically tries to get search params from a string, or else returns an
3177
+ * empty search params object.
3178
+ */
3179
+ function searchParamsOrEmpty(url) {
3180
+ if (!(url === null || url === void 0 ? void 0 : url.includes('?'))) {
3181
+ return {};
3182
+ }
3183
+ const [_, ...rest] = url.split('?');
3184
+ return querystringDecode(rest.join('?'));
3185
+ }
3186
+
3187
+ /**
3188
+ * @license
3189
+ * Copyright 2021 Google LLC
3190
+ *
3191
+ * Licensed under the Apache License, Version 2.0 (the "License");
3192
+ * you may not use this file except in compliance with the License.
3193
+ * You may obtain a copy of the License at
3194
+ *
3195
+ * http://www.apache.org/licenses/LICENSE-2.0
3196
+ *
3197
+ * Unless required by applicable law or agreed to in writing, software
3198
+ * distributed under the License is distributed on an "AS IS" BASIS,
3199
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3200
+ * See the License for the specific language governing permissions and
3201
+ * limitations under the License.
3202
+ */
3203
+ /**
3204
+ * How long to wait for the initial auth event before concluding no
3205
+ * redirect pending
3206
+ */
3207
+ const INITIAL_EVENT_TIMEOUT_MS = 500;
3208
+ class CordovaPopupRedirectResolver {
3209
+ constructor() {
3210
+ this._redirectPersistence = browserSessionPersistence;
3211
+ this._shouldInitProactively = true; // This is lightweight for Cordova
3212
+ this.eventManagers = new Map();
3213
+ this.originValidationPromises = {};
3214
+ this._completeRedirectFn = _getRedirectResult;
3215
+ this._overrideRedirectResult = _overrideRedirectResult;
3216
+ }
3217
+ async _initialize(auth) {
3218
+ const key = auth._key();
3219
+ let manager = this.eventManagers.get(key);
3220
+ if (!manager) {
3221
+ manager = new CordovaAuthEventManager(auth);
3222
+ this.eventManagers.set(key, manager);
3223
+ this.attachCallbackListeners(auth, manager);
3224
+ }
3225
+ return manager;
3226
+ }
3227
+ _openPopup(auth) {
3228
+ _fail(auth, "operation-not-supported-in-this-environment" /* AuthErrorCode.OPERATION_NOT_SUPPORTED */);
3229
+ }
3230
+ async _openRedirect(auth, provider, authType, eventId) {
3231
+ _checkCordovaConfiguration(auth);
3232
+ const manager = await this._initialize(auth);
3233
+ await manager.initialized();
3234
+ // Reset the persisted redirect states. This does not matter on Web where
3235
+ // the redirect always blows away application state entirely. On Cordova,
3236
+ // the app maintains control flow through the redirect.
3237
+ manager.resetRedirect();
3238
+ _clearRedirectOutcomes();
3239
+ await this._originValidation(auth);
3240
+ const event = _generateNewEvent(auth, authType, eventId);
3241
+ await _savePartialEvent(auth, event);
3242
+ const url = await _generateHandlerUrl(auth, event, provider);
3243
+ const iabRef = await _performRedirect(url);
3244
+ return _waitForAppResume(auth, manager, iabRef);
3245
+ }
3246
+ _isIframeWebStorageSupported(_auth, _cb) {
3247
+ throw new Error('Method not implemented.');
3248
+ }
3249
+ _originValidation(auth) {
3250
+ const key = auth._key();
3251
+ if (!this.originValidationPromises[key]) {
3252
+ this.originValidationPromises[key] = _validateOrigin(auth);
3253
+ }
3254
+ return this.originValidationPromises[key];
3255
+ }
3256
+ attachCallbackListeners(auth, manager) {
3257
+ // Get the global plugins
3258
+ const { universalLinks, handleOpenURL, BuildInfo } = _cordovaWindow();
3259
+ const noEventTimeout = setTimeout(async () => {
3260
+ // We didn't see that initial event. Clear any pending object and
3261
+ // dispatch no event
3262
+ await _getAndRemoveEvent(auth);
3263
+ manager.onEvent(generateNoEvent());
3264
+ }, INITIAL_EVENT_TIMEOUT_MS);
3265
+ const universalLinksCb = async (eventData) => {
3266
+ // We have an event so we can clear the no event timeout
3267
+ clearTimeout(noEventTimeout);
3268
+ const partialEvent = await _getAndRemoveEvent(auth);
3269
+ let finalEvent = null;
3270
+ if (partialEvent && (eventData === null || eventData === void 0 ? void 0 : eventData['url'])) {
3271
+ finalEvent = _eventFromPartialAndUrl(partialEvent, eventData['url']);
3272
+ }
3273
+ // If finalEvent is never filled, trigger with no event
3274
+ manager.onEvent(finalEvent || generateNoEvent());
3275
+ };
3276
+ // Universal links subscriber doesn't exist for iOS, so we need to check
3277
+ if (typeof universalLinks !== 'undefined' &&
3278
+ typeof universalLinks.subscribe === 'function') {
3279
+ universalLinks.subscribe(null, universalLinksCb);
3280
+ }
3281
+ // iOS 7 or 8 custom URL schemes.
3282
+ // This is also the current default behavior for iOS 9+.
3283
+ // For this to work, cordova-plugin-customurlscheme needs to be installed.
3284
+ // https://github.com/EddyVerbruggen/Custom-URL-scheme
3285
+ // Do not overwrite the existing developer's URL handler.
3286
+ const existingHandleOpenURL = handleOpenURL;
3287
+ const packagePrefix = `${BuildInfo.packageName.toLowerCase()}://`;
3288
+ _cordovaWindow().handleOpenURL = async (url) => {
3289
+ if (url.toLowerCase().startsWith(packagePrefix)) {
3290
+ // We want this intentionally to float
3291
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
3292
+ universalLinksCb({ url });
3293
+ }
3294
+ // Call the developer's handler if it is present.
3295
+ if (typeof existingHandleOpenURL === 'function') {
3296
+ try {
3297
+ existingHandleOpenURL(url);
3298
+ }
3299
+ catch (e) {
3300
+ // This is a developer error. Don't stop the flow of the SDK.
3301
+ console.error(e);
3302
+ }
3303
+ }
3304
+ };
3305
+ }
3306
+ }
3307
+ /**
3308
+ * An implementation of {@link PopupRedirectResolver} suitable for Cordova
3309
+ * based applications.
3310
+ *
3311
+ * @public
3312
+ */
3313
+ const cordovaPopupRedirectResolver = CordovaPopupRedirectResolver;
3314
+ function generateNoEvent() {
3315
+ return {
3316
+ type: "unknown" /* AuthEventType.UNKNOWN */,
3317
+ eventId: null,
3318
+ sessionId: null,
3319
+ urlResponse: null,
3320
+ postBody: null,
3321
+ tenantId: null,
3322
+ error: _createError("no-auth-event" /* AuthErrorCode.NO_AUTH_EVENT */)
3323
+ };
3324
+ }
3325
+
3326
+ /**
3327
+ * @license
3328
+ * Copyright 2017 Google LLC
3329
+ *
3330
+ * Licensed under the Apache License, Version 2.0 (the "License");
3331
+ * you may not use this file except in compliance with the License.
3332
+ * You may obtain a copy of the License at
3333
+ *
3334
+ * http://www.apache.org/licenses/LICENSE-2.0
3335
+ *
3336
+ * Unless required by applicable law or agreed to in writing, software
3337
+ * distributed under the License is distributed on an "AS IS" BASIS,
3338
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3339
+ * See the License for the specific language governing permissions and
3340
+ * limitations under the License.
3341
+ */
3342
+ // This function should only be called by frameworks (e.g. FirebaseUI-web) to log their usage.
3343
+ // It is not intended for direct use by developer apps. NO jsdoc here to intentionally leave it out
3344
+ // of autogenerated documentation pages to reduce accidental misuse.
3345
+ function addFrameworkForLogging(auth, framework) {
3346
+ _castAuth(auth)._logFramework(framework);
3347
+ }
3348
+
3349
+ export { ActionCodeOperation, AuthPopup, FactorId, OperationType, PhoneAuthProvider, PhoneMultiFactorGenerator, ProviderId, RecaptchaVerifier, SignInMethod, _getRedirectResult, _overrideRedirectResult, addFrameworkForLogging, browserLocalPersistence, browserPopupRedirectResolver, browserSessionPersistence, cordovaPopupRedirectResolver, getAuth, getRedirectResult, linkWithPhoneNumber, linkWithPopup, linkWithRedirect, reauthenticateWithPhoneNumber, reauthenticateWithPopup, reauthenticateWithRedirect, signInWithPhoneNumber, signInWithPopup, signInWithRedirect, updatePhoneNumber };
3350
+ //# sourceMappingURL=internal.js.map