@techelusive/nest-auth 0.0.0-stage → 0.2.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 (340) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/LICENSE +21 -0
  3. package/README.md +204 -2
  4. package/api/openapi.json +4399 -0
  5. package/api/techelusive-authentication.postman_collection.json +3178 -0
  6. package/dist/auth-options.d.ts +156 -0
  7. package/dist/auth-options.js +3 -0
  8. package/dist/auth-options.js.map +1 -0
  9. package/dist/auth-options.validation.d.ts +9 -0
  10. package/dist/auth-options.validation.js +74 -0
  11. package/dist/auth-options.validation.js.map +1 -0
  12. package/dist/auth.module.d.ts +38 -0
  13. package/dist/auth.module.js +173 -0
  14. package/dist/auth.module.js.map +1 -0
  15. package/dist/common/auth-error.d.ts +16 -0
  16. package/dist/common/auth-error.js +23 -0
  17. package/dist/common/auth-error.js.map +1 -0
  18. package/dist/common/auth-exception.filter.d.ts +24 -0
  19. package/dist/common/auth-exception.filter.js +66 -0
  20. package/dist/common/auth-exception.filter.js.map +1 -0
  21. package/dist/common/crypto/jwt.d.ts +89 -0
  22. package/dist/common/crypto/jwt.js +144 -0
  23. package/dist/common/crypto/jwt.js.map +1 -0
  24. package/dist/common/crypto/random-secrets.d.ts +78 -0
  25. package/dist/common/crypto/random-secrets.js +113 -0
  26. package/dist/common/crypto/random-secrets.js.map +1 -0
  27. package/dist/common/crypto/remote-public-keys.d.ts +49 -0
  28. package/dist/common/crypto/remote-public-keys.js +105 -0
  29. package/dist/common/crypto/remote-public-keys.js.map +1 -0
  30. package/dist/common/crypto/totp.d.ts +68 -0
  31. package/dist/common/crypto/totp.js +148 -0
  32. package/dist/common/crypto/totp.js.map +1 -0
  33. package/dist/common/encryption.service.d.ts +36 -0
  34. package/dist/common/encryption.service.js +111 -0
  35. package/dist/common/encryption.service.js.map +1 -0
  36. package/dist/common/identifiers.d.ts +48 -0
  37. package/dist/common/identifiers.js +89 -0
  38. package/dist/common/identifiers.js.map +1 -0
  39. package/dist/common/network-safety.d.ts +19 -0
  40. package/dist/common/network-safety.js +72 -0
  41. package/dist/common/network-safety.js.map +1 -0
  42. package/dist/common/rate-limiter.service.d.ts +63 -0
  43. package/dist/common/rate-limiter.service.js +158 -0
  44. package/dist/common/rate-limiter.service.js.map +1 -0
  45. package/dist/common/refresh-token-cookie.d.ts +78 -0
  46. package/dist/common/refresh-token-cookie.js +185 -0
  47. package/dist/common/refresh-token-cookie.js.map +1 -0
  48. package/dist/common/request-context.d.ts +14 -0
  49. package/dist/common/request-context.js +22 -0
  50. package/dist/common/request-context.js.map +1 -0
  51. package/dist/common/strict-validation.pipe.d.ts +8 -0
  52. package/dist/common/strict-validation.pipe.js +16 -0
  53. package/dist/common/strict-validation.pipe.js.map +1 -0
  54. package/dist/common/time.d.ts +15 -0
  55. package/dist/common/time.js +34 -0
  56. package/dist/common/time.js.map +1 -0
  57. package/dist/constants.d.ts +1326 -0
  58. package/dist/constants.js +1142 -0
  59. package/dist/constants.js.map +1 -0
  60. package/dist/database/create-auth-tables.migration.d.ts +26 -0
  61. package/dist/database/create-auth-tables.migration.js +291 -0
  62. package/dist/database/create-auth-tables.migration.js.map +1 -0
  63. package/dist/database/email-change-and-retention.migration.d.ts +25 -0
  64. package/dist/database/email-change-and-retention.migration.js +54 -0
  65. package/dist/database/email-change-and-retention.migration.js.map +1 -0
  66. package/dist/database/entities/api-key.entity.d.ts +17 -0
  67. package/dist/database/entities/api-key.entity.js +80 -0
  68. package/dist/database/entities/api-key.entity.js.map +1 -0
  69. package/dist/database/entities/audit-log.entity.d.ts +13 -0
  70. package/dist/database/entities/audit-log.entity.js +64 -0
  71. package/dist/database/entities/audit-log.entity.js.map +1 -0
  72. package/dist/database/entities/backup-code.entity.d.ts +9 -0
  73. package/dist/database/entities/backup-code.entity.js +52 -0
  74. package/dist/database/entities/backup-code.entity.js.map +1 -0
  75. package/dist/database/entities/index.d.ts +43 -0
  76. package/dist/database/entities/index.js +82 -0
  77. package/dist/database/entities/index.js.map +1 -0
  78. package/dist/database/entities/json-object.d.ts +12 -0
  79. package/dist/database/entities/json-object.js +3 -0
  80. package/dist/database/entities/json-object.js.map +1 -0
  81. package/dist/database/entities/link-token.entity.d.ts +15 -0
  82. package/dist/database/entities/link-token.entity.js +64 -0
  83. package/dist/database/entities/link-token.entity.js.map +1 -0
  84. package/dist/database/entities/one-time-code.entity.d.ts +16 -0
  85. package/dist/database/entities/one-time-code.entity.js +69 -0
  86. package/dist/database/entities/one-time-code.entity.js.map +1 -0
  87. package/dist/database/entities/organization-invitation.entity.d.ts +14 -0
  88. package/dist/database/entities/organization-invitation.entity.js +73 -0
  89. package/dist/database/entities/organization-invitation.entity.js.map +1 -0
  90. package/dist/database/entities/organization-member.entity.d.ts +9 -0
  91. package/dist/database/entities/organization-member.entity.js +48 -0
  92. package/dist/database/entities/organization-member.entity.js.map +1 -0
  93. package/dist/database/entities/organization.entity.d.ts +12 -0
  94. package/dist/database/entities/organization.entity.js +58 -0
  95. package/dist/database/entities/organization.entity.js.map +1 -0
  96. package/dist/database/entities/passkey.entity.d.ts +19 -0
  97. package/dist/database/entities/passkey.entity.js +78 -0
  98. package/dist/database/entities/passkey.entity.js.map +1 -0
  99. package/dist/database/entities/password.entity.d.ts +6 -0
  100. package/dist/database/entities/password.entity.js +36 -0
  101. package/dist/database/entities/password.entity.js.map +1 -0
  102. package/dist/database/entities/refresh-token.entity.d.ts +9 -0
  103. package/dist/database/entities/refresh-token.entity.js +53 -0
  104. package/dist/database/entities/refresh-token.entity.js.map +1 -0
  105. package/dist/database/entities/session.entity.d.ts +20 -0
  106. package/dist/database/entities/session.entity.js +87 -0
  107. package/dist/database/entities/session.entity.js.map +1 -0
  108. package/dist/database/entities/settings.entity.d.ts +7 -0
  109. package/dist/database/entities/settings.entity.js +41 -0
  110. package/dist/database/entities/settings.entity.js.map +1 -0
  111. package/dist/database/entities/sign-in-challenge.entity.d.ts +23 -0
  112. package/dist/database/entities/sign-in-challenge.entity.js +80 -0
  113. package/dist/database/entities/sign-in-challenge.entity.js.map +1 -0
  114. package/dist/database/entities/signing-key.entity.d.ts +11 -0
  115. package/dist/database/entities/signing-key.entity.js +54 -0
  116. package/dist/database/entities/signing-key.entity.js.map +1 -0
  117. package/dist/database/entities/social-account.entity.d.ts +13 -0
  118. package/dist/database/entities/social-account.entity.js +54 -0
  119. package/dist/database/entities/social-account.entity.js.map +1 -0
  120. package/dist/database/entities/two-factor-secret.entity.d.ts +10 -0
  121. package/dist/database/entities/two-factor-secret.entity.js +48 -0
  122. package/dist/database/entities/two-factor-secret.entity.js.map +1 -0
  123. package/dist/database/entities/user.entity.d.ts +34 -0
  124. package/dist/database/entities/user.entity.js +129 -0
  125. package/dist/database/entities/user.entity.js.map +1 -0
  126. package/dist/database/entities/webhook-delivery.entity.d.ts +17 -0
  127. package/dist/database/entities/webhook-delivery.entity.js +79 -0
  128. package/dist/database/entities/webhook-delivery.entity.js.map +1 -0
  129. package/dist/database/entities/webhook.entity.d.ts +12 -0
  130. package/dist/database/entities/webhook.entity.js +58 -0
  131. package/dist/database/entities/webhook.entity.js.map +1 -0
  132. package/dist/database/typeorm-row.d.ts +21 -0
  133. package/dist/database/typeorm-row.js +29 -0
  134. package/dist/database/typeorm-row.js.map +1 -0
  135. package/dist/features/account/account.controller.d.ts +259 -0
  136. package/dist/features/account/account.controller.js +372 -0
  137. package/dist/features/account/account.controller.js.map +1 -0
  138. package/dist/features/account/account.dto.d.ts +16 -0
  139. package/dist/features/account/account.dto.js +61 -0
  140. package/dist/features/account/account.dto.js.map +1 -0
  141. package/dist/features/account/data-export.service.d.ts +85 -0
  142. package/dist/features/account/data-export.service.js +125 -0
  143. package/dist/features/account/data-export.service.js.map +1 -0
  144. package/dist/features/account/health.service.d.ts +30 -0
  145. package/dist/features/account/health.service.js +59 -0
  146. package/dist/features/account/health.service.js.map +1 -0
  147. package/dist/features/admin/admin.controller.d.ts +382 -0
  148. package/dist/features/admin/admin.controller.js +623 -0
  149. package/dist/features/admin/admin.controller.js.map +1 -0
  150. package/dist/features/admin/admin.dto.d.ts +61 -0
  151. package/dist/features/admin/admin.dto.js +253 -0
  152. package/dist/features/admin/admin.dto.js.map +1 -0
  153. package/dist/features/admin/admin.service.d.ts +142 -0
  154. package/dist/features/admin/admin.service.js +227 -0
  155. package/dist/features/admin/admin.service.js.map +1 -0
  156. package/dist/features/api-keys/api-keys.service.d.ts +67 -0
  157. package/dist/features/api-keys/api-keys.service.js +144 -0
  158. package/dist/features/api-keys/api-keys.service.js.map +1 -0
  159. package/dist/features/email-change/email-change.controller.d.ts +38 -0
  160. package/dist/features/email-change/email-change.controller.js +85 -0
  161. package/dist/features/email-change/email-change.controller.js.map +1 -0
  162. package/dist/features/email-change/email-change.dto.d.ts +10 -0
  163. package/dist/features/email-change/email-change.dto.js +43 -0
  164. package/dist/features/email-change/email-change.dto.js.map +1 -0
  165. package/dist/features/email-change/email-change.service.d.ts +74 -0
  166. package/dist/features/email-change/email-change.service.js +179 -0
  167. package/dist/features/email-change/email-change.service.js.map +1 -0
  168. package/dist/features/email-links/email-verification.service.d.ts +46 -0
  169. package/dist/features/email-links/email-verification.service.js +94 -0
  170. package/dist/features/email-links/email-verification.service.js.map +1 -0
  171. package/dist/features/email-links/link-tokens.service.d.ts +44 -0
  172. package/dist/features/email-links/link-tokens.service.js +122 -0
  173. package/dist/features/email-links/link-tokens.service.js.map +1 -0
  174. package/dist/features/events/auth-events.service.d.ts +52 -0
  175. package/dist/features/events/auth-events.service.js +117 -0
  176. package/dist/features/events/auth-events.service.js.map +1 -0
  177. package/dist/features/maintenance/data-retention.service.d.ts +60 -0
  178. package/dist/features/maintenance/data-retention.service.js +182 -0
  179. package/dist/features/maintenance/data-retention.service.js.map +1 -0
  180. package/dist/features/notifications/notifications.service.d.ts +40 -0
  181. package/dist/features/notifications/notifications.service.js +94 -0
  182. package/dist/features/notifications/notifications.service.js.map +1 -0
  183. package/dist/features/one-time-codes/one-time-codes.service.d.ts +40 -0
  184. package/dist/features/one-time-codes/one-time-codes.service.js +102 -0
  185. package/dist/features/one-time-codes/one-time-codes.service.js.map +1 -0
  186. package/dist/features/organizations/organizations.controller.d.ts +220 -0
  187. package/dist/features/organizations/organizations.controller.js +337 -0
  188. package/dist/features/organizations/organizations.controller.js.map +1 -0
  189. package/dist/features/organizations/organizations.dto.d.ts +31 -0
  190. package/dist/features/organizations/organizations.dto.js +100 -0
  191. package/dist/features/organizations/organizations.dto.js.map +1 -0
  192. package/dist/features/organizations/organizations.service.d.ts +274 -0
  193. package/dist/features/organizations/organizations.service.js +481 -0
  194. package/dist/features/organizations/organizations.service.js.map +1 -0
  195. package/dist/features/passkeys/passkeys.controller.d.ts +92 -0
  196. package/dist/features/passkeys/passkeys.controller.js +183 -0
  197. package/dist/features/passkeys/passkeys.controller.js.map +1 -0
  198. package/dist/features/passkeys/passkeys.dto.d.ts +13 -0
  199. package/dist/features/passkeys/passkeys.dto.js +50 -0
  200. package/dist/features/passkeys/passkeys.dto.js.map +1 -0
  201. package/dist/features/passkeys/passkeys.service.d.ts +159 -0
  202. package/dist/features/passkeys/passkeys.service.js +350 -0
  203. package/dist/features/passkeys/passkeys.service.js.map +1 -0
  204. package/dist/features/passwordless/passwordless-auth.service.d.ts +152 -0
  205. package/dist/features/passwordless/passwordless-auth.service.js +304 -0
  206. package/dist/features/passwordless/passwordless-auth.service.js.map +1 -0
  207. package/dist/features/passwordless/passwordless.controller.d.ts +75 -0
  208. package/dist/features/passwordless/passwordless.controller.js +163 -0
  209. package/dist/features/passwordless/passwordless.controller.js.map +1 -0
  210. package/dist/features/passwordless/passwordless.dto.d.ts +29 -0
  211. package/dist/features/passwordless/passwordless.dto.js +101 -0
  212. package/dist/features/passwordless/passwordless.dto.js.map +1 -0
  213. package/dist/features/passwords/password-auth.service.d.ts +154 -0
  214. package/dist/features/passwords/password-auth.service.js +317 -0
  215. package/dist/features/passwords/password-auth.service.js.map +1 -0
  216. package/dist/features/passwords/password-policy.service.d.ts +63 -0
  217. package/dist/features/passwords/password-policy.service.js +175 -0
  218. package/dist/features/passwords/password-policy.service.js.map +1 -0
  219. package/dist/features/passwords/password.controller.d.ts +95 -0
  220. package/dist/features/passwords/password.controller.js +193 -0
  221. package/dist/features/passwords/password.controller.js.map +1 -0
  222. package/dist/features/passwords/password.dto.d.ts +36 -0
  223. package/dist/features/passwords/password.dto.js +140 -0
  224. package/dist/features/passwords/password.dto.js.map +1 -0
  225. package/dist/features/sessions/session.service.d.ts +132 -0
  226. package/dist/features/sessions/session.service.js +308 -0
  227. package/dist/features/sessions/session.service.js.map +1 -0
  228. package/dist/features/sessions/session.types.d.ts +34 -0
  229. package/dist/features/sessions/session.types.js +3 -0
  230. package/dist/features/sessions/session.types.js.map +1 -0
  231. package/dist/features/settings/settings.defaults.d.ts +2 -0
  232. package/dist/features/settings/settings.defaults.js +7 -0
  233. package/dist/features/settings/settings.defaults.js.map +1 -0
  234. package/dist/features/settings/settings.service.d.ts +44 -0
  235. package/dist/features/settings/settings.service.js +112 -0
  236. package/dist/features/settings/settings.service.js.map +1 -0
  237. package/dist/features/settings/settings.types.d.ts +133 -0
  238. package/dist/features/settings/settings.types.js +3 -0
  239. package/dist/features/settings/settings.types.js.map +1 -0
  240. package/dist/features/settings/settings.validation.d.ts +33 -0
  241. package/dist/features/settings/settings.validation.js +614 -0
  242. package/dist/features/settings/settings.validation.js.map +1 -0
  243. package/dist/features/sign-in/sign-in-challenges.service.d.ts +54 -0
  244. package/dist/features/sign-in/sign-in-challenges.service.js +104 -0
  245. package/dist/features/sign-in/sign-in-challenges.service.js.map +1 -0
  246. package/dist/features/sign-in/sign-in.service.d.ts +127 -0
  247. package/dist/features/sign-in/sign-in.service.js +248 -0
  248. package/dist/features/sign-in/sign-in.service.js.map +1 -0
  249. package/dist/features/sign-in/sign-in.types.d.ts +22 -0
  250. package/dist/features/sign-in/sign-in.types.js +3 -0
  251. package/dist/features/sign-in/sign-in.types.js.map +1 -0
  252. package/dist/features/signing-keys/jwks.controller.d.ts +17 -0
  253. package/dist/features/signing-keys/jwks.controller.js +51 -0
  254. package/dist/features/signing-keys/jwks.controller.js.map +1 -0
  255. package/dist/features/signing-keys/signing-keys.service.d.ts +67 -0
  256. package/dist/features/signing-keys/signing-keys.service.js +142 -0
  257. package/dist/features/signing-keys/signing-keys.service.js.map +1 -0
  258. package/dist/features/social/social-auth.service.d.ts +100 -0
  259. package/dist/features/social/social-auth.service.js +232 -0
  260. package/dist/features/social/social-auth.service.js.map +1 -0
  261. package/dist/features/social/social-providers.service.d.ts +97 -0
  262. package/dist/features/social/social-providers.service.js +214 -0
  263. package/dist/features/social/social-providers.service.js.map +1 -0
  264. package/dist/features/social/social.controller.d.ts +54 -0
  265. package/dist/features/social/social.controller.js +124 -0
  266. package/dist/features/social/social.controller.js.map +1 -0
  267. package/dist/features/social/social.dto.d.ts +11 -0
  268. package/dist/features/social/social.dto.js +38 -0
  269. package/dist/features/social/social.dto.js.map +1 -0
  270. package/dist/features/two-factor/two-factor.controller.d.ts +84 -0
  271. package/dist/features/two-factor/two-factor.controller.js +174 -0
  272. package/dist/features/two-factor/two-factor.controller.js.map +1 -0
  273. package/dist/features/two-factor/two-factor.dto.d.ts +10 -0
  274. package/dist/features/two-factor/two-factor.dto.js +37 -0
  275. package/dist/features/two-factor/two-factor.dto.js.map +1 -0
  276. package/dist/features/two-factor/two-factor.service.d.ts +171 -0
  277. package/dist/features/two-factor/two-factor.service.js +348 -0
  278. package/dist/features/two-factor/two-factor.service.js.map +1 -0
  279. package/dist/features/users/sign-in-methods.service.d.ts +40 -0
  280. package/dist/features/users/sign-in-methods.service.js +81 -0
  281. package/dist/features/users/sign-in-methods.service.js.map +1 -0
  282. package/dist/features/users/sign-up-rules.d.ts +12 -0
  283. package/dist/features/users/sign-up-rules.js +29 -0
  284. package/dist/features/users/sign-up-rules.js.map +1 -0
  285. package/dist/features/users/users.service.d.ts +246 -0
  286. package/dist/features/users/users.service.js +509 -0
  287. package/dist/features/users/users.service.js.map +1 -0
  288. package/dist/features/users/users.types.d.ts +24 -0
  289. package/dist/features/users/users.types.js +3 -0
  290. package/dist/features/users/users.types.js.map +1 -0
  291. package/dist/features/webhooks/webhook-delivery.worker.d.ts +55 -0
  292. package/dist/features/webhooks/webhook-delivery.worker.js +175 -0
  293. package/dist/features/webhooks/webhook-delivery.worker.js.map +1 -0
  294. package/dist/features/webhooks/webhook-signature.d.ts +28 -0
  295. package/dist/features/webhooks/webhook-signature.js +85 -0
  296. package/dist/features/webhooks/webhook-signature.js.map +1 -0
  297. package/dist/features/webhooks/webhooks.service.d.ts +144 -0
  298. package/dist/features/webhooks/webhooks.service.js +238 -0
  299. package/dist/features/webhooks/webhooks.service.js.map +1 -0
  300. package/dist/guards/auth.decorators.d.ts +65 -0
  301. package/dist/guards/auth.decorators.js +68 -0
  302. package/dist/guards/auth.decorators.js.map +1 -0
  303. package/dist/guards/auth.guard.d.ts +47 -0
  304. package/dist/guards/auth.guard.js +132 -0
  305. package/dist/guards/auth.guard.js.map +1 -0
  306. package/dist/index.d.ts +38 -0
  307. package/dist/index.js +95 -0
  308. package/dist/index.js.map +1 -0
  309. package/dist/integrations/console-email-sender.d.ts +15 -0
  310. package/dist/integrations/console-email-sender.js +26 -0
  311. package/dist/integrations/console-email-sender.js.map +1 -0
  312. package/dist/integrations/msg91-sms-sender.d.ts +28 -0
  313. package/dist/integrations/msg91-sms-sender.js +46 -0
  314. package/dist/integrations/msg91-sms-sender.js.map +1 -0
  315. package/docs/README.md +39 -0
  316. package/docs/admin-api-keys-webhooks.md +147 -0
  317. package/docs/api-reference.md +175 -0
  318. package/docs/architecture.md +119 -0
  319. package/docs/client-integration.md +192 -0
  320. package/docs/code-walkthrough.md +273 -0
  321. package/docs/configuration.md +229 -0
  322. package/docs/endpoints/README.md +151 -0
  323. package/docs/endpoints/account.md +363 -0
  324. package/docs/endpoints/admin.md +422 -0
  325. package/docs/endpoints/email-password.md +261 -0
  326. package/docs/endpoints/organizations.md +192 -0
  327. package/docs/endpoints/passkeys.md +195 -0
  328. package/docs/endpoints/passwordless.md +214 -0
  329. package/docs/endpoints/social.md +116 -0
  330. package/docs/endpoints/two-factor.md +146 -0
  331. package/docs/error-codes.md +100 -0
  332. package/docs/events.md +83 -0
  333. package/docs/getting-started.md +139 -0
  334. package/docs/manual-testing.md +215 -0
  335. package/docs/organizations.md +86 -0
  336. package/docs/production-checklist.md +60 -0
  337. package/docs/protecting-routes.md +147 -0
  338. package/docs/security.md +61 -0
  339. package/docs/sign-in-flows.md +294 -0
  340. package/package.json +92 -4
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.TwoFactorController = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const strict_validation_pipe_1 = require("../../common/strict-validation.pipe.js");
18
+ const request_context_1 = require("../../common/request-context.js");
19
+ const auth_decorators_1 = require("../../guards/auth.decorators.js");
20
+ const users_service_1 = require("../users/users.service.js");
21
+ const two_factor_dto_1 = require("./two-factor.dto");
22
+ const two_factor_service_1 = require("./two-factor.service");
23
+ const constants_1 = require("../../constants.js");
24
+ const refresh_token_cookie_1 = require("../../common/refresh-token-cookie.js");
25
+ /**
26
+ * Two-factor authentication (authenticator app + backup codes).
27
+ *
28
+ * GET /auth/2fa is it on? how many backup codes are left?
29
+ * POST /auth/2fa/setup start: get the secret and QR-code URL
30
+ * POST /auth/2fa/enable finish: first code -> backup codes
31
+ * POST /auth/2fa/disable turn off (needs a code)
32
+ * POST /auth/2fa/backup-codes new backup codes (needs a code)
33
+ * POST /auth/2fa/verify second step of sign-in
34
+ */
35
+ let TwoFactorController = class TwoFactorController {
36
+ twoFactor;
37
+ users;
38
+ constructor(twoFactor, users) {
39
+ this.twoFactor = twoFactor;
40
+ this.users = users;
41
+ }
42
+ /**
43
+ * GET /auth/2fa — Is 2FA on for the signed-in user, and how many backup codes are left?
44
+ *
45
+ * @param userId - From the access token.
46
+ * @returns `{ isEnabled, remainingBackupCodes }`.
47
+ */
48
+ async getStatus(userId) {
49
+ const user = await this.users.getUserOrThrow(userId);
50
+ return {
51
+ success: true,
52
+ isEnabled: user.isTwoFactorEnabled,
53
+ remainingBackupCodes: user.isTwoFactorEnabled ? await this.twoFactor.countRemainingBackupCodes(userId) : 0,
54
+ };
55
+ }
56
+ /**
57
+ * POST /auth/2fa/setup — Starts setup and returns the secret and QR-code URL.
58
+ *
59
+ * @param userId - From the access token.
60
+ * @returns See `TwoFactorService.startSetup`.
61
+ */
62
+ startSetup(userId) {
63
+ return this.twoFactor.startSetup(userId);
64
+ }
65
+ /**
66
+ * POST /auth/2fa/enable — Confirms setup with the first code and returns backup codes.
67
+ *
68
+ * @param user - The access token's claims (user id and session id).
69
+ * @param body - `{ code }`.
70
+ * @param request - Who is asking.
71
+ * @returns See `TwoFactorService.confirmSetup`.
72
+ */
73
+ enable(user, body, request) {
74
+ return this.twoFactor.confirmSetup(user.sub, user.sid, body.code, request);
75
+ }
76
+ /**
77
+ * POST /auth/2fa/disable — Turns 2FA off.
78
+ *
79
+ * @param userId - From the access token.
80
+ * @param body - `{ code }`: an authenticator or backup code.
81
+ * @param request - Who is asking.
82
+ * @returns `{ success: true }`.
83
+ */
84
+ disable(userId, body, request) {
85
+ return this.twoFactor.disable(userId, body.code, request);
86
+ }
87
+ /**
88
+ * POST /auth/2fa/backup-codes — Replaces all backup codes.
89
+ *
90
+ * @param userId - From the access token.
91
+ * @param body - `{ code }`: an authenticator or backup code.
92
+ * @returns The new backup codes.
93
+ */
94
+ regenerateBackupCodes(userId, body) {
95
+ return this.twoFactor.regenerateBackupCodes(userId, body.code);
96
+ }
97
+ /**
98
+ * POST /auth/2fa/verify — The second step of sign-in. Public: the caller has no tokens yet.
99
+ *
100
+ * @param body - `{ challengeToken, code }`.
101
+ * @param request - Who is asking.
102
+ * @returns Access and refresh tokens.
103
+ */
104
+ verify(body, request) {
105
+ return this.twoFactor.verifySignInChallenge(body.challengeToken, body.code, request);
106
+ }
107
+ };
108
+ exports.TwoFactorController = TwoFactorController;
109
+ __decorate([
110
+ (0, common_1.Get)(),
111
+ __param(0, (0, auth_decorators_1.CurrentUserId)()),
112
+ __metadata("design:type", Function),
113
+ __metadata("design:paramtypes", [String]),
114
+ __metadata("design:returntype", Promise)
115
+ ], TwoFactorController.prototype, "getStatus", null);
116
+ __decorate([
117
+ (0, common_1.Post)(constants_1.ROUTES.twoFactor.setup),
118
+ (0, auth_decorators_1.CheckSession)(),
119
+ (0, common_1.HttpCode)(common_1.HttpStatus.OK),
120
+ __param(0, (0, auth_decorators_1.CurrentUserId)()),
121
+ __metadata("design:type", Function),
122
+ __metadata("design:paramtypes", [String]),
123
+ __metadata("design:returntype", void 0)
124
+ ], TwoFactorController.prototype, "startSetup", null);
125
+ __decorate([
126
+ (0, common_1.Post)(constants_1.ROUTES.twoFactor.enable),
127
+ (0, auth_decorators_1.CheckSession)(),
128
+ (0, common_1.HttpCode)(common_1.HttpStatus.OK),
129
+ __param(0, (0, auth_decorators_1.CurrentUser)()),
130
+ __param(1, (0, common_1.Body)()),
131
+ __param(2, (0, request_context_1.CurrentRequest)()),
132
+ __metadata("design:type", Function),
133
+ __metadata("design:paramtypes", [Object, two_factor_dto_1.TwoFactorCodeInput, Object]),
134
+ __metadata("design:returntype", void 0)
135
+ ], TwoFactorController.prototype, "enable", null);
136
+ __decorate([
137
+ (0, common_1.Post)(constants_1.ROUTES.twoFactor.disable),
138
+ (0, auth_decorators_1.CheckSession)(),
139
+ (0, common_1.HttpCode)(common_1.HttpStatus.OK),
140
+ __param(0, (0, auth_decorators_1.CurrentUserId)()),
141
+ __param(1, (0, common_1.Body)()),
142
+ __param(2, (0, request_context_1.CurrentRequest)()),
143
+ __metadata("design:type", Function),
144
+ __metadata("design:paramtypes", [String, two_factor_dto_1.TwoFactorCodeInput, Object]),
145
+ __metadata("design:returntype", void 0)
146
+ ], TwoFactorController.prototype, "disable", null);
147
+ __decorate([
148
+ (0, common_1.Post)(constants_1.ROUTES.twoFactor.backupCodes),
149
+ (0, auth_decorators_1.CheckSession)(),
150
+ (0, common_1.HttpCode)(common_1.HttpStatus.OK),
151
+ __param(0, (0, auth_decorators_1.CurrentUserId)()),
152
+ __param(1, (0, common_1.Body)()),
153
+ __metadata("design:type", Function),
154
+ __metadata("design:paramtypes", [String, two_factor_dto_1.TwoFactorCodeInput]),
155
+ __metadata("design:returntype", void 0)
156
+ ], TwoFactorController.prototype, "regenerateBackupCodes", null);
157
+ __decorate([
158
+ (0, common_1.Post)(constants_1.ROUTES.twoFactor.verify),
159
+ (0, auth_decorators_1.Public)(),
160
+ (0, common_1.HttpCode)(common_1.HttpStatus.OK),
161
+ __param(0, (0, common_1.Body)()),
162
+ __param(1, (0, request_context_1.CurrentRequest)()),
163
+ __metadata("design:type", Function),
164
+ __metadata("design:paramtypes", [two_factor_dto_1.VerifyTwoFactorChallengeInput, Object]),
165
+ __metadata("design:returntype", void 0)
166
+ ], TwoFactorController.prototype, "verify", null);
167
+ exports.TwoFactorController = TwoFactorController = __decorate([
168
+ (0, common_1.Controller)(constants_1.ROUTES.twoFactor.prefix),
169
+ (0, refresh_token_cookie_1.LibraryController)(),
170
+ (0, common_1.UsePipes)(strict_validation_pipe_1.strictValidationPipe),
171
+ __metadata("design:paramtypes", [two_factor_service_1.TwoFactorService,
172
+ users_service_1.UsersService])
173
+ ], TwoFactorController);
174
+ //# sourceMappingURL=two-factor.controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"two-factor.controller.js","sourceRoot":"","sources":["../../../src/features/two-factor/two-factor.controller.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,10 @@
1
+ /** POST /auth/2fa/enable, /auth/2fa/disable, /auth/2fa/backup-codes */
2
+ export declare class TwoFactorCodeInput {
3
+ /** The 6-digit code from the authenticator app, or a backup code such as "k7m2-x9p4". */
4
+ code: string;
5
+ }
6
+ /** POST /auth/2fa/verify (second step of sign-in) */
7
+ export declare class VerifyTwoFactorChallengeInput extends TwoFactorCodeInput {
8
+ /** The challengeToken from the sign-in response. */
9
+ challengeToken: string;
10
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.VerifyTwoFactorChallengeInput = exports.TwoFactorCodeInput = void 0;
13
+ const class_validator_1 = require("class-validator");
14
+ const constants_1 = require("../../constants.js");
15
+ /** POST /auth/2fa/enable, /auth/2fa/disable, /auth/2fa/backup-codes */
16
+ class TwoFactorCodeInput {
17
+ /** The 6-digit code from the authenticator app, or a backup code such as "k7m2-x9p4". */
18
+ code;
19
+ }
20
+ exports.TwoFactorCodeInput = TwoFactorCodeInput;
21
+ __decorate([
22
+ (0, class_validator_1.IsString)(),
23
+ (0, class_validator_1.MaxLength)(constants_1.CODE_INPUT_MAX_LENGTH),
24
+ __metadata("design:type", String)
25
+ ], TwoFactorCodeInput.prototype, "code", void 0);
26
+ /** POST /auth/2fa/verify (second step of sign-in) */
27
+ class VerifyTwoFactorChallengeInput extends TwoFactorCodeInput {
28
+ /** The challengeToken from the sign-in response. */
29
+ challengeToken;
30
+ }
31
+ exports.VerifyTwoFactorChallengeInput = VerifyTwoFactorChallengeInput;
32
+ __decorate([
33
+ (0, class_validator_1.IsString)(),
34
+ (0, class_validator_1.MaxLength)(constants_1.RANDOM_TOKEN_INPUT_MAX_LENGTH),
35
+ __metadata("design:type", String)
36
+ ], VerifyTwoFactorChallengeInput.prototype, "challengeToken", void 0);
37
+ //# sourceMappingURL=two-factor.dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"two-factor.dto.js","sourceRoot":"","sources":["../../../src/features/two-factor/two-factor.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAsD;AACtD,2CAAmF;AAEnF,uEAAuE;AACvE,MAAa,kBAAkB;IAC7B,yFAAyF;IAEzF,IAAI,CAAS;CACd;AAJD,gDAIC;AADC;IADC,IAAA,0BAAQ,GAAE;IAAE,IAAA,2BAAS,EAAC,iCAAqB,CAAC;;gDAChC;AAGf,qDAAqD;AACrD,MAAa,6BAA8B,SAAQ,kBAAkB;IACnE,oDAAoD;IAEpD,cAAc,CAAS;CACxB;AAJD,sEAIC;AADC;IADC,IAAA,0BAAQ,GAAE;IAAE,IAAA,2BAAS,EAAC,yCAA6B,CAAC;;qEAC9B"}
@@ -0,0 +1,171 @@
1
+ import { AuthOptions } from '../../auth-options.js';
2
+ import { EncryptionService } from '../../common/encryption.service.js';
3
+ import { RateLimiterService } from '../../common/rate-limiter.service.js';
4
+ import { RequestContext } from '../../common/request-context.js';
5
+ import { AuthEventsService } from '../events/auth-events.service.js';
6
+ import { SessionService } from '../sessions/session.service.js';
7
+ import { SettingsService } from '../settings/settings.service.js';
8
+ import { SignInChallengesService } from '../sign-in/sign-in-challenges.service.js';
9
+ import { SignInService } from '../sign-in/sign-in.service.js';
10
+ import { SignedInResult } from '../sign-in/sign-in.types.js';
11
+ import { UsersService } from '../users/users.service.js';
12
+ /**
13
+ * Two-factor authentication with an authenticator app (Google Authenticator, Microsoft
14
+ * Authenticator, 1Password, Authy...), plus single-use backup codes for a lost phone.
15
+ *
16
+ * Turning it on: POST /auth/2fa/setup -> secret + QR-code URL
17
+ * POST /auth/2fa/enable -> first code from the app; returns backup codes (shown once)
18
+ * Signing in: sign-in returns { status: "two_factor_required", challengeToken }
19
+ * POST /auth/2fa/verify -> challengeToken + code (or a backup code) -> tokens
20
+ */
21
+ export declare class TwoFactorService {
22
+ private readonly options;
23
+ private readonly settingsService;
24
+ private readonly encryption;
25
+ private readonly users;
26
+ private readonly sessions;
27
+ private readonly signIn;
28
+ private readonly challenges;
29
+ private readonly rateLimiter;
30
+ private readonly events;
31
+ private readonly database;
32
+ constructor(options: AuthOptions, settingsService: SettingsService, encryption: EncryptionService, users: UsersService, sessions: SessionService, signIn: SignInService, challenges: SignInChallengesService, rateLimiter: RateLimiterService, events: AuthEventsService);
33
+ /**
34
+ * Starts setup: creates a new secret. Show `authenticatorAppUrl` as a QR code (and `secret` for
35
+ * typing by hand). Nothing changes for the user until they confirm with a code (`confirmSetup`).
36
+ * Calling it again replaces the unconfirmed secret.
37
+ *
38
+ * @param userId - The signed-in user.
39
+ * @returns The plain secret and the otpauth:// URL for the QR code.
40
+ * @throws AuthError FEATURE_DISABLED when 2FA is turned off in settings.
41
+ * @throws AuthError TWO_FACTOR_ALREADY_ENABLED when the user already has 2FA on.
42
+ */
43
+ startSetup(userId: string): Promise<{
44
+ success: true;
45
+ secret: string;
46
+ authenticatorAppUrl: string;
47
+ }>;
48
+ /**
49
+ * Finishes setup: the user types the first code from their app. Turns 2FA on, signs out other
50
+ * devices, and returns backup codes. Show them once and ask the user to save them.
51
+ *
52
+ * @param userId - The signed-in user.
53
+ * @param currentSessionId - This device's session, which stays signed in.
54
+ * @param code - The 6-digit code from the authenticator app.
55
+ * @param request - Who is asking (for the audit log).
56
+ * @returns The plain backup codes, formatted like "k7m2-x9p4".
57
+ * @throws AuthError TWO_FACTOR_SETUP_NOT_STARTED when `startSetup` wasn't called first.
58
+ * @throws AuthError INVALID_OTP when the code is wrong.
59
+ * @throws AuthError TOO_MANY_REQUESTS after too many attempts.
60
+ */
61
+ confirmSetup(userId: string, currentSessionId: string, code: unknown, request: RequestContext): Promise<{
62
+ success: true;
63
+ backupCodes: string[];
64
+ }>;
65
+ /**
66
+ * Turns 2FA off. Requires a current authenticator code or a backup code.
67
+ *
68
+ * @param userId - The signed-in user.
69
+ * @param code - An authenticator code or a backup code.
70
+ * @param request - Who is asking (for the audit log).
71
+ * @returns `{ success: true }`.
72
+ * @throws AuthError TWO_FACTOR_NOT_ENABLED when 2FA is already off.
73
+ * @throws AuthError INVALID_OTP when the code is wrong.
74
+ */
75
+ disable(userId: string, code: unknown, request: RequestContext): Promise<{
76
+ success: true;
77
+ }>;
78
+ /**
79
+ * Replaces all backup codes (e.g. the user lost the list). The old codes stop working.
80
+ *
81
+ * @param userId - The signed-in user.
82
+ * @param code - An authenticator code or a backup code.
83
+ * @returns The new plain backup codes.
84
+ * @throws AuthError TWO_FACTOR_NOT_ENABLED when 2FA is off.
85
+ * @throws AuthError INVALID_OTP when the code is wrong.
86
+ */
87
+ regenerateBackupCodes(userId: string, code: unknown): Promise<{
88
+ success: true;
89
+ backupCodes: string[];
90
+ }>;
91
+ /**
92
+ * Counts the unused backup codes (show a warning when it gets low).
93
+ *
94
+ * @param userId - The user to check.
95
+ * @returns How many backup codes are left.
96
+ */
97
+ countRemainingBackupCodes(userId: string): Promise<number>;
98
+ /**
99
+ * Admin: turns 2FA off for a user who lost their phone and backup codes.
100
+ * Only call this after checking who the user is some other way.
101
+ *
102
+ * @param userId - The user whose 2FA is removed.
103
+ * @param adminUserId - The admin doing it (recorded in the audit log).
104
+ * @param request - Who is asking (for the audit log).
105
+ * @returns `{ success: true }`.
106
+ * @throws AuthError NOT_FOUND when the user doesn't exist.
107
+ */
108
+ resetForUser(userId: string, adminUserId: string, request: RequestContext): Promise<{
109
+ success: true;
110
+ }>;
111
+ /**
112
+ * The second step of sign-in: checks the code for a challenge token returned by the first step.
113
+ *
114
+ * @param challengeToken - The "ch_..." token from `{ status: "two_factor_required" }`.
115
+ * @param code - An authenticator code or a backup code.
116
+ * @param request - Who is asking (for rate limits, sessions and the audit log).
117
+ * @returns The signed-in result with access and refresh tokens.
118
+ * @throws AuthError INVALID_TOKEN when the challenge is unknown, used, expired or burnt by wrong codes.
119
+ * @throws AuthError INVALID_OTP when the code is wrong.
120
+ */
121
+ verifySignInChallenge(challengeToken: unknown, code: unknown, request: RequestContext): Promise<SignedInResult>;
122
+ /**
123
+ * @throws AuthError FEATURE_DISABLED when 2FA is turned off in settings.
124
+ */
125
+ private assertTwoFactorAllowed;
126
+ /**
127
+ * Accepts a 6-digit authenticator code, or a backup code (which is then used up).
128
+ *
129
+ * @param userId - The user the code belongs to.
130
+ * @param code - What the user typed.
131
+ * @returns True when the code was correct.
132
+ */
133
+ private checkAnyCode;
134
+ /**
135
+ * Checks an authenticator code and remembers its time step, so the same code can't be used twice.
136
+ * The UPDATE only succeeds if no newer code was accepted meanwhile (two requests at once).
137
+ *
138
+ * @param storedSecret - The user's row with the encrypted secret.
139
+ * @param code - What the user typed.
140
+ * @returns True when the code was correct and not used before.
141
+ */
142
+ private checkAuthenticatorCode;
143
+ /**
144
+ * Checks a backup code and marks it used, so it works only once.
145
+ *
146
+ * @param userId - The user the code belongs to.
147
+ * @param typedCode - What the user typed; dashes, spaces and capitals are ignored.
148
+ * @returns True when the code matched an unused backup code (and this request was the one to use it).
149
+ */
150
+ private useBackupCode;
151
+ /**
152
+ * Deletes old backup codes and creates new ones. Only their hashes are stored.
153
+ *
154
+ * @param userId - The user to create codes for.
155
+ * @returns The plain codes, formatted like "k7m2-x9p4", to show the user once.
156
+ */
157
+ private replaceBackupCodes;
158
+ /**
159
+ * Deletes the secret and backup codes and turns 2FA off, all in one transaction.
160
+ *
161
+ * @param userId - The user to turn 2FA off for.
162
+ */
163
+ private removeTwoFactor;
164
+ /**
165
+ * Binds the encrypted secret to its user, so a secret copied to another user's row won't decrypt.
166
+ *
167
+ * @param userId - The secret's owner.
168
+ * @returns The context for `EncryptionService`.
169
+ */
170
+ private encryptionContext;
171
+ }