@firebase/auth 0.18.3 → 0.19.0-canary.0b3ca78eb

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 (365) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/auth-public.d.ts +28 -19
  3. package/dist/auth.d.ts +29 -20
  4. package/dist/cordova/index.js +2 -2
  5. package/dist/cordova/index.rn.d.ts +3 -0
  6. package/dist/cordova/internal.js +7 -3
  7. package/dist/cordova/internal.js.map +1 -1
  8. package/dist/cordova/{popup_redirect-f608cd47.js → popup_redirect-680c56fc.js} +54 -33
  9. package/dist/cordova/popup_redirect-680c56fc.js.map +1 -0
  10. package/dist/cordova/src/core/errors.d.ts +2 -2
  11. package/dist/cordova/src/core/strategies/abstract_popup_redirect_operation.d.ts +1 -1
  12. package/dist/cordova/src/mfa/mfa_error.d.ts +4 -5
  13. package/dist/cordova/src/model/public_types.d.ts +25 -19
  14. package/dist/cordova/src/platform_browser/persistence/browser.d.ts +4 -3
  15. package/dist/cordova/src/platform_browser/persistence/browser.test.d.ts +17 -0
  16. package/dist/cordova/src/platform_browser/strategies/phone.d.ts +3 -0
  17. package/dist/cordova/test/helpers/erroring_unavailable_persistence.d.ts +36 -0
  18. package/dist/esm2017/{index-f41a0691.js → index-100be16e.js} +43 -25
  19. package/dist/esm2017/index-100be16e.js.map +1 -0
  20. package/dist/esm2017/index.js +1 -1
  21. package/dist/esm2017/index.rn.d.ts +3 -0
  22. package/dist/esm2017/internal.js +2 -2
  23. package/dist/esm2017/src/core/errors.d.ts +2 -2
  24. package/dist/esm2017/src/core/strategies/abstract_popup_redirect_operation.d.ts +1 -1
  25. package/dist/esm2017/src/mfa/mfa_error.d.ts +4 -5
  26. package/dist/esm2017/src/model/public_types.d.ts +25 -19
  27. package/dist/esm2017/src/platform_browser/persistence/browser.d.ts +4 -3
  28. package/dist/esm2017/src/platform_browser/persistence/browser.test.d.ts +17 -0
  29. package/dist/esm2017/src/platform_browser/strategies/phone.d.ts +3 -0
  30. package/dist/esm2017/test/helpers/erroring_unavailable_persistence.d.ts +36 -0
  31. package/dist/esm5/{index-fd8b7af5.js → index-4c58d8b7.js} +59 -34
  32. package/dist/esm5/index-4c58d8b7.js.map +1 -0
  33. package/dist/esm5/index.js +1 -1
  34. package/dist/esm5/index.rn.d.ts +3 -0
  35. package/dist/esm5/internal.js +2 -2
  36. package/dist/esm5/src/core/errors.d.ts +2 -2
  37. package/dist/esm5/src/core/strategies/abstract_popup_redirect_operation.d.ts +1 -1
  38. package/dist/esm5/src/mfa/mfa_error.d.ts +4 -5
  39. package/dist/esm5/src/model/public_types.d.ts +25 -19
  40. package/dist/esm5/src/platform_browser/persistence/browser.d.ts +4 -3
  41. package/dist/esm5/src/platform_browser/persistence/browser.test.d.ts +17 -0
  42. package/dist/esm5/src/platform_browser/strategies/phone.d.ts +3 -0
  43. package/dist/esm5/test/helpers/erroring_unavailable_persistence.d.ts +36 -0
  44. package/dist/index.rn.d.ts +3 -0
  45. package/dist/index.webworker.esm5.js +25 -23
  46. package/dist/index.webworker.esm5.js.map +1 -1
  47. package/dist/node/{index-358613ec.js → index-8505a33c.js} +26 -24
  48. package/dist/node/index-8505a33c.js.map +1 -0
  49. package/dist/node/index.js +1 -1
  50. package/dist/node/index.rn.d.ts +3 -0
  51. package/dist/node/internal.js +29 -10
  52. package/dist/node/internal.js.map +1 -1
  53. package/dist/node/src/core/errors.d.ts +2 -2
  54. package/dist/node/src/core/strategies/abstract_popup_redirect_operation.d.ts +1 -1
  55. package/dist/node/src/mfa/mfa_error.d.ts +4 -5
  56. package/dist/node/src/model/public_types.d.ts +25 -19
  57. package/dist/node/src/platform_browser/persistence/browser.d.ts +4 -3
  58. package/dist/node/src/platform_browser/persistence/browser.test.d.ts +17 -0
  59. package/dist/node/src/platform_browser/strategies/phone.d.ts +3 -0
  60. package/dist/node/test/helpers/erroring_unavailable_persistence.d.ts +36 -0
  61. package/dist/node-esm/index-4b759c81.js +6031 -0
  62. package/dist/node-esm/index-4b759c81.js.map +1 -0
  63. package/dist/node-esm/index.cordova.d.ts +32 -0
  64. package/dist/node-esm/index.d.ts +36 -0
  65. package/dist/node-esm/index.doc.d.ts +24 -0
  66. package/dist/node-esm/index.js +8 -0
  67. package/dist/node-esm/index.js.map +1 -0
  68. package/dist/node-esm/index.node.d.ts +17 -0
  69. package/dist/node-esm/index.rn.d.ts +30 -0
  70. package/dist/node-esm/index.shared.d.ts +19 -0
  71. package/dist/node-esm/index.webworker.d.ts +21 -0
  72. package/dist/node-esm/internal/index.d.ts +41 -0
  73. package/dist/node-esm/internal.js +1455 -0
  74. package/dist/node-esm/internal.js.map +1 -0
  75. package/dist/node-esm/package.json +1 -0
  76. package/dist/node-esm/scripts/run_node_tests.d.ts +17 -0
  77. package/dist/node-esm/src/api/account_management/account.d.ts +59 -0
  78. package/dist/node-esm/src/api/account_management/account.test.d.ts +17 -0
  79. package/dist/node-esm/src/api/account_management/email_and_password.d.ts +47 -0
  80. package/dist/node-esm/src/api/account_management/email_and_password.test.d.ts +17 -0
  81. package/dist/node-esm/src/api/account_management/mfa.d.ts +69 -0
  82. package/dist/node-esm/src/api/account_management/mfa.test.d.ts +17 -0
  83. package/dist/node-esm/src/api/account_management/profile.d.ts +29 -0
  84. package/dist/node-esm/src/api/account_management/profile.test.d.ts +17 -0
  85. package/dist/node-esm/src/api/authentication/create_auth_uri.d.ts +26 -0
  86. package/dist/node-esm/src/api/authentication/create_auth_uri.test.d.ts +17 -0
  87. package/dist/node-esm/src/api/authentication/custom_token.d.ts +26 -0
  88. package/dist/node-esm/src/api/authentication/custom_token.test.d.ts +17 -0
  89. package/dist/node-esm/src/api/authentication/email_and_password.d.ts +76 -0
  90. package/dist/node-esm/src/api/authentication/email_and_password.test.d.ts +17 -0
  91. package/dist/node-esm/src/api/authentication/email_link.d.ts +32 -0
  92. package/dist/node-esm/src/api/authentication/email_link.test.d.ts +17 -0
  93. package/dist/node-esm/src/api/authentication/idp.d.ts +40 -0
  94. package/dist/node-esm/src/api/authentication/idp.test.d.ts +17 -0
  95. package/dist/node-esm/src/api/authentication/mfa.d.ts +58 -0
  96. package/dist/node-esm/src/api/authentication/mfa.test.d.ts +17 -0
  97. package/dist/node-esm/src/api/authentication/recaptcha.d.ts +18 -0
  98. package/dist/node-esm/src/api/authentication/recaptcha.test.d.ts +17 -0
  99. package/dist/node-esm/src/api/authentication/sign_up.d.ts +29 -0
  100. package/dist/node-esm/src/api/authentication/sign_up.test.d.ts +17 -0
  101. package/dist/node-esm/src/api/authentication/sms.d.ts +50 -0
  102. package/dist/node-esm/src/api/authentication/sms.test.d.ts +17 -0
  103. package/dist/node-esm/src/api/authentication/token.d.ts +26 -0
  104. package/dist/node-esm/src/api/authentication/token.test.d.ts +17 -0
  105. package/dist/node-esm/src/api/errors.d.ts +118 -0
  106. package/dist/node-esm/src/api/index.d.ts +67 -0
  107. package/dist/node-esm/src/api/index.test.d.ts +17 -0
  108. package/dist/node-esm/src/api/project_config/get_project_config.d.ts +25 -0
  109. package/dist/node-esm/src/api/project_config/get_project_config.test.d.ts +17 -0
  110. package/dist/node-esm/src/core/action_code_url.d.ts +73 -0
  111. package/dist/node-esm/src/core/action_code_url.test.d.ts +17 -0
  112. package/dist/node-esm/src/core/auth/auth_event_manager.d.ts +34 -0
  113. package/dist/node-esm/src/core/auth/auth_event_manager.test.d.ts +17 -0
  114. package/dist/node-esm/src/core/auth/auth_impl.d.ts +106 -0
  115. package/dist/node-esm/src/core/auth/auth_impl.test.d.ts +17 -0
  116. package/dist/node-esm/src/core/auth/emulator.d.ts +42 -0
  117. package/dist/node-esm/src/core/auth/emulator.test.d.ts +17 -0
  118. package/dist/node-esm/src/core/auth/firebase_internal.d.ts +35 -0
  119. package/dist/node-esm/src/core/auth/firebase_internal.test.d.ts +17 -0
  120. package/dist/node-esm/src/core/auth/initialize.d.ts +46 -0
  121. package/dist/node-esm/src/core/auth/initialize.test.d.ts +17 -0
  122. package/dist/node-esm/src/core/auth/register.d.ts +23 -0
  123. package/dist/node-esm/src/core/credentials/auth_credential.d.ts +75 -0
  124. package/dist/node-esm/src/core/credentials/email.d.ts +60 -0
  125. package/dist/node-esm/src/core/credentials/email.test.d.ts +17 -0
  126. package/dist/node-esm/src/core/credentials/index.d.ts +23 -0
  127. package/dist/node-esm/src/core/credentials/oauth.d.ts +81 -0
  128. package/dist/node-esm/src/core/credentials/oauth.test.d.ts +17 -0
  129. package/dist/node-esm/src/core/credentials/phone.d.ts +52 -0
  130. package/dist/node-esm/src/core/credentials/phone.test.d.ts +17 -0
  131. package/dist/node-esm/src/core/credentials/saml.d.ts +52 -0
  132. package/dist/node-esm/src/core/credentials/saml.test.d.ts +17 -0
  133. package/dist/node-esm/src/core/errors.d.ts +299 -0
  134. package/dist/node-esm/src/core/errors.test.d.ts +17 -0
  135. package/dist/node-esm/src/core/index.d.ts +141 -0
  136. package/dist/node-esm/src/core/persistence/in_memory.d.ts +35 -0
  137. package/dist/node-esm/src/core/persistence/in_memory.test.d.ts +17 -0
  138. package/dist/node-esm/src/core/persistence/index.d.ts +41 -0
  139. package/dist/node-esm/src/core/persistence/persistence_user_manager.d.ts +45 -0
  140. package/dist/node-esm/src/core/persistence/persistence_user_manager.test.d.ts +17 -0
  141. package/dist/node-esm/src/core/providers/email.d.ts +83 -0
  142. package/dist/node-esm/src/core/providers/email.test.d.ts +17 -0
  143. package/dist/node-esm/src/core/providers/facebook.d.ts +93 -0
  144. package/dist/node-esm/src/core/providers/facebook.test.d.ts +17 -0
  145. package/dist/node-esm/src/core/providers/federated.d.ts +64 -0
  146. package/dist/node-esm/src/core/providers/federated.test.d.ts +17 -0
  147. package/dist/node-esm/src/core/providers/github.d.ts +89 -0
  148. package/dist/node-esm/src/core/providers/github.test.d.ts +17 -0
  149. package/dist/node-esm/src/core/providers/google.d.ts +96 -0
  150. package/dist/node-esm/src/core/providers/google.test.d.ts +17 -0
  151. package/dist/node-esm/src/core/providers/oauth.d.ts +151 -0
  152. package/dist/node-esm/src/core/providers/oauth.test.d.ts +17 -0
  153. package/dist/node-esm/src/core/providers/saml.d.ts +62 -0
  154. package/dist/node-esm/src/core/providers/saml.test.d.ts +17 -0
  155. package/dist/node-esm/src/core/providers/twitter.d.ts +103 -0
  156. package/dist/node-esm/src/core/providers/twitter.test.d.ts +17 -0
  157. package/dist/node-esm/src/core/strategies/abstract_popup_redirect_operation.d.ts +44 -0
  158. package/dist/node-esm/src/core/strategies/abstract_popup_redirect_operation.test.d.ts +17 -0
  159. package/dist/node-esm/src/core/strategies/action_code_settings.d.ts +19 -0
  160. package/dist/node-esm/src/core/strategies/action_code_settings.test.d.ts +17 -0
  161. package/dist/node-esm/src/core/strategies/anonymous.d.ts +29 -0
  162. package/dist/node-esm/src/core/strategies/anonymous.test.d.ts +17 -0
  163. package/dist/node-esm/src/core/strategies/credential.d.ts +57 -0
  164. package/dist/node-esm/src/core/strategies/credential.test.d.ts +17 -0
  165. package/dist/node-esm/src/core/strategies/custom_token.d.ts +34 -0
  166. package/dist/node-esm/src/core/strategies/custom_token.test.d.ts +17 -0
  167. package/dist/node-esm/src/core/strategies/email.d.ts +98 -0
  168. package/dist/node-esm/src/core/strategies/email.test.d.ts +17 -0
  169. package/dist/node-esm/src/core/strategies/email_and_password.d.ts +126 -0
  170. package/dist/node-esm/src/core/strategies/email_and_password.test.d.ts +17 -0
  171. package/dist/node-esm/src/core/strategies/email_link.d.ts +103 -0
  172. package/dist/node-esm/src/core/strategies/email_link.test.d.ts +17 -0
  173. package/dist/node-esm/src/core/strategies/idp.d.ts +32 -0
  174. package/dist/node-esm/src/core/strategies/idp.test.d.ts +17 -0
  175. package/dist/node-esm/src/core/strategies/redirect.d.ts +35 -0
  176. package/dist/node-esm/src/core/strategies/redirect.test.d.ts +17 -0
  177. package/dist/node-esm/src/core/user/account_info.d.ts +60 -0
  178. package/dist/node-esm/src/core/user/account_info.test.d.ts +17 -0
  179. package/dist/node-esm/src/core/user/additional_user_info.d.ts +31 -0
  180. package/dist/node-esm/src/core/user/additional_user_info.test.d.ts +17 -0
  181. package/dist/node-esm/src/core/user/id_token_result.d.ts +48 -0
  182. package/dist/node-esm/src/core/user/id_token_result.test.d.ts +17 -0
  183. package/dist/node-esm/src/core/user/invalidation.d.ts +18 -0
  184. package/dist/node-esm/src/core/user/invalidation.test.d.ts +17 -0
  185. package/dist/node-esm/src/core/user/link_unlink.d.ts +30 -0
  186. package/dist/node-esm/src/core/user/link_unlink.test.d.ts +17 -0
  187. package/dist/node-esm/src/core/user/proactive_refresh.d.ts +34 -0
  188. package/dist/node-esm/src/core/user/proactive_refresh.test.d.ts +17 -0
  189. package/dist/node-esm/src/core/user/reauthenticate.d.ts +20 -0
  190. package/dist/node-esm/src/core/user/reauthenticate.test.d.ts +17 -0
  191. package/dist/node-esm/src/core/user/reload.d.ts +27 -0
  192. package/dist/node-esm/src/core/user/reload.test.d.ts +17 -0
  193. package/dist/node-esm/src/core/user/token_manager.d.ts +49 -0
  194. package/dist/node-esm/src/core/user/token_manager.test.d.ts +17 -0
  195. package/dist/node-esm/src/core/user/user_credential_impl.d.ts +37 -0
  196. package/dist/node-esm/src/core/user/user_credential_impl.test.d.ts +17 -0
  197. package/dist/node-esm/src/core/user/user_impl.d.ts +68 -0
  198. package/dist/node-esm/src/core/user/user_impl.test.d.ts +17 -0
  199. package/dist/node-esm/src/core/user/user_metadata.d.ts +27 -0
  200. package/dist/node-esm/src/core/util/assert.d.ts +93 -0
  201. package/dist/node-esm/src/core/util/assert.test.d.ts +17 -0
  202. package/dist/node-esm/src/core/util/browser.d.ts +50 -0
  203. package/dist/node-esm/src/core/util/browser.test.d.ts +17 -0
  204. package/dist/node-esm/src/core/util/delay.d.ts +31 -0
  205. package/dist/node-esm/src/core/util/delay.test.d.ts +17 -0
  206. package/dist/node-esm/src/core/util/emulator.d.ts +18 -0
  207. package/dist/node-esm/src/core/util/emulator.test.d.ts +17 -0
  208. package/dist/node-esm/src/core/util/event_id.d.ts +17 -0
  209. package/dist/node-esm/src/core/util/event_id.test.d.ts +17 -0
  210. package/dist/node-esm/src/core/util/fetch_provider.d.ts +25 -0
  211. package/dist/node-esm/src/core/util/handler.d.ts +20 -0
  212. package/dist/node-esm/src/core/util/instantiator.d.ts +28 -0
  213. package/dist/node-esm/src/core/util/instantiator.test.d.ts +17 -0
  214. package/dist/node-esm/src/core/util/location.d.ts +19 -0
  215. package/dist/node-esm/src/core/util/log.d.ts +22 -0
  216. package/dist/node-esm/src/core/util/navigator.d.ts +21 -0
  217. package/dist/node-esm/src/core/util/providers.d.ts +23 -0
  218. package/dist/node-esm/src/core/util/resolver.d.ts +25 -0
  219. package/dist/node-esm/src/core/util/time.d.ts +17 -0
  220. package/dist/node-esm/src/core/util/validate_origin.d.ts +18 -0
  221. package/dist/node-esm/src/core/util/validate_origin.test.d.ts +17 -0
  222. package/dist/node-esm/src/core/util/version.d.ts +30 -0
  223. package/dist/node-esm/src/core/util/version.test.d.ts +17 -0
  224. package/dist/node-esm/src/index.d.ts +18 -0
  225. package/dist/node-esm/src/mfa/index.d.ts +18 -0
  226. package/dist/node-esm/src/mfa/mfa_assertion.d.ts +27 -0
  227. package/dist/node-esm/src/mfa/mfa_error.d.ts +35 -0
  228. package/dist/node-esm/src/mfa/mfa_info.d.ts +32 -0
  229. package/dist/node-esm/src/mfa/mfa_info.test.d.ts +17 -0
  230. package/dist/node-esm/src/mfa/mfa_resolver.d.ts +41 -0
  231. package/dist/node-esm/src/mfa/mfa_resolver.test.d.ts +17 -0
  232. package/dist/node-esm/src/mfa/mfa_session.d.ts +37 -0
  233. package/dist/node-esm/src/mfa/mfa_session.test.d.ts +17 -0
  234. package/dist/node-esm/src/mfa/mfa_user.d.ts +38 -0
  235. package/dist/node-esm/src/mfa/mfa_user.test.d.ts +17 -0
  236. package/dist/node-esm/src/model/application_verifier.d.ts +23 -0
  237. package/dist/node-esm/src/model/auth.d.ts +75 -0
  238. package/dist/node-esm/src/model/enum_maps.d.ts +97 -0
  239. package/dist/node-esm/src/model/enums.d.ts +74 -0
  240. package/dist/node-esm/src/model/id_token.d.ts +84 -0
  241. package/dist/node-esm/src/model/popup_redirect.d.ts +92 -0
  242. package/dist/node-esm/src/model/public_types.d.ts +1139 -0
  243. package/dist/node-esm/src/model/user.d.ts +79 -0
  244. package/dist/node-esm/src/platform_browser/auth.test.d.ts +17 -0
  245. package/dist/node-esm/src/platform_browser/auth_window.d.ts +37 -0
  246. package/dist/node-esm/src/platform_browser/iframe/gapi.d.ts +19 -0
  247. package/dist/node-esm/src/platform_browser/iframe/gapi.iframes.d.ts +47 -0
  248. package/dist/node-esm/src/platform_browser/iframe/gapi.test.d.ts +17 -0
  249. package/dist/node-esm/src/platform_browser/iframe/iframe.d.ts +18 -0
  250. package/dist/node-esm/src/platform_browser/iframe/iframe.test.d.ts +17 -0
  251. package/dist/node-esm/src/platform_browser/index.d.ts +27 -0
  252. package/dist/node-esm/src/platform_browser/load_js.d.ts +18 -0
  253. package/dist/node-esm/src/platform_browser/load_js.test.d.ts +17 -0
  254. package/dist/node-esm/src/platform_browser/messagechannel/index.d.ts +87 -0
  255. package/dist/node-esm/src/platform_browser/messagechannel/promise.d.ts +33 -0
  256. package/dist/node-esm/src/platform_browser/messagechannel/promise.test.d.ts +17 -0
  257. package/dist/node-esm/src/platform_browser/messagechannel/receiver.d.ts +63 -0
  258. package/dist/node-esm/src/platform_browser/messagechannel/receiver.test.d.ts +17 -0
  259. package/dist/node-esm/src/platform_browser/messagechannel/sender.d.ts +46 -0
  260. package/dist/node-esm/src/platform_browser/messagechannel/sender.test.d.ts +17 -0
  261. package/dist/node-esm/src/platform_browser/mfa/assertions/phone.d.ts +56 -0
  262. package/dist/node-esm/src/platform_browser/mfa/assertions/phone.test.d.ts +17 -0
  263. package/dist/node-esm/src/platform_browser/persistence/browser.d.ts +27 -0
  264. package/dist/node-esm/src/platform_browser/persistence/browser.test.d.ts +17 -0
  265. package/dist/node-esm/src/platform_browser/persistence/indexed_db.d.ts +33 -0
  266. package/dist/node-esm/src/platform_browser/persistence/indexed_db.test.d.ts +17 -0
  267. package/dist/node-esm/src/platform_browser/persistence/local_storage.d.ts +25 -0
  268. package/dist/node-esm/src/platform_browser/persistence/local_storage.test.d.ts +17 -0
  269. package/dist/node-esm/src/platform_browser/persistence/session_storage.d.ts +24 -0
  270. package/dist/node-esm/src/platform_browser/persistence/session_storage.test.d.ts +17 -0
  271. package/dist/node-esm/src/platform_browser/popup_redirect.d.ts +24 -0
  272. package/dist/node-esm/src/platform_browser/popup_redirect.test.d.ts +17 -0
  273. package/dist/node-esm/src/platform_browser/providers/phone.d.ts +149 -0
  274. package/dist/node-esm/src/platform_browser/providers/phone.test.d.ts +17 -0
  275. package/dist/node-esm/src/platform_browser/recaptcha/recaptcha.d.ts +23 -0
  276. package/dist/node-esm/src/platform_browser/recaptcha/recaptcha_loader.d.ts +44 -0
  277. package/dist/node-esm/src/platform_browser/recaptcha/recaptcha_loader.test.d.ts +17 -0
  278. package/dist/node-esm/src/platform_browser/recaptcha/recaptcha_mock.d.ts +51 -0
  279. package/dist/node-esm/src/platform_browser/recaptcha/recaptcha_mock.test.d.ts +17 -0
  280. package/dist/node-esm/src/platform_browser/recaptcha/recaptcha_verifier.d.ts +94 -0
  281. package/dist/node-esm/src/platform_browser/recaptcha/recaptcha_verifier.test.d.ts +17 -0
  282. package/dist/node-esm/src/platform_browser/strategies/phone.d.ts +98 -0
  283. package/dist/node-esm/src/platform_browser/strategies/phone.test.d.ts +17 -0
  284. package/dist/node-esm/src/platform_browser/strategies/popup.d.ts +103 -0
  285. package/dist/node-esm/src/platform_browser/strategies/popup.test.d.ts +17 -0
  286. package/dist/node-esm/src/platform_browser/strategies/redirect.d.ts +156 -0
  287. package/dist/node-esm/src/platform_browser/strategies/redirect.test.d.ts +17 -0
  288. package/dist/node-esm/src/platform_browser/util/popup.d.ts +24 -0
  289. package/dist/node-esm/src/platform_browser/util/popup.test.d.ts +17 -0
  290. package/dist/node-esm/src/platform_browser/util/worker.d.ts +20 -0
  291. package/dist/node-esm/src/platform_cordova/plugins.d.ts +42 -0
  292. package/dist/node-esm/src/platform_cordova/popup_redirect/events.d.ts +39 -0
  293. package/dist/node-esm/src/platform_cordova/popup_redirect/events.test.d.ts +17 -0
  294. package/dist/node-esm/src/platform_cordova/popup_redirect/popup_redirect.d.ts +24 -0
  295. package/dist/node-esm/src/platform_cordova/popup_redirect/popup_redirect.test.d.ts +17 -0
  296. package/dist/node-esm/src/platform_cordova/popup_redirect/utils.d.ts +47 -0
  297. package/dist/node-esm/src/platform_cordova/popup_redirect/utils.test.d.ts +17 -0
  298. package/dist/node-esm/src/platform_cordova/strategies/redirect.d.ts +20 -0
  299. package/dist/node-esm/src/platform_node/index.d.ts +49 -0
  300. package/dist/node-esm/src/platform_react_native/persistence/react_native.d.ts +31 -0
  301. package/dist/node-esm/src/platform_react_native/persistence/react_native.test.d.ts +17 -0
  302. package/dist/node-esm/test/helpers/api/helper.d.ts +20 -0
  303. package/dist/node-esm/test/helpers/delay.d.ts +20 -0
  304. package/dist/node-esm/test/helpers/erroring_unavailable_persistence.d.ts +36 -0
  305. package/dist/node-esm/test/helpers/fake_service_worker.d.ts +22 -0
  306. package/dist/node-esm/test/helpers/id_token_response.d.ts +18 -0
  307. package/dist/node-esm/test/helpers/iframe_event.d.ts +19 -0
  308. package/dist/node-esm/test/helpers/integration/emulator_rest_helpers.d.ts +35 -0
  309. package/dist/node-esm/test/helpers/integration/helpers.d.ts +20 -0
  310. package/dist/node-esm/test/helpers/integration/settings.d.ts +23 -0
  311. package/dist/node-esm/test/helpers/jwt.d.ts +17 -0
  312. package/dist/node-esm/test/helpers/mock_auth.d.ts +37 -0
  313. package/dist/node-esm/test/helpers/mock_auth_credential.d.ts +31 -0
  314. package/dist/node-esm/test/helpers/mock_fetch.d.ts +30 -0
  315. package/dist/node-esm/test/helpers/mock_fetch.test.d.ts +17 -0
  316. package/dist/node-esm/test/helpers/mock_popup_redirect_resolver.d.ts +24 -0
  317. package/dist/node-esm/test/helpers/redirect_persistence.d.ts +24 -0
  318. package/dist/node-esm/test/helpers/timeout_stub.d.ts +34 -0
  319. package/dist/node-esm/test/integration/flows/anonymous.test.d.ts +17 -0
  320. package/dist/node-esm/test/integration/flows/custom.local.test.d.ts +17 -0
  321. package/dist/node-esm/test/integration/flows/email.test.d.ts +17 -0
  322. package/dist/node-esm/test/integration/flows/idp.local.test.d.ts +17 -0
  323. package/dist/node-esm/test/integration/flows/oob.local.test.d.ts +17 -0
  324. package/dist/node-esm/test/integration/flows/phone.test.d.ts +17 -0
  325. package/dist/node-esm/test/integration/webdriver/anonymous.test.d.ts +17 -0
  326. package/dist/node-esm/test/integration/webdriver/compat/firebaseui.test.d.ts +17 -0
  327. package/dist/node-esm/test/integration/webdriver/persistence.test.d.ts +17 -0
  328. package/dist/node-esm/test/integration/webdriver/popup.test.d.ts +17 -0
  329. package/dist/node-esm/test/integration/webdriver/redirect.test.d.ts +17 -0
  330. package/dist/node-esm/test/integration/webdriver/util/auth_driver.d.ts +46 -0
  331. package/dist/node-esm/test/integration/webdriver/util/functions.d.ts +77 -0
  332. package/dist/node-esm/test/integration/webdriver/util/idp_page.d.ts +31 -0
  333. package/dist/node-esm/test/integration/webdriver/util/js_load_condition.d.ts +25 -0
  334. package/dist/node-esm/test/integration/webdriver/util/test_runner.d.ts +19 -0
  335. package/dist/node-esm/test/integration/webdriver/util/test_server.d.ts +27 -0
  336. package/dist/node-esm/test/integration/webdriver/util/ui_page.d.ts +33 -0
  337. package/dist/rn/index.js +70 -64
  338. package/dist/rn/index.js.map +1 -1
  339. package/dist/rn/index.rn.d.ts +3 -0
  340. package/dist/rn/internal.js +338 -1465
  341. package/dist/rn/internal.js.map +1 -1
  342. package/dist/rn/{enum_maps-81db3ff6.js → phone-fe0b5242.js} +1195 -34
  343. package/dist/rn/phone-fe0b5242.js.map +1 -0
  344. package/dist/rn/src/core/errors.d.ts +2 -2
  345. package/dist/rn/src/core/strategies/abstract_popup_redirect_operation.d.ts +1 -1
  346. package/dist/rn/src/mfa/mfa_error.d.ts +4 -5
  347. package/dist/rn/src/model/public_types.d.ts +25 -19
  348. package/dist/rn/src/platform_browser/persistence/browser.d.ts +4 -3
  349. package/dist/rn/src/platform_browser/persistence/browser.test.d.ts +17 -0
  350. package/dist/rn/src/platform_browser/strategies/phone.d.ts +3 -0
  351. package/dist/rn/test/helpers/erroring_unavailable_persistence.d.ts +36 -0
  352. package/dist/src/core/errors.d.ts +2 -2
  353. package/dist/src/core/strategies/abstract_popup_redirect_operation.d.ts +1 -1
  354. package/dist/src/mfa/mfa_error.d.ts +4 -5
  355. package/dist/src/model/public_types.d.ts +25 -19
  356. package/dist/src/platform_browser/persistence/browser.d.ts +4 -3
  357. package/dist/src/platform_browser/persistence/browser.test.d.ts +17 -0
  358. package/dist/src/platform_browser/strategies/phone.d.ts +3 -0
  359. package/dist/test/helpers/erroring_unavailable_persistence.d.ts +36 -0
  360. package/package.json +31 -9
  361. package/dist/cordova/popup_redirect-f608cd47.js.map +0 -1
  362. package/dist/esm2017/index-f41a0691.js.map +0 -1
  363. package/dist/esm5/index-fd8b7af5.js.map +0 -1
  364. package/dist/node/index-358613ec.js.map +0 -1
  365. package/dist/rn/enum_maps-81db3ff6.js.map +0 -1
