@effect-auth/core 0.1.0-alpha.16 → 0.1.0-alpha.19

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 (637) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +307 -133
  3. package/dist/AbuseProtection.d.ts +100 -0
  4. package/dist/AbuseProtection.d.ts.map +1 -0
  5. package/dist/AbuseProtection.js +71 -0
  6. package/dist/AbuseProtection.js.map +1 -0
  7. package/dist/AccessGrant.d.ts +344 -0
  8. package/dist/AccessGrant.d.ts.map +1 -0
  9. package/dist/AccessGrant.js +687 -0
  10. package/dist/AccessGrant.js.map +1 -0
  11. package/dist/ApiKey.d.ts +0 -12
  12. package/dist/ApiKey.d.ts.map +1 -1
  13. package/dist/ApiKey.js +36 -27
  14. package/dist/ApiKey.js.map +1 -1
  15. package/dist/Assurance.d.ts +415 -0
  16. package/dist/Assurance.d.ts.map +1 -0
  17. package/dist/Assurance.js +764 -0
  18. package/dist/Assurance.js.map +1 -0
  19. package/dist/AtomicPlanExecutor.d.ts +28 -0
  20. package/dist/AtomicPlanExecutor.d.ts.map +1 -0
  21. package/dist/AtomicPlanExecutor.js +5 -0
  22. package/dist/AtomicPlanExecutor.js.map +1 -0
  23. package/dist/AuditLog.d.ts +2314 -52
  24. package/dist/AuditLog.d.ts.map +1 -1
  25. package/dist/AuditLog.js +511 -33
  26. package/dist/AuditLog.js.map +1 -1
  27. package/dist/AuthFlow.d.ts +128 -38
  28. package/dist/AuthFlow.d.ts.map +1 -1
  29. package/dist/AuthFlow.js +611 -263
  30. package/dist/AuthFlow.js.map +1 -1
  31. package/dist/AuthRateLimit.d.ts +96 -0
  32. package/dist/AuthRateLimit.d.ts.map +1 -0
  33. package/dist/AuthRateLimit.js +212 -0
  34. package/dist/AuthRateLimit.js.map +1 -0
  35. package/dist/Challenge.d.ts +0 -3
  36. package/dist/Challenge.d.ts.map +1 -1
  37. package/dist/Challenge.js +1 -4
  38. package/dist/Challenge.js.map +1 -1
  39. package/dist/Client.d.ts +205 -10
  40. package/dist/Client.d.ts.map +1 -1
  41. package/dist/Client.js +397 -16
  42. package/dist/Client.js.map +1 -1
  43. package/dist/CloudflareTurnstile.d.ts +28 -0
  44. package/dist/CloudflareTurnstile.d.ts.map +1 -0
  45. package/dist/CloudflareTurnstile.js +205 -0
  46. package/dist/CloudflareTurnstile.js.map +1 -0
  47. package/dist/Crypto.d.ts +0 -3
  48. package/dist/Crypto.d.ts.map +1 -1
  49. package/dist/Crypto.js +1 -4
  50. package/dist/Crypto.js.map +1 -1
  51. package/dist/DelegatedAccessStorageMigrations.d.ts +7 -0
  52. package/dist/DelegatedAccessStorageMigrations.d.ts.map +1 -0
  53. package/dist/DelegatedAccessStorageMigrations.js +159 -0
  54. package/dist/DelegatedAccessStorageMigrations.js.map +1 -0
  55. package/dist/DevEmail.d.ts +44 -0
  56. package/dist/DevEmail.d.ts.map +1 -0
  57. package/dist/DevEmail.js +115 -0
  58. package/dist/DevEmail.js.map +1 -0
  59. package/dist/DevelopmentSeed.d.ts +47 -0
  60. package/dist/DevelopmentSeed.d.ts.map +1 -0
  61. package/dist/DevelopmentSeed.js +337 -0
  62. package/dist/DevelopmentSeed.js.map +1 -0
  63. package/dist/DisposableEmailDomains.d.ts +19 -0
  64. package/dist/DisposableEmailDomains.d.ts.map +1 -0
  65. package/dist/DisposableEmailDomains.js +85 -0
  66. package/dist/DisposableEmailDomains.js.map +1 -0
  67. package/dist/DomainVerification.d.ts +0 -9
  68. package/dist/DomainVerification.d.ts.map +1 -1
  69. package/dist/DomainVerification.js +36 -22
  70. package/dist/DomainVerification.js.map +1 -1
  71. package/dist/DrizzleBunSqliteStorage.d.ts +18 -0
  72. package/dist/DrizzleBunSqliteStorage.d.ts.map +1 -0
  73. package/dist/DrizzleBunSqliteStorage.js +11 -0
  74. package/dist/DrizzleBunSqliteStorage.js.map +1 -0
  75. package/dist/DrizzleD1SqliteStorage.d.ts +4 -4
  76. package/dist/DrizzleD1SqliteStorage.d.ts.map +1 -1
  77. package/dist/DrizzleD1SqliteStorage.js +5 -5
  78. package/dist/DrizzleD1SqliteStorage.js.map +1 -1
  79. package/dist/DrizzleEffectSqliteStorage.d.ts +13 -4
  80. package/dist/DrizzleEffectSqliteStorage.d.ts.map +1 -1
  81. package/dist/DrizzleEffectSqliteStorage.js +71 -4
  82. package/dist/DrizzleEffectSqliteStorage.js.map +1 -1
  83. package/dist/DrizzleNodeSqliteStorage.d.ts +18 -0
  84. package/dist/DrizzleNodeSqliteStorage.d.ts.map +1 -0
  85. package/dist/DrizzleNodeSqliteStorage.js +11 -0
  86. package/dist/DrizzleNodeSqliteStorage.js.map +1 -0
  87. package/dist/DrizzlePostgresStorage.d.ts +26 -0
  88. package/dist/DrizzlePostgresStorage.d.ts.map +1 -0
  89. package/dist/DrizzlePostgresStorage.js +14 -0
  90. package/dist/DrizzlePostgresStorage.js.map +1 -0
  91. package/dist/EffectQbPostgresDelegatedAccessStorage.d.ts +34 -0
  92. package/dist/EffectQbPostgresDelegatedAccessStorage.d.ts.map +1 -0
  93. package/dist/EffectQbPostgresDelegatedAccessStorage.js +499 -0
  94. package/dist/EffectQbPostgresDelegatedAccessStorage.js.map +1 -0
  95. package/dist/EffectQbPostgresStorage.d.ts +178 -0
  96. package/dist/EffectQbPostgresStorage.d.ts.map +1 -0
  97. package/dist/EffectQbPostgresStorage.js +4637 -0
  98. package/dist/EffectQbPostgresStorage.js.map +1 -0
  99. package/dist/EffectQbSqliteDelegatedAccessStorage.d.ts +112 -0
  100. package/dist/EffectQbSqliteDelegatedAccessStorage.d.ts.map +1 -0
  101. package/dist/EffectQbSqliteDelegatedAccessStorage.js +602 -0
  102. package/dist/EffectQbSqliteDelegatedAccessStorage.js.map +1 -0
  103. package/dist/EffectQbSqliteStorage.d.ts +221 -23
  104. package/dist/EffectQbSqliteStorage.d.ts.map +1 -1
  105. package/dist/EffectQbSqliteStorage.js +2064 -135
  106. package/dist/EffectQbSqliteStorage.js.map +1 -1
  107. package/dist/EmailAuth.d.ts +65 -0
  108. package/dist/EmailAuth.d.ts.map +1 -0
  109. package/dist/EmailAuth.js +171 -0
  110. package/dist/EmailAuth.js.map +1 -0
  111. package/dist/EmailIdentityAuth.d.ts +30 -0
  112. package/dist/EmailIdentityAuth.d.ts.map +1 -0
  113. package/dist/EmailIdentityAuth.js +142 -0
  114. package/dist/EmailIdentityAuth.js.map +1 -0
  115. package/dist/EmailOtp.d.ts +10 -11
  116. package/dist/EmailOtp.d.ts.map +1 -1
  117. package/dist/EmailOtp.js +44 -81
  118. package/dist/EmailOtp.js.map +1 -1
  119. package/dist/EmailRisk.d.ts +48 -0
  120. package/dist/EmailRisk.d.ts.map +1 -0
  121. package/dist/EmailRisk.js +33 -0
  122. package/dist/EmailRisk.js.map +1 -0
  123. package/dist/EmailVerification.d.ts +10 -16
  124. package/dist/EmailVerification.d.ts.map +1 -1
  125. package/dist/EmailVerification.js +85 -42
  126. package/dist/EmailVerification.js.map +1 -1
  127. package/dist/Guard.d.ts +11 -0
  128. package/dist/Guard.d.ts.map +1 -0
  129. package/dist/Guard.js +11 -0
  130. package/dist/Guard.js.map +1 -0
  131. package/dist/HibpPwnedPasswords.d.ts +56 -0
  132. package/dist/HibpPwnedPasswords.d.ts.map +1 -0
  133. package/dist/HibpPwnedPasswords.js +232 -0
  134. package/dist/HibpPwnedPasswords.js.map +1 -0
  135. package/dist/HttpApi/AdminPermissionDefinition.d.ts +4 -0
  136. package/dist/HttpApi/AdminPermissionDefinition.d.ts.map +1 -0
  137. package/dist/HttpApi/AdminPermissionDefinition.js +4 -0
  138. package/dist/HttpApi/AdminPermissionDefinition.js.map +1 -0
  139. package/dist/HttpApi/AdminSecurityTimeline.d.ts +4 -0
  140. package/dist/HttpApi/AdminSecurityTimeline.d.ts.map +1 -0
  141. package/dist/HttpApi/AdminSecurityTimeline.js +4 -0
  142. package/dist/HttpApi/AdminSecurityTimeline.js.map +1 -0
  143. package/dist/HttpApi/AdminSession.d.ts +4 -0
  144. package/dist/HttpApi/AdminSession.d.ts.map +1 -0
  145. package/dist/HttpApi/AdminSession.js +4 -0
  146. package/dist/HttpApi/AdminSession.js.map +1 -0
  147. package/dist/HttpApi/AdminTrustedDevice.d.ts +4 -0
  148. package/dist/HttpApi/AdminTrustedDevice.d.ts.map +1 -0
  149. package/dist/HttpApi/AdminTrustedDevice.js +4 -0
  150. package/dist/HttpApi/AdminTrustedDevice.js.map +1 -0
  151. package/dist/HttpApi/Api.d.ts +939 -884
  152. package/dist/HttpApi/Api.d.ts.map +1 -1
  153. package/dist/HttpApi/Api.js +2254 -940
  154. package/dist/HttpApi/Api.js.map +1 -1
  155. package/dist/HttpApi/ApiKey.d.ts +4 -0
  156. package/dist/HttpApi/ApiKey.d.ts.map +1 -0
  157. package/dist/HttpApi/ApiKey.js +4 -0
  158. package/dist/HttpApi/ApiKey.js.map +1 -0
  159. package/dist/HttpApi/Audit.d.ts +6 -0
  160. package/dist/HttpApi/Audit.d.ts.map +1 -0
  161. package/dist/HttpApi/Audit.js +10 -0
  162. package/dist/HttpApi/Audit.js.map +1 -0
  163. package/dist/HttpApi/ClientApi.d.ts +917 -0
  164. package/dist/HttpApi/ClientApi.d.ts.map +1 -0
  165. package/dist/HttpApi/ClientApi.js +101 -0
  166. package/dist/HttpApi/ClientApi.js.map +1 -0
  167. package/dist/HttpApi/EmailAuth.d.ts +6 -0
  168. package/dist/HttpApi/EmailAuth.d.ts.map +1 -0
  169. package/dist/HttpApi/EmailAuth.js +6 -0
  170. package/dist/HttpApi/EmailAuth.js.map +1 -0
  171. package/dist/HttpApi/EmailGuards.d.ts +115 -0
  172. package/dist/HttpApi/EmailGuards.d.ts.map +1 -0
  173. package/dist/HttpApi/EmailGuards.js +191 -0
  174. package/dist/HttpApi/EmailGuards.js.map +1 -0
  175. package/dist/HttpApi/EmailOtp.d.ts +6 -0
  176. package/dist/HttpApi/EmailOtp.d.ts.map +1 -0
  177. package/dist/HttpApi/EmailOtp.js +6 -0
  178. package/dist/HttpApi/EmailOtp.js.map +1 -0
  179. package/dist/HttpApi/EmailVerification.d.ts +6 -0
  180. package/dist/HttpApi/EmailVerification.d.ts.map +1 -0
  181. package/dist/HttpApi/EmailVerification.js +6 -0
  182. package/dist/HttpApi/EmailVerification.js.map +1 -0
  183. package/dist/HttpApi/Endpoints.d.ts +661 -301
  184. package/dist/HttpApi/Endpoints.d.ts.map +1 -1
  185. package/dist/HttpApi/Endpoints.js +207 -120
  186. package/dist/HttpApi/Endpoints.js.map +1 -1
  187. package/dist/HttpApi/Errors.d.ts +37 -10
  188. package/dist/HttpApi/Errors.d.ts.map +1 -1
  189. package/dist/HttpApi/Errors.js +42 -4
  190. package/dist/HttpApi/Errors.js.map +1 -1
  191. package/dist/HttpApi/Identity.d.ts +6 -0
  192. package/dist/HttpApi/Identity.d.ts.map +1 -0
  193. package/dist/HttpApi/Identity.js +6 -0
  194. package/dist/HttpApi/Identity.js.map +1 -0
  195. package/dist/HttpApi/IdentityGuards.d.ts +31 -0
  196. package/dist/HttpApi/IdentityGuards.d.ts.map +1 -0
  197. package/dist/HttpApi/IdentityGuards.js +33 -0
  198. package/dist/HttpApi/IdentityGuards.js.map +1 -0
  199. package/dist/HttpApi/Jwt.d.ts +4 -0
  200. package/dist/HttpApi/Jwt.d.ts.map +1 -0
  201. package/dist/HttpApi/Jwt.js +4 -0
  202. package/dist/HttpApi/Jwt.js.map +1 -0
  203. package/dist/HttpApi/JwtDiscovery.d.ts +4 -0
  204. package/dist/HttpApi/JwtDiscovery.d.ts.map +1 -0
  205. package/dist/HttpApi/JwtDiscovery.js +4 -0
  206. package/dist/HttpApi/JwtDiscovery.js.map +1 -0
  207. package/dist/HttpApi/LoginApproval.d.ts +5 -0
  208. package/dist/HttpApi/LoginApproval.d.ts.map +1 -0
  209. package/dist/HttpApi/LoginApproval.js +5 -0
  210. package/dist/HttpApi/LoginApproval.js.map +1 -0
  211. package/dist/HttpApi/LoginNotification.d.ts +5 -0
  212. package/dist/HttpApi/LoginNotification.d.ts.map +1 -0
  213. package/dist/HttpApi/LoginNotification.js +5 -0
  214. package/dist/HttpApi/LoginNotification.js.map +1 -0
  215. package/dist/HttpApi/MagicLink.d.ts +6 -0
  216. package/dist/HttpApi/MagicLink.d.ts.map +1 -0
  217. package/dist/HttpApi/MagicLink.js +6 -0
  218. package/dist/HttpApi/MagicLink.js.map +1 -0
  219. package/dist/HttpApi/Mfa.d.ts +5 -0
  220. package/dist/HttpApi/Mfa.d.ts.map +1 -0
  221. package/dist/HttpApi/Mfa.js +5 -0
  222. package/dist/HttpApi/Mfa.js.map +1 -0
  223. package/dist/HttpApi/Middleware.d.ts +26 -0
  224. package/dist/HttpApi/Middleware.d.ts.map +1 -0
  225. package/dist/HttpApi/Middleware.js +13 -0
  226. package/dist/HttpApi/Middleware.js.map +1 -0
  227. package/dist/HttpApi/OAuth.d.ts +4 -0
  228. package/dist/HttpApi/OAuth.d.ts.map +1 -0
  229. package/dist/HttpApi/OAuth.js +4 -0
  230. package/dist/HttpApi/OAuth.js.map +1 -0
  231. package/dist/HttpApi/OAuthDeviceAuthorization.d.ts +106 -0
  232. package/dist/HttpApi/OAuthDeviceAuthorization.d.ts.map +1 -0
  233. package/dist/HttpApi/OAuthDeviceAuthorization.js +415 -0
  234. package/dist/HttpApi/OAuthDeviceAuthorization.js.map +1 -0
  235. package/dist/HttpApi/OAuthProviderAuthorization.d.ts +4 -0
  236. package/dist/HttpApi/OAuthProviderAuthorization.d.ts.map +1 -0
  237. package/dist/HttpApi/OAuthProviderAuthorization.js +4 -0
  238. package/dist/HttpApi/OAuthProviderAuthorization.js.map +1 -0
  239. package/dist/HttpApi/OAuthToken.d.ts +4 -0
  240. package/dist/HttpApi/OAuthToken.d.ts.map +1 -0
  241. package/dist/HttpApi/OAuthToken.js +4 -0
  242. package/dist/HttpApi/OAuthToken.js.map +1 -0
  243. package/dist/HttpApi/OidcDiscovery.d.ts +4 -0
  244. package/dist/HttpApi/OidcDiscovery.d.ts.map +1 -0
  245. package/dist/HttpApi/OidcDiscovery.js +4 -0
  246. package/dist/HttpApi/OidcDiscovery.js.map +1 -0
  247. package/dist/HttpApi/Operations/AdminPermissionDefinition.d.ts +28 -0
  248. package/dist/HttpApi/Operations/AdminPermissionDefinition.d.ts.map +1 -0
  249. package/dist/HttpApi/Operations/AdminPermissionDefinition.js +5 -0
  250. package/dist/HttpApi/Operations/AdminPermissionDefinition.js.map +1 -0
  251. package/dist/HttpApi/Operations/AdminSession.d.ts +16 -0
  252. package/dist/HttpApi/Operations/AdminSession.d.ts.map +1 -0
  253. package/dist/HttpApi/Operations/AdminSession.js +5 -0
  254. package/dist/HttpApi/Operations/AdminSession.js.map +1 -0
  255. package/dist/HttpApi/Operations/ApiKey.d.ts +16 -0
  256. package/dist/HttpApi/Operations/ApiKey.d.ts.map +1 -0
  257. package/dist/HttpApi/Operations/ApiKey.js +5 -0
  258. package/dist/HttpApi/Operations/ApiKey.js.map +1 -0
  259. package/dist/HttpApi/Operations/Discovery.d.ts +19 -0
  260. package/dist/HttpApi/Operations/Discovery.d.ts.map +1 -0
  261. package/dist/HttpApi/Operations/Discovery.js +7 -0
  262. package/dist/HttpApi/Operations/Discovery.js.map +1 -0
  263. package/dist/HttpApi/Operations/EmailAuth.d.ts +12 -0
  264. package/dist/HttpApi/Operations/EmailAuth.d.ts.map +1 -0
  265. package/dist/HttpApi/Operations/EmailAuth.js +5 -0
  266. package/dist/HttpApi/Operations/EmailAuth.js.map +1 -0
  267. package/dist/HttpApi/Operations/EmailOtp.d.ts +14 -0
  268. package/dist/HttpApi/Operations/EmailOtp.d.ts.map +1 -0
  269. package/dist/HttpApi/Operations/EmailOtp.js +5 -0
  270. package/dist/HttpApi/Operations/EmailOtp.js.map +1 -0
  271. package/dist/HttpApi/Operations/EmailVerification.d.ts +14 -0
  272. package/dist/HttpApi/Operations/EmailVerification.d.ts.map +1 -0
  273. package/dist/HttpApi/Operations/EmailVerification.js +5 -0
  274. package/dist/HttpApi/Operations/EmailVerification.js.map +1 -0
  275. package/dist/HttpApi/Operations/HttpOperation.d.ts +4 -0
  276. package/dist/HttpApi/Operations/HttpOperation.d.ts.map +1 -0
  277. package/dist/HttpApi/Operations/HttpOperation.js +2 -0
  278. package/dist/HttpApi/Operations/HttpOperation.js.map +1 -0
  279. package/dist/HttpApi/Operations/Identity.d.ts +22 -0
  280. package/dist/HttpApi/Operations/Identity.d.ts.map +1 -0
  281. package/dist/HttpApi/Operations/Identity.js +5 -0
  282. package/dist/HttpApi/Operations/Identity.js.map +1 -0
  283. package/dist/HttpApi/Operations/Jwt.d.ts +14 -0
  284. package/dist/HttpApi/Operations/Jwt.d.ts.map +1 -0
  285. package/dist/HttpApi/Operations/Jwt.js +5 -0
  286. package/dist/HttpApi/Operations/Jwt.js.map +1 -0
  287. package/dist/HttpApi/Operations/LoginApproval.d.ts +16 -0
  288. package/dist/HttpApi/Operations/LoginApproval.d.ts.map +1 -0
  289. package/dist/HttpApi/Operations/LoginApproval.js +5 -0
  290. package/dist/HttpApi/Operations/LoginApproval.js.map +1 -0
  291. package/dist/HttpApi/Operations/MagicLink.d.ts +14 -0
  292. package/dist/HttpApi/Operations/MagicLink.d.ts.map +1 -0
  293. package/dist/HttpApi/Operations/MagicLink.js +5 -0
  294. package/dist/HttpApi/Operations/MagicLink.js.map +1 -0
  295. package/dist/HttpApi/Operations/Mfa.d.ts +24 -0
  296. package/dist/HttpApi/Operations/Mfa.d.ts.map +1 -0
  297. package/dist/HttpApi/Operations/Mfa.js +5 -0
  298. package/dist/HttpApi/Operations/Mfa.js.map +1 -0
  299. package/dist/HttpApi/Operations/OAuth.d.ts +20 -0
  300. package/dist/HttpApi/Operations/OAuth.d.ts.map +1 -0
  301. package/dist/HttpApi/Operations/OAuth.js +5 -0
  302. package/dist/HttpApi/Operations/OAuth.js.map +1 -0
  303. package/dist/HttpApi/Operations/OAuthDeviceAuthorization.d.ts +23 -0
  304. package/dist/HttpApi/Operations/OAuthDeviceAuthorization.d.ts.map +1 -0
  305. package/dist/HttpApi/Operations/OAuthDeviceAuthorization.js +7 -0
  306. package/dist/HttpApi/Operations/OAuthDeviceAuthorization.js.map +1 -0
  307. package/dist/HttpApi/Operations/OAuthProviderAuthorization.d.ts +12 -0
  308. package/dist/HttpApi/Operations/OAuthProviderAuthorization.d.ts.map +1 -0
  309. package/dist/HttpApi/Operations/OAuthProviderAuthorization.js +5 -0
  310. package/dist/HttpApi/Operations/OAuthProviderAuthorization.js.map +1 -0
  311. package/dist/HttpApi/Operations/OAuthToken.d.ts +26 -0
  312. package/dist/HttpApi/Operations/OAuthToken.d.ts.map +1 -0
  313. package/dist/HttpApi/Operations/OAuthToken.js +9 -0
  314. package/dist/HttpApi/Operations/OAuthToken.js.map +1 -0
  315. package/dist/HttpApi/Operations/Passkey.d.ts +22 -0
  316. package/dist/HttpApi/Operations/Passkey.d.ts.map +1 -0
  317. package/dist/HttpApi/Operations/Passkey.js +5 -0
  318. package/dist/HttpApi/Operations/Passkey.js.map +1 -0
  319. package/dist/HttpApi/Operations/Password.d.ts +22 -0
  320. package/dist/HttpApi/Operations/Password.d.ts.map +1 -0
  321. package/dist/HttpApi/Operations/Password.js +5 -0
  322. package/dist/HttpApi/Operations/Password.js.map +1 -0
  323. package/dist/HttpApi/Operations/RecoveryCodes.d.ts +20 -0
  324. package/dist/HttpApi/Operations/RecoveryCodes.d.ts.map +1 -0
  325. package/dist/HttpApi/Operations/RecoveryCodes.js +5 -0
  326. package/dist/HttpApi/Operations/RecoveryCodes.js.map +1 -0
  327. package/dist/HttpApi/Operations/RefreshToken.d.ts +12 -0
  328. package/dist/HttpApi/Operations/RefreshToken.d.ts.map +1 -0
  329. package/dist/HttpApi/Operations/RefreshToken.js +5 -0
  330. package/dist/HttpApi/Operations/RefreshToken.js.map +1 -0
  331. package/dist/HttpApi/Operations/Security.d.ts +12 -0
  332. package/dist/HttpApi/Operations/Security.d.ts.map +1 -0
  333. package/dist/HttpApi/Operations/Security.js +5 -0
  334. package/dist/HttpApi/Operations/Security.js.map +1 -0
  335. package/dist/HttpApi/Operations/SecurityTimeline.d.ts +19 -0
  336. package/dist/HttpApi/Operations/SecurityTimeline.d.ts.map +1 -0
  337. package/dist/HttpApi/Operations/SecurityTimeline.js +7 -0
  338. package/dist/HttpApi/Operations/SecurityTimeline.js.map +1 -0
  339. package/dist/HttpApi/Operations/Session.d.ts +22 -0
  340. package/dist/HttpApi/Operations/Session.d.ts.map +1 -0
  341. package/dist/HttpApi/Operations/Session.js +5 -0
  342. package/dist/HttpApi/Operations/Session.js.map +1 -0
  343. package/dist/HttpApi/Operations/StepUp.d.ts +22 -0
  344. package/dist/HttpApi/Operations/StepUp.d.ts.map +1 -0
  345. package/dist/HttpApi/Operations/StepUp.js +5 -0
  346. package/dist/HttpApi/Operations/StepUp.js.map +1 -0
  347. package/dist/HttpApi/Operations/Totp.d.ts +20 -0
  348. package/dist/HttpApi/Operations/Totp.d.ts.map +1 -0
  349. package/dist/HttpApi/Operations/Totp.js +5 -0
  350. package/dist/HttpApi/Operations/Totp.js.map +1 -0
  351. package/dist/HttpApi/Operations/TrustedDevice.d.ts +23 -0
  352. package/dist/HttpApi/Operations/TrustedDevice.d.ts.map +1 -0
  353. package/dist/HttpApi/Operations/TrustedDevice.js +7 -0
  354. package/dist/HttpApi/Operations/TrustedDevice.js.map +1 -0
  355. package/dist/HttpApi/Operations/index.d.ts +28 -0
  356. package/dist/HttpApi/Operations/index.d.ts.map +1 -0
  357. package/dist/HttpApi/Operations/index.js +28 -0
  358. package/dist/HttpApi/Operations/index.js.map +1 -0
  359. package/dist/HttpApi/Passkey.d.ts +5 -0
  360. package/dist/HttpApi/Passkey.d.ts.map +1 -0
  361. package/dist/HttpApi/Passkey.js +5 -0
  362. package/dist/HttpApi/Passkey.js.map +1 -0
  363. package/dist/HttpApi/Password.d.ts +220 -0
  364. package/dist/HttpApi/Password.d.ts.map +1 -0
  365. package/dist/HttpApi/Password.js +237 -0
  366. package/dist/HttpApi/Password.js.map +1 -0
  367. package/dist/HttpApi/PasswordContract.d.ts +307 -0
  368. package/dist/HttpApi/PasswordContract.d.ts.map +1 -0
  369. package/dist/HttpApi/PasswordContract.js +63 -0
  370. package/dist/HttpApi/PasswordContract.js.map +1 -0
  371. package/dist/HttpApi/PasswordGuards.d.ts +82 -0
  372. package/dist/HttpApi/PasswordGuards.d.ts.map +1 -0
  373. package/dist/HttpApi/PasswordGuards.js +179 -0
  374. package/dist/HttpApi/PasswordGuards.js.map +1 -0
  375. package/dist/HttpApi/RecoveryCodes.d.ts +5 -0
  376. package/dist/HttpApi/RecoveryCodes.d.ts.map +1 -0
  377. package/dist/HttpApi/RecoveryCodes.js +5 -0
  378. package/dist/HttpApi/RecoveryCodes.js.map +1 -0
  379. package/dist/HttpApi/RefreshToken.d.ts +4 -0
  380. package/dist/HttpApi/RefreshToken.d.ts.map +1 -0
  381. package/dist/HttpApi/RefreshToken.js +4 -0
  382. package/dist/HttpApi/RefreshToken.js.map +1 -0
  383. package/dist/HttpApi/RequestGuards.d.ts +42 -0
  384. package/dist/HttpApi/RequestGuards.d.ts.map +1 -0
  385. package/dist/HttpApi/RequestGuards.js +194 -0
  386. package/dist/HttpApi/RequestGuards.js.map +1 -0
  387. package/dist/HttpApi/Schemas.d.ts +399 -84
  388. package/dist/HttpApi/Schemas.d.ts.map +1 -1
  389. package/dist/HttpApi/Schemas.js +225 -27
  390. package/dist/HttpApi/Schemas.js.map +1 -1
  391. package/dist/HttpApi/Security.d.ts +12 -93
  392. package/dist/HttpApi/Security.d.ts.map +1 -1
  393. package/dist/HttpApi/Security.js +65 -356
  394. package/dist/HttpApi/Security.js.map +1 -1
  395. package/dist/HttpApi/SecurityTimeline.d.ts +4 -0
  396. package/dist/HttpApi/SecurityTimeline.d.ts.map +1 -0
  397. package/dist/HttpApi/SecurityTimeline.js +4 -0
  398. package/dist/HttpApi/SecurityTimeline.js.map +1 -0
  399. package/dist/HttpApi/Session.d.ts +5 -0
  400. package/dist/HttpApi/Session.d.ts.map +1 -0
  401. package/dist/HttpApi/Session.js +5 -0
  402. package/dist/HttpApi/Session.js.map +1 -0
  403. package/dist/HttpApi/SessionGuards.d.ts +15 -0
  404. package/dist/HttpApi/SessionGuards.d.ts.map +1 -0
  405. package/dist/HttpApi/SessionGuards.js +37 -0
  406. package/dist/HttpApi/SessionGuards.js.map +1 -0
  407. package/dist/HttpApi/StepUp.d.ts +5 -0
  408. package/dist/HttpApi/StepUp.d.ts.map +1 -0
  409. package/dist/HttpApi/StepUp.js +5 -0
  410. package/dist/HttpApi/StepUp.js.map +1 -0
  411. package/dist/HttpApi/Totp.d.ts +5 -0
  412. package/dist/HttpApi/Totp.d.ts.map +1 -0
  413. package/dist/HttpApi/Totp.js +5 -0
  414. package/dist/HttpApi/Totp.js.map +1 -0
  415. package/dist/HttpApi/Transport.d.ts +4 -6
  416. package/dist/HttpApi/Transport.d.ts.map +1 -1
  417. package/dist/HttpApi/Transport.js +62 -36
  418. package/dist/HttpApi/Transport.js.map +1 -1
  419. package/dist/HttpApi/TrustedDevice.d.ts +4 -0
  420. package/dist/HttpApi/TrustedDevice.d.ts.map +1 -0
  421. package/dist/HttpApi/TrustedDevice.js +4 -0
  422. package/dist/HttpApi/TrustedDevice.js.map +1 -0
  423. package/dist/HttpApi/index.d.ts +11 -3
  424. package/dist/HttpApi/index.d.ts.map +1 -1
  425. package/dist/HttpApi/index.js +10 -2
  426. package/dist/HttpApi/index.js.map +1 -1
  427. package/dist/Identity.d.ts +138 -0
  428. package/dist/Identity.d.ts.map +1 -0
  429. package/dist/Identity.js +105 -0
  430. package/dist/Identity.js.map +1 -0
  431. package/dist/IdentityManagement.d.ts +189 -0
  432. package/dist/IdentityManagement.d.ts.map +1 -0
  433. package/dist/IdentityManagement.js +317 -0
  434. package/dist/IdentityManagement.js.map +1 -0
  435. package/dist/IncidentAction.d.ts +1 -4
  436. package/dist/IncidentAction.d.ts.map +1 -1
  437. package/dist/IncidentAction.js +15 -9
  438. package/dist/IncidentAction.js.map +1 -1
  439. package/dist/Internal.d.ts +2 -0
  440. package/dist/Internal.d.ts.map +1 -1
  441. package/dist/Internal.js +30 -0
  442. package/dist/Internal.js.map +1 -1
  443. package/dist/Invitation.d.ts +362 -0
  444. package/dist/Invitation.d.ts.map +1 -0
  445. package/dist/Invitation.js +633 -0
  446. package/dist/Invitation.js.map +1 -0
  447. package/dist/IpQualityScore.d.ts +38 -0
  448. package/dist/IpQualityScore.d.ts.map +1 -0
  449. package/dist/IpQualityScore.js +215 -0
  450. package/dist/IpQualityScore.js.map +1 -0
  451. package/dist/Jwt.d.ts +8 -29
  452. package/dist/Jwt.d.ts.map +1 -1
  453. package/dist/Jwt.js +67 -56
  454. package/dist/Jwt.js.map +1 -1
  455. package/dist/LoginApproval.d.ts +15 -30
  456. package/dist/LoginApproval.d.ts.map +1 -1
  457. package/dist/LoginApproval.js +47 -41
  458. package/dist/LoginApproval.js.map +1 -1
  459. package/dist/LoginNotification.d.ts +7 -11
  460. package/dist/LoginNotification.d.ts.map +1 -1
  461. package/dist/LoginNotification.js +30 -17
  462. package/dist/LoginNotification.js.map +1 -1
  463. package/dist/LoginRisk.d.ts +11 -13
  464. package/dist/LoginRisk.d.ts.map +1 -1
  465. package/dist/LoginRisk.js +66 -26
  466. package/dist/LoginRisk.js.map +1 -1
  467. package/dist/LoginRiskEnrichment.d.ts +145 -0
  468. package/dist/LoginRiskEnrichment.d.ts.map +1 -0
  469. package/dist/LoginRiskEnrichment.js +220 -0
  470. package/dist/LoginRiskEnrichment.js.map +1 -0
  471. package/dist/MagicLink.d.ts +9 -8
  472. package/dist/MagicLink.d.ts.map +1 -1
  473. package/dist/MagicLink.js +40 -73
  474. package/dist/MagicLink.js.map +1 -1
  475. package/dist/Mailer.d.ts +19 -12
  476. package/dist/Mailer.d.ts.map +1 -1
  477. package/dist/Mailer.js +10 -12
  478. package/dist/Mailer.js.map +1 -1
  479. package/dist/OAuth.d.ts +138 -96
  480. package/dist/OAuth.d.ts.map +1 -1
  481. package/dist/OAuth.js +522 -221
  482. package/dist/OAuth.js.map +1 -1
  483. package/dist/OAuthDeviceAuthorization.d.ts +378 -0
  484. package/dist/OAuthDeviceAuthorization.d.ts.map +1 -0
  485. package/dist/OAuthDeviceAuthorization.js +860 -0
  486. package/dist/OAuthDeviceAuthorization.js.map +1 -0
  487. package/dist/OAuthDeviceClient.d.ts +76 -0
  488. package/dist/OAuthDeviceClient.d.ts.map +1 -0
  489. package/dist/OAuthDeviceClient.js +362 -0
  490. package/dist/OAuthDeviceClient.js.map +1 -0
  491. package/dist/Passkey.d.ts +15 -17
  492. package/dist/Passkey.d.ts.map +1 -1
  493. package/dist/Passkey.js +86 -39
  494. package/dist/Passkey.js.map +1 -1
  495. package/dist/PasskeyBrowser.d.ts +39 -0
  496. package/dist/PasskeyBrowser.d.ts.map +1 -0
  497. package/dist/PasskeyBrowser.js +206 -0
  498. package/dist/PasskeyBrowser.js.map +1 -0
  499. package/dist/PasskeySimpleWebAuthn.d.ts.map +1 -1
  500. package/dist/PasskeySimpleWebAuthn.js +19 -7
  501. package/dist/PasskeySimpleWebAuthn.js.map +1 -1
  502. package/dist/Password.d.ts +71 -37
  503. package/dist/Password.d.ts.map +1 -1
  504. package/dist/Password.js +295 -81
  505. package/dist/Password.js.map +1 -1
  506. package/dist/PasswordRisk.d.ts +63 -0
  507. package/dist/PasswordRisk.d.ts.map +1 -0
  508. package/dist/PasswordRisk.js +37 -0
  509. package/dist/PasswordRisk.js.map +1 -0
  510. package/dist/Permission.d.ts +308 -0
  511. package/dist/Permission.d.ts.map +1 -0
  512. package/dist/Permission.js +827 -0
  513. package/dist/Permission.js.map +1 -0
  514. package/dist/Policy.d.ts +31 -18
  515. package/dist/Policy.d.ts.map +1 -1
  516. package/dist/Policy.js +58 -14
  517. package/dist/Policy.js.map +1 -1
  518. package/dist/PostgresDelegatedAccessStorageMigrations.d.ts +7 -0
  519. package/dist/PostgresDelegatedAccessStorageMigrations.d.ts.map +1 -0
  520. package/dist/PostgresDelegatedAccessStorageMigrations.js +119 -0
  521. package/dist/PostgresDelegatedAccessStorageMigrations.js.map +1 -0
  522. package/dist/PostgresStorageMigrations.d.ts +16 -0
  523. package/dist/PostgresStorageMigrations.d.ts.map +1 -0
  524. package/dist/PostgresStorageMigrations.js +674 -0
  525. package/dist/PostgresStorageMigrations.js.map +1 -0
  526. package/dist/Privacy.d.ts +0 -3
  527. package/dist/Privacy.d.ts.map +1 -1
  528. package/dist/Privacy.js +2 -5
  529. package/dist/Privacy.js.map +1 -1
  530. package/dist/RateLimiter.d.ts +0 -3
  531. package/dist/RateLimiter.d.ts.map +1 -1
  532. package/dist/RateLimiter.js +1 -4
  533. package/dist/RateLimiter.js.map +1 -1
  534. package/dist/RecoveryCode.d.ts +83 -11
  535. package/dist/RecoveryCode.d.ts.map +1 -1
  536. package/dist/RecoveryCode.js +273 -75
  537. package/dist/RecoveryCode.js.map +1 -1
  538. package/dist/RecoveryPolicy.d.ts +81 -0
  539. package/dist/RecoveryPolicy.d.ts.map +1 -0
  540. package/dist/RecoveryPolicy.js +119 -0
  541. package/dist/RecoveryPolicy.js.map +1 -0
  542. package/dist/RefreshToken.d.ts +0 -9
  543. package/dist/RefreshToken.d.ts.map +1 -1
  544. package/dist/RefreshToken.js +31 -22
  545. package/dist/RefreshToken.js.map +1 -1
  546. package/dist/Retention.d.ts +6 -1
  547. package/dist/Retention.d.ts.map +1 -1
  548. package/dist/Retention.js +49 -12
  549. package/dist/Retention.js.map +1 -1
  550. package/dist/SecurityTimeline.d.ts +1 -4
  551. package/dist/SecurityTimeline.d.ts.map +1 -1
  552. package/dist/SecurityTimeline.js +110 -17
  553. package/dist/SecurityTimeline.js.map +1 -1
  554. package/dist/Sessions.d.ts +124 -29
  555. package/dist/Sessions.d.ts.map +1 -1
  556. package/dist/Sessions.js +626 -94
  557. package/dist/Sessions.js.map +1 -1
  558. package/dist/SqliteStorageSchemaData.d.ts +2 -0
  559. package/dist/SqliteStorageSchemaData.d.ts.map +1 -0
  560. package/dist/SqliteStorageSchemaData.js +508 -0
  561. package/dist/SqliteStorageSchemaData.js.map +1 -0
  562. package/dist/StepUp.d.ts +132 -11
  563. package/dist/StepUp.d.ts.map +1 -1
  564. package/dist/StepUp.js +387 -19
  565. package/dist/StepUp.js.map +1 -1
  566. package/dist/Storage.d.ts +89 -23
  567. package/dist/Storage.d.ts.map +1 -1
  568. package/dist/Storage.js +10 -12
  569. package/dist/Storage.js.map +1 -1
  570. package/dist/StorageMigrations.d.ts +7 -1
  571. package/dist/StorageMigrations.d.ts.map +1 -1
  572. package/dist/StorageMigrations.js +256 -0
  573. package/dist/StorageMigrations.js.map +1 -1
  574. package/dist/StorageSchemaGenerator.d.ts +544 -0
  575. package/dist/StorageSchemaGenerator.d.ts.map +1 -0
  576. package/dist/StorageSchemaGenerator.js +1418 -0
  577. package/dist/StorageSchemaGenerator.js.map +1 -0
  578. package/dist/StrongFactor.d.ts +64 -0
  579. package/dist/StrongFactor.d.ts.map +1 -0
  580. package/dist/StrongFactor.js +100 -0
  581. package/dist/StrongFactor.js.map +1 -0
  582. package/dist/Testing.js +2 -2
  583. package/dist/Testing.js.map +1 -1
  584. package/dist/Totp.d.ts +88 -13
  585. package/dist/Totp.d.ts.map +1 -1
  586. package/dist/Totp.js +192 -34
  587. package/dist/Totp.js.map +1 -1
  588. package/dist/TrustedDevice.d.ts +0 -9
  589. package/dist/TrustedDevice.d.ts.map +1 -1
  590. package/dist/TrustedDevice.js +15 -17
  591. package/dist/TrustedDevice.js.map +1 -1
  592. package/dist/WaitUntil.d.ts +0 -3
  593. package/dist/WaitUntil.d.ts.map +1 -1
  594. package/dist/WaitUntil.js +1 -4
  595. package/dist/WaitUntil.js.map +1 -1
  596. package/dist/Webhook.d.ts +42 -12
  597. package/dist/Webhook.d.ts.map +1 -1
  598. package/dist/Webhook.js +165 -26
  599. package/dist/Webhook.js.map +1 -1
  600. package/dist/alchemy/cloudflare/Email.d.ts.map +1 -1
  601. package/dist/alchemy/cloudflare/Email.js +9 -4
  602. package/dist/alchemy/cloudflare/Email.js.map +1 -1
  603. package/dist/cloudflare/Email.js +1 -1
  604. package/dist/cloudflare/Email.js.map +1 -1
  605. package/dist/cloudflare/RequestMetadata.d.ts +49 -0
  606. package/dist/cloudflare/RequestMetadata.d.ts.map +1 -0
  607. package/dist/cloudflare/RequestMetadata.js +71 -0
  608. package/dist/cloudflare/RequestMetadata.js.map +1 -0
  609. package/dist/index.d.ts +0 -35
  610. package/dist/index.d.ts.map +1 -1
  611. package/dist/index.js +0 -35
  612. package/dist/index.js.map +1 -1
  613. package/dist/internal/AuthFlowFinalizer.d.ts +31 -0
  614. package/dist/internal/AuthFlowFinalizer.d.ts.map +1 -0
  615. package/dist/internal/AuthFlowFinalizer.js +182 -0
  616. package/dist/internal/AuthFlowFinalizer.js.map +1 -0
  617. package/migrations/0001_auth_storage.sql +1 -0
  618. package/migrations/0006_auth_totp_factor.sql +1 -0
  619. package/migrations/0024_auth_permission.sql +39 -0
  620. package/migrations/0025_auth_permission_definition.sql +19 -0
  621. package/migrations/0026_auth_user_identity.sql +59 -0
  622. package/migrations/0027_auth_audit_log_storage_order.sql +46 -0
  623. package/migrations/0028_auth_oauth_client_secret_key.sql +39 -0
  624. package/migrations/0029_auth_oauth_device_authorization.sql +28 -0
  625. package/migrations/delegated-access/0001_auth_delegated_access.sql +152 -0
  626. package/migrations/postgres/0001_auth_core.sql +77 -0
  627. package/migrations/postgres/0002_auth_security_oauth.sql +65 -0
  628. package/migrations/postgres/0003_auth_credentials_tokens.sql +43 -0
  629. package/migrations/postgres/0004_auth_security_history.sql +103 -0
  630. package/migrations/postgres/0005_auth_webhooks.sql +29 -0
  631. package/migrations/postgres/0006_auth_domain_timeline.sql +50 -0
  632. package/migrations/postgres/0007_auth_oauth_clients.sql +85 -0
  633. package/migrations/postgres/0008_auth_oauth_tokens.sql +63 -0
  634. package/migrations/postgres/0009_auth_permissions.sql +66 -0
  635. package/migrations/postgres/0010_auth_oauth_device_authorization.sql +50 -0
  636. package/migrations/postgres/delegated-access/0001_auth_delegated_access.sql +112 -0
  637. package/package.json +309 -2
