@oxyhq/services 22.12.4 → 22.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (446) hide show
  1. package/README.md +16 -46
  2. package/lib/commonjs/index.js +18 -12
  3. package/lib/commonjs/index.js.map +1 -1
  4. package/lib/commonjs/ui/boot/runProviderColdBoot.js +51 -9
  5. package/lib/commonjs/ui/boot/runProviderColdBoot.js.map +1 -1
  6. package/lib/commonjs/ui/client.js +0 -13
  7. package/lib/commonjs/ui/client.js.map +1 -1
  8. package/lib/commonjs/ui/components/OxyAccountDialogScreen.js +27 -4
  9. package/lib/commonjs/ui/components/OxyAccountDialogScreen.js.map +1 -1
  10. package/lib/commonjs/ui/components/OxyAuthChooser.js +72 -1123
  11. package/lib/commonjs/ui/components/OxyAuthChooser.js.map +1 -1
  12. package/lib/commonjs/ui/components/OxyConsentScreen.js +50 -12
  13. package/lib/commonjs/ui/components/OxyConsentScreen.js.map +1 -1
  14. package/lib/commonjs/ui/components/OxyProvider.js +4 -4
  15. package/lib/commonjs/ui/components/OxyProvider.js.map +1 -1
  16. package/lib/commonjs/ui/components/OxySignInButton.js +74 -40
  17. package/lib/commonjs/ui/components/OxySignInButton.js.map +1 -1
  18. package/lib/commonjs/ui/components/authChooser/AccountsMenuView.js +527 -0
  19. package/lib/commonjs/ui/components/authChooser/AccountsMenuView.js.map +1 -0
  20. package/lib/commonjs/ui/components/authChooser/SignInEntryView.js +90 -0
  21. package/lib/commonjs/ui/components/authChooser/SignInEntryView.js.map +1 -0
  22. package/lib/commonjs/ui/components/authChooser/SignInRequestView.js +144 -0
  23. package/lib/commonjs/ui/components/authChooser/SignInRequestView.js.map +1 -0
  24. package/lib/commonjs/ui/components/authChooser/SignUpView.js +188 -0
  25. package/lib/commonjs/ui/components/authChooser/SignUpView.js.map +1 -0
  26. package/lib/commonjs/ui/components/authChooser/TroubleDisclosure.js +63 -0
  27. package/lib/commonjs/ui/components/authChooser/TroubleDisclosure.js.map +1 -0
  28. package/lib/commonjs/ui/components/authChooser/primitives.js +169 -0
  29. package/lib/commonjs/ui/components/authChooser/primitives.js.map +1 -0
  30. package/lib/commonjs/ui/components/authChooser/requestSurfaces.js +149 -0
  31. package/lib/commonjs/ui/components/authChooser/requestSurfaces.js.map +1 -0
  32. package/lib/commonjs/ui/components/authChooser/signInProgress.js +54 -0
  33. package/lib/commonjs/ui/components/authChooser/signInProgress.js.map +1 -0
  34. package/lib/commonjs/ui/components/{oxyAuthChooserStyles.js → authChooser/styles.js} +19 -1
  35. package/lib/commonjs/ui/components/authChooser/styles.js.map +1 -0
  36. package/lib/commonjs/ui/components/authChooser/types.js +59 -0
  37. package/lib/commonjs/ui/components/authChooser/types.js.map +1 -0
  38. package/lib/commonjs/ui/components/authChooser/useUsernameAvailability.js +50 -0
  39. package/lib/commonjs/ui/components/authChooser/useUsernameAvailability.js.map +1 -0
  40. package/lib/commonjs/ui/context/OxyContext.js +205 -30
  41. package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
  42. package/lib/commonjs/ui/context/commitSessionFlow.js +46 -0
  43. package/lib/commonjs/ui/context/commitSessionFlow.js.map +1 -1
  44. package/lib/commonjs/ui/context/hooks/useAuthOperations.js +15 -2
  45. package/lib/commonjs/ui/context/hooks/useAuthOperations.js.map +1 -1
  46. package/lib/commonjs/ui/context/useOxyAccountGraph.js +13 -5
  47. package/lib/commonjs/ui/context/useOxyAccountGraph.js.map +1 -1
  48. package/lib/commonjs/ui/hooks/useSwitchableAccounts.js +6 -1
  49. package/lib/commonjs/ui/hooks/useSwitchableAccounts.js.map +1 -1
  50. package/lib/commonjs/ui/index.js +0 -13
  51. package/lib/commonjs/ui/index.js.map +1 -1
  52. package/lib/commonjs/ui/oauth/browserAuthTransport.js +170 -0
  53. package/lib/commonjs/ui/oauth/browserAuthTransport.js.map +1 -0
  54. package/lib/commonjs/ui/oauth/completeOAuthCode.js +78 -0
  55. package/lib/commonjs/ui/oauth/completeOAuthCode.js.map +1 -0
  56. package/lib/commonjs/ui/oauth/legacyRedirectLanes.js +48 -0
  57. package/lib/commonjs/ui/oauth/legacyRedirectLanes.js.map +1 -0
  58. package/lib/commonjs/ui/oauth/oauthHandshake.js +53 -0
  59. package/lib/commonjs/ui/oauth/oauthHandshake.js.map +1 -0
  60. package/lib/commonjs/ui/oauth/oauthPopup.js +276 -0
  61. package/lib/commonjs/ui/oauth/oauthPopup.js.map +1 -0
  62. package/lib/commonjs/ui/oauth/oauthPopupMessages.js +141 -0
  63. package/lib/commonjs/ui/oauth/oauthPopupMessages.js.map +1 -0
  64. package/lib/commonjs/ui/oauth/types.js +2 -0
  65. package/lib/commonjs/ui/oauth/types.js.map +1 -0
  66. package/lib/commonjs/ui/server.js +2 -5
  67. package/lib/commonjs/ui/server.js.map +1 -1
  68. package/lib/commonjs/ui/session/authStore.js +6 -75
  69. package/lib/commonjs/ui/session/authStore.js.map +1 -1
  70. package/lib/commonjs/ui/session/createSessionClient.js +11 -3
  71. package/lib/commonjs/ui/session/createSessionClient.js.map +1 -1
  72. package/lib/commonjs/ui/session/identityBinding.js +95 -0
  73. package/lib/commonjs/ui/session/identityBinding.js.map +1 -0
  74. package/lib/commonjs/ui/session/index.js +13 -0
  75. package/lib/commonjs/ui/session/index.js.map +1 -1
  76. package/lib/commonjs/ui/session/nativeSecureStorage.js +90 -0
  77. package/lib/commonjs/ui/session/nativeSecureStorage.js.map +1 -0
  78. package/lib/commonjs/ui/session/tokenTransport.js +11 -1
  79. package/lib/commonjs/ui/session/tokenTransport.js.map +1 -1
  80. package/lib/commonjs/ui/utils/crossOriginRestore.js +5 -4
  81. package/lib/commonjs/ui/utils/crossOriginRestore.js.map +1 -1
  82. package/lib/commonjs/ui/utils/deliveryPlatform.js +58 -0
  83. package/lib/commonjs/ui/utils/deliveryPlatform.js.map +1 -0
  84. package/lib/commonjs/ui/utils/oauthReturn.js +72 -46
  85. package/lib/commonjs/ui/utils/oauthReturn.js.map +1 -1
  86. package/lib/module/index.js +9 -4
  87. package/lib/module/index.js.map +1 -1
  88. package/lib/module/ui/boot/runProviderColdBoot.js +51 -9
  89. package/lib/module/ui/boot/runProviderColdBoot.js.map +1 -1
  90. package/lib/module/ui/client.js +0 -1
  91. package/lib/module/ui/client.js.map +1 -1
  92. package/lib/module/ui/components/OxyAccountDialogScreen.js +27 -4
  93. package/lib/module/ui/components/OxyAccountDialogScreen.js.map +1 -1
  94. package/lib/module/ui/components/OxyAuthChooser.js +76 -1128
  95. package/lib/module/ui/components/OxyAuthChooser.js.map +1 -1
  96. package/lib/module/ui/components/OxyConsentScreen.js +50 -12
  97. package/lib/module/ui/components/OxyConsentScreen.js.map +1 -1
  98. package/lib/module/ui/components/OxyProvider.js +4 -4
  99. package/lib/module/ui/components/OxyProvider.js.map +1 -1
  100. package/lib/module/ui/components/OxySignInButton.js +76 -42
  101. package/lib/module/ui/components/OxySignInButton.js.map +1 -1
  102. package/lib/module/ui/components/authChooser/AccountsMenuView.js +523 -0
  103. package/lib/module/ui/components/authChooser/AccountsMenuView.js.map +1 -0
  104. package/lib/module/ui/components/authChooser/SignInEntryView.js +85 -0
  105. package/lib/module/ui/components/authChooser/SignInEntryView.js.map +1 -0
  106. package/lib/module/ui/components/authChooser/SignInRequestView.js +139 -0
  107. package/lib/module/ui/components/authChooser/SignInRequestView.js.map +1 -0
  108. package/lib/module/ui/components/authChooser/SignUpView.js +184 -0
  109. package/lib/module/ui/components/authChooser/SignUpView.js.map +1 -0
  110. package/lib/module/ui/components/authChooser/TroubleDisclosure.js +59 -0
  111. package/lib/module/ui/components/authChooser/TroubleDisclosure.js.map +1 -0
  112. package/lib/module/ui/components/authChooser/primitives.js +163 -0
  113. package/lib/module/ui/components/authChooser/primitives.js.map +1 -0
  114. package/lib/module/ui/components/authChooser/requestSurfaces.js +139 -0
  115. package/lib/module/ui/components/authChooser/requestSurfaces.js.map +1 -0
  116. package/lib/module/ui/components/authChooser/signInProgress.js +50 -0
  117. package/lib/module/ui/components/authChooser/signInProgress.js.map +1 -0
  118. package/lib/module/ui/components/{oxyAuthChooserStyles.js → authChooser/styles.js} +19 -1
  119. package/lib/module/ui/components/authChooser/styles.js.map +1 -0
  120. package/lib/module/ui/components/authChooser/types.js +55 -0
  121. package/lib/module/ui/components/authChooser/types.js.map +1 -0
  122. package/lib/module/ui/components/authChooser/useUsernameAvailability.js +46 -0
  123. package/lib/module/ui/components/authChooser/useUsernameAvailability.js.map +1 -0
  124. package/lib/module/ui/context/OxyContext.js +208 -33
  125. package/lib/module/ui/context/OxyContext.js.map +1 -1
  126. package/lib/module/ui/context/commitSessionFlow.js +45 -0
  127. package/lib/module/ui/context/commitSessionFlow.js.map +1 -1
  128. package/lib/module/ui/context/hooks/useAuthOperations.js +15 -2
  129. package/lib/module/ui/context/hooks/useAuthOperations.js.map +1 -1
  130. package/lib/module/ui/context/useOxyAccountGraph.js +13 -5
  131. package/lib/module/ui/context/useOxyAccountGraph.js.map +1 -1
  132. package/lib/module/ui/hooks/useSwitchableAccounts.js +6 -1
  133. package/lib/module/ui/hooks/useSwitchableAccounts.js.map +1 -1
  134. package/lib/module/ui/index.js +0 -1
  135. package/lib/module/ui/index.js.map +1 -1
  136. package/lib/module/ui/oauth/browserAuthTransport.js +167 -0
  137. package/lib/module/ui/oauth/browserAuthTransport.js.map +1 -0
  138. package/lib/module/ui/oauth/completeOAuthCode.js +75 -0
  139. package/lib/module/ui/oauth/completeOAuthCode.js.map +1 -0
  140. package/lib/module/ui/oauth/legacyRedirectLanes.js +44 -0
  141. package/lib/module/ui/oauth/legacyRedirectLanes.js.map +1 -0
  142. package/lib/module/ui/oauth/oauthHandshake.js +50 -0
  143. package/lib/module/ui/oauth/oauthHandshake.js.map +1 -0
  144. package/lib/module/ui/oauth/oauthPopup.js +268 -0
  145. package/lib/module/ui/oauth/oauthPopup.js.map +1 -0
  146. package/lib/module/ui/oauth/oauthPopupMessages.js +135 -0
  147. package/lib/module/ui/oauth/oauthPopupMessages.js.map +1 -0
  148. package/lib/module/ui/oauth/types.js +2 -0
  149. package/lib/module/ui/oauth/types.js.map +1 -0
  150. package/lib/module/ui/server.js +0 -2
  151. package/lib/module/ui/server.js.map +1 -1
  152. package/lib/module/ui/session/authStore.js +5 -75
  153. package/lib/module/ui/session/authStore.js.map +1 -1
  154. package/lib/module/ui/session/createSessionClient.js +11 -3
  155. package/lib/module/ui/session/createSessionClient.js.map +1 -1
  156. package/lib/module/ui/session/identityBinding.js +89 -0
  157. package/lib/module/ui/session/identityBinding.js.map +1 -0
  158. package/lib/module/ui/session/index.js +5 -2
  159. package/lib/module/ui/session/index.js.map +1 -1
  160. package/lib/module/ui/session/nativeSecureStorage.js +88 -0
  161. package/lib/module/ui/session/nativeSecureStorage.js.map +1 -0
  162. package/lib/module/ui/session/tokenTransport.js +11 -1
  163. package/lib/module/ui/session/tokenTransport.js.map +1 -1
  164. package/lib/module/ui/utils/crossOriginRestore.js +6 -5
  165. package/lib/module/ui/utils/crossOriginRestore.js.map +1 -1
  166. package/lib/module/ui/utils/deliveryPlatform.js +55 -0
  167. package/lib/module/ui/utils/deliveryPlatform.js.map +1 -0
  168. package/lib/module/ui/utils/oauthReturn.js +73 -47
  169. package/lib/module/ui/utils/oauthReturn.js.map +1 -1
  170. package/lib/typescript/commonjs/index.d.ts +4 -1
  171. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  172. package/lib/typescript/commonjs/ui/boot/runProviderColdBoot.d.ts +34 -2
  173. package/lib/typescript/commonjs/ui/boot/runProviderColdBoot.d.ts.map +1 -1
  174. package/lib/typescript/commonjs/ui/client.d.ts +0 -1
  175. package/lib/typescript/commonjs/ui/client.d.ts.map +1 -1
  176. package/lib/typescript/commonjs/ui/components/OxyAccountDialogScreen.d.ts.map +1 -1
  177. package/lib/typescript/commonjs/ui/components/OxyAuthChooser.d.ts +21 -29
  178. package/lib/typescript/commonjs/ui/components/OxyAuthChooser.d.ts.map +1 -1
  179. package/lib/typescript/commonjs/ui/components/OxyConsentScreen.d.ts.map +1 -1
  180. package/lib/typescript/commonjs/ui/components/OxyProvider.d.ts.map +1 -1
  181. package/lib/typescript/commonjs/ui/components/OxySignInButton.d.ts +17 -12
  182. package/lib/typescript/commonjs/ui/components/OxySignInButton.d.ts.map +1 -1
  183. package/lib/typescript/commonjs/ui/components/authChooser/AccountsMenuView.d.ts +38 -0
  184. package/lib/typescript/commonjs/ui/components/authChooser/AccountsMenuView.d.ts.map +1 -0
  185. package/lib/typescript/commonjs/ui/components/authChooser/SignInEntryView.d.ts +32 -0
  186. package/lib/typescript/commonjs/ui/components/authChooser/SignInEntryView.d.ts.map +1 -0
  187. package/lib/typescript/commonjs/ui/components/authChooser/SignInRequestView.d.ts +34 -0
  188. package/lib/typescript/commonjs/ui/components/authChooser/SignInRequestView.d.ts.map +1 -0
  189. package/lib/typescript/commonjs/ui/components/authChooser/SignUpView.d.ts +34 -0
  190. package/lib/typescript/commonjs/ui/components/authChooser/SignUpView.d.ts.map +1 -0
  191. package/lib/typescript/commonjs/ui/components/authChooser/TroubleDisclosure.d.ts +43 -0
  192. package/lib/typescript/commonjs/ui/components/authChooser/TroubleDisclosure.d.ts.map +1 -0
  193. package/lib/typescript/commonjs/ui/components/authChooser/primitives.d.ts +55 -0
  194. package/lib/typescript/commonjs/ui/components/authChooser/primitives.d.ts.map +1 -0
  195. package/lib/typescript/commonjs/ui/components/authChooser/requestSurfaces.d.ts +54 -0
  196. package/lib/typescript/commonjs/ui/components/authChooser/requestSurfaces.d.ts.map +1 -0
  197. package/lib/typescript/commonjs/ui/components/authChooser/signInProgress.d.ts +26 -0
  198. package/lib/typescript/commonjs/ui/components/authChooser/signInProgress.d.ts.map +1 -0
  199. package/lib/typescript/{module/ui/components/oxyAuthChooserStyles.d.ts → commonjs/ui/components/authChooser/styles.d.ts} +19 -1
  200. package/lib/typescript/commonjs/ui/components/authChooser/styles.d.ts.map +1 -0
  201. package/lib/typescript/commonjs/ui/components/authChooser/types.d.ts +85 -0
  202. package/lib/typescript/commonjs/ui/components/authChooser/types.d.ts.map +1 -0
  203. package/lib/typescript/commonjs/ui/components/authChooser/useUsernameAvailability.d.ts +16 -0
  204. package/lib/typescript/commonjs/ui/components/authChooser/useUsernameAvailability.d.ts.map +1 -0
  205. package/lib/typescript/commonjs/ui/context/OxyContext.d.ts.map +1 -1
  206. package/lib/typescript/commonjs/ui/context/commitSessionFlow.d.ts +40 -0
  207. package/lib/typescript/commonjs/ui/context/commitSessionFlow.d.ts.map +1 -1
  208. package/lib/typescript/commonjs/ui/context/hooks/useAuthOperations.d.ts +11 -2
  209. package/lib/typescript/commonjs/ui/context/hooks/useAuthOperations.d.ts.map +1 -1
  210. package/lib/typescript/commonjs/ui/context/oxyContextTypes.d.ts +44 -1
  211. package/lib/typescript/commonjs/ui/context/oxyContextTypes.d.ts.map +1 -1
  212. package/lib/typescript/commonjs/ui/context/useOxyAccountGraph.d.ts +7 -1
  213. package/lib/typescript/commonjs/ui/context/useOxyAccountGraph.d.ts.map +1 -1
  214. package/lib/typescript/commonjs/ui/hooks/useSwitchableAccounts.d.ts.map +1 -1
  215. package/lib/typescript/commonjs/ui/index.d.ts +0 -1
  216. package/lib/typescript/commonjs/ui/index.d.ts.map +1 -1
  217. package/lib/typescript/commonjs/ui/oauth/browserAuthTransport.d.ts +56 -0
  218. package/lib/typescript/commonjs/ui/oauth/browserAuthTransport.d.ts.map +1 -0
  219. package/lib/typescript/commonjs/ui/oauth/completeOAuthCode.d.ts +49 -0
  220. package/lib/typescript/commonjs/ui/oauth/completeOAuthCode.d.ts.map +1 -0
  221. package/lib/typescript/commonjs/ui/oauth/legacyRedirectLanes.d.ts +40 -0
  222. package/lib/typescript/commonjs/ui/oauth/legacyRedirectLanes.d.ts.map +1 -0
  223. package/lib/typescript/commonjs/ui/oauth/oauthHandshake.d.ts +50 -0
  224. package/lib/typescript/commonjs/ui/oauth/oauthHandshake.d.ts.map +1 -0
  225. package/lib/typescript/commonjs/ui/oauth/oauthPopup.d.ts +83 -0
  226. package/lib/typescript/commonjs/ui/oauth/oauthPopup.d.ts.map +1 -0
  227. package/lib/typescript/commonjs/ui/oauth/oauthPopupMessages.d.ts +67 -0
  228. package/lib/typescript/commonjs/ui/oauth/oauthPopupMessages.d.ts.map +1 -0
  229. package/lib/typescript/commonjs/ui/oauth/types.d.ts +176 -0
  230. package/lib/typescript/commonjs/ui/oauth/types.d.ts.map +1 -0
  231. package/lib/typescript/commonjs/ui/server.d.ts +0 -2
  232. package/lib/typescript/commonjs/ui/server.d.ts.map +1 -1
  233. package/lib/typescript/commonjs/ui/session/authStore.d.ts +3 -7
  234. package/lib/typescript/commonjs/ui/session/authStore.d.ts.map +1 -1
  235. package/lib/typescript/commonjs/ui/session/createSessionClient.d.ts +8 -1
  236. package/lib/typescript/commonjs/ui/session/createSessionClient.d.ts.map +1 -1
  237. package/lib/typescript/commonjs/ui/session/identityBinding.d.ts +66 -0
  238. package/lib/typescript/commonjs/ui/session/identityBinding.d.ts.map +1 -0
  239. package/lib/typescript/commonjs/ui/session/index.d.ts +6 -2
  240. package/lib/typescript/commonjs/ui/session/index.d.ts.map +1 -1
  241. package/lib/typescript/commonjs/ui/session/nativeSecureStorage.d.ts +25 -0
  242. package/lib/typescript/commonjs/ui/session/nativeSecureStorage.d.ts.map +1 -0
  243. package/lib/typescript/commonjs/ui/session/tokenTransport.d.ts +8 -1
  244. package/lib/typescript/commonjs/ui/session/tokenTransport.d.ts.map +1 -1
  245. package/lib/typescript/commonjs/ui/types/navigation.d.ts +44 -0
  246. package/lib/typescript/commonjs/ui/types/navigation.d.ts.map +1 -1
  247. package/lib/typescript/commonjs/ui/utils/crossOriginRestore.d.ts.map +1 -1
  248. package/lib/typescript/commonjs/ui/utils/deliveryPlatform.d.ts +33 -0
  249. package/lib/typescript/commonjs/ui/utils/deliveryPlatform.d.ts.map +1 -0
  250. package/lib/typescript/commonjs/ui/utils/oauthReturn.d.ts +30 -16
  251. package/lib/typescript/commonjs/ui/utils/oauthReturn.d.ts.map +1 -1
  252. package/lib/typescript/module/index.d.ts +4 -1
  253. package/lib/typescript/module/index.d.ts.map +1 -1
  254. package/lib/typescript/module/ui/boot/runProviderColdBoot.d.ts +34 -2
  255. package/lib/typescript/module/ui/boot/runProviderColdBoot.d.ts.map +1 -1
  256. package/lib/typescript/module/ui/client.d.ts +0 -1
  257. package/lib/typescript/module/ui/client.d.ts.map +1 -1
  258. package/lib/typescript/module/ui/components/OxyAccountDialogScreen.d.ts.map +1 -1
  259. package/lib/typescript/module/ui/components/OxyAuthChooser.d.ts +21 -29
  260. package/lib/typescript/module/ui/components/OxyAuthChooser.d.ts.map +1 -1
  261. package/lib/typescript/module/ui/components/OxyConsentScreen.d.ts.map +1 -1
  262. package/lib/typescript/module/ui/components/OxyProvider.d.ts.map +1 -1
  263. package/lib/typescript/module/ui/components/OxySignInButton.d.ts +17 -12
  264. package/lib/typescript/module/ui/components/OxySignInButton.d.ts.map +1 -1
  265. package/lib/typescript/module/ui/components/authChooser/AccountsMenuView.d.ts +38 -0
  266. package/lib/typescript/module/ui/components/authChooser/AccountsMenuView.d.ts.map +1 -0
  267. package/lib/typescript/module/ui/components/authChooser/SignInEntryView.d.ts +32 -0
  268. package/lib/typescript/module/ui/components/authChooser/SignInEntryView.d.ts.map +1 -0
  269. package/lib/typescript/module/ui/components/authChooser/SignInRequestView.d.ts +34 -0
  270. package/lib/typescript/module/ui/components/authChooser/SignInRequestView.d.ts.map +1 -0
  271. package/lib/typescript/module/ui/components/authChooser/SignUpView.d.ts +34 -0
  272. package/lib/typescript/module/ui/components/authChooser/SignUpView.d.ts.map +1 -0
  273. package/lib/typescript/module/ui/components/authChooser/TroubleDisclosure.d.ts +43 -0
  274. package/lib/typescript/module/ui/components/authChooser/TroubleDisclosure.d.ts.map +1 -0
  275. package/lib/typescript/module/ui/components/authChooser/primitives.d.ts +55 -0
  276. package/lib/typescript/module/ui/components/authChooser/primitives.d.ts.map +1 -0
  277. package/lib/typescript/module/ui/components/authChooser/requestSurfaces.d.ts +54 -0
  278. package/lib/typescript/module/ui/components/authChooser/requestSurfaces.d.ts.map +1 -0
  279. package/lib/typescript/module/ui/components/authChooser/signInProgress.d.ts +26 -0
  280. package/lib/typescript/module/ui/components/authChooser/signInProgress.d.ts.map +1 -0
  281. package/lib/typescript/{commonjs/ui/components/oxyAuthChooserStyles.d.ts → module/ui/components/authChooser/styles.d.ts} +19 -1
  282. package/lib/typescript/module/ui/components/authChooser/styles.d.ts.map +1 -0
  283. package/lib/typescript/module/ui/components/authChooser/types.d.ts +85 -0
  284. package/lib/typescript/module/ui/components/authChooser/types.d.ts.map +1 -0
  285. package/lib/typescript/module/ui/components/authChooser/useUsernameAvailability.d.ts +16 -0
  286. package/lib/typescript/module/ui/components/authChooser/useUsernameAvailability.d.ts.map +1 -0
  287. package/lib/typescript/module/ui/context/OxyContext.d.ts.map +1 -1
  288. package/lib/typescript/module/ui/context/commitSessionFlow.d.ts +40 -0
  289. package/lib/typescript/module/ui/context/commitSessionFlow.d.ts.map +1 -1
  290. package/lib/typescript/module/ui/context/hooks/useAuthOperations.d.ts +11 -2
  291. package/lib/typescript/module/ui/context/hooks/useAuthOperations.d.ts.map +1 -1
  292. package/lib/typescript/module/ui/context/oxyContextTypes.d.ts +44 -1
  293. package/lib/typescript/module/ui/context/oxyContextTypes.d.ts.map +1 -1
  294. package/lib/typescript/module/ui/context/useOxyAccountGraph.d.ts +7 -1
  295. package/lib/typescript/module/ui/context/useOxyAccountGraph.d.ts.map +1 -1
  296. package/lib/typescript/module/ui/hooks/useSwitchableAccounts.d.ts.map +1 -1
  297. package/lib/typescript/module/ui/index.d.ts +0 -1
  298. package/lib/typescript/module/ui/index.d.ts.map +1 -1
  299. package/lib/typescript/module/ui/oauth/browserAuthTransport.d.ts +56 -0
  300. package/lib/typescript/module/ui/oauth/browserAuthTransport.d.ts.map +1 -0
  301. package/lib/typescript/module/ui/oauth/completeOAuthCode.d.ts +49 -0
  302. package/lib/typescript/module/ui/oauth/completeOAuthCode.d.ts.map +1 -0
  303. package/lib/typescript/module/ui/oauth/legacyRedirectLanes.d.ts +40 -0
  304. package/lib/typescript/module/ui/oauth/legacyRedirectLanes.d.ts.map +1 -0
  305. package/lib/typescript/module/ui/oauth/oauthHandshake.d.ts +50 -0
  306. package/lib/typescript/module/ui/oauth/oauthHandshake.d.ts.map +1 -0
  307. package/lib/typescript/module/ui/oauth/oauthPopup.d.ts +83 -0
  308. package/lib/typescript/module/ui/oauth/oauthPopup.d.ts.map +1 -0
  309. package/lib/typescript/module/ui/oauth/oauthPopupMessages.d.ts +67 -0
  310. package/lib/typescript/module/ui/oauth/oauthPopupMessages.d.ts.map +1 -0
  311. package/lib/typescript/module/ui/oauth/types.d.ts +176 -0
  312. package/lib/typescript/module/ui/oauth/types.d.ts.map +1 -0
  313. package/lib/typescript/module/ui/server.d.ts +0 -2
  314. package/lib/typescript/module/ui/server.d.ts.map +1 -1
  315. package/lib/typescript/module/ui/session/authStore.d.ts +3 -7
  316. package/lib/typescript/module/ui/session/authStore.d.ts.map +1 -1
  317. package/lib/typescript/module/ui/session/createSessionClient.d.ts +8 -1
  318. package/lib/typescript/module/ui/session/createSessionClient.d.ts.map +1 -1
  319. package/lib/typescript/module/ui/session/identityBinding.d.ts +66 -0
  320. package/lib/typescript/module/ui/session/identityBinding.d.ts.map +1 -0
  321. package/lib/typescript/module/ui/session/index.d.ts +6 -2
  322. package/lib/typescript/module/ui/session/index.d.ts.map +1 -1
  323. package/lib/typescript/module/ui/session/nativeSecureStorage.d.ts +25 -0
  324. package/lib/typescript/module/ui/session/nativeSecureStorage.d.ts.map +1 -0
  325. package/lib/typescript/module/ui/session/tokenTransport.d.ts +8 -1
  326. package/lib/typescript/module/ui/session/tokenTransport.d.ts.map +1 -1
  327. package/lib/typescript/module/ui/types/navigation.d.ts +44 -0
  328. package/lib/typescript/module/ui/types/navigation.d.ts.map +1 -1
  329. package/lib/typescript/module/ui/utils/crossOriginRestore.d.ts.map +1 -1
  330. package/lib/typescript/module/ui/utils/deliveryPlatform.d.ts +33 -0
  331. package/lib/typescript/module/ui/utils/deliveryPlatform.d.ts.map +1 -0
  332. package/lib/typescript/module/ui/utils/oauthReturn.d.ts +30 -16
  333. package/lib/typescript/module/ui/utils/oauthReturn.d.ts.map +1 -1
  334. package/package.json +6 -8
  335. package/src/index.ts +19 -5
  336. package/src/ui/boot/__tests__/coldBootWebAuthMode.test.ts +281 -0
  337. package/src/ui/boot/runProviderColdBoot.ts +83 -13
  338. package/src/ui/client.ts +0 -1
  339. package/src/ui/components/OxyAccountDialogScreen.tsx +33 -4
  340. package/src/ui/components/OxyAuthChooser.tsx +100 -1230
  341. package/src/ui/components/OxyConsentScreen.tsx +56 -13
  342. package/src/ui/components/OxyProvider.tsx +4 -4
  343. package/src/ui/components/OxySignInButton.tsx +119 -78
  344. package/src/ui/components/__tests__/OxyConsentScreen.test.tsx +27 -0
  345. package/src/ui/components/authChooser/AccountsMenuView.tsx +569 -0
  346. package/src/ui/components/authChooser/SignInEntryView.tsx +115 -0
  347. package/src/ui/components/authChooser/SignInRequestView.tsx +163 -0
  348. package/src/ui/components/authChooser/SignUpView.tsx +174 -0
  349. package/src/ui/components/authChooser/TroubleDisclosure.tsx +81 -0
  350. package/src/ui/components/authChooser/primitives.tsx +144 -0
  351. package/src/ui/components/authChooser/requestSurfaces.tsx +116 -0
  352. package/src/ui/components/authChooser/signInProgress.ts +54 -0
  353. package/src/ui/components/{oxyAuthChooserStyles.ts → authChooser/styles.ts} +18 -0
  354. package/src/ui/components/authChooser/types.ts +101 -0
  355. package/src/ui/components/authChooser/useUsernameAvailability.ts +60 -0
  356. package/src/ui/context/OxyContext.tsx +226 -24
  357. package/src/ui/context/__tests__/commitSessionFlow.test.ts +102 -0
  358. package/src/ui/context/commitSessionFlow.ts +64 -0
  359. package/src/ui/context/hooks/useAuthOperations.ts +26 -1
  360. package/src/ui/context/oxyContextTypes.ts +45 -1
  361. package/src/ui/context/useOxyAccountGraph.ts +19 -5
  362. package/src/ui/hooks/useSwitchableAccounts.ts +12 -1
  363. package/src/ui/index.ts +0 -1
  364. package/src/ui/oauth/__tests__/browserAuthTransport.test.ts +335 -0
  365. package/src/ui/oauth/__tests__/completeOAuthCode.test.ts +142 -0
  366. package/src/ui/oauth/__tests__/oauthPopup.test.ts +352 -0
  367. package/src/ui/oauth/__tests__/oauthPopupMessages.test.ts +189 -0
  368. package/src/ui/oauth/__tests__/sharedCompletionPath.test.ts +174 -0
  369. package/src/ui/oauth/browserAuthTransport.ts +193 -0
  370. package/src/ui/oauth/completeOAuthCode.ts +93 -0
  371. package/src/ui/oauth/legacyRedirectLanes.ts +43 -0
  372. package/src/ui/oauth/oauthHandshake.ts +74 -0
  373. package/src/ui/oauth/oauthPopup.ts +277 -0
  374. package/src/ui/oauth/oauthPopupMessages.ts +136 -0
  375. package/src/ui/oauth/types.ts +150 -0
  376. package/src/ui/server.ts +0 -2
  377. package/src/ui/session/__tests__/createSessionClient.test.ts +26 -0
  378. package/src/ui/session/__tests__/tokenTransport.test.ts +34 -0
  379. package/src/ui/session/authStore.ts +5 -89
  380. package/src/ui/session/createSessionClient.ts +15 -2
  381. package/src/ui/session/identityBinding.ts +116 -0
  382. package/src/ui/session/index.ts +6 -2
  383. package/src/ui/session/nativeSecureStorage.ts +98 -0
  384. package/src/ui/session/tokenTransport.ts +14 -1
  385. package/src/ui/types/navigation.ts +44 -1
  386. package/src/ui/utils/__tests__/crossOriginRestore.test.ts +17 -0
  387. package/src/ui/utils/crossOriginRestore.ts +9 -13
  388. package/src/ui/utils/deliveryPlatform.ts +65 -0
  389. package/src/ui/utils/oauthReturn.ts +79 -65
  390. package/lib/commonjs/assets/assets/fonts/Inter/Inter_18pt-Black.ttf +0 -0
  391. package/lib/commonjs/assets/assets/fonts/Inter/Inter_18pt-Bold.ttf +0 -0
  392. package/lib/commonjs/assets/assets/fonts/Inter/Inter_18pt-ExtraBold.ttf +0 -0
  393. package/lib/commonjs/assets/assets/fonts/Inter/Inter_18pt-Light.ttf +0 -0
  394. package/lib/commonjs/assets/assets/fonts/Inter/Inter_18pt-Medium.ttf +0 -0
  395. package/lib/commonjs/assets/assets/fonts/Inter/Inter_18pt-Regular.ttf +0 -0
  396. package/lib/commonjs/assets/assets/fonts/Inter/Inter_18pt-SemiBold.ttf +0 -0
  397. package/lib/commonjs/assets/fonts/Inter/Inter_18pt-Black.ttf +0 -0
  398. package/lib/commonjs/assets/fonts/Inter/Inter_18pt-Bold.ttf +0 -0
  399. package/lib/commonjs/assets/fonts/Inter/Inter_18pt-ExtraBold.ttf +0 -0
  400. package/lib/commonjs/assets/fonts/Inter/Inter_18pt-Light.ttf +0 -0
  401. package/lib/commonjs/assets/fonts/Inter/Inter_18pt-Medium.ttf +0 -0
  402. package/lib/commonjs/assets/fonts/Inter/Inter_18pt-Regular.ttf +0 -0
  403. package/lib/commonjs/assets/fonts/Inter/Inter_18pt-SemiBold.ttf +0 -0
  404. package/lib/commonjs/ui/components/FontLoader.js +0 -35
  405. package/lib/commonjs/ui/components/FontLoader.js.map +0 -1
  406. package/lib/commonjs/ui/components/FontLoader.native.js +0 -88
  407. package/lib/commonjs/ui/components/FontLoader.native.js.map +0 -1
  408. package/lib/commonjs/ui/components/oxyAuthChooserStyles.js.map +0 -1
  409. package/lib/module/assets/assets/fonts/Inter/Inter_18pt-Black.ttf +0 -0
  410. package/lib/module/assets/assets/fonts/Inter/Inter_18pt-Bold.ttf +0 -0
  411. package/lib/module/assets/assets/fonts/Inter/Inter_18pt-ExtraBold.ttf +0 -0
  412. package/lib/module/assets/assets/fonts/Inter/Inter_18pt-Light.ttf +0 -0
  413. package/lib/module/assets/assets/fonts/Inter/Inter_18pt-Medium.ttf +0 -0
  414. package/lib/module/assets/assets/fonts/Inter/Inter_18pt-Regular.ttf +0 -0
  415. package/lib/module/assets/assets/fonts/Inter/Inter_18pt-SemiBold.ttf +0 -0
  416. package/lib/module/assets/fonts/Inter/Inter_18pt-Black.ttf +0 -0
  417. package/lib/module/assets/fonts/Inter/Inter_18pt-Bold.ttf +0 -0
  418. package/lib/module/assets/fonts/Inter/Inter_18pt-ExtraBold.ttf +0 -0
  419. package/lib/module/assets/fonts/Inter/Inter_18pt-Light.ttf +0 -0
  420. package/lib/module/assets/fonts/Inter/Inter_18pt-Medium.ttf +0 -0
  421. package/lib/module/assets/fonts/Inter/Inter_18pt-Regular.ttf +0 -0
  422. package/lib/module/assets/fonts/Inter/Inter_18pt-SemiBold.ttf +0 -0
  423. package/lib/module/ui/components/FontLoader.js +0 -29
  424. package/lib/module/ui/components/FontLoader.js.map +0 -1
  425. package/lib/module/ui/components/FontLoader.native.js +0 -83
  426. package/lib/module/ui/components/FontLoader.native.js.map +0 -1
  427. package/lib/module/ui/components/oxyAuthChooserStyles.js.map +0 -1
  428. package/lib/typescript/commonjs/ui/components/FontLoader.d.ts +0 -24
  429. package/lib/typescript/commonjs/ui/components/FontLoader.d.ts.map +0 -1
  430. package/lib/typescript/commonjs/ui/components/FontLoader.native.d.ts +0 -13
  431. package/lib/typescript/commonjs/ui/components/FontLoader.native.d.ts.map +0 -1
  432. package/lib/typescript/commonjs/ui/components/oxyAuthChooserStyles.d.ts.map +0 -1
  433. package/lib/typescript/module/ui/components/FontLoader.d.ts +0 -24
  434. package/lib/typescript/module/ui/components/FontLoader.d.ts.map +0 -1
  435. package/lib/typescript/module/ui/components/FontLoader.native.d.ts +0 -13
  436. package/lib/typescript/module/ui/components/FontLoader.native.d.ts.map +0 -1
  437. package/lib/typescript/module/ui/components/oxyAuthChooserStyles.d.ts.map +0 -1
  438. package/src/assets/fonts/Inter/Inter_18pt-Black.ttf +0 -0
  439. package/src/assets/fonts/Inter/Inter_18pt-Bold.ttf +0 -0
  440. package/src/assets/fonts/Inter/Inter_18pt-ExtraBold.ttf +0 -0
  441. package/src/assets/fonts/Inter/Inter_18pt-Light.ttf +0 -0
  442. package/src/assets/fonts/Inter/Inter_18pt-Medium.ttf +0 -0
  443. package/src/assets/fonts/Inter/Inter_18pt-Regular.ttf +0 -0
  444. package/src/assets/fonts/Inter/Inter_18pt-SemiBold.ttf +0 -0
  445. package/src/ui/components/FontLoader.native.tsx +0 -88
  446. package/src/ui/components/FontLoader.tsx +0 -27