@@ -0,0 +1,1455 @@
1
+ import { ao as _getInstance, ap as _assert, aq as _signInWithCredential, ar as _reauthenticate, as as _link$1, G as AuthCredential, at as signInWithIdp, au as _fail, av as debugAssert, aw as _persistenceKeyName, ax as _castAuth, ay as FederatedAuthProvider, az as BaseOAuthProvider, aA as _emulatorUrl, aB as _performApiRequest, aC as _isIOS7Or8, aD as _isIOS, aE as _isAndroid, aF as _createError, aG as _isSafari, aH as _isIframe, aI as _isMobileBrowser, aJ as _isIE10 } from './index-4b759c81.js';
2
+ export { A as ActionCodeOperation, ac as ActionCodeURL, G as AuthCredential, C as AuthErrorCodes, aL as AuthImpl, H as EmailAuthCredential, L as EmailAuthProvider, M as FacebookAuthProvider, F as FactorId, aN as FetchProvider, Q as GithubAuthProvider, N as GoogleAuthProvider, I as OAuthCredential, T as OAuthProvider, O as OperationType, J as PhoneAuthCredential, P as PhoneAuthProvider, m as PhoneMultiFactorGenerator, o as ProviderId, R as RecaptchaVerifier, aO as SAMLAuthCredential, U as SAMLAuthProvider, S as SignInMethod, V as TwitterAuthProvider, aK as UserImpl, ap as _assert, ax as _castAuth, au as _fail, aM as _getClientVersion, ao as _getInstance, aw as _persistenceKeyName, a1 as applyActionCode, b as browserLocalPersistence, k as browserPopupRedirectResolver, a as browserSessionPersistence, a2 as checkActionCode, a0 as confirmPasswordReset, E as connectAuthEmulator, a4 as createUserWithEmailAndPassword, z as debugErrorMap, y as deleteUser, a9 as fetchSignInMethodsForEmail, ak as getAdditionalUserInfo, n as getAuth, ah as getIdToken, ai as getIdTokenResult, am as getMultiFactorResolver, j as getRedirectResult, K as inMemoryPersistence, i as indexedDBLocalPersistence, D as initializeAuth, a7 as isSignInWithEmailLink, Y as linkWithCredential, l as linkWithPhoneNumber, d as linkWithPopup, g as linkWithRedirect, an as multiFactor, t as onAuthStateChanged, q as onIdTokenChanged, ad as parseActionCodeURL, B as prodErrorMap, Z as reauthenticateWithCredential, r as reauthenticateWithPhoneNumber, e as reauthenticateWithPopup, h as reauthenticateWithRedirect, al as reload, aa as sendEmailVerification, $ as sendPasswordResetEmail, a6 as sendSignInLinkToEmail, p as setPersistence, W as signInAnonymously, X as signInWithCredential, _ as signInWithCustomToken, a5 as signInWithEmailAndPassword, a8 as signInWithEmailLink, s as signInWithPhoneNumber, c as signInWithPopup, f as signInWithRedirect, x as signOut, aj as unlink, w as updateCurrentUser, af as updateEmail, ag as updatePassword, u as updatePhoneNumber, ae as updateProfile, v as useDeviceLanguage, ab as verifyBeforeUpdateEmail, a3 as verifyPasswordResetCode } from './index-4b759c81.js';
3
+ import { querystring, isEmpty, getUA, querystringDecode } from '@firebase/util';
4
+ import 'tslib';
5
+ import { SDK_VERSION } from '@firebase/app';
6
+ import '@firebase/logger';
7
+ import '@firebase/component';
8
+ import 'node-fetch';
9
+
10
+ /**
11
+ * @license
12
+ * Copyright 2020 Google LLC
13
+ *
14
+ * Licensed under the Apache License, Version 2.0 (the "License");
15
+ * you may not use this file except in compliance with the License.
16
+ * You may obtain a copy of the License at
17
+ *
18
+ * http://www.apache.org/licenses/LICENSE-2.0
19
+ *
20
+ * Unless required by applicable law or agreed to in writing, software
21
+ * distributed under the License is distributed on an "AS IS" BASIS,
22
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
+ * See the License for the specific language governing permissions and
24
+ * limitations under the License.
25
+ */
26
+ function _generateEventId(prefix = '', digits = 10) {
27
+ let random = '';
28
+ for (let i = 0; i < digits; i++) {
29
+ random += Math.floor(Math.random() * 10);
30
+ }
31
+ return prefix + random;
32
+ }
33
+
34
+ /**
35
+ * @license
36
+ * Copyright 2020 Google LLC.
37
+ *
38
+ * Licensed under the Apache License, Version 2.0 (the "License");
39
+ * you may not use this file except in compliance with the License.
40
+ * You may obtain a copy of the License at
41
+ *
42
+ * http://www.apache.org/licenses/LICENSE-2.0
43
+ *
44
+ * Unless required by applicable law or agreed to in writing, software
45
+ * distributed under the License is distributed on an "AS IS" BASIS,
46
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
47
+ * See the License for the specific language governing permissions and
48
+ * limitations under the License.
49
+ */
50
+ class AuthPopup {
51
+ constructor(window) {
52
+ this.window = window;
53
+ this.associatedEvent = null;
54
+ }
55
+ close() {
56
+ if (this.window) {
57
+ try {
58
+ this.window.close();
59
+ }
60
+ catch (e) { }
61
+ }
62
+ }
63
+ }
64
+
65
+ /**
66
+ * @license
67
+ * Copyright 2021 Google LLC
68
+ *
69
+ * Licensed under the Apache License, Version 2.0 (the "License");
70
+ * you may not use this file except in compliance with the License.
71
+ * You may obtain a copy of the License at
72
+ *
73
+ * http://www.apache.org/licenses/LICENSE-2.0
74
+ *
75
+ * Unless required by applicable law or agreed to in writing, software
76
+ * distributed under the License is distributed on an "AS IS" BASIS,
77
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
78
+ * See the License for the specific language governing permissions and
79
+ * limitations under the License.
80
+ */
81
+ /**
82
+ * Chooses a popup/redirect resolver to use. This prefers the override (which
83
+ * is directly passed in), and falls back to the property set on the auth
84
+ * object. If neither are available, this function errors w/ an argument error.
85
+ */
86
+ function _withDefaultResolver(auth, resolverOverride) {
87
+ if (resolverOverride) {
88
+ return _getInstance(resolverOverride);
89
+ }
90
+ _assert(auth._popupRedirectResolver, auth, "argument-error" /* ARGUMENT_ERROR */);
91
+ return auth._popupRedirectResolver;
92
+ }
93
+
94
+ /**
95
+ * @license
96
+ * Copyright 2019 Google LLC
97
+ *
98
+ * Licensed under the Apache License, Version 2.0 (the "License");
99
+ * you may not use this file except in compliance with the License.
100
+ * You may obtain a copy of the License at
101
+ *
102
+ * http://www.apache.org/licenses/LICENSE-2.0
103
+ *
104
+ * Unless required by applicable law or agreed to in writing, software
105
+ * distributed under the License is distributed on an "AS IS" BASIS,
106
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
107
+ * See the License for the specific language governing permissions and
108
+ * limitations under the License.
109
+ */
110
+ class IdpCredential extends AuthCredential {
111
+ constructor(params) {
112
+ super("custom" /* CUSTOM */, "custom" /* CUSTOM */);
113
+ this.params = params;
114
+ }
115
+ _getIdTokenResponse(auth) {
116
+ return signInWithIdp(auth, this._buildIdpRequest());
117
+ }
118
+ _linkToIdToken(auth, idToken) {
119
+ return signInWithIdp(auth, this._buildIdpRequest(idToken));
120
+ }
121
+ _getReauthenticationResolver(auth) {
122
+ return signInWithIdp(auth, this._buildIdpRequest());
123
+ }
124
+ _buildIdpRequest(idToken) {
125
+ const request = {
126
+ requestUri: this.params.requestUri,
127
+ sessionId: this.params.sessionId,
128
+ postBody: this.params.postBody,
129
+ tenantId: this.params.tenantId,
130
+ pendingToken: this.params.pendingToken,
131
+ returnSecureToken: true,
132
+ returnIdpCredential: true
133
+ };
134
+ if (idToken) {
135
+ request.idToken = idToken;
136
+ }
137
+ return request;
138
+ }
139
+ }
140
+ function _signIn(params) {
141
+ return _signInWithCredential(params.auth, new IdpCredential(params), params.bypassAuthState);
142
+ }
143
+ function _reauth(params) {
144
+ const { auth, user } = params;
145
+ _assert(user, auth, "internal-error" /* INTERNAL_ERROR */);
146
+ return _reauthenticate(user, new IdpCredential(params), params.bypassAuthState);
147
+ }
148
+ async function _link(params) {
149
+ const { auth, user } = params;
150
+ _assert(user, auth, "internal-error" /* INTERNAL_ERROR */);
151
+ return _link$1(user, new IdpCredential(params), params.bypassAuthState);
152
+ }
153
+
154
+ /**
155
+ * @license
156
+ * Copyright 2020 Google LLC
157
+ *
158
+ * Licensed under the Apache License, Version 2.0 (the "License");
159
+ * you may not use this file except in compliance with the License.
160
+ * You may obtain a copy of the License at
161
+ *
162
+ * http://www.apache.org/licenses/LICENSE-2.0
163
+ *
164
+ * Unless required by applicable law or agreed to in writing, software
165
+ * distributed under the License is distributed on an "AS IS" BASIS,
166
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
167
+ * See the License for the specific language governing permissions and
168
+ * limitations under the License.
169
+ */
170
+ /**
171
+ * Popup event manager. Handles the popup's entire lifecycle; listens to auth
172
+ * events
173
+ */
174
+ class AbstractPopupRedirectOperation {
175
+ constructor(auth, filter, resolver, user, bypassAuthState = false) {
176
+ this.auth = auth;
177
+ this.resolver = resolver;
178
+ this.user = user;
179
+ this.bypassAuthState = bypassAuthState;
180
+ this.pendingPromise = null;
181
+ this.eventManager = null;
182
+ this.filter = Array.isArray(filter) ? filter : [filter];
183
+ }
184
+ execute() {
185
+ return new Promise(async (resolve, reject) => {
186
+ this.pendingPromise = { resolve, reject };
187
+ try {
188
+ this.eventManager = await this.resolver._initialize(this.auth);
189
+ await this.onExecution();
190
+ this.eventManager.registerConsumer(this);
191
+ }
192
+ catch (e) {
193
+ this.reject(e);
194
+ }
195
+ });
196
+ }
197
+ async onAuthEvent(event) {
198
+ const { urlResponse, sessionId, postBody, tenantId, error, type } = event;
199
+ if (error) {
200
+ this.reject(error);
201
+ return;
202
+ }
203
+ const params = {
204
+ auth: this.auth,
205
+ requestUri: urlResponse,
206
+ sessionId: sessionId,
207
+ tenantId: tenantId || undefined,
208
+ postBody: postBody || undefined,
209
+ user: this.user,
210
+ bypassAuthState: this.bypassAuthState
211
+ };
212
+ try {
213
+ this.resolve(await this.getIdpTask(type)(params));
214
+ }
215
+ catch (e) {
216
+ this.reject(e);
217
+ }
218
+ }
219
+ onError(error) {
220
+ this.reject(error);
221
+ }
222
+ getIdpTask(type) {
223
+ switch (type) {
224
+ case "signInViaPopup" /* SIGN_IN_VIA_POPUP */:
225
+ case "signInViaRedirect" /* SIGN_IN_VIA_REDIRECT */:
226
+ return _signIn;
227
+ case "linkViaPopup" /* LINK_VIA_POPUP */:
228
+ case "linkViaRedirect" /* LINK_VIA_REDIRECT */:
229
+ return _link;
230
+ case "reauthViaPopup" /* REAUTH_VIA_POPUP */:
231
+ case "reauthViaRedirect" /* REAUTH_VIA_REDIRECT */:
232
+ return _reauth;
233
+ default:
234
+ _fail(this.auth, "internal-error" /* INTERNAL_ERROR */);
235
+ }
236
+ }
237
+ resolve(cred) {
238
+ debugAssert(this.pendingPromise, 'Pending promise was never set');
239
+ this.pendingPromise.resolve(cred);
240
+ this.unregisterAndCleanUp();
241
+ }
242
+ reject(error) {
243
+ debugAssert(this.pendingPromise, 'Pending promise was never set');
244
+ this.pendingPromise.reject(error);
245
+ this.unregisterAndCleanUp();
246
+ }
247
+ unregisterAndCleanUp() {
248
+ if (this.eventManager) {
249
+ this.eventManager.unregisterConsumer(this);
250
+ }
251
+ this.pendingPromise = null;
252
+ this.cleanUp();
253
+ }
254
+ }
255
+
256
+ /**
257
+ * @license
258
+ * Copyright 2020 Google LLC
259
+ *
260
+ * Licensed under the Apache License, Version 2.0 (the "License");
261
+ * you may not use this file except in compliance with the License.
262
+ * You may obtain a copy of the License at
263
+ *
264
+ * http://www.apache.org/licenses/LICENSE-2.0
265
+ *
266
+ * Unless required by applicable law or agreed to in writing, software
267
+ * distributed under the License is distributed on an "AS IS" BASIS,
268
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
269
+ * See the License for the specific language governing permissions and
270
+ * limitations under the License.
271
+ */
272
+ const PENDING_REDIRECT_KEY = 'pendingRedirect';
273
+ // We only get one redirect outcome for any one auth, so just store it
274
+ // in here.
275
+ const redirectOutcomeMap = new Map();
276
+ class RedirectAction extends AbstractPopupRedirectOperation {
277
+ constructor(auth, resolver, bypassAuthState = false) {
278
+ super(auth, [
279
+ "signInViaRedirect" /* SIGN_IN_VIA_REDIRECT */,
280
+ "linkViaRedirect" /* LINK_VIA_REDIRECT */,
281
+ "reauthViaRedirect" /* REAUTH_VIA_REDIRECT */,
282
+ "unknown" /* UNKNOWN */
283
+ ], resolver, undefined, bypassAuthState);
284
+ this.eventId = null;
285
+ }
286
+ /**
287
+ * Override the execute function; if we already have a redirect result, then
288
+ * just return it.
289
+ */
290
+ async execute() {
291
+ let readyOutcome = redirectOutcomeMap.get(this.auth._key());
292
+ if (!readyOutcome) {
293
+ try {
294
+ const hasPendingRedirect = await _getAndClearPendingRedirectStatus(this.resolver, this.auth);
295
+ const result = hasPendingRedirect ? await super.execute() : null;
296
+ readyOutcome = () => Promise.resolve(result);
297
+ }
298
+ catch (e) {
299
+ readyOutcome = () => Promise.reject(e);
300
+ }
301
+ redirectOutcomeMap.set(this.auth._key(), readyOutcome);
302
+ }
303
+ // If we're not bypassing auth state, the ready outcome should be set to
304
+ // null.
305
+ if (!this.bypassAuthState) {
306
+ redirectOutcomeMap.set(this.auth._key(), () => Promise.resolve(null));
307
+ }
308
+ return readyOutcome();
309
+ }
310
+ async onAuthEvent(event) {
311
+ if (event.type === "signInViaRedirect" /* SIGN_IN_VIA_REDIRECT */) {
312
+ return super.onAuthEvent(event);
313
+ }
314
+ else if (event.type === "unknown" /* UNKNOWN */) {
315
+ // This is a sentinel value indicating there's no pending redirect
316
+ this.resolve(null);
317
+ return;
318
+ }
319
+ if (event.eventId) {
320
+ const user = await this.auth._redirectUserForId(event.eventId);
321
+ if (user) {
322
+ this.user = user;
323
+ return super.onAuthEvent(event);
324
+ }
325
+ else {
326
+ this.resolve(null);
327
+ }
328
+ }
329
+ }
330
+ async onExecution() { }
331
+ cleanUp() { }
332
+ }
333
+ async function _getAndClearPendingRedirectStatus(resolver, auth) {
334
+ const key = pendingRedirectKey(auth);
335
+ const persistence = resolverPersistence(resolver);
336
+ if (!(await persistence._isAvailable())) {
337
+ return false;
338
+ }
339
+ const hasPendingRedirect = (await persistence._get(key)) === 'true';
340
+ await persistence._remove(key);
341
+ return hasPendingRedirect;
342
+ }
343
+ function _clearRedirectOutcomes() {
344
+ redirectOutcomeMap.clear();
345
+ }
346
+ function resolverPersistence(resolver) {
347
+ return _getInstance(resolver._redirectPersistence);
348
+ }
349
+ function pendingRedirectKey(auth) {
350
+ return _persistenceKeyName(PENDING_REDIRECT_KEY, auth.config.apiKey, auth.name);
351
+ }
352
+
353
+ /**
354
+ * @license
355
+ * Copyright 2020 Google LLC
356
+ *
357
+ * Licensed under the Apache License, Version 2.0 (the "License");
358
+ * you may not use this file except in compliance with the License.
359
+ * You may obtain a copy of the License at
360
+ *
361
+ * http://www.apache.org/licenses/LICENSE-2.0
362
+ *
363
+ * Unless required by applicable law or agreed to in writing, software
364
+ * distributed under the License is distributed on an "AS IS" BASIS,
365
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
366
+ * See the License for the specific language governing permissions and
367
+ * limitations under the License.
368
+ */
369
+ async function _getRedirectResult(auth, resolverExtern, bypassAuthState = false) {
370
+ const authInternal = _castAuth(auth);
371
+ const resolver = _withDefaultResolver(authInternal, resolverExtern);
372
+ const action = new RedirectAction(authInternal, resolver, bypassAuthState);
373
+ const result = await action.execute();
374
+ if (result && !bypassAuthState) {
375
+ delete result.user._redirectEventId;
376
+ await authInternal._persistUserIfCurrent(result.user);
377
+ await authInternal._setRedirectUser(null, resolverExtern);
378
+ }
379
+ return result;
380
+ }
381
+
382
+ const STORAGE_AVAILABLE_KEY = '__sak';
383
+
384
+ /**
385
+ * @license
386
+ * Copyright 2019 Google LLC
387
+ *
388
+ * Licensed under the Apache License, Version 2.0 (the "License");
389
+ * you may not use this file except in compliance with the License.
390
+ * You may obtain a copy of the License at
391
+ *
392
+ * http://www.apache.org/licenses/LICENSE-2.0
393
+ *
394
+ * Unless required by applicable law or agreed to in writing, software
395
+ * distributed under the License is distributed on an "AS IS" BASIS,
396
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
397
+ * See the License for the specific language governing permissions and
398
+ * limitations under the License.
399
+ */
400
+ // There are two different browser persistence types: local and session.
401
+ // Both have the same implementation but use a different underlying storage
402
+ // object.
403
+ class BrowserPersistenceClass {
404
+ constructor(storageRetriever, type) {
405
+ this.storageRetriever = storageRetriever;
406
+ this.type = type;
407
+ }
408
+ _isAvailable() {
409
+ try {
410
+ if (!this.storage) {
411
+ return Promise.resolve(false);
412
+ }
413
+ this.storage.setItem(STORAGE_AVAILABLE_KEY, '1');
414
+ this.storage.removeItem(STORAGE_AVAILABLE_KEY);
415
+ return Promise.resolve(true);
416
+ }
417
+ catch (_a) {
418
+ return Promise.resolve(false);
419
+ }
420
+ }
421
+ _set(key, value) {
422
+ this.storage.setItem(key, JSON.stringify(value));
423
+ return Promise.resolve();
424
+ }
425
+ _get(key) {
426
+ const json = this.storage.getItem(key);
427
+ return Promise.resolve(json ? JSON.parse(json) : null);
428
+ }
429
+ _remove(key) {
430
+ this.storage.removeItem(key);
431
+ return Promise.resolve();
432
+ }
433
+ get storage() {
434
+ return this.storageRetriever();
435
+ }
436
+ }
437
+
438
+ /**
439
+ * @license
440
+ * Copyright 2020 Google LLC
441
+ *
442
+ * Licensed under the Apache License, Version 2.0 (the "License");
443
+ * you may not use this file except in compliance with the License.
444
+ * You may obtain a copy of the License at
445
+ *
446
+ * http://www.apache.org/licenses/LICENSE-2.0
447
+ *
448
+ * Unless required by applicable law or agreed to in writing, software
449
+ * distributed under the License is distributed on an "AS IS" BASIS,
450
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
451
+ * See the License for the specific language governing permissions and
452
+ * limitations under the License.
453
+ */
454
+ class BrowserSessionPersistence extends BrowserPersistenceClass {
455
+ constructor() {
456
+ super(() => window.sessionStorage, "SESSION" /* SESSION */);
457
+ }
458
+ _addListener(_key, _listener) {
459
+ // Listeners are not supported for session storage since it cannot be shared across windows
460
+ return;
461
+ }
462
+ _removeListener(_key, _listener) {
463
+ // Listeners are not supported for session storage since it cannot be shared across windows
464
+ return;
465
+ }
466
+ }
467
+ BrowserSessionPersistence.type = 'SESSION';
468
+ /**
469
+ * An implementation of {@link Persistence} of `SESSION` using `sessionStorage`
470
+ * for the underlying storage.
471
+ *
472
+ * @public
473
+ */
474
+ const browserSessionPersistence = BrowserSessionPersistence;
475
+
476
+ /**
477
+ * @license
478
+ * Copyright 2021 Google LLC
479
+ *
480
+ * Licensed under the Apache License, Version 2.0 (the "License");
481
+ * you may not use this file except in compliance with the License.
482
+ * You may obtain a copy of the License at
483
+ *
484
+ * http://www.apache.org/licenses/LICENSE-2.0
485
+ *
486
+ * Unless required by applicable law or agreed to in writing, software
487
+ * distributed under the License is distributed on an "AS IS" BASIS,
488
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
489
+ * See the License for the specific language governing permissions and
490
+ * limitations under the License.
491
+ */
492
+ /**
493
+ * URL for Authentication widget which will initiate the OAuth handshake
494
+ *
495
+ * @internal
496
+ */
497
+ const WIDGET_PATH = '__/auth/handler';
498
+ /**
499
+ * URL for emulated environment
500
+ *
501
+ * @internal
502
+ */
503
+ const EMULATOR_WIDGET_PATH = 'emulator/auth/handler';
504
+ function _getRedirectUrl(auth, provider, authType, redirectUrl, eventId, additionalParams) {
505
+ _assert(auth.config.authDomain, auth, "auth-domain-config-required" /* MISSING_AUTH_DOMAIN */);
506
+ _assert(auth.config.apiKey, auth, "invalid-api-key" /* INVALID_API_KEY */);
507
+ const params = {
508
+ apiKey: auth.config.apiKey,
509
+ appName: auth.name,
510
+ authType,
511
+ redirectUrl,
512
+ v: SDK_VERSION,
513
+ eventId
514
+ };
515
+ if (provider instanceof FederatedAuthProvider) {
516
+ provider.setDefaultLanguage(auth.languageCode);
517
+ params.providerId = provider.providerId || '';
518
+ if (!isEmpty(provider.getCustomParameters())) {
519
+ params.customParameters = JSON.stringify(provider.getCustomParameters());
520
+ }
521
+ // TODO set additionalParams from the provider as well?
522
+ for (const [key, value] of Object.entries(additionalParams || {})) {
523
+ params[key] = value;
524
+ }
525
+ }
526
+ if (provider instanceof BaseOAuthProvider) {
527
+ const scopes = provider.getScopes().filter(scope => scope !== '');
528
+ if (scopes.length > 0) {
529
+ params.scopes = scopes.join(',');
530
+ }
531
+ }
532
+ if (auth.tenantId) {
533
+ params.tid = auth.tenantId;
534
+ }
535
+ // TODO: maybe set eid as endipointId
536
+ // TODO: maybe set fw as Frameworks.join(",")
537
+ const paramsDict = params;
538
+ for (const key of Object.keys(paramsDict)) {
539
+ if (paramsDict[key] === undefined) {
540
+ delete paramsDict[key];
541
+ }
542
+ }
543
+ return `${getHandlerBase(auth)}?${querystring(paramsDict).slice(1)}`;
544
+ }
545
+ function getHandlerBase({ config }) {
546
+ if (!config.emulator) {
547
+ return `https://${config.authDomain}/${WIDGET_PATH}`;
548
+ }
549
+ return _emulatorUrl(config, EMULATOR_WIDGET_PATH);
550
+ }
551
+
552
+ /**
553
+ * @license
554
+ * Copyright 2021 Google LLC
555
+ *
556
+ * Licensed under the Apache License, Version 2.0 (the "License");
557
+ * you may not use this file except in compliance with the License.
558
+ * You may obtain a copy of the License at
559
+ *
560
+ * http://www.apache.org/licenses/LICENSE-2.0
561
+ *
562
+ * Unless required by applicable law or agreed to in writing, software
563
+ * distributed under the License is distributed on an "AS IS" BASIS,
564
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
565
+ * See the License for the specific language governing permissions and
566
+ * limitations under the License.
567
+ */
568
+ function _cordovaWindow() {
569
+ return window;
570
+ }
571
+
572
+ /**
573
+ * @license
574
+ * Copyright 2020 Google LLC
575
+ *
576
+ * Licensed under the Apache License, Version 2.0 (the "License");
577
+ * you may not use this file except in compliance with the License.
578
+ * You may obtain a copy of the License at
579
+ *
580
+ * http://www.apache.org/licenses/LICENSE-2.0
581
+ *
582
+ * Unless required by applicable law or agreed to in writing, software
583
+ * distributed under the License is distributed on an "AS IS" BASIS,
584
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
585
+ * See the License for the specific language governing permissions and
586
+ * limitations under the License.
587
+ */
588
+ async function _getProjectConfig(auth, request = {}) {
589
+ return _performApiRequest(auth, "GET" /* GET */, "/v1/projects" /* GET_PROJECT_CONFIG */, request);
590
+ }
591
+
592
+ /**
593
+ * @license
594
+ * Copyright 2020 Google LLC
595
+ *
596
+ * Licensed under the Apache License, Version 2.0 (the "License");
597
+ * you may not use this file except in compliance with the License.
598
+ * You may obtain a copy of the License at
599
+ *
600
+ * http://www.apache.org/licenses/LICENSE-2.0
601
+ *
602
+ * Unless required by applicable law or agreed to in writing, software
603
+ * distributed under the License is distributed on an "AS IS" BASIS,
604
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
605
+ * See the License for the specific language governing permissions and
606
+ * limitations under the License.
607
+ */
608
+ /**
609
+ * How long to wait after the app comes back into focus before concluding that
610
+ * the user closed the sign in tab.
611
+ */
612
+ const REDIRECT_TIMEOUT_MS = 2000;
613
+ /**
614
+ * Generates the URL for the OAuth handler.
615
+ */
616
+ async function _generateHandlerUrl(auth, event, provider) {
617
+ var _a;
618
+ // Get the cordova plugins
619
+ const { BuildInfo } = _cordovaWindow();
620
+ debugAssert(event.sessionId, 'AuthEvent did not contain a session ID');
621
+ const sessionDigest = await computeSha256(event.sessionId);
622
+ const additionalParams = {};
623
+ if (_isIOS()) {
624
+ // iOS app identifier
625
+ additionalParams['ibi'] = BuildInfo.packageName;
626
+ }
627
+ else if (_isAndroid()) {
628
+ // Android app identifier
629
+ additionalParams['apn'] = BuildInfo.packageName;
630
+ }
631
+ else {
632
+ _fail(auth, "operation-not-supported-in-this-environment" /* OPERATION_NOT_SUPPORTED */);
633
+ }
634
+ // Add the display name if available
635
+ if (BuildInfo.displayName) {
636
+ additionalParams['appDisplayName'] = BuildInfo.displayName;
637
+ }
638
+ // Attached the hashed session ID
639
+ additionalParams['sessionId'] = sessionDigest;
640
+ return _getRedirectUrl(auth, provider, event.type, undefined, (_a = event.eventId) !== null && _a !== void 0 ? _a : undefined, additionalParams);
641
+ }
642
+ /**
643
+ * Validates that this app is valid for this project configuration
644
+ */
645
+ async function _validateOrigin(auth) {
646
+ const { BuildInfo } = _cordovaWindow();
647
+ const request = {};
648
+ if (_isIOS()) {
649
+ request.iosBundleId = BuildInfo.packageName;
650
+ }
651
+ else if (_isAndroid()) {
652
+ request.androidPackageName = BuildInfo.packageName;
653
+ }
654
+ else {
655
+ _fail(auth, "operation-not-supported-in-this-environment" /* OPERATION_NOT_SUPPORTED */);
656
+ }
657
+ // Will fail automatically if package name is not authorized
658
+ await _getProjectConfig(auth, request);
659
+ }
660
+ function _performRedirect(handlerUrl) {
661
+ // Get the cordova plugins
662
+ const { cordova } = _cordovaWindow();
663
+ return new Promise(resolve => {
664
+ cordova.plugins.browsertab.isAvailable(browserTabIsAvailable => {
665
+ let iabRef = null;
666
+ if (browserTabIsAvailable) {
667
+ cordova.plugins.browsertab.openUrl(handlerUrl);
668
+ }
669
+ else {
670
+ // TODO: Return the inappbrowser ref that's returned from the open call
671
+ iabRef = cordova.InAppBrowser.open(handlerUrl, _isIOS7Or8() ? '_blank' : '_system', 'location=yes');
672
+ }
673
+ resolve(iabRef);
674
+ });
675
+ });
676
+ }
677
+ /**
678
+ * This function waits for app activity to be seen before resolving. It does
679
+ * this by attaching listeners to various dom events. Once the app is determined
680
+ * to be visible, this promise resolves. AFTER that resolution, the listeners
681
+ * are detached and any browser tabs left open will be closed.
682
+ */
683
+ async function _waitForAppResume(auth, eventListener, iabRef) {
684
+ // Get the cordova plugins
685
+ const { cordova } = _cordovaWindow();
686
+ let cleanup = () => { };
687
+ try {
688
+ await new Promise((resolve, reject) => {
689
+ let onCloseTimer = null;
690
+ // DEFINE ALL THE CALLBACKS =====
691
+ function authEventSeen() {
692
+ var _a;
693
+ // Auth event was detected. Resolve this promise and close the extra
694
+ // window if it's still open.
695
+ resolve();
696
+ const closeBrowserTab = (_a = cordova.plugins.browsertab) === null || _a === void 0 ? void 0 : _a.close;
697
+ if (typeof closeBrowserTab === 'function') {
698
+ closeBrowserTab();
699
+ }
700
+ // Close inappbrowser emebedded webview in iOS7 and 8 case if still
701
+ // open.
702
+ if (typeof (iabRef === null || iabRef === void 0 ? void 0 : iabRef.close) === 'function') {
703
+ iabRef.close();
704
+ }
705
+ }
706
+ function resumed() {
707
+ if (onCloseTimer) {
708
+ // This code already ran; do not rerun.
709
+ return;
710
+ }
711
+ onCloseTimer = window.setTimeout(() => {
712
+ // Wait two seeconds after resume then reject.
713
+ reject(_createError(auth, "redirect-cancelled-by-user" /* REDIRECT_CANCELLED_BY_USER */));
714
+ }, REDIRECT_TIMEOUT_MS);
715
+ }
716
+ function visibilityChanged() {
717
+ if ((document === null || document === void 0 ? void 0 : document.visibilityState) === 'visible') {
718
+ resumed();
719
+ }
720
+ }
721
+ // ATTACH ALL THE LISTENERS =====
722
+ // Listen for the auth event
723
+ eventListener.addPassiveListener(authEventSeen);
724
+ // Listen for resume and visibility events
725
+ document.addEventListener('resume', resumed, false);
726
+ if (_isAndroid()) {
727
+ document.addEventListener('visibilitychange', visibilityChanged, false);
728
+ }
729
+ // SETUP THE CLEANUP FUNCTION =====
730
+ cleanup = () => {
731
+ eventListener.removePassiveListener(authEventSeen);
732
+ document.removeEventListener('resume', resumed, false);
733
+ document.removeEventListener('visibilitychange', visibilityChanged, false);
734
+ if (onCloseTimer) {
735
+ window.clearTimeout(onCloseTimer);
736
+ }
737
+ };
738
+ });
739
+ }
740
+ finally {
741
+ cleanup();
742
+ }
743
+ }
744
+ /**
745
+ * Checks the configuration of the Cordova environment. This has no side effect
746
+ * if the configuration is correct; otherwise it throws an error with the
747
+ * missing plugin.
748
+ */
749
+ function _checkCordovaConfiguration(auth) {
750
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
751
+ const win = _cordovaWindow();
752
+ // Check all dependencies installed.
753
+ // https://github.com/nordnet/cordova-universal-links-plugin
754
+ // Note that cordova-universal-links-plugin has been abandoned.
755
+ // A fork with latest fixes is available at:
756
+ // https://www.npmjs.com/package/cordova-universal-links-plugin-fix
757
+ _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" /* INVALID_CORDOVA_CONFIGURATION */, {
758
+ missingPlugin: 'cordova-universal-links-plugin-fix'
759
+ });
760
+ // https://www.npmjs.com/package/cordova-plugin-buildinfo
761
+ _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" /* INVALID_CORDOVA_CONFIGURATION */, {
762
+ missingPlugin: 'cordova-plugin-buildInfo'
763
+ });
764
+ // https://github.com/google/cordova-plugin-browsertab
765
+ _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" /* INVALID_CORDOVA_CONFIGURATION */, {
766
+ missingPlugin: 'cordova-plugin-browsertab'
767
+ });
768
+ _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" /* INVALID_CORDOVA_CONFIGURATION */, {
769
+ missingPlugin: 'cordova-plugin-browsertab'
770
+ });
771
+ // https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-inappbrowser/
772
+ _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" /* INVALID_CORDOVA_CONFIGURATION */, {
773
+ missingPlugin: 'cordova-plugin-inappbrowser'
774
+ });
775
+ }
776
+ /**
777
+ * Computes the SHA-256 of a session ID. The SubtleCrypto interface is only
778
+ * available in "secure" contexts, which covers Cordova (which is served on a file
779
+ * protocol).
780
+ */
781
+ async function computeSha256(sessionId) {
782
+ const bytes = stringToArrayBuffer(sessionId);
783
+ // TODO: For IE11 crypto has a different name and this operation comes back
784
+ // as an object, not a promise. This is the old proposed standard that
785
+ // is used by IE11:
786
+ // https://www.w3.org/TR/2013/WD-WebCryptoAPI-20130108/#cryptooperation-interface
787
+ const buf = await crypto.subtle.digest('SHA-256', bytes);
788
+ const arr = Array.from(new Uint8Array(buf));
789
+ return arr.map(num => num.toString(16).padStart(2, '0')).join('');
790
+ }
791
+ function stringToArrayBuffer(str) {
792
+ // This function is only meant to deal with an ASCII charset and makes
793
+ // certain simplifying assumptions.
794
+ debugAssert(/[0-9a-zA-Z]+/.test(str), 'Can only convert alpha-numeric strings');
795
+ if (typeof TextEncoder !== 'undefined') {
796
+ return new TextEncoder().encode(str);
797
+ }
798
+ const buff = new ArrayBuffer(str.length);
799
+ const view = new Uint8Array(buff);
800
+ for (let i = 0; i < str.length; i++) {
801
+ view[i] = str.charCodeAt(i);
802
+ }
803
+ return view;
804
+ }
805
+
806
+ /**
807
+ * @license
808
+ * Copyright 2020 Google LLC
809
+ *
810
+ * Licensed under the Apache License, Version 2.0 (the "License");
811
+ * you may not use this file except in compliance with the License.
812
+ * You may obtain a copy of the License at
813
+ *
814
+ * http://www.apache.org/licenses/LICENSE-2.0
815
+ *
816
+ * Unless required by applicable law or agreed to in writing, software
817
+ * distributed under the License is distributed on an "AS IS" BASIS,
818
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
819
+ * See the License for the specific language governing permissions and
820
+ * limitations under the License.
821
+ */
822
+ // The amount of time to store the UIDs of seen events; this is
823
+ // set to 10 min by default
824
+ const EVENT_DUPLICATION_CACHE_DURATION_MS = 10 * 60 * 1000;
825
+ class AuthEventManager {
826
+ constructor(auth) {
827
+ this.auth = auth;
828
+ this.cachedEventUids = new Set();
829
+ this.consumers = new Set();
830
+ this.queuedRedirectEvent = null;
831
+ this.hasHandledPotentialRedirect = false;
832
+ this.lastProcessedEventTime = Date.now();
833
+ }
834
+ registerConsumer(authEventConsumer) {
835
+ this.consumers.add(authEventConsumer);
836
+ if (this.queuedRedirectEvent &&
837
+ this.isEventForConsumer(this.queuedRedirectEvent, authEventConsumer)) {
838
+ this.sendToConsumer(this.queuedRedirectEvent, authEventConsumer);
839
+ this.saveEventToCache(this.queuedRedirectEvent);
840
+ this.queuedRedirectEvent = null;
841
+ }
842
+ }
843
+ unregisterConsumer(authEventConsumer) {
844
+ this.consumers.delete(authEventConsumer);
845
+ }
846
+ onEvent(event) {
847
+ // Check if the event has already been handled
848
+ if (this.hasEventBeenHandled(event)) {
849
+ return false;
850
+ }
851
+ let handled = false;
852
+ this.consumers.forEach(consumer => {
853
+ if (this.isEventForConsumer(event, consumer)) {
854
+ handled = true;
855
+ this.sendToConsumer(event, consumer);
856
+ this.saveEventToCache(event);
857
+ }
858
+ });
859
+ if (this.hasHandledPotentialRedirect || !isRedirectEvent(event)) {
860
+ // If we've already seen a redirect before, or this is a popup event,
861
+ // bail now
862
+ return handled;
863
+ }
864
+ this.hasHandledPotentialRedirect = true;
865
+ // If the redirect wasn't handled, hang on to it
866
+ if (!handled) {
867
+ this.queuedRedirectEvent = event;
868
+ handled = true;
869
+ }
870
+ return handled;
871
+ }
872
+ sendToConsumer(event, consumer) {
873
+ var _a;
874
+ if (event.error && !isNullRedirectEvent(event)) {
875
+ const code = ((_a = event.error.code) === null || _a === void 0 ? void 0 : _a.split('auth/')[1]) ||
876
+ "internal-error" /* INTERNAL_ERROR */;
877
+ consumer.onError(_createError(this.auth, code));
878
+ }
879
+ else {
880
+ consumer.onAuthEvent(event);
881
+ }
882
+ }
883
+ isEventForConsumer(event, consumer) {
884
+ const eventIdMatches = consumer.eventId === null ||
885
+ (!!event.eventId && event.eventId === consumer.eventId);
886
+ return consumer.filter.includes(event.type) && eventIdMatches;
887
+ }
888
+ hasEventBeenHandled(event) {
889
+ if (Date.now() - this.lastProcessedEventTime >=
890
+ EVENT_DUPLICATION_CACHE_DURATION_MS) {
891
+ this.cachedEventUids.clear();
892
+ }
893
+ return this.cachedEventUids.has(eventUid(event));
894
+ }
895
+ saveEventToCache(event) {
896
+ this.cachedEventUids.add(eventUid(event));
897
+ this.lastProcessedEventTime = Date.now();
898
+ }
899
+ }
900
+ function eventUid(e) {
901
+ return [e.type, e.eventId, e.sessionId, e.tenantId].filter(v => v).join('-');
902
+ }
903
+ function isNullRedirectEvent({ type, error }) {
904
+ return (type === "unknown" /* UNKNOWN */ &&
905
+ (error === null || error === void 0 ? void 0 : error.code) === `auth/${"no-auth-event" /* NO_AUTH_EVENT */}`);
906
+ }
907
+ function isRedirectEvent(event) {
908
+ switch (event.type) {
909
+ case "signInViaRedirect" /* SIGN_IN_VIA_REDIRECT */:
910
+ case "linkViaRedirect" /* LINK_VIA_REDIRECT */:
911
+ case "reauthViaRedirect" /* REAUTH_VIA_REDIRECT */:
912
+ return true;
913
+ case "unknown" /* UNKNOWN */:
914
+ return isNullRedirectEvent(event);
915
+ default:
916
+ return false;
917
+ }
918
+ }
919
+
920
+ /**
921
+ * @license
922
+ * Copyright 2020 Google LLC
923
+ *
924
+ * Licensed under the Apache License, Version 2.0 (the "License");
925
+ * you may not use this file except in compliance with the License.
926
+ * You may obtain a copy of the License at
927
+ *
928
+ * http://www.apache.org/licenses/LICENSE-2.0
929
+ *
930
+ * Unless required by applicable law or agreed to in writing, software
931
+ * distributed under the License is distributed on an "AS IS" BASIS,
932
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
933
+ * See the License for the specific language governing permissions and
934
+ * limitations under the License.
935
+ */
936
+ function _iframeCannotSyncWebStorage() {
937
+ const ua = getUA();
938
+ return _isSafari(ua) || _isIOS(ua);
939
+ }
940
+ // The polling period in case events are not supported
941
+ const _POLLING_INTERVAL_MS = 1000;
942
+ // The IE 10 localStorage cross tab synchronization delay in milliseconds
943
+ const IE10_LOCAL_STORAGE_SYNC_DELAY = 10;
944
+ class BrowserLocalPersistence extends BrowserPersistenceClass {
945
+ constructor() {
946
+ super(() => window.localStorage, "LOCAL" /* LOCAL */);
947
+ this.boundEventHandler = (event, poll) => this.onStorageEvent(event, poll);
948
+ this.listeners = {};
949
+ this.localCache = {};
950
+ // setTimeout return value is platform specific
951
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
952
+ this.pollTimer = null;
953
+ // Safari or iOS browser and embedded in an iframe.
954
+ this.safariLocalStorageNotSynced = _iframeCannotSyncWebStorage() && _isIframe();
955
+ // Whether to use polling instead of depending on window events
956
+ this.fallbackToPolling = _isMobileBrowser();
957
+ this._shouldAllowMigration = true;
958
+ }
959
+ forAllChangedKeys(cb) {
960
+ // Check all keys with listeners on them.
961
+ for (const key of Object.keys(this.listeners)) {
962
+ // Get value from localStorage.
963
+ const newValue = this.storage.getItem(key);
964
+ const oldValue = this.localCache[key];
965
+ // If local map value does not match, trigger listener with storage event.
966
+ // Differentiate this simulated event from the real storage event.
967
+ if (newValue !== oldValue) {
968
+ cb(key, oldValue, newValue);
969
+ }
970
+ }
971
+ }
972
+ onStorageEvent(event, poll = false) {
973
+ // Key would be null in some situations, like when localStorage is cleared
974
+ if (!event.key) {
975
+ this.forAllChangedKeys((key, _oldValue, newValue) => {
976
+ this.notifyListeners(key, newValue);
977
+ });
978
+ return;
979
+ }
980
+ const key = event.key;
981
+ // Check the mechanism how this event was detected.
982
+ // The first event will dictate the mechanism to be used.
983
+ if (poll) {
984
+ // Environment detects storage changes via polling.
985
+ // Remove storage event listener to prevent possible event duplication.
986
+ this.detachListener();
987
+ }
988
+ else {
989
+ // Environment detects storage changes via storage event listener.
990
+ // Remove polling listener to prevent possible event duplication.
991
+ this.stopPolling();
992
+ }
993
+ // Safari embedded iframe. Storage event will trigger with the delta
994
+ // changes but no changes will be applied to the iframe localStorage.
995
+ if (this.safariLocalStorageNotSynced) {
996
+ // Get current iframe page value.
997
+ const storedValue = this.storage.getItem(key);
998
+ // Value not synchronized, synchronize manually.
999
+ if (event.newValue !== storedValue) {
1000
+ if (event.newValue !== null) {
1001
+ // Value changed from current value.
1002
+ this.storage.setItem(key, event.newValue);
1003
+ }
1004
+ else {
1005
+ // Current value deleted.
1006
+ this.storage.removeItem(key);
1007
+ }
1008
+ }
1009
+ else if (this.localCache[key] === event.newValue && !poll) {
1010
+ // Already detected and processed, do not trigger listeners again.
1011
+ return;
1012
+ }
1013
+ }
1014
+ const triggerListeners = () => {
1015
+ // Keep local map up to date in case storage event is triggered before
1016
+ // poll.
1017
+ const storedValue = this.storage.getItem(key);
1018
+ if (!poll && this.localCache[key] === storedValue) {
1019
+ // Real storage event which has already been detected, do nothing.
1020
+ // This seems to trigger in some IE browsers for some reason.
1021
+ return;
1022
+ }
1023
+ this.notifyListeners(key, storedValue);
1024
+ };
1025
+ const storedValue = this.storage.getItem(key);
1026
+ if (_isIE10() &&
1027
+ storedValue !== event.newValue &&
1028
+ event.newValue !== event.oldValue) {
1029
+ // IE 10 has this weird bug where a storage event would trigger with the
1030
+ // correct key, oldValue and newValue but localStorage.getItem(key) does
1031
+ // not yield the updated value until a few milliseconds. This ensures
1032
+ // this recovers from that situation.
1033
+ setTimeout(triggerListeners, IE10_LOCAL_STORAGE_SYNC_DELAY);
1034
+ }
1035
+ else {
1036
+ triggerListeners();
1037
+ }
1038
+ }
1039
+ notifyListeners(key, value) {
1040
+ this.localCache[key] = value;
1041
+ const listeners = this.listeners[key];
1042
+ if (listeners) {
1043
+ for (const listener of Array.from(listeners)) {
1044
+ listener(value ? JSON.parse(value) : value);
1045
+ }
1046
+ }
1047
+ }
1048
+ startPolling() {
1049
+ this.stopPolling();
1050
+ this.pollTimer = setInterval(() => {
1051
+ this.forAllChangedKeys((key, oldValue, newValue) => {
1052
+ this.onStorageEvent(new StorageEvent('storage', {
1053
+ key,
1054
+ oldValue,
1055
+ newValue
1056
+ }),
1057
+ /* poll */ true);
1058
+ });
1059
+ }, _POLLING_INTERVAL_MS);
1060
+ }
1061
+ stopPolling() {
1062
+ if (this.pollTimer) {
1063
+ clearInterval(this.pollTimer);
1064
+ this.pollTimer = null;
1065
+ }
1066
+ }
1067
+ attachListener() {
1068
+ window.addEventListener('storage', this.boundEventHandler);
1069
+ }
1070
+ detachListener() {
1071
+ window.removeEventListener('storage', this.boundEventHandler);
1072
+ }
1073
+ _addListener(key, listener) {
1074
+ if (Object.keys(this.listeners).length === 0) {
1075
+ // Whether browser can detect storage event when it had already been pushed to the background.
1076
+ // This may happen in some mobile browsers. A localStorage change in the foreground window
1077
+ // will not be detected in the background window via the storage event.
1078
+ // This was detected in iOS 7.x mobile browsers
1079
+ if (this.fallbackToPolling) {
1080
+ this.startPolling();
1081
+ }
1082
+ else {
1083
+ this.attachListener();
1084
+ }
1085
+ }
1086
+ if (!this.listeners[key]) {
1087
+ this.listeners[key] = new Set();
1088
+ // Populate the cache to avoid spuriously triggering on first poll.
1089
+ this.localCache[key] = this.storage.getItem(key);
1090
+ }
1091
+ this.listeners[key].add(listener);
1092
+ }
1093
+ _removeListener(key, listener) {
1094
+ if (this.listeners[key]) {
1095
+ this.listeners[key].delete(listener);
1096
+ if (this.listeners[key].size === 0) {
1097
+ delete this.listeners[key];
1098
+ }
1099
+ }
1100
+ if (Object.keys(this.listeners).length === 0) {
1101
+ this.detachListener();
1102
+ this.stopPolling();
1103
+ }
1104
+ }
1105
+ // Update local cache on base operations:
1106
+ async _set(key, value) {
1107
+ await super._set(key, value);
1108
+ this.localCache[key] = JSON.stringify(value);
1109
+ }
1110
+ async _get(key) {
1111
+ const value = await super._get(key);
1112
+ this.localCache[key] = JSON.stringify(value);
1113
+ return value;
1114
+ }
1115
+ async _remove(key) {
1116
+ await super._remove(key);
1117
+ delete this.localCache[key];
1118
+ }
1119
+ }
1120
+ BrowserLocalPersistence.type = 'LOCAL';
1121
+ /**
1122
+ * An implementation of {@link Persistence} of type `LOCAL` using `localStorage`
1123
+ * for the underlying storage.
1124
+ *
1125
+ * @public
1126
+ */
1127
+ const browserLocalPersistence = BrowserLocalPersistence;
1128
+
1129
+ /**
1130
+ * @license
1131
+ * Copyright 2020 Google LLC
1132
+ *
1133
+ * Licensed under the Apache License, Version 2.0 (the "License");
1134
+ * you may not use this file except in compliance with the License.
1135
+ * You may obtain a copy of the License at
1136
+ *
1137
+ * http://www.apache.org/licenses/LICENSE-2.0
1138
+ *
1139
+ * Unless required by applicable law or agreed to in writing, software
1140
+ * distributed under the License is distributed on an "AS IS" BASIS,
1141
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1142
+ * See the License for the specific language governing permissions and
1143
+ * limitations under the License.
1144
+ */
1145
+ const SESSION_ID_LENGTH = 20;
1146
+ /** Custom AuthEventManager that adds passive listeners to events */
1147
+ class CordovaAuthEventManager extends AuthEventManager {
1148
+ constructor() {
1149
+ super(...arguments);
1150
+ this.passiveListeners = new Set();
1151
+ this.initPromise = new Promise(resolve => {
1152
+ this.resolveInialized = resolve;
1153
+ });
1154
+ }
1155
+ addPassiveListener(cb) {
1156
+ this.passiveListeners.add(cb);
1157
+ }
1158
+ removePassiveListener(cb) {
1159
+ this.passiveListeners.delete(cb);
1160
+ }
1161
+ // In a Cordova environment, this manager can live through multiple redirect
1162
+ // operations
1163
+ resetRedirect() {
1164
+ this.queuedRedirectEvent = null;
1165
+ this.hasHandledPotentialRedirect = false;
1166
+ }
1167
+ /** Override the onEvent method */
1168
+ onEvent(event) {
1169
+ this.resolveInialized();
1170
+ this.passiveListeners.forEach(cb => cb(event));
1171
+ return super.onEvent(event);
1172
+ }
1173
+ async initialized() {
1174
+ await this.initPromise;
1175
+ }
1176
+ }
1177
+ /**
1178
+ * Generates a (partial) {@link AuthEvent}.
1179
+ */
1180
+ function _generateNewEvent(auth, type, eventId = null) {
1181
+ return {
1182
+ type,
1183
+ eventId,
1184
+ urlResponse: null,
1185
+ sessionId: generateSessionId(),
1186
+ postBody: null,
1187
+ tenantId: auth.tenantId,
1188
+ error: _createError(auth, "no-auth-event" /* NO_AUTH_EVENT */)
1189
+ };
1190
+ }
1191
+ function _savePartialEvent(auth, event) {
1192
+ return storage()._set(persistenceKey(auth), event);
1193
+ }
1194
+ async function _getAndRemoveEvent(auth) {
1195
+ const event = (await storage()._get(persistenceKey(auth)));
1196
+ if (event) {
1197
+ await storage()._remove(persistenceKey(auth));
1198
+ }
1199
+ return event;
1200
+ }
1201
+ function _eventFromPartialAndUrl(partialEvent, url) {
1202
+ var _a, _b;
1203
+ // Parse the deep link within the dynamic link URL.
1204
+ const callbackUrl = _getDeepLinkFromCallback(url);
1205
+ // Confirm it is actually a callback URL.
1206
+ // Currently the universal link will be of this format:
1207
+ // https://<AUTH_DOMAIN>/__/auth/callback<OAUTH_RESPONSE>
1208
+ // This is a fake URL but is not intended to take the user anywhere
1209
+ // and just redirect to the app.
1210
+ if (callbackUrl.includes('/__/auth/callback')) {
1211
+ // Check if there is an error in the URL.
1212
+ // This mechanism is also used to pass errors back to the app:
1213
+ // https://<AUTH_DOMAIN>/__/auth/callback?firebaseError=<STRINGIFIED_ERROR>
1214
+ const params = searchParamsOrEmpty(callbackUrl);
1215
+ // Get the error object corresponding to the stringified error if found.
1216
+ const errorObject = params['firebaseError']
1217
+ ? parseJsonOrNull(decodeURIComponent(params['firebaseError']))
1218
+ : null;
1219
+ 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];
1220
+ const error = code ? _createError(code) : null;
1221
+ if (error) {
1222
+ return {
1223
+ type: partialEvent.type,
1224
+ eventId: partialEvent.eventId,
1225
+ tenantId: partialEvent.tenantId,
1226
+ error,
1227
+ urlResponse: null,
1228
+ sessionId: null,
1229
+ postBody: null
1230
+ };
1231
+ }
1232
+ else {
1233
+ return {
1234
+ type: partialEvent.type,
1235
+ eventId: partialEvent.eventId,
1236
+ tenantId: partialEvent.tenantId,
1237
+ sessionId: partialEvent.sessionId,
1238
+ urlResponse: callbackUrl,
1239
+ postBody: null
1240
+ };
1241
+ }
1242
+ }
1243
+ return null;
1244
+ }
1245
+ function generateSessionId() {
1246
+ const chars = [];
1247
+ const allowedChars = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
1248
+ for (let i = 0; i < SESSION_ID_LENGTH; i++) {
1249
+ const idx = Math.floor(Math.random() * allowedChars.length);
1250
+ chars.push(allowedChars.charAt(idx));
1251
+ }
1252
+ return chars.join('');
1253
+ }
1254
+ function storage() {
1255
+ return _getInstance(browserLocalPersistence);
1256
+ }
1257
+ function persistenceKey(auth) {
1258
+ return _persistenceKeyName("authEvent" /* AUTH_EVENT */, auth.config.apiKey, auth.name);
1259
+ }
1260
+ function parseJsonOrNull(json) {
1261
+ try {
1262
+ return JSON.parse(json);
1263
+ }
1264
+ catch (e) {
1265
+ return null;
1266
+ }
1267
+ }
1268
+ // Exported for testing
1269
+ function _getDeepLinkFromCallback(url) {
1270
+ const params = searchParamsOrEmpty(url);
1271
+ const link = params['link'] ? decodeURIComponent(params['link']) : undefined;
1272
+ // Double link case (automatic redirect)
1273
+ const doubleDeepLink = searchParamsOrEmpty(link)['link'];
1274
+ // iOS custom scheme links.
1275
+ const iOSDeepLink = params['deep_link_id']
1276
+ ? decodeURIComponent(params['deep_link_id'])
1277
+ : undefined;
1278
+ const iOSDoubleDeepLink = searchParamsOrEmpty(iOSDeepLink)['link'];
1279
+ return iOSDoubleDeepLink || iOSDeepLink || doubleDeepLink || link || url;
1280
+ }
1281
+ /**
1282
+ * Optimistically tries to get search params from a string, or else returns an
1283
+ * empty search params object.
1284
+ */
1285
+ function searchParamsOrEmpty(url) {
1286
+ if (!(url === null || url === void 0 ? void 0 : url.includes('?'))) {
1287
+ return {};
1288
+ }
1289
+ const [_, ...rest] = url.split('?');
1290
+ return querystringDecode(rest.join('?'));
1291
+ }
1292
+
1293
+ /**
1294
+ * @license
1295
+ * Copyright 2021 Google LLC
1296
+ *
1297
+ * Licensed under the Apache License, Version 2.0 (the "License");
1298
+ * you may not use this file except in compliance with the License.
1299
+ * You may obtain a copy of the License at
1300
+ *
1301
+ * http://www.apache.org/licenses/LICENSE-2.0
1302
+ *
1303
+ * Unless required by applicable law or agreed to in writing, software
1304
+ * distributed under the License is distributed on an "AS IS" BASIS,
1305
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1306
+ * See the License for the specific language governing permissions and
1307
+ * limitations under the License.
1308
+ */
1309
+ /**
1310
+ * How long to wait for the initial auth event before concluding no
1311
+ * redirect pending
1312
+ */
1313
+ const INITIAL_EVENT_TIMEOUT_MS = 500;
1314
+ class CordovaPopupRedirectResolver {
1315
+ constructor() {
1316
+ this._redirectPersistence = browserSessionPersistence;
1317
+ this._shouldInitProactively = true; // This is lightweight for Cordova
1318
+ this.eventManagers = new Map();
1319
+ this.originValidationPromises = {};
1320
+ this._completeRedirectFn = _getRedirectResult;
1321
+ }
1322
+ async _initialize(auth) {
1323
+ const key = auth._key();
1324
+ let manager = this.eventManagers.get(key);
1325
+ if (!manager) {
1326
+ manager = new CordovaAuthEventManager(auth);
1327
+ this.eventManagers.set(key, manager);
1328
+ this.attachCallbackListeners(auth, manager);
1329
+ }
1330
+ return manager;
1331
+ }
1332
+ _openPopup(auth) {
1333
+ _fail(auth, "operation-not-supported-in-this-environment" /* OPERATION_NOT_SUPPORTED */);
1334
+ }
1335
+ async _openRedirect(auth, provider, authType, eventId) {
1336
+ _checkCordovaConfiguration(auth);
1337
+ const manager = await this._initialize(auth);
1338
+ await manager.initialized();
1339
+ // Reset the persisted redirect states. This does not matter on Web where
1340
+ // the redirect always blows away application state entirely. On Cordova,
1341
+ // the app maintains control flow through the redirect.
1342
+ manager.resetRedirect();
1343
+ _clearRedirectOutcomes();
1344
+ await this._originValidation(auth);
1345
+ const event = _generateNewEvent(auth, authType, eventId);
1346
+ await _savePartialEvent(auth, event);
1347
+ const url = await _generateHandlerUrl(auth, event, provider);
1348
+ const iabRef = await _performRedirect(url);
1349
+ return _waitForAppResume(auth, manager, iabRef);
1350
+ }
1351
+ _isIframeWebStorageSupported(_auth, _cb) {
1352
+ throw new Error('Method not implemented.');
1353
+ }
1354
+ _originValidation(auth) {
1355
+ const key = auth._key();
1356
+ if (!this.originValidationPromises[key]) {
1357
+ this.originValidationPromises[key] = _validateOrigin(auth);
1358
+ }
1359
+ return this.originValidationPromises[key];
1360
+ }
1361
+ attachCallbackListeners(auth, manager) {
1362
+ // Get the global plugins
1363
+ const { universalLinks, handleOpenURL, BuildInfo } = _cordovaWindow();
1364
+ const noEventTimeout = setTimeout(async () => {
1365
+ // We didn't see that initial event. Clear any pending object and
1366
+ // dispatch no event
1367
+ await _getAndRemoveEvent(auth);
1368
+ manager.onEvent(generateNoEvent());
1369
+ }, INITIAL_EVENT_TIMEOUT_MS);
1370
+ const universalLinksCb = async (eventData) => {
1371
+ // We have an event so we can clear the no event timeout
1372
+ clearTimeout(noEventTimeout);
1373
+ const partialEvent = await _getAndRemoveEvent(auth);
1374
+ let finalEvent = null;
1375
+ if (partialEvent && (eventData === null || eventData === void 0 ? void 0 : eventData['url'])) {
1376
+ finalEvent = _eventFromPartialAndUrl(partialEvent, eventData['url']);
1377
+ }
1378
+ // If finalEvent is never filled, trigger with no event
1379
+ manager.onEvent(finalEvent || generateNoEvent());
1380
+ };
1381
+ // Universal links subscriber doesn't exist for iOS, so we need to check
1382
+ if (typeof universalLinks !== 'undefined' &&
1383
+ typeof universalLinks.subscribe === 'function') {
1384
+ universalLinks.subscribe(null, universalLinksCb);
1385
+ }
1386
+ // iOS 7 or 8 custom URL schemes.
1387
+ // This is also the current default behavior for iOS 9+.
1388
+ // For this to work, cordova-plugin-customurlscheme needs to be installed.
1389
+ // https://github.com/EddyVerbruggen/Custom-URL-scheme
1390
+ // Do not overwrite the existing developer's URL handler.
1391
+ const existingHandleOpenURL = handleOpenURL;
1392
+ const packagePrefix = `${BuildInfo.packageName.toLowerCase()}://`;
1393
+ _cordovaWindow().handleOpenURL = async (url) => {
1394
+ if (url.toLowerCase().startsWith(packagePrefix)) {
1395
+ // We want this intentionally to float
1396
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
1397
+ universalLinksCb({ url });
1398
+ }
1399
+ // Call the developer's handler if it is present.
1400
+ if (typeof existingHandleOpenURL === 'function') {
1401
+ try {
1402
+ existingHandleOpenURL(url);
1403
+ }
1404
+ catch (e) {
1405
+ // This is a developer error. Don't stop the flow of the SDK.
1406
+ console.error(e);
1407
+ }
1408
+ }
1409
+ };
1410
+ }
1411
+ }
1412
+ /**
1413
+ * An implementation of {@link PopupRedirectResolver} suitable for Cordova
1414
+ * based applications.
1415
+ *
1416
+ * @public
1417
+ */
1418
+ const cordovaPopupRedirectResolver = CordovaPopupRedirectResolver;
1419
+ function generateNoEvent() {
1420
+ return {
1421
+ type: "unknown" /* UNKNOWN */,
1422
+ eventId: null,
1423
+ sessionId: null,
1424
+ urlResponse: null,
1425
+ postBody: null,
1426
+ tenantId: null,
1427
+ error: _createError("no-auth-event" /* NO_AUTH_EVENT */)
1428
+ };
1429
+ }
1430
+
1431
+ /**
1432
+ * @license
1433
+ * Copyright 2017 Google LLC
1434
+ *
1435
+ * Licensed under the Apache License, Version 2.0 (the "License");
1436
+ * you may not use this file except in compliance with the License.
1437
+ * You may obtain a copy of the License at
1438
+ *
1439
+ * http://www.apache.org/licenses/LICENSE-2.0
1440
+ *
1441
+ * Unless required by applicable law or agreed to in writing, software
1442
+ * distributed under the License is distributed on an "AS IS" BASIS,
1443
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1444
+ * See the License for the specific language governing permissions and
1445
+ * limitations under the License.
1446
+ */
1447
+ // This function should only be called by frameworks (e.g. FirebaseUI-web) to log their usage.
1448
+ // It is not intended for direct use by developer apps. NO jsdoc here to intentionally leave it out
1449
+ // of autogenerated documentation pages to reduce accidental misuse.
1450
+ function addFrameworkForLogging(auth, framework) {
1451
+ _castAuth(auth)._logFramework(framework);
1452
+ }
1453
+
1454
+ export { AuthPopup, _generateEventId, _getRedirectResult, addFrameworkForLogging, cordovaPopupRedirectResolver };
1455
+ //# sourceMappingURL=internal.js.map