package/dist/AuthFlow.js CHANGED
@@ -1,21 +1,24 @@
1
1
  // oxlint-disable complexity
2
2
  import { Context, Data, Duration, Effect, Layer, Option, Redacted, } from "effect";
3
+ import { parseAuthenticationEvents } from "./Assurance.js";
3
4
  import { AuthEmailVerificationSessionPolicyConfig } from "./AuthConfig.js";
4
5
  import { Challenge } from "./Challenge.js";
5
6
  import { Crypto } from "./Crypto.js";
6
- import { AuthFlowId, ChallengeId, Email, UserId } from "./Identifiers.js";
7
+ import { AuthFlowId, ChallengeId, UnixMillis, UserId } from "./Identifiers.js";
7
8
  import { currentUnixMillis } from "./Internal.js";
9
+ import { AuthFlowFinalizer, AuthFlowFinalizerLive, makeAuthFlowTerminal, } from "./internal/AuthFlowFinalizer.js";
8
10
  import { LoginApprovalFlow, LoginApprovalPolicy, LoginApprovalReview, makeLoginApprovalPolicy, unknownLoginDeviceContext, } from "./LoginApproval.js";
9
11
  import { LoginNotification } from "./LoginNotification.js";
10
12
  import { LoginRiskEngine, defaultLoginRiskContext, makeLoginRiskEngineNoop, } from "./LoginRisk.js";