@@ -0,0 +1,142 @@
1
+ import type { OxyServices } from '@oxyhq/core';
2
+ import { completeOAuthCode } from '../completeOAuthCode';
3
+ import type { OAuthSessionCommitInput } from '../types';
4
+
5
+ const HANDSHAKE = { state: 'state-abc', codeVerifier: 'verifier-xyz' };
6
+ const REDIRECT_URI = 'https://mention.earth';
7
+
8
+ const SESSION = {
9
+ sessionId: 'sess-1',
10
+ deviceId: 'dev-1',
11
+ deviceSecret: 'secret-1',
12
+ accessToken: 'token-1',
13
+ expiresAt: '2099-01-01T00:00:00.000Z',
14
+ user: { id: 'user-1', username: 'nate', avatar: 'a1' },
15
+ };
16
+
17
+ function makeOxyServices(exchange: jest.Mock): OxyServices {
18
+ return { exchangeOAuthCode: exchange } as unknown as OxyServices;
19
+ }
20
+
21
+ describe('completeOAuthCode', () => {
22
+ it('exchanges the code and commits the session it returns', async () => {
23
+ const exchange = jest.fn().mockResolvedValue(SESSION);
24
+ const committed: OAuthSessionCommitInput[] = [];
25
+
26
+ const result = await completeOAuthCode({
27
+ oxyServices: makeOxyServices(exchange),
28
+ clientId: 'oxy_dk_test',
29
+ code: 'code-1',
30
+ returnedState: HANDSHAKE.state,
31
+ handshake: HANDSHAKE,
32
+ redirectUri: REDIRECT_URI,
33
+ commitSession: async (input) => {
34
+ committed.push(input);
35
+ },
36
+ });
37
+
38
+ expect(result).toEqual({ ok: true });
39
+ expect(exchange).toHaveBeenCalledWith({
40
+ code: 'code-1',
41
+ clientId: 'oxy_dk_test',
42
+ redirectUri: REDIRECT_URI,
43
+ codeVerifier: HANDSHAKE.codeVerifier,
44
+ });
45
+ expect(committed).toEqual([
46
+ {
47
+ sessionId: 'sess-1',
48
+ accessToken: 'token-1',
49
+ deviceId: 'dev-1',
50
+ deviceSecret: 'secret-1',
51
+ userId: 'user-1',
52
+ expiresAt: '2099-01-01T00:00:00.000Z',
53
+ user: SESSION.user,
54
+ },
55
+ ]);
56
+ });
57
+
58
+ it('cleans up BEFORE committing, so a stale code cannot re-enter the exchange', async () => {
59
+ const order: string[] = [];
60
+ const result = await completeOAuthCode({
61
+ oxyServices: makeOxyServices(jest.fn().mockResolvedValue(SESSION)),
62
+ clientId: 'oxy_dk_test',
63
+ code: 'code-1',
64
+ returnedState: HANDSHAKE.state,
65
+ handshake: HANDSHAKE,
66
+ redirectUri: REDIRECT_URI,
67
+ commitSession: async () => {
68
+ order.push('commit');
69
+ },
70
+ cleanup: () => {
71
+ order.push('cleanup');
72
+ },
73
+ });
74
+
75
+ expect(result).toEqual({ ok: true });
76
+ expect(order).toEqual(['cleanup', 'commit']);
77
+ });
78
+
79
+ it.each([
80
+ ['a mismatched state', 'someone-elses-state', HANDSHAKE],
81
+ ['no returned state', null, HANDSHAKE],
82
+ ['no stored handshake', HANDSHAKE.state, null],
83
+ ])('refuses to exchange the code with %s', async (_label, returnedState, handshake) => {
84
+ const exchange = jest.fn();
85
+ const commitSession = jest.fn();
86
+ const cleanup = jest.fn();
87
+
88
+ const result = await completeOAuthCode({
89
+ oxyServices: makeOxyServices(exchange),
90
+ clientId: 'oxy_dk_test',
91
+ code: 'code-1',
92
+ returnedState,
93
+ handshake,
94
+ redirectUri: REDIRECT_URI,
95
+ commitSession,
96
+ cleanup,
97
+ });
98
+
99
+ expect(result).toEqual({ ok: false, reason: 'state-mismatch' });
100
+ expect(exchange).not.toHaveBeenCalled();
101
+ expect(commitSession).not.toHaveBeenCalled();
102
+ expect(cleanup).toHaveBeenCalledTimes(1);
103
+ });
104
+
105
+ it('reports a failed exchange without throwing, and still cleans up', async () => {
106
+ const cleanup = jest.fn();
107
+ const commitSession = jest.fn();
108
+
109
+ const result = await completeOAuthCode({
110
+ oxyServices: makeOxyServices(jest.fn().mockRejectedValue(new Error('invalid_grant'))),
111
+ clientId: 'oxy_dk_test',
112
+ code: 'code-1',
113
+ returnedState: HANDSHAKE.state,
114
+ handshake: HANDSHAKE,
115
+ redirectUri: REDIRECT_URI,
116
+ commitSession,
117
+ cleanup,
118
+ });
119
+
120
+ expect(result).toEqual({ ok: false, reason: 'exchange-failed' });
121
+ expect(commitSession).not.toHaveBeenCalled();
122
+ expect(cleanup).toHaveBeenCalledTimes(1);
123
+ });
124
+
125
+ it('reports a failed commit without throwing, and cleans up exactly once', async () => {
126
+ const cleanup = jest.fn();
127
+
128
+ const result = await completeOAuthCode({
129
+ oxyServices: makeOxyServices(jest.fn().mockResolvedValue(SESSION)),
130
+ clientId: 'oxy_dk_test',
131
+ code: 'code-1',
132
+ returnedState: HANDSHAKE.state,
133
+ handshake: HANDSHAKE,
134
+ redirectUri: REDIRECT_URI,
135
+ commitSession: jest.fn().mockRejectedValue(new Error('commit blew up')),
136
+ cleanup,
137
+ });
138
+
139
+ expect(result).toEqual({ ok: false, reason: 'exchange-failed' });
140
+ expect(cleanup).toHaveBeenCalledTimes(1);
141
+ });
142
+ });
@@ -0,0 +1,352 @@
1
+ import {
2
+ awaitOAuthPopupResult,
3
+ closeOAuthPopup,
4
+ navigateOAuthPopup,
5
+ openOAuthPopup,
6
+ OXY_OAUTH_POPUP_WINDOW_NAME,
7
+ } from '../oauthPopup';
8
+ import { OXY_OAUTH_CODE_MESSAGE_TYPE, OXY_OAUTH_ERROR_MESSAGE_TYPE } from '../oauthPopupMessages';
9
+ import type { OAuthPopupHandle, OAuthPopupOutcome } from '../types';
10
+
11
+ const IDP_ORIGIN = 'https://auth.oxy.so';
12
+ const REDIRECT_URI = 'https://mention.earth';
13
+ const STATE = 'state-abc';
14
+
15
+ interface ControllablePopup extends OAuthPopupHandle {
16
+ close: jest.Mock;
17
+ setClosed: () => void;
18
+ }
19
+
20
+ function fakePopup(): ControllablePopup {
21
+ let closed = false;
22
+ return {
23
+ get closed() {
24
+ return closed;
25
+ },
26
+ close: jest.fn(() => {
27
+ closed = true;
28
+ }),
29
+ location: { href: '' },
30
+ setClosed: () => {
31
+ closed = true;
32
+ },
33
+ };
34
+ }
35
+
36
+ function dispatchMessage(init: { data: unknown; origin: string; source: unknown }): void {
37
+ const event = new Event('message');
38
+ Object.assign(event, init);
39
+ window.dispatchEvent(event);
40
+ }
41
+
42
+ function codeMessage(source: unknown, state = STATE, origin = IDP_ORIGIN) {
43
+ return {
44
+ data: { type: OXY_OAUTH_CODE_MESSAGE_TYPE, code: 'code-1', state },
45
+ origin,
46
+ source,
47
+ };
48
+ }
49
+
50
+ /** Resolve the outcome, or `'pending'` when the promise has not settled yet. */
51
+ async function outcomeOrPending(
52
+ promise: Promise<OAuthPopupOutcome>,
53
+ ): Promise<OAuthPopupOutcome | 'pending'> {
54
+ return Promise.race([
55
+ promise,
56
+ Promise.resolve().then(() => 'pending' as const),
57
+ ]);
58
+ }
59
+
60
+ describe('openOAuthPopup', () => {
61
+ afterEach(() => {
62
+ jest.restoreAllMocks();
63
+ });
64
+
65
+ it('opens an empty, named window so a second press reuses it', () => {
66
+ const handle = fakePopup();
67
+ const openSpy = jest
68
+ .spyOn(window, 'open')
69
+ .mockReturnValue(handle as unknown as Window);
70
+
71
+ expect(openOAuthPopup()).toBe(handle);
72
+ expect(openSpy).toHaveBeenCalledWith('', OXY_OAUTH_POPUP_WINDOW_NAME, expect.any(String));
73
+ // The window is navigated later, once the authorize URL exists.
74
+ expect(openSpy.mock.calls[0][0]).toBe('');
75
+ });
76
+
77
+ it('returns null when the browser blocks the popup', () => {
78
+ jest.spyOn(window, 'open').mockReturnValue(null);
79
+ expect(openOAuthPopup()).toBeNull();
80
+ });
81
+
82
+ it('returns null instead of throwing when window.open throws', () => {
83
+ jest.spyOn(window, 'open').mockImplementation(() => {
84
+ throw new Error('blocked');
85
+ });
86
+ expect(openOAuthPopup()).toBeNull();
87
+ });
88
+ });
89
+
90
+ describe('navigateOAuthPopup', () => {
91
+ it('points the popup at the authorize URL', () => {
92
+ const popup = fakePopup();
93
+ expect(navigateOAuthPopup(popup, `${IDP_ORIGIN}/authorize?x=1`)).toBe(true);
94
+ expect(popup.location.href).toBe(`${IDP_ORIGIN}/authorize?x=1`);
95
+ });
96
+
97
+ it('reports failure instead of throwing when the window is gone', () => {
98
+ const popup: OAuthPopupHandle = {
99
+ closed: true,
100
+ close: () => undefined,
101
+ get location(): { href: string } {
102
+ throw new Error('window closed');
103
+ },
104
+ };
105
+ expect(navigateOAuthPopup(popup, `${IDP_ORIGIN}/authorize`)).toBe(false);
106
+ });
107
+ });
108
+
109
+ describe('closeOAuthPopup', () => {
110
+ it('is a no-op for null and for an already-closed window', () => {
111
+ expect(() => closeOAuthPopup(null)).not.toThrow();
112
+ const popup = fakePopup();
113
+ popup.setClosed();
114
+ closeOAuthPopup(popup);
115
+ expect(popup.close).not.toHaveBeenCalled();
116
+ });
117
+
118
+ it('closes an open window and swallows a close that throws', () => {
119
+ const popup = fakePopup();
120
+ closeOAuthPopup(popup);
121
+ expect(popup.close).toHaveBeenCalledTimes(1);
122
+
123
+ const hostile: OAuthPopupHandle = {
124
+ closed: false,
125
+ close: () => {
126
+ throw new Error('denied');
127
+ },
128
+ location: { href: '' },
129
+ };
130
+ expect(() => closeOAuthPopup(hostile)).not.toThrow();
131
+ });
132
+ });
133
+
134
+ describe('awaitOAuthPopupResult', () => {
135
+ let addSpy: jest.SpyInstance;
136
+ let removeSpy: jest.SpyInstance;
137
+
138
+ beforeEach(() => {
139
+ jest.useFakeTimers();
140
+ addSpy = jest.spyOn(window, 'addEventListener');
141
+ removeSpy = jest.spyOn(window, 'removeEventListener');
142
+ });
143
+
144
+ afterEach(() => {
145
+ jest.useRealTimers();
146
+ jest.restoreAllMocks();
147
+ });
148
+
149
+ /** Every exit path must leave zero listeners and zero timers behind. */
150
+ function expectFullCleanup(): void {
151
+ const registered = addSpy.mock.calls.filter(([type]) => type === 'message');
152
+ const removed = removeSpy.mock.calls.filter(([type]) => type === 'message');
153
+ expect(registered).toHaveLength(1);
154
+ expect(removed).toHaveLength(1);
155
+ expect(removed[0][1]).toBe(registered[0][1]);
156
+ expect(jest.getTimerCount()).toBe(0);
157
+ }
158
+
159
+ it('resolves with the authorization code on a valid message', async () => {
160
+ const popup = fakePopup();
161
+ const promise = awaitOAuthPopupResult({
162
+ popup,
163
+ expectedOrigin: IDP_ORIGIN,
164
+ expectedState: STATE,
165
+ redirectUri: REDIRECT_URI,
166
+ });
167
+
168
+ dispatchMessage(codeMessage(popup));
169
+
170
+ await expect(promise).resolves.toEqual({ kind: 'code', code: 'code-1', state: STATE });
171
+ expectFullCleanup();
172
+ });
173
+
174
+ it('resolves with a typed IdP error', async () => {
175
+ const popup = fakePopup();
176
+ const promise = awaitOAuthPopupResult({
177
+ popup,
178
+ expectedOrigin: IDP_ORIGIN,
179
+ expectedState: STATE,
180
+ redirectUri: REDIRECT_URI,
181
+ });
182
+
183
+ dispatchMessage({
184
+ data: {
185
+ type: OXY_OAUTH_ERROR_MESSAGE_TYPE,
186
+ error: 'access_denied',
187
+ errorDescription: 'user declined',
188
+ state: STATE,
189
+ },
190
+ origin: IDP_ORIGIN,
191
+ source: popup,
192
+ });
193
+
194
+ await expect(promise).resolves.toEqual({
195
+ kind: 'oauth-error',
196
+ error: 'access_denied',
197
+ errorDescription: 'user declined',
198
+ });
199
+ expectFullCleanup();
200
+ });
201
+
202
+ it('resolves with a state mismatch when our popup answers another request', async () => {
203
+ const popup = fakePopup();
204
+ const promise = awaitOAuthPopupResult({
205
+ popup,
206
+ expectedOrigin: IDP_ORIGIN,
207
+ expectedState: STATE,
208
+ redirectUri: REDIRECT_URI,
209
+ });
210
+
211
+ dispatchMessage(codeMessage(popup, 'a-different-state'));
212
+
213
+ await expect(promise).resolves.toEqual({ kind: 'state-mismatch' });
214
+ expectFullCleanup();
215
+ });
216
+
217
+ it.each([
218
+ ['a foreign origin', () => codeMessage(fakePopup(), STATE, 'https://evil.example')],
219
+ ['a foreign window', () => codeMessage(fakePopup())],
220
+ ])('keeps waiting after a message from %s', async (_label, build) => {
221
+ const popup = fakePopup();
222
+ const promise = awaitOAuthPopupResult({
223
+ popup,
224
+ expectedOrigin: IDP_ORIGIN,
225
+ expectedState: STATE,
226
+ redirectUri: REDIRECT_URI,
227
+ timeoutMs: 60_000,
228
+ });
229
+
230
+ dispatchMessage(build());
231
+ expect(await outcomeOrPending(promise)).toBe('pending');
232
+
233
+ // The real popup can still complete the flow afterwards.
234
+ dispatchMessage(codeMessage(popup));
235
+ await expect(promise).resolves.toEqual({ kind: 'code', code: 'code-1', state: STATE });
236
+ expectFullCleanup();
237
+ });
238
+
239
+ it('keeps waiting after a malformed payload from the real popup', async () => {
240
+ const popup = fakePopup();
241
+ const promise = awaitOAuthPopupResult({
242
+ popup,
243
+ expectedOrigin: IDP_ORIGIN,
244
+ expectedState: STATE,
245
+ redirectUri: REDIRECT_URI,
246
+ timeoutMs: 60_000,
247
+ });
248
+
249
+ dispatchMessage({ data: { type: 'oxy:oauth:code' }, origin: IDP_ORIGIN, source: popup });
250
+ expect(await outcomeOrPending(promise)).toBe('pending');
251
+
252
+ dispatchMessage(codeMessage(popup));
253
+ await expect(promise).resolves.toEqual({ kind: 'code', code: 'code-1', state: STATE });
254
+ expectFullCleanup();
255
+ });
256
+
257
+ it('ignores a duplicate result: the first message wins and the listener is gone', async () => {
258
+ const popup = fakePopup();
259
+ const promise = awaitOAuthPopupResult({
260
+ popup,
261
+ expectedOrigin: IDP_ORIGIN,
262
+ expectedState: STATE,
263
+ redirectUri: REDIRECT_URI,
264
+ });
265
+
266
+ dispatchMessage(codeMessage(popup));
267
+ await expect(promise).resolves.toEqual({ kind: 'code', code: 'code-1', state: STATE });
268
+
269
+ // A late redelivery (or a second, contradicting message) reaches nothing.
270
+ expect(() =>
271
+ dispatchMessage({
272
+ data: { type: OXY_OAUTH_ERROR_MESSAGE_TYPE, error: 'access_denied', state: STATE },
273
+ origin: IDP_ORIGIN,
274
+ source: popup,
275
+ }),
276
+ ).not.toThrow();
277
+ await expect(promise).resolves.toEqual({ kind: 'code', code: 'code-1', state: STATE });
278
+ expectFullCleanup();
279
+ });
280
+
281
+ it('reports cancellation once the user closes the window', async () => {
282
+ const popup = fakePopup();
283
+ const promise = awaitOAuthPopupResult({
284
+ popup,
285
+ expectedOrigin: IDP_ORIGIN,
286
+ expectedState: STATE,
287
+ redirectUri: REDIRECT_URI,
288
+ });
289
+
290
+ popup.setClosed();
291
+ jest.advanceTimersByTime(1000);
292
+ // The close is not reported instantly: an already-queued message may still win.
293
+ expect(await outcomeOrPending(promise)).toBe('pending');
294
+
295
+ jest.advanceTimersByTime(400);
296
+ await expect(promise).resolves.toEqual({ kind: 'closed' });
297
+ expectFullCleanup();
298
+ });
299
+
300
+ it('lets a result that arrived just before the close win the race', async () => {
301
+ const popup = fakePopup();
302
+ const promise = awaitOAuthPopupResult({
303
+ popup,
304
+ expectedOrigin: IDP_ORIGIN,
305
+ expectedState: STATE,
306
+ redirectUri: REDIRECT_URI,
307
+ });
308
+
309
+ // The IdP posts its result and immediately closes itself.
310
+ popup.setClosed();
311
+ jest.advanceTimersByTime(1000);
312
+ dispatchMessage(codeMessage(popup));
313
+ jest.advanceTimersByTime(1000);
314
+
315
+ await expect(promise).resolves.toEqual({ kind: 'code', code: 'code-1', state: STATE });
316
+ expectFullCleanup();
317
+ });
318
+
319
+ it('times out when nothing ever answers', async () => {
320
+ const popup = fakePopup();
321
+ const promise = awaitOAuthPopupResult({
322
+ popup,
323
+ expectedOrigin: IDP_ORIGIN,
324
+ expectedState: STATE,
325
+ redirectUri: REDIRECT_URI,
326
+ timeoutMs: 30_000,
327
+ });
328
+
329
+ jest.advanceTimersByTime(29_999);
330
+ expect(await outcomeOrPending(promise)).toBe('pending');
331
+
332
+ jest.advanceTimersByTime(1);
333
+ await expect(promise).resolves.toEqual({ kind: 'timed-out' });
334
+ expectFullCleanup();
335
+ });
336
+
337
+ it('reads a same-origin redirect fallback from the popup URL when postMessage is unavailable', async () => {
338
+ const popup = fakePopup();
339
+ popup.location.href = `${REDIRECT_URI}?code=auth-code&state=${STATE}`;
340
+ const promise = awaitOAuthPopupResult({
341
+ popup,
342
+ expectedOrigin: IDP_ORIGIN,
343
+ expectedState: STATE,
344
+ redirectUri: REDIRECT_URI,
345
+ });
346
+
347
+ jest.advanceTimersByTime(1000);
348
+
349
+ await expect(promise).resolves.toEqual({ kind: 'code', code: 'auth-code', state: STATE });
350
+ expectFullCleanup();
351
+ });
352
+ });
@@ -0,0 +1,189 @@
1
+ import {
2
+ OXY_OAUTH_CODE_MESSAGE_TYPE,
3
+ OXY_OAUTH_ERROR_MESSAGE_TYPE,
4
+ parseOAuthPopupMessage,
5
+ readOAuthPopupMessage,
6
+ } from '../oauthPopupMessages';
7
+ import type { OAuthPopupHandle } from '../types';
8
+
9
+ const IDP_ORIGIN = 'https://auth.oxy.so';
10
+ const STATE = 'state-abc';
11
+
12
+ /** A stand-in for the popup `Window`; identity is all the validator compares. */
13
+ function fakePopup(): OAuthPopupHandle {
14
+ return { closed: false, close: () => undefined, location: { href: '' } };
15
+ }
16
+
17
+ /**
18
+ * Build a `message` event with attacker-controllable fields. jsdom's
19
+ * `MessageEvent` constructor refuses a non-`Window` `source`, so the event is
20
+ * assembled the way the browser hands it to the listener instead.
21
+ */
22
+ function makeMessageEvent(init: {
23
+ data: unknown;
24
+ origin: string;
25
+ source: unknown;
26
+ }): MessageEvent {
27
+ const event = new Event('message');
28
+ Object.assign(event, init);
29
+ return event as MessageEvent;
30
+ }
31
+
32
+ describe('parseOAuthPopupMessage', () => {
33
+ it('accepts a well-formed code message', () => {
34
+ expect(
35
+ parseOAuthPopupMessage({ type: OXY_OAUTH_CODE_MESSAGE_TYPE, code: 'c1', state: STATE }),
36
+ ).toEqual({ type: OXY_OAUTH_CODE_MESSAGE_TYPE, code: 'c1', state: STATE });
37
+ });
38
+
39
+ it('accepts a well-formed error message and its optional fields', () => {
40
+ expect(
41
+ parseOAuthPopupMessage({
42
+ type: OXY_OAUTH_ERROR_MESSAGE_TYPE,
43
+ error: 'access_denied',
44
+ errorDescription: 'user said no',
45
+ state: STATE,
46
+ }),
47
+ ).toEqual({
48
+ type: OXY_OAUTH_ERROR_MESSAGE_TYPE,
49
+ error: 'access_denied',
50
+ errorDescription: 'user said no',
51
+ state: STATE,
52
+ });
53
+ });
54
+
55
+ it('drops optional error fields that are not non-empty strings', () => {
56
+ expect(
57
+ parseOAuthPopupMessage({
58
+ type: OXY_OAUTH_ERROR_MESSAGE_TYPE,
59
+ error: 'server_error',
60
+ errorDescription: 42,
61
+ state: '',
62
+ }),
63
+ ).toEqual({ type: OXY_OAUTH_ERROR_MESSAGE_TYPE, error: 'server_error' });
64
+ });
65
+
66
+ it('never surfaces extra properties a sender smuggled in', () => {
67
+ const parsed = parseOAuthPopupMessage({
68
+ type: OXY_OAUTH_CODE_MESSAGE_TYPE,
69
+ code: 'c1',
70
+ state: STATE,
71
+ accessToken: 'leaked',
72
+ deviceSecret: 'leaked',
73
+ });
74
+ expect(parsed).toEqual({ type: OXY_OAUTH_CODE_MESSAGE_TYPE, code: 'c1', state: STATE });
75
+ });
76
+
77
+ it.each([
78
+ ['null', null],
79
+ ['undefined', undefined],
80
+ ['a string', 'oxy:oauth:code'],
81
+ ['a number', 7],
82
+ ['an array', [{ type: OXY_OAUTH_CODE_MESSAGE_TYPE, code: 'c', state: STATE }]],
83
+ ['an unknown type', { type: 'oxy:oauth:token', code: 'c', state: STATE }],
84
+ ['a code message with no code', { type: OXY_OAUTH_CODE_MESSAGE_TYPE, state: STATE }],
85
+ ['a code message with an empty code', { type: OXY_OAUTH_CODE_MESSAGE_TYPE, code: '', state: STATE }],
86
+ ['a code message with no state', { type: OXY_OAUTH_CODE_MESSAGE_TYPE, code: 'c' }],
87
+ ['a code message with a non-string code', { type: OXY_OAUTH_CODE_MESSAGE_TYPE, code: 1, state: STATE }],
88
+ ['an error message with no error', { type: OXY_OAUTH_ERROR_MESSAGE_TYPE, state: STATE }],
89
+ ])('rejects %s', (_label, data) => {
90
+ expect(parseOAuthPopupMessage(data)).toBeNull();
91
+ });
92
+ });
93
+
94
+ describe('readOAuthPopupMessage', () => {
95
+ const popup = fakePopup();
96
+ const context = { expectedOrigin: IDP_ORIGIN, expectedState: STATE, popup };
97
+
98
+ it('returns the code when origin, source, shape and state all match', () => {
99
+ const verdict = readOAuthPopupMessage(
100
+ makeMessageEvent({
101
+ data: { type: OXY_OAUTH_CODE_MESSAGE_TYPE, code: 'c1', state: STATE },
102
+ origin: IDP_ORIGIN,
103
+ source: popup,
104
+ }),
105
+ context,
106
+ );
107
+ expect(verdict).toEqual({ kind: 'code', code: 'c1', state: STATE });
108
+ });
109
+
110
+ it('ignores a message from another origin, even with a valid payload', () => {
111
+ const verdict = readOAuthPopupMessage(
112
+ makeMessageEvent({
113
+ data: { type: OXY_OAUTH_CODE_MESSAGE_TYPE, code: 'evil', state: STATE },
114
+ origin: 'https://evil.example',
115
+ source: popup,
116
+ }),
117
+ context,
118
+ );
119
+ expect(verdict).toEqual({ kind: 'ignore' });
120
+ });
121
+
122
+ it('ignores a message from a window that is not the popup we opened', () => {
123
+ const verdict = readOAuthPopupMessage(
124
+ makeMessageEvent({
125
+ data: { type: OXY_OAUTH_CODE_MESSAGE_TYPE, code: 'evil', state: STATE },
126
+ origin: IDP_ORIGIN,
127
+ source: fakePopup(),
128
+ }),
129
+ context,
130
+ );
131
+ expect(verdict).toEqual({ kind: 'ignore' });
132
+ });
133
+
134
+ it('ignores a message with no source at all', () => {
135
+ const verdict = readOAuthPopupMessage(
136
+ makeMessageEvent({
137
+ data: { type: OXY_OAUTH_CODE_MESSAGE_TYPE, code: 'c1', state: STATE },
138
+ origin: IDP_ORIGIN,
139
+ source: null,
140
+ }),
141
+ context,
142
+ );
143
+ expect(verdict).toEqual({ kind: 'ignore' });
144
+ });
145
+
146
+ it('ignores a malformed payload from the real popup', () => {
147
+ const verdict = readOAuthPopupMessage(
148
+ makeMessageEvent({ data: { hello: 'world' }, origin: IDP_ORIGIN, source: popup }),
149
+ context,
150
+ );
151
+ expect(verdict).toEqual({ kind: 'ignore' });
152
+ });
153
+
154
+ it('reports a state mismatch on a code message bound to another request', () => {
155
+ const verdict = readOAuthPopupMessage(
156
+ makeMessageEvent({
157
+ data: { type: OXY_OAUTH_CODE_MESSAGE_TYPE, code: 'c1', state: 'other-state' },
158
+ origin: IDP_ORIGIN,
159
+ source: popup,
160
+ }),
161
+ context,
162
+ );
163
+ expect(verdict).toEqual({ kind: 'state-mismatch' });
164
+ });
165
+
166
+ it('accepts an error message that carries no state', () => {
167
+ const verdict = readOAuthPopupMessage(
168
+ makeMessageEvent({
169
+ data: { type: OXY_OAUTH_ERROR_MESSAGE_TYPE, error: 'access_denied' },
170
+ origin: IDP_ORIGIN,
171
+ source: popup,
172
+ }),
173
+ context,
174
+ );
175
+ expect(verdict).toEqual({ kind: 'oauth-error', error: 'access_denied' });
176
+ });
177
+
178
+ it('reports a state mismatch on an error message bound to another request', () => {
179
+ const verdict = readOAuthPopupMessage(
180
+ makeMessageEvent({
181
+ data: { type: OXY_OAUTH_ERROR_MESSAGE_TYPE, error: 'access_denied', state: 'other' },
182
+ origin: IDP_ORIGIN,
183
+ source: popup,
184
+ }),
185
+ context,
186
+ );
187
+ expect(verdict).toEqual({ kind: 'state-mismatch' });
188
+ });
189
+ });