13
+ import { PasskeyCredentialManagement } from "./Passkey.js";
14
+ import { RecoveryCodeManagement } from "./RecoveryCode.js";
15
+ import { RecoveryRequirementPolicy } from "./RecoveryPolicy.js";
11
16
  import { Sessions, sessionRequestMetadataKey } from "./Sessions.js";
17
+ import { TotpFactorManagement } from "./Totp.js";
12
18
  import { TrustedDevice } from "./TrustedDevice.js";
13
19
  export const defaultLoginApprovalSameDeviceSecretBytes = 32;
14
20
  export class EmailVerificationSessionPolicy extends Context.Service()("auth/EmailVerificationSessionPolicy") {
15
21
  }
16
- (function (EmailVerificationSessionPolicy) {
17
- EmailVerificationSessionPolicy.make = (service) => EmailVerificationSessionPolicy.of(service);
18
- })(EmailVerificationSessionPolicy || (EmailVerificationSessionPolicy = {}));
19
22
  const addEmailVerificationRequirement = (requirements) => requirements?.includes("email_verification") === true
20
23
  ? requirements
21
24
  : [...(requirements ?? []), "email_verification"];
@@ -23,40 +26,40 @@ const removeEmailVerificationRequirement = (requirements) => {
23
26
  const filtered = requirements?.filter((requirement) => requirement !== "email_verification");
24
27
  return filtered?.length === 0 ? undefined : filtered;
25
28
  };
26
- const withEmailVerified = (claims, emailVerified) => {
29
+ const withVerifiedIdentityKind = (claims, kind) => {
27
30
  const { requirements: _requirements, ...rest } = claims ?? {};
28
- const requirements = emailVerified
31
+ const requirements = kind === "email"
29
32
  ? removeEmailVerificationRequirement(claims?.requirements)
30
33
  : claims?.requirements;
34
+ const verifiedIdentityKinds = claims?.verifiedIdentityKinds?.includes(kind)
35
+ ? claims.verifiedIdentityKinds
36
+ : [...(claims?.verifiedIdentityKinds ?? []), kind];
31
37
  return {
32
38
  ...rest,
33
- emailVerified,
39
+ verifiedIdentityKinds,
34
40
  ...(requirements === undefined ? {} : { requirements }),
35
41
  };
36
42
  };
37
43
  const withEmailVerificationRequirement = (claims) => ({
38
44
  ...claims,
39
- emailVerified: false,
40
45
  requirements: addEmailVerificationRequirement(claims?.requirements),
41
46
  });
42
47
  export const makeEmailVerificationSessionPolicy = (options = {}) => {
43
48
  const mode = options.mode ?? "allow-unverified";
44
- return EmailVerificationSessionPolicy.make({
49
+ return EmailVerificationSessionPolicy.of({
45
50
  decide: Effect.fn("auth.email_verification_session_policy.decide")(function* (input) {
46
- const emailVerified = input.claims?.emailVerified;
47
- if (emailVerified !== false) {
51
+ const emailVerified = input.claims?.verifiedIdentityKinds?.includes("email");
52
+ if (emailVerified === true) {
48
53
  return {
49
54
  _tag: "CreateSession",
50
- claims: emailVerified === true
51
- ? withEmailVerified(input.claims, true)
52
- : input.claims,
55
+ claims: withVerifiedIdentityKind(input.claims, "email"),
53
56
  };
54
57
  }
55
58
  switch (mode) {
56
59
  case "allow-unverified": {
57
60
  return {
58
61
  _tag: "CreateSession",
59
- claims: withEmailVerified(input.claims, false),
62
+ claims: input.claims,
60
63
  };
61
64
  }
62
65
  case "limited-session": {
@@ -70,35 +73,119 @@ export const makeEmailVerificationSessionPolicy = (options = {}) => {
70
73
  });
71
74
  };
72
75
  export const EmailVerificationSessionPolicyLive = (options) => Layer.succeed(EmailVerificationSessionPolicy)(makeEmailVerificationSessionPolicy(options));
76
+ export class MfaRequirementPolicy extends Context.Service()("auth/MfaRequirementPolicy") {
77
+ }
78
+ export const defaultMfaRequirementMethods = [
79
+ "password",
80
+ "email-otp",
81
+ "magic-link",
82
+ "oauth",
83
+ ];
84
+ export const makeMfaRequirementPolicy = (options = {}) => {
85
+ const mode = options.mode ?? "when-factors-present";
86
+ const methods = new Set(options.methods ?? defaultMfaRequirementMethods);
87
+ return MfaRequirementPolicy.of({
88
+ decide: Effect.fn("auth.mfa_requirement_policy.decide")(function* (input) {
89
+ if (mode === "disabled" ||
90
+ input.intent === "sign-up" ||
91
+ !methods.has(input.method) ||
92
+ input.factors.length === 0) {
93
+ return { _tag: "Continue" };
94
+ }
95
+ return {
96
+ _tag: "RequireMfa",
97
+ factors: input.factors,
98
+ };
99
+ }),
100
+ });
101
+ };
102
+ export const MfaRequirementPolicyLive = (options) => Layer.succeed(MfaRequirementPolicy)(makeMfaRequirementPolicy(options));
103
+ export class AuthFlowPipeline extends Context.Service()("auth/AuthFlowPipeline") {
104
+ }
105
+ (function (AuthFlowPipeline) {
106
+ AuthFlowPipeline.continueWith = () => ({
107
+ _tag: "Continue",
108
+ });
109
+ AuthFlowPipeline.deny = (reason) => ({
110
+ _tag: "PolicyDenied",
111
+ ...(reason === undefined ? {} : { reason }),
112
+ });
113
+ })(AuthFlowPipeline || (AuthFlowPipeline = {}));
114
+ export const makeAuthFlowPipeline = (stages = []) => AuthFlowPipeline.of({
115
+ advance: (initial) => Effect.gen(function* () {
116
+ for (const stage of stages) {
117
+ if (stage.phases !== undefined &&
118
+ !stage.phases.includes(initial.phase)) {
119
+ continue;
120
+ }
121
+ const decision = yield* stage.run(initial);
122
+ if (decision._tag === "PolicyDenied") {
123
+ return decision;
124
+ }
125
+ }
126
+ return AuthFlowPipeline.continueWith();
127
+ }),
128
+ });
129
+ export const AuthFlowPipelineLive = (stages = []) => Layer.succeed(AuthFlowPipeline)(makeAuthFlowPipeline(stages));
73
130
  export const AuthResult = Data.taggedEnum();
74
131
  export class AuthFlowStateError extends Data.TaggedError("AuthFlowStateError") {
75
132
  }
76
133
  export class AuthFlowState extends Context.Service()("auth/AuthFlowState") {
77
134
  }
78
- (function (AuthFlowState) {
79
- AuthFlowState.make = (service) => AuthFlowState.of(service);
80
- })(AuthFlowState || (AuthFlowState = {}));
81
135
  export const defaultAuthFlowStateTtl = Duration.minutes(10);
82
- const flowStateMetadata = (input) => ({
83
- ...input.metadata,
84
- method: input.method,
85
- amr: input.amr,
86
- aal: input.aal,
87
- ...(input.email === undefined ? {} : { email: input.email }),
88
- ...(input.intent === undefined ? {} : { intent: input.intent }),
89
- ...(input.device === undefined ? {} : { deviceStatus: input.device.status }),
90
- ...(input.claims === undefined ? {} : { claims: input.claims }),
91
- });
136
+ const mfaFactorsMetadataKey = "__authMfaFactors";
137
+ const applicationFlowStateMetadata = (metadata) => {
138
+ if (metadata === undefined) {
139
+ return undefined;
140
+ }
141
+ const { method: _method, evidence: _evidence, identity: _identity, emailDestination: _emailDestination, intent: _intent, deviceStatus: _deviceStatus, deviceKey: _deviceKey, locationKey: _locationKey, claims: _claims, [sessionRequestMetadataKey]: _request, [mfaFactorsMetadataKey]: _mfaFactors, ...rest } = metadata;
142
+ return Object.keys(rest).length === 0 ? undefined : rest;
143
+ };
144
+ const flowStateMetadata = (input) => {
145
+ const metadata = applicationFlowStateMetadata(input.metadata);
146
+ return {
147
+ ...metadata,
148
+ ...(input.request === undefined
149
+ ? {}
150
+ : { [sessionRequestMetadataKey]: input.request }),
151
+ method: input.method,
152
+ evidence: input.evidence,
153
+ ...(input.identity === undefined ? {} : { identity: input.identity }),
154
+ ...(input.emailDestination === undefined
155
+ ? {}
156
+ : { emailDestination: input.emailDestination }),
157
+ ...(input.intent === undefined ? {} : { intent: input.intent }),
158
+ ...(input.device === undefined
159
+ ? {}
160
+ : { deviceStatus: input.device.status }),
161
+ ...(input.deviceKey === undefined ? {} : { deviceKey: input.deviceKey }),
162
+ ...(input.locationKey === undefined
163
+ ? {}
164
+ : { locationKey: input.locationKey }),
165
+ ...(input.claims === undefined ? {} : { claims: input.claims }),
166
+ ...(input.factors === undefined
167
+ ? {}
168
+ : { [mfaFactorsMetadataKey]: input.factors }),
169
+ };
170
+ };
92
171
  const metadataString = (metadata, key) => {
93
172
  const value = metadata?.[key];
94
173
  return typeof value === "string" && value.length > 0 ? value : undefined;
95
174
  };
96
- const metadataStringArray = (metadata, key) => {
97
- const value = metadata?.[key];
98
- return Array.isArray(value) && value.every((item) => typeof item === "string")
175
+ const loginRequestContextFromMetadata = (metadata) => {
176
+ const value = metadata?.[sessionRequestMetadataKey];
177
+ return typeof value === "object" && value !== null && !Array.isArray(value)
99
178
  ? value
100
179
  : undefined;
101
180
  };
181
+ const metadataEvidence = (metadata) => {
182
+ try {
183
+ return parseAuthenticationEvents(metadata?.evidence);
184
+ }
185
+ catch {
186
+ return undefined;
187
+ }
188
+ };
102
189
  const metadataClaims = (metadata) => {
103
190
  const value = metadata?.claims;
104
191
  if (value === undefined) {
@@ -109,8 +196,18 @@ const metadataClaims = (metadata) => {
109
196
  }
110
197
  const shape = value;
111
198
  const { requirements } = shape;
112
- if (shape.emailVerified !== undefined &&
113
- typeof shape.emailVerified !== "boolean") {
199
+ if (shape.verifiedIdentityKinds !== undefined &&
200
+ (!Array.isArray(shape.verifiedIdentityKinds) ||
201
+ !shape.verifiedIdentityKinds.every((item) => typeof item === "string"))) {
202
+ return undefined;
203
+ }
204
+ const recoveryEnrollment = shape.recoveryEnrollment;
205
+ if (recoveryEnrollment !== undefined &&
206
+ (typeof recoveryEnrollment !== "object" ||
207
+ recoveryEnrollment === null ||
208
+ !Array.isArray(recoveryEnrollment.allowed) ||
209
+ recoveryEnrollment.allowed.length === 0 ||
210
+ !recoveryEnrollment.allowed.every((item) => typeof item === "string"))) {
114
211
  return undefined;
115
212
  }
116
213
  if (requirements !== undefined &&
@@ -119,16 +216,49 @@ const metadataClaims = (metadata) => {
119
216
  return undefined;
120
217
  }
121
218
  return {
122
- ...(shape.emailVerified === undefined
219
+ ...(shape.verifiedIdentityKinds === undefined
123
220
  ? {}
124
- : { emailVerified: shape.emailVerified }),
221
+ : {
222
+ verifiedIdentityKinds: shape.verifiedIdentityKinds,
223
+ }),
125
224
  ...(requirements === undefined ? {} : { requirements }),
225
+ ...(recoveryEnrollment === undefined
226
+ ? {}
227
+ : {
228
+ recoveryEnrollment: {
229
+ allowed: recoveryEnrollment.allowed,
230
+ },
231
+ }),
126
232
  };
127
233
  };
128
- const metadataAal = (metadata) => {
129
- const value = metadataString(metadata, "aal");
130
- return value === "aal1" || value === "aal2" || value === "aal3"
131
- ? value
234
+ const metadataIdentity = (metadata) => {
235
+ const value = metadata?.identity;
236
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
237
+ return undefined;
238
+ }
239
+ const identity = value;
240
+ return typeof identity.identityId === "string" &&
241
+ typeof identity.kind === "string" &&
242
+ typeof identity.verified === "boolean"
243
+ ? {
244
+ identityId: identity.identityId,
245
+ kind: identity.kind,
246
+ verified: identity.verified,
247
+ }
248
+ : undefined;
249
+ };
250
+ const metadataEmailDestination = (metadata) => {
251
+ const value = metadata?.emailDestination;
252
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
253
+ return undefined;
254
+ }
255
+ const destination = value;
256
+ return typeof destination.identityId === "string" &&
257
+ typeof destination.email === "string"
258
+ ? {
259
+ identityId: destination.identityId,
260
+ email: destination.email,
261
+ }
132
262
  : undefined;
133
263
  };
134
264
  const metadataIntent = (metadata) => {
@@ -141,34 +271,45 @@ const metadataDevice = (metadata) => {
141
271
  ? { status: value }
142
272
  : undefined;
143
273
  };
144
- const appMetadata = (metadata) => {
145
- if (metadata === undefined) {
146
- return undefined;
147
- }
148
- const { method: _method, amr: _amr, aal: _aal, email: _email, intent: _intent, deviceStatus: _deviceStatus, claims: _claims, ...rest } = metadata;
149
- return Object.keys(rest).length === 0 ? undefined : rest;
150
- };
274
+ const metadataKey = (metadata, key) => metadataString(metadata, key);
275
+ const appMetadata = applicationFlowStateMetadata;
151
276
  const authFlowStateFromChallenge = (flowId, verified) => Effect.gen(function* () {
152
277
  const method = metadataString(verified.metadata, "method");
153
- const amr = metadataStringArray(verified.metadata, "amr");
154
- const aal = metadataAal(verified.metadata);
155
- const email = metadataString(verified.metadata, "email");
278
+ const evidence = metadataEvidence(verified.metadata);
279
+ const identity = metadataIdentity(verified.metadata);
280
+ const emailDestination = metadataEmailDestination(verified.metadata);
156
281
  const intent = metadataIntent(verified.metadata);
157
282
  const device = metadataDevice(verified.metadata);
283
+ const deviceKey = metadataKey(verified.metadata, "deviceKey");
284
+ const locationKey = metadataKey(verified.metadata, "locationKey");
158
285
  const claims = metadataClaims(verified.metadata);
286
+ const request = loginRequestContextFromMetadata(verified.metadata);
287
+ const rawFactors = verified.metadata?.[mfaFactorsMetadataKey];
288
+ let factors;
289
+ if (rawFactors !== undefined) {
290
+ if (!Array.isArray(rawFactors) ||
291
+ rawFactors.length === 0 ||
292
+ !rawFactors.every((factor) => typeof factor === "object" &&
293
+ factor !== null &&
294
+ !Array.isArray(factor) &&
295
+ typeof factor.type === "string" &&
296
+ factor.type.length > 0)) {
297
+ return yield* new AuthFlowStateError({
298
+ message: "Auth flow state has invalid MFA factor metadata",
299
+ });
300
+ }
301
+ factors = rawFactors.map((factor) => ({
302
+ type: factor.type,
303
+ }));
304
+ }
159
305
  if (method === undefined) {
160
306
  return yield* new AuthFlowStateError({
161
307
  message: "Auth flow state is missing method metadata",
162
308
  });
163
309
  }
164
- if (amr === undefined) {
165
- return yield* new AuthFlowStateError({
166
- message: "Auth flow state is missing AMR metadata",
167
- });
168
- }
169
- if (aal === undefined) {
310
+ if (evidence === undefined) {
170
311
  return yield* new AuthFlowStateError({
171
- message: "Auth flow state is missing AAL metadata",
312
+ message: "Auth flow state has invalid evidence metadata",
172
313
  });
173
314
  }
174
315
  if (verified.metadata?.claims !== undefined && claims === undefined) {
@@ -179,19 +320,23 @@ const authFlowStateFromChallenge = (flowId, verified) => Effect.gen(function* ()
179
320
  return {
180
321
  flowId,
181
322
  userId: UserId(verified.subject),
182
- ...(email === undefined ? {} : { email: Email(email) }),
323
+ ...(identity === undefined ? {} : { identity }),
324
+ ...(emailDestination === undefined ? {} : { emailDestination }),
183
325
  ...(intent === undefined ? {} : { intent }),
184
326
  method,
185
- amr,
186
- aal,
327
+ evidence,
187
328
  ...(device === undefined ? {} : { device }),
329
+ ...(deviceKey === undefined ? {} : { deviceKey }),
330
+ ...(locationKey === undefined ? {} : { locationKey }),
188
331
  ...(claims === undefined ? {} : { claims }),
332
+ ...(request === undefined ? {} : { request }),
333
+ ...(factors === undefined ? {} : { factors }),
189
334
  metadata: appMetadata(verified.metadata),
190
335
  };
191
336
  });
192
337
  export const makeAuthFlowState = (dependencies) => {
193
338
  const ttl = dependencies.ttl ?? defaultAuthFlowStateTtl;
194
- return AuthFlowState.make({
339
+ return AuthFlowState.of({
195
340
  start: Effect.fn("auth.auth_flow_state.start")(function* (input) {
196
341
  const issued = yield* dependencies.challenge
197
342
  .issue({
@@ -252,16 +397,10 @@ export const AuthFlowStateLive = (options) => Layer.effect(AuthFlowState)(Effect
252
397
  }));
253
398
  export class AuthFlow extends Context.Service()("auth/AuthFlow") {
254
399
  }
255
- (function (AuthFlow) {
256
- AuthFlow.make = (service) => AuthFlow.of(service);
257
- })(AuthFlow || (AuthFlow = {}));
258
400
  export class LoginApprovalFinalize extends Context.Service()("auth/LoginApprovalFinalize") {
259
401
  }
260
- (function (LoginApprovalFinalize) {
261
- LoginApprovalFinalize.make = (service) => LoginApprovalFinalize.of(service);
262
- })(LoginApprovalFinalize || (LoginApprovalFinalize = {}));
263
402
  const loginApprovalFinalizeDenied = (reason) => AuthResult.PolicyDenied({ reason });
264
- export const makeLoginApprovalFinalize = (dependencies) => LoginApprovalFinalize.make({
403
+ export const makeLoginApprovalFinalize = (dependencies) => LoginApprovalFinalize.of({
265
404
  complete: Effect.fn("auth.login_approval_finalize.complete")(function* (input) {
266
405
  const recordOption = yield* dependencies.loginApprovalReview.status({
267
406
  approvalChallengeId: input.approvalChallengeId,
@@ -287,19 +426,19 @@ export const makeLoginApprovalFinalize = (dependencies) => LoginApprovalFinalize
287
426
  if (consumed.userId !== record.userId) {
288
427
  return loginApprovalFinalizeDenied("Invalid login approval review");
289
428
  }
290
- return yield* dependencies.authFlow.complete(consumed);
429
+ return yield* dependencies.finalizeAuthFlow(consumed);
291
430
  }),
292
431
  });
293
- export const LoginApprovalFinalizeLive = Layer.effect(LoginApprovalFinalize)(Effect.gen(function* () {
432
+ export const LoginApprovalFinalizeLive = Layer.effect(LoginApprovalFinalize, Effect.gen(function* () {
294
433
  const loginApprovalReview = yield* LoginApprovalReview;
295
434
  const authFlowState = yield* AuthFlowState;
296
- const authFlow = yield* AuthFlow;
435
+ const authFlowFinalizer = yield* AuthFlowFinalizer;
297
436
  return makeLoginApprovalFinalize({
298
437
  loginApprovalReview,
299
438
  authFlowState,
300
- authFlow,
439
+ finalizeAuthFlow: authFlowFinalizer.complete,
301
440
  });
302
- }));
441
+ })).pipe(Layer.provide(AuthFlowFinalizerLive));
303
442
  const loginApprovalFlowIdMetadata = (flowId, metadata) => ({
304
443
  ...metadata,
305
444
  flowId,
@@ -319,61 +458,15 @@ const mergeMetadata = (left, right) => {
319
458
  }
320
459
  return { ...left, ...right };
321
460
  };
322
- const aalRank = {
323
- aal1: 1,
324
- aal2: 2,
325
- aal3: 3,
326
- };
327
- const strongerAal = (left, right) => (aalRank[left] >= aalRank[right] ? left : right);
328
- const authMethodReference = (method) => {
329
- switch (method) {
330
- case "password": {
331
- return "pwd";
332
- }
333
- case "email-otp": {
334
- return "otp";
335
- }
336
- case "magic-link": {
337
- return "magic_link";
338
- }
339
- case "backup-code": {
340
- return "backup_code";
341
- }
342
- default: {
343
- return method;
344
- }
345
- }
346
- };
347
- const appendAuthMethods = (current, methods) => {
348
- const next = [...current];
349
- for (const method of methods) {
350
- if (!next.includes(method)) {
351
- next.push(method);
352
- }
353
- }
354
- return next;
355
- };
356
- const loginNotificationSession = (session) => ({
357
- sessionId: session.sessionId,
358
- userId: session.userId,
359
- authTime: session.authTime,
360
- expiresAt: session.expiresAt,
361
- aal: session.aal,
362
- amr: session.amr,
363
- ...(session.claims === undefined ? {} : { claims: session.claims }),
364
- });
365
- const loginRequestContextFromMetadata = (metadata) => {
366
- const value = metadata?.[sessionRequestMetadataKey];
367
- return typeof value === "object" && value !== null && !Array.isArray(value)
368
- ? value
369
- : undefined;
370
- };
371
461
  const loginApprovalNotConfigured = () => AuthResult.PolicyDenied({
372
462
  reason: "Login approval is not configured",
373
463
  });
374
464
  const loginApprovalEmailMissing = () => AuthResult.PolicyDenied({
375
465
  reason: "Login approval requires an email address",
376
466
  });
467
+ const loginApprovalIdentityNotBound = () => AuthResult.PolicyDenied({
468
+ reason: "Login approval identity verification is not bound to an email identity",
469
+ });
377
470
  const loginApprovalSameDeviceNotConfigured = () => AuthResult.PolicyDenied({
378
471
  reason: "Login approval same-device binding is not configured",
379
472
  });
@@ -386,7 +479,39 @@ const mfaFlowStateNotConfigured = () => AuthResult.PolicyDenied({
386
479
  const mfaFlowUserMismatch = () => AuthResult.PolicyDenied({
387
480
  reason: "MFA flow user mismatch",
388
481
  });
482
+ const mfaFlowFactorNotAllowed = () => AuthResult.PolicyDenied({
483
+ reason: "MFA factor is not allowed for this flow",
484
+ });
485
+ const completedMfaFactorType = (input) => {
486
+ if (input.method === "totp") {
487
+ return input.evidence.type === "totp" ? "totp" : undefined;
488
+ }
489
+ if (input.method === "backup-code") {
490
+ return input.evidence.type === "recovery_code" ? "backup-code" : undefined;
491
+ }
492
+ if (input.method === "passkey") {
493
+ return input.evidence.type === "passkey" &&
494
+ input.evidence.userVerification === "verified"
495
+ ? "passkey"
496
+ : undefined;
497
+ }
498
+ return undefined;
499
+ };
500
+ const authFlowStateAllowsMfa = (state, input) => {
501
+ const factorType = completedMfaFactorType(input);
502
+ return (factorType !== undefined &&
503
+ state.factors?.some((factor) => factor.type === factorType) === true);
504
+ };
505
+ const primaryFactorNotEstablished = () => AuthResult.PolicyDenied({
506
+ reason: "Authentication evidence did not establish a primary factor",
507
+ });
389
508
  const optionalLoginApprovalDependencies = Effect.gen(function* () {
509
+ const pipeline = yield* Effect.serviceOption(AuthFlowPipeline);
510
+ const emailVerificationSessionPolicy = yield* Effect.serviceOption(EmailVerificationSessionPolicy);
511
+ const mfaRequirementPolicy = yield* Effect.serviceOption(MfaRequirementPolicy);
512
+ const totpFactorManagement = yield* Effect.serviceOption(TotpFactorManagement);
513
+ const recoveryCodeManagement = yield* Effect.serviceOption(RecoveryCodeManagement);
514
+ const passkeyCredentialManagement = yield* Effect.serviceOption(PasskeyCredentialManagement);
390
515
  const loginApprovalPolicy = yield* Effect.serviceOption(LoginApprovalPolicy);
391
516
  const loginApprovalFlow = yield* Effect.serviceOption(LoginApprovalFlow);
392
517
  const authFlowState = yield* Effect.serviceOption(AuthFlowState);
@@ -395,7 +520,24 @@ const optionalLoginApprovalDependencies = Effect.gen(function* () {
395
520
  const loginRiskEngine = yield* Effect.serviceOption(LoginRiskEngine);
396
521
  const loginApprovalReview = yield* Effect.serviceOption(LoginApprovalReview);
397
522
  const loginNotification = yield* Effect.serviceOption(LoginNotification);
523
+ const recoveryRequirementPolicy = yield* Effect.serviceOption(RecoveryRequirementPolicy);
398
524
  return {
525
+ ...(Option.isSome(pipeline) ? { pipeline: pipeline.value } : {}),
526
+ ...(Option.isSome(emailVerificationSessionPolicy)
527
+ ? { emailVerificationSessionPolicy: emailVerificationSessionPolicy.value }
528
+ : {}),
529
+ ...(Option.isSome(mfaRequirementPolicy)
530
+ ? { mfaRequirementPolicy: mfaRequirementPolicy.value }
531
+ : {}),
532
+ ...(Option.isSome(totpFactorManagement)
533
+ ? { totpFactorManagement: totpFactorManagement.value }
534
+ : {}),
535
+ ...(Option.isSome(recoveryCodeManagement)
536
+ ? { recoveryCodeManagement: recoveryCodeManagement.value }
537
+ : {}),
538
+ ...(Option.isSome(passkeyCredentialManagement)
539
+ ? { passkeyCredentialManagement: passkeyCredentialManagement.value }
540
+ : {}),
399
541
  ...(Option.isSome(loginApprovalPolicy)
400
542
  ? { loginApprovalPolicy: loginApprovalPolicy.value }
401
543
  : {}),
@@ -418,15 +560,22 @@ const optionalLoginApprovalDependencies = Effect.gen(function* () {
418
560
  ...(Option.isSome(loginNotification)
419
561
  ? { loginNotification: loginNotification.value }
420
562
  : {}),
563
+ ...(Option.isSome(recoveryRequirementPolicy)
564
+ ? { recoveryRequirementPolicy: recoveryRequirementPolicy.value }
565
+ : {}),
421
566
  };
422
567
  });
423
568
  export const makeAuthFlow = (dependencies) => {
424
569
  const emailVerificationSessionPolicy = dependencies.emailVerificationSessionPolicy ??
425
570
  makeEmailVerificationSessionPolicy();
571
+ const mfaRequirementPolicy = dependencies.mfaRequirementPolicy ?? makeMfaRequirementPolicy();
426
572
  const loginApprovalPolicy = dependencies.loginApprovalPolicy ?? makeLoginApprovalPolicy();
427
573
  const loginRiskEngine = dependencies.loginRiskEngine ?? makeLoginRiskEngineNoop();
574
+ const pipeline = dependencies.pipeline ?? makeAuthFlowPipeline();
428
575
  const loginApprovalSameDeviceSecretBytes = dependencies.loginApprovalSameDeviceSecretBytes ??
429
576
  defaultLoginApprovalSameDeviceSecretBytes;
577
+ const flowTerminal = makeAuthFlowTerminal(dependencies);
578
+ const deriveFlowInput = flowTerminal.derive;
430
579
  const resolveDevice = (input) => {
431
580
  if (input.device !== undefined) {
432
581
  return Effect.succeed(input.device);
@@ -439,79 +588,223 @@ export const makeAuthFlow = (dependencies) => {
439
588
  token: input.trustedDeviceToken,
440
589
  });
441
590
  };
442
- const notifyLogin = (input, session) => dependencies.loginNotification === undefined
443
- ? Effect.void
444
- : dependencies.loginNotification
445
- .notify({
446
- userId: input.userId,
447
- ...(input.email === undefined ? {} : { email: input.email }),
448
- ...(input.intent === undefined ? {} : { intent: input.intent }),
449
- method: input.method,
450
- amr: input.amr,
451
- aal: input.aal,
452
- session: loginNotificationSession(session),
453
- device: input.device ?? unknownLoginDeviceContext,
454
- risk: input.risk ?? defaultLoginRiskContext,
455
- request: input.request ?? loginRequestContextFromMetadata(input.metadata),
456
- ...(input.metadata === undefined ? {} : { metadata: input.metadata }),
457
- })
458
- .pipe(Effect.catchCause(() => Effect.void));
459
- const complete = Effect.fn("auth.auth_flow.complete")(function* (input) {
460
- yield* Effect.annotateCurrentSpan({
461
- "auth.method": input.method,
462
- "auth.aal": input.aal,
463
- "auth.amr_count": input.amr.length,
591
+ const detectMfaFactors = (input) => Effect.gen(function* () {
592
+ const factors = [];
593
+ if (dependencies.totpFactorManagement !== undefined &&
594
+ !input.amr.includes("totp")) {
595
+ const totpFactors = yield* dependencies.totpFactorManagement.listForUser({
596
+ userId: input.userId,
597
+ });
598
+ if (totpFactors.length > 0) {
599
+ factors.push({ type: "totp" });
600
+ }
601
+ }
602
+ if (dependencies.recoveryCodeManagement !== undefined &&
603
+ !input.amr.includes("recovery_code")) {
604
+ const recoveryCodes = yield* dependencies.recoveryCodeManagement.listForUser({
605
+ userId: input.userId,
606
+ });
607
+ if (recoveryCodes.length > 0) {
608
+ factors.push({ type: "backup-code" });
609
+ }
610
+ }
611
+ if (dependencies.passkeyCredentialManagement !== undefined &&
612
+ !input.amr.includes("passkey")) {
613
+ const credentials = yield* dependencies.passkeyCredentialManagement.listForUser({
614
+ userId: input.userId,
615
+ });
616
+ if (credentials.length > 0) {
617
+ factors.push({ type: "passkey" });
618
+ }
619
+ }
620
+ return factors;
621
+ });
622
+ const requireMfaIfNeeded = (input) => Effect.gen(function* () {
623
+ const factors = yield* detectMfaFactors(input);
624
+ const decision = yield* mfaRequirementPolicy.decide({
625
+ ...input,
626
+ factors,
464
627
  });
465
- const session = yield* dependencies.sessions.create({
466
- userId: input.userId,
467
- method: input.method,
468
- amr: input.amr,
469
- aal: input.aal,
470
- claims: input.claims,
471
- ...(input.mfaVerifiedAt === undefined
628
+ return decision._tag === "RequireMfa"
629
+ ? Option.some(yield* requireMfa({
630
+ ...input,
631
+ factors: decision.factors,
632
+ }))
633
+ : Option.none();
634
+ });
635
+ const requireMfa = Effect.fn("auth.auth_flow.require_mfa")(function* (input) {
636
+ if (dependencies.authFlowState === undefined) {
637
+ yield* Effect.annotateCurrentSpan("auth.result", "PolicyDenied");
638
+ return mfaFlowStateNotConfigured();
639
+ }
640
+ const derived = yield* deriveFlowInput(input);
641
+ if (!derived.primaryEstablished) {
642
+ yield* Effect.annotateCurrentSpan("auth.result", "PolicyDenied");
643
+ return primaryFactorNotEstablished();
644
+ }
645
+ const emailVerificationDecision = yield* emailVerificationSessionPolicy.decide({
646
+ claims: derived.claims,
647
+ });
648
+ const metadata = sessionMetadata(applicationFlowStateMetadata(derived.metadata), derived.request);
649
+ const device = yield* resolveDevice(derived);
650
+ const flowState = yield* dependencies.authFlowState.start({
651
+ userId: derived.userId,
652
+ method: derived.method,
653
+ evidence: derived.evidence,
654
+ ...(derived.identity === undefined ? {} : { identity: derived.identity }),
655
+ ...(derived.emailDestination === undefined
472
656
  ? {}
473
- : { mfaVerifiedAt: input.mfaVerifiedAt }),
474
- metadata: input.metadata,
657
+ : { emailDestination: derived.emailDestination }),
658
+ ...(derived.intent === undefined ? {} : { intent: derived.intent }),
659
+ device,
660
+ ...(derived.deviceKey === undefined
661
+ ? {}
662
+ : { deviceKey: derived.deviceKey }),
663
+ ...(derived.locationKey === undefined
664
+ ? {}
665
+ : { locationKey: derived.locationKey }),
666
+ ...(derived.request === undefined ? {} : { request: derived.request }),
667
+ claims: emailVerificationDecision.claims,
668
+ ...(input.secret === undefined ? {} : { secret: input.secret }),
669
+ ...(input.ttl === undefined ? {} : { ttl: input.ttl }),
670
+ factors: input.factors,
671
+ ...(metadata === undefined ? {} : { metadata }),
672
+ });
673
+ yield* Effect.annotateCurrentSpan({
674
+ "auth.result": "RequiresMfa",
675
+ "auth.mfa.factor_count": input.factors.length,
676
+ });
677
+ return AuthResult.RequiresMfa({
678
+ flowId: flowState.flowId,
679
+ factors: input.factors,
475
680
  });
476
- yield* notifyLogin(input, session);
477
- yield* Effect.annotateCurrentSpan("auth.result", "Authenticated");
478
- return AuthResult.Authenticated({ session });
479
681
  });
480
- const completePrimaryFactor = Effect.fn("auth.auth_flow.complete_primary_factor")(function* (input) {
682
+ const advance = Effect.fn("auth.auth_flow.advance")(function* (initial, mfaSatisfied, terminal, handleLoginApproval, mfaMethod) {
683
+ let input = yield* deriveFlowInput(initial);
684
+ if (!input.primaryEstablished) {
685
+ yield* Effect.annotateCurrentSpan("auth.result", "PolicyDenied");
686
+ return primaryFactorNotEstablished();
687
+ }
688
+ if (mfaMethod !== undefined) {
689
+ yield* Effect.annotateCurrentSpan({
690
+ "auth.mfa.method": mfaMethod,
691
+ "auth.mfa.aal": input.aal,
692
+ "auth.mfa.amr_count": input.amr.length,
693
+ });
694
+ }
481
695
  const emailVerificationDecision = yield* emailVerificationSessionPolicy.decide({
482
696
  claims: input.claims,
483
697
  });
484
- const metadata = sessionMetadata(input.metadata, input.request);
698
+ const metadata = sessionMetadata(applicationFlowStateMetadata(input.metadata), input.request);
485
699
  const device = yield* resolveDevice(input);
700
+ input = {
701
+ ...input,
702
+ claims: emailVerificationDecision.claims,
703
+ device,
704
+ ...(input.request === undefined && metadata !== undefined
705
+ ? { request: loginRequestContextFromMetadata(metadata) }
706
+ : {}),
707
+ ...(metadata === undefined ? {} : { metadata }),
708
+ };
709
+ const beforeRisk = yield* pipeline.advance({
710
+ phase: "before-risk",
711
+ input,
712
+ mfaSatisfied,
713
+ });
714
+ if (beforeRisk._tag === "PolicyDenied") {
715
+ return AuthResult.PolicyDenied({ reason: beforeRisk.reason });
716
+ }
486
717
  const risk = yield* loginRiskEngine.assess({
487
718
  userId: input.userId,
488
- ...(input.email === undefined ? {} : { email: input.email }),
489
- emailVerified: emailVerificationDecision.claims?.emailVerified,
719
+ ...(input.identity === undefined ? {} : { identity: input.identity }),
720
+ ...(input.emailDestination === undefined
721
+ ? {}
722
+ : { emailDestination: input.emailDestination }),
490
723
  method: input.method,
491
724
  amr: input.amr,
492
725
  aal: input.aal,
493
- device,
726
+ device: input.device ?? unknownLoginDeviceContext,
727
+ ...(input.deviceKey === undefined ? {} : { deviceKey: input.deviceKey }),
728
+ ...(input.locationKey === undefined
729
+ ? {}
730
+ : { locationKey: input.locationKey }),
494
731
  ...(input.request === undefined ? {} : { request: input.request }),
495
- ...(metadata === undefined ? {} : { metadata }),
732
+ ...(input.metadata === undefined ? {} : { metadata: input.metadata }),
733
+ });
734
+ input = { ...input, risk };
735
+ const afterRisk = yield* pipeline.advance({
736
+ phase: "after-risk",
737
+ input,
738
+ mfaSatisfied,
739
+ });
740
+ if (afterRisk._tag === "PolicyDenied") {
741
+ return AuthResult.PolicyDenied({ reason: afterRisk.reason });
742
+ }
743
+ const beforeMfa = yield* pipeline.advance({
744
+ phase: "before-mfa",
745
+ input,
746
+ mfaSatisfied,
747
+ });
748
+ if (beforeMfa._tag === "PolicyDenied") {
749
+ return AuthResult.PolicyDenied({ reason: beforeMfa.reason });
750
+ }
751
+ if (!mfaSatisfied) {
752
+ const mfaResult = yield* requireMfaIfNeeded({
753
+ ...input,
754
+ claims: input.claims,
755
+ device: input.device,
756
+ risk: input.risk,
757
+ metadata: input.metadata,
758
+ });
759
+ if (Option.isSome(mfaResult)) {
760
+ return mfaResult.value;
761
+ }
762
+ }
763
+ const afterMfa = yield* pipeline.advance({
764
+ phase: "after-mfa",
765
+ input,
766
+ mfaSatisfied,
496
767
  });
768
+ if (afterMfa._tag === "PolicyDenied") {
769
+ return AuthResult.PolicyDenied({ reason: afterMfa.reason });
770
+ }
771
+ const beforeLoginApproval = yield* pipeline.advance({
772
+ phase: "before-login-approval",
773
+ input,
774
+ mfaSatisfied,
775
+ });
776
+ if (beforeLoginApproval._tag === "PolicyDenied") {
777
+ return AuthResult.PolicyDenied({ reason: beforeLoginApproval.reason });
778
+ }
497
779
  const loginApprovalDecision = yield* loginApprovalPolicy.decide({
498
780
  ...(input.intent === undefined ? {} : { intent: input.intent }),
499
781
  userId: input.userId,
500
- ...(input.email === undefined ? {} : { email: input.email }),
501
- emailVerified: emailVerificationDecision.claims?.emailVerified,
782
+ ...(input.identity === undefined ? {} : { identity: input.identity }),
783
+ ...(input.emailDestination === undefined
784
+ ? {}
785
+ : { emailDestination: input.emailDestination }),
502
786
  method: input.method,
503
787
  amr: input.amr,
504
788
  aal: input.aal,
505
- device,
506
- risk,
507
- ...(metadata === undefined ? {} : { metadata }),
789
+ device: input.device ?? unknownLoginDeviceContext,
790
+ risk: input.risk ?? defaultLoginRiskContext,
791
+ ...(input.metadata === undefined ? {} : { metadata: input.metadata }),
508
792
  });
509
793
  if (loginApprovalDecision._tag === "RequiresApproval") {
510
794
  if (loginApprovalDecision.channel === "email" &&
511
- input.email === undefined) {
795
+ input.emailDestination === undefined) {
512
796
  yield* Effect.annotateCurrentSpan("auth.result", "PolicyDenied");
513
797
  return loginApprovalEmailMissing();
514
798
  }
799
+ if (loginApprovalDecision.markIdentityVerified === true &&
800
+ (loginApprovalDecision.channel !== "email" ||
801
+ loginApprovalDecision.sessionBinding === "none" ||
802
+ input.identity?.kind !== "email" ||
803
+ input.emailDestination === undefined ||
804
+ input.identity.identityId !== input.emailDestination.identityId)) {
805
+ yield* Effect.annotateCurrentSpan("auth.result", "PolicyDenied");
806
+ return loginApprovalIdentityNotBound();
807
+ }
515
808
  if (dependencies.authFlowState === undefined ||
516
809
  dependencies.loginApprovalFlow === undefined) {
517
810
  yield* Effect.annotateCurrentSpan("auth.result", "PolicyDenied");
@@ -523,124 +816,179 @@ export const makeAuthFlow = (dependencies) => {
523
816
  yield* Effect.annotateCurrentSpan("auth.result", "PolicyDenied");
524
817
  return loginApprovalReviewNotConfigured();
525
818
  }
526
- let sameDeviceSecret;
527
- if (loginApprovalDecision.sameDeviceRequired) {
528
- if (dependencies.crypto === undefined) {
529
- yield* Effect.annotateCurrentSpan("auth.result", "PolicyDenied");
530
- return loginApprovalSameDeviceNotConfigured();
531
- }
532
- sameDeviceSecret = Redacted.make(yield* dependencies.crypto
533
- .randomToken(loginApprovalSameDeviceSecretBytes)
534
- .pipe(Effect.mapError((cause) => new AuthFlowStateError({
535
- message: "Failed to create login approval same-device binding",
536
- cause,
537
- }))));
819
+ if (loginApprovalDecision.sameDeviceRequired &&
820
+ dependencies.crypto === undefined) {
821
+ yield* Effect.annotateCurrentSpan("auth.result", "PolicyDenied");
822
+ return loginApprovalSameDeviceNotConfigured();
538
823
  }
539
- const claims = loginApprovalDecision.markEmailVerified === true
540
- ? withEmailVerified(emailVerificationDecision.claims, true)
541
- : emailVerificationDecision.claims;
542
- const flowState = yield* dependencies.authFlowState.start({
543
- userId: input.userId,
544
- method: input.method,
545
- amr: input.amr,
546
- aal: input.aal,
547
- ...(input.email === undefined ? {} : { email: input.email }),
548
- ...(input.intent === undefined ? {} : { intent: input.intent }),
549
- device,
550
- claims,
551
- secret: sameDeviceSecret,
552
- ...(metadata === undefined ? {} : { metadata }),
553
- });
554
- const approval = yield* dependencies.loginApprovalFlow.start({
555
- userId: input.userId,
556
- ...(input.email === undefined ? {} : { email: input.email }),
557
- channel: loginApprovalDecision.channel,
558
- reason: loginApprovalDecision.reason,
559
- sessionBinding: loginApprovalDecision.sessionBinding,
560
- sameDeviceRequired: loginApprovalDecision.sameDeviceRequired,
561
- ...(loginApprovalDecision.markEmailVerified === true
562
- ? { markEmailVerified: true }
563
- : {}),
564
- risk,
565
- metadata: loginApprovalFlowIdMetadata(flowState.flowId, metadata),
566
- });
567
- if (approval.sessionBinding === "none" &&
568
- loginApprovalReview !== undefined) {
569
- yield* loginApprovalReview.start({
570
- approval,
824
+ const approvalInput = input;
825
+ const completeLoginApproval = Effect.gen(function* () {
826
+ let sameDeviceSecret;
827
+ if (loginApprovalDecision.sameDeviceRequired) {
828
+ sameDeviceSecret = Redacted.make(yield* dependencies
829
+ .crypto.randomToken(loginApprovalSameDeviceSecretBytes)
830
+ .pipe(Effect.mapError((cause) => new AuthFlowStateError({
831
+ message: "Failed to create login approval same-device binding",
832
+ cause,
833
+ }))));
834
+ }
835
+ const claims = loginApprovalDecision.markIdentityVerified === true
836
+ ? withVerifiedIdentityKind(approvalInput.claims, "email")
837
+ : approvalInput.claims;
838
+ const flowState = yield* dependencies.authFlowState.start({
839
+ userId: approvalInput.userId,
840
+ method: approvalInput.method,
841
+ evidence: approvalInput.evidence,
842
+ ...(approvalInput.identity === undefined
843
+ ? {}
844
+ : { identity: approvalInput.identity }),
845
+ ...(approvalInput.emailDestination === undefined
846
+ ? {}
847
+ : { emailDestination: approvalInput.emailDestination }),
848
+ ...(approvalInput.intent === undefined
849
+ ? {}
850
+ : { intent: approvalInput.intent }),
851
+ device: approvalInput.device,
852
+ ...(approvalInput.deviceKey === undefined
853
+ ? {}
854
+ : { deviceKey: approvalInput.deviceKey }),
855
+ ...(approvalInput.locationKey === undefined
856
+ ? {}
857
+ : { locationKey: approvalInput.locationKey }),
858
+ ...(approvalInput.request === undefined
859
+ ? {}
860
+ : { request: approvalInput.request }),
861
+ claims,
862
+ secret: sameDeviceSecret,
863
+ ...(approvalInput.metadata === undefined
864
+ ? {}
865
+ : { metadata: approvalInput.metadata }),
866
+ });
867
+ const approval = yield* dependencies.loginApprovalFlow.start({
868
+ userId: approvalInput.userId,
869
+ ...(approvalInput.emailDestination === undefined
870
+ ? {}
871
+ : { emailDestination: approvalInput.emailDestination }),
872
+ channel: loginApprovalDecision.channel,
873
+ reason: loginApprovalDecision.reason,
874
+ sessionBinding: loginApprovalDecision.sessionBinding,
875
+ sameDeviceRequired: loginApprovalDecision.sameDeviceRequired,
876
+ ...(loginApprovalDecision.markIdentityVerified === true
877
+ ? { markIdentityVerified: true }
878
+ : {}),
879
+ risk: approvalInput.risk ?? defaultLoginRiskContext,
880
+ metadata: loginApprovalFlowIdMetadata(flowState.flowId, approvalInput.metadata),
881
+ });
882
+ if (approval.sessionBinding === "none" &&
883
+ loginApprovalReview !== undefined) {
884
+ yield* loginApprovalReview.start({
885
+ approval,
886
+ flowId: flowState.flowId,
887
+ metadata: approvalInput.metadata,
888
+ });
889
+ }
890
+ yield* Effect.annotateCurrentSpan({
891
+ "auth.result": "RequiresLoginApproval",
892
+ "auth.login_approval.reason": approval.reason,
893
+ "auth.login_approval.session_binding": approval.sessionBinding,
894
+ "auth.login_approval.same_device_required": approval.sameDeviceRequired,
895
+ });
896
+ return AuthResult.RequiresLoginApproval({
571
897
  flowId: flowState.flowId,
572
- metadata,
898
+ approvalChallengeId: approval.challengeId,
899
+ channel: approval.channel,
900
+ sessionBinding: approval.sessionBinding,
901
+ sameDeviceRequired: approval.sameDeviceRequired,
902
+ reason: approval.reason,
903
+ expiresAt: flowState.expiresAt,
904
+ ...(sameDeviceSecret === undefined ? {} : { sameDeviceSecret }),
573
905
  });
574
- }
575
- yield* Effect.annotateCurrentSpan({
576
- "auth.result": "RequiresLoginApproval",
577
- "auth.login_approval.reason": approval.reason,
578
- "auth.login_approval.session_binding": approval.sessionBinding,
579
- "auth.login_approval.same_device_required": approval.sameDeviceRequired,
580
- });
581
- return AuthResult.RequiresLoginApproval({
582
- flowId: flowState.flowId,
583
- approvalChallengeId: approval.challengeId,
584
- channel: approval.channel,
585
- sessionBinding: approval.sessionBinding,
586
- sameDeviceRequired: approval.sameDeviceRequired,
587
- reason: approval.reason,
588
- expiresAt: flowState.expiresAt,
589
- ...(sameDeviceSecret === undefined ? {} : { sameDeviceSecret }),
590
906
  });
907
+ return yield* handleLoginApproval(completeLoginApproval);
591
908
  }
592
- return yield* complete({
593
- userId: input.userId,
594
- ...(input.email === undefined ? {} : { email: input.email }),
595
- ...(input.intent === undefined ? {} : { intent: input.intent }),
596
- method: input.method,
597
- amr: input.amr,
598
- aal: input.aal,
599
- device,
600
- ...(input.request === undefined ? {} : { request: input.request }),
601
- risk,
602
- claims: emailVerificationDecision.claims,
603
- metadata,
604
- });
909
+ return yield* terminal(input);
605
910
  });
911
+ const completePrimaryFactor = Effect.fn("auth.auth_flow.complete_primary_factor")((input) => advance(input, false, flowTerminal.complete, (complete) => complete));
606
912
  const completeMfa = Effect.fn("auth.auth_flow.complete_mfa")(function* (input) {
607
913
  if (dependencies.authFlowState === undefined) {
608
914
  yield* Effect.annotateCurrentSpan("auth.result", "PolicyDenied");
609
915
  return mfaFlowStateNotConfigured();
610
916
  }
611
- const consumed = yield* dependencies.authFlowState.consume(input.flowId, input.secret);
612
- if (input.userId !== undefined && consumed.userId !== input.userId) {
917
+ const pending = yield* dependencies.authFlowState.inspect(input.flowId, input.secret);
918
+ if (input.userId !== undefined && pending.userId !== input.userId) {
613
919
  yield* Effect.annotateCurrentSpan("auth.result", "PolicyDenied");
614
920
  return mfaFlowUserMismatch();
615
921
  }
616
- const mfaVerifiedAt = input.now ?? (yield* currentUnixMillis);
617
- const amr = appendAuthMethods(consumed.amr, input.amr ?? [authMethodReference(input.method)]);
618
- const aal = strongerAal(consumed.aal, input.aal ?? "aal2");
619
- const metadata = mergeMetadata(consumed.metadata, input.metadata);
620
- yield* Effect.annotateCurrentSpan({
621
- "auth.result": "Authenticated",
622
- "auth.mfa.method": input.method,
623
- "auth.mfa.aal": aal,
624
- "auth.mfa.amr_count": amr.length,
625
- });
626
- return yield* complete({
922
+ if (!authFlowStateAllowsMfa(pending, input)) {
923
+ yield* Effect.annotateCurrentSpan("auth.result", "PolicyDenied");
924
+ return mfaFlowFactorNotAllowed();
925
+ }
926
+ const consumed = yield* dependencies.authFlowState.consume(input.flowId, input.secret);
927
+ if (consumed.userId !== pending.userId ||
928
+ !authFlowStateAllowsMfa(consumed, input)) {
929
+ yield* Effect.annotateCurrentSpan("auth.result", "PolicyDenied");
930
+ return mfaFlowFactorNotAllowed();
931
+ }
932
+ const evidence = [...consumed.evidence, input.evidence];
933
+ const metadata = mergeMetadata(consumed.metadata, applicationFlowStateMetadata(input.metadata));
934
+ const result = yield* advance({
627
935
  userId: consumed.userId,
628
- ...(consumed.email === undefined ? {} : { email: consumed.email }),
936
+ ...(consumed.identity === undefined
937
+ ? {}
938
+ : { identity: consumed.identity }),
939
+ ...(consumed.emailDestination === undefined
940
+ ? {}
941
+ : { emailDestination: consumed.emailDestination }),
629
942
  ...(consumed.intent === undefined ? {} : { intent: consumed.intent }),
630
943
  method: consumed.method,
631
- amr,
632
- aal,
944
+ evidence,
633
945
  ...(consumed.device === undefined ? {} : { device: consumed.device }),
946
+ ...(consumed.deviceKey === undefined
947
+ ? {}
948
+ : { deviceKey: consumed.deviceKey }),
949
+ ...(consumed.locationKey === undefined
950
+ ? {}
951
+ : { locationKey: consumed.locationKey }),
952
+ ...(consumed.request === undefined
953
+ ? {}
954
+ : { request: consumed.request }),
634
955
  claims: consumed.claims,
635
- mfaVerifiedAt,
636
956
  metadata,
637
- });
957
+ }, true, flowTerminal.complete, (complete) => complete, input.method);
958
+ return result._tag === "RequiresMfa"
959
+ ? AuthResult.PolicyDenied({ reason: "MFA is already satisfied" })
960
+ : result;
638
961
  });
639
- return AuthFlow.make({
962
+ const prepareMfa = Effect.fn("auth.auth_flow.prepare_mfa")(function* (input) {
963
+ if (dependencies.authFlowState === undefined) {
964
+ return mfaFlowStateNotConfigured();
965
+ }
966
+ const inspected = yield* dependencies.authFlowState.inspect(input.flowId, input.secret);
967
+ if (input.userId !== undefined && inspected.userId !== input.userId) {
968
+ return mfaFlowUserMismatch();
969
+ }
970
+ if (!authFlowStateAllowsMfa(inspected, input)) {
971
+ return mfaFlowFactorNotAllowed();
972
+ }
973
+ const evidence = [...inspected.evidence, input.evidence];
974
+ const result = yield* advance({
975
+ ...inspected,
976
+ evidence,
977
+ metadata: mergeMetadata(inspected.metadata, applicationFlowStateMetadata(input.metadata)),
978
+ }, true, flowTerminal.prepare, (complete) => Effect.succeed({
979
+ _tag: "PreparedLoginApproval",
980
+ complete,
981
+ }), input.method);
982
+ return result._tag === "RequiresMfa"
983
+ ? AuthResult.PolicyDenied({ reason: "MFA is already satisfied" })
984
+ : result;
985
+ });
986
+ return AuthFlow.of({
640
987
  startPrimaryFactor: completePrimaryFactor,
988
+ requireMfa,
641
989
  completePrimaryFactor,
642
990
  completeMfa,
643
- complete,
991
+ prepareMfa,
644
992
  });
645
993
  };
646
994
  export const AuthFlowLive = Layer.effect(AuthFlow)(Effect.gen(function* () {
@@ -653,13 +1001,13 @@ export const AuthFlowLive = Layer.effect(AuthFlow)(Effect.gen(function* () {
653
1001
  ...loginApprovalDependencies,
654
1002
  });
655
1003
  }));
656
- export const AuthFlowLiveWithEmailVerificationPolicy = (options) => Layer.effect(AuthFlow)(Effect.gen(function* () {
1004
+ export const AuthFlowWithEmailVerificationPolicyLive = (options) => Layer.effect(AuthFlow)(Effect.gen(function* () {
657
1005
  const sessions = yield* Sessions;
658
1006
  const loginApprovalDependencies = yield* optionalLoginApprovalDependencies;
659
1007
  return makeAuthFlow({
660
1008
  sessions,
661
- emailVerificationSessionPolicy: makeEmailVerificationSessionPolicy(options),
662
1009
  ...loginApprovalDependencies,
1010
+ emailVerificationSessionPolicy: makeEmailVerificationSessionPolicy(options),
663
1011
  });
664
1012
  }));
665
1013
  //# sourceMappingURL=AuthFlow.js.map