@acorex-platform/module-security-management-server 0.0.18 → 2.0.0-next.42

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 (453) hide show
  1. package/contracts/src/AXM_USER_ACCESS_STATE_DEFINITION_KEY.js.map +1 -1
  2. package/contracts/src/AXM_USER_EFFECTIVE_STATE_DEFINITION_KEY.js.map +1 -1
  3. package/contracts/src/ROLE_PERMISSIONS_PAGE_COMPONENT_KEY.d.ts +2 -0
  4. package/contracts/src/ROLE_PERMISSIONS_PAGE_COMPONENT_KEY.js +6 -0
  5. package/contracts/src/ROLE_PERMISSIONS_PAGE_COMPONENT_KEY.js.map +1 -0
  6. package/contracts/src/USER_ROLES_PAGE_COMPONENT_KEY.d.ts +1 -0
  7. package/contracts/src/USER_ROLES_PAGE_COMPONENT_KEY.js +5 -0
  8. package/contracts/src/USER_ROLES_PAGE_COMPONENT_KEY.js.map +1 -0
  9. package/contracts/src/create-application-role-rows.util.d.ts +15 -0
  10. package/contracts/src/create-application-role-rows.util.js +67 -0
  11. package/contracts/src/create-application-role-rows.util.js.map +1 -0
  12. package/contracts/src/device-session-admin-scope.d.ts +15 -0
  13. package/contracts/src/device-session-admin-scope.js +16 -0
  14. package/contracts/src/device-session-admin-scope.js.map +1 -0
  15. package/contracts/src/entities/device-sessions/device-sessions.entity.js +50 -1
  16. package/contracts/src/entities/device-sessions/device-sessions.entity.js.map +1 -1
  17. package/contracts/src/entities/device-sessions/device-sessions.types.d.ts +7 -0
  18. package/contracts/src/entities/device-sessions/device-sessions.types.js.map +1 -1
  19. package/contracts/src/entities/device-sessions/index.d.ts +0 -1
  20. package/contracts/src/entities/device-sessions/index.js +0 -1
  21. package/contracts/src/entities/device-sessions/index.js.map +1 -1
  22. package/contracts/src/entities/identity-provider/identity-provider.entity.d.ts +2 -0
  23. package/contracts/src/entities/identity-provider/identity-provider.entity.js +453 -0
  24. package/contracts/src/entities/identity-provider/identity-provider.entity.js.map +1 -0
  25. package/contracts/src/entities/identity-provider/identity-provider.types.d.ts +61 -0
  26. package/contracts/src/entities/identity-provider/identity-provider.types.js +14 -0
  27. package/contracts/src/entities/identity-provider/identity-provider.types.js.map +1 -0
  28. package/contracts/src/entities/identity-provider/index.d.ts +1 -0
  29. package/contracts/src/entities/identity-provider/index.js +5 -0
  30. package/contracts/src/entities/identity-provider/index.js.map +1 -0
  31. package/contracts/src/entities/index.d.ts +4 -0
  32. package/contracts/src/entities/index.js +4 -0
  33. package/contracts/src/entities/index.js.map +1 -1
  34. package/contracts/src/entities/policy/index.d.ts +0 -1
  35. package/contracts/src/entities/policy/index.js +0 -1
  36. package/contracts/src/entities/policy/index.js.map +1 -1
  37. package/contracts/src/entities/policy/policy.entity.js +15 -0
  38. package/contracts/src/entities/policy/policy.entity.js.map +1 -1
  39. package/contracts/src/entities/policy/policy.types.js.map +1 -1
  40. package/contracts/src/entities/profile/index.d.ts +0 -1
  41. package/contracts/src/entities/profile/index.js +0 -1
  42. package/contracts/src/entities/profile/index.js.map +1 -1
  43. package/contracts/src/entities/profile/profile.entity.js +15 -0
  44. package/contracts/src/entities/profile/profile.entity.js.map +1 -1
  45. package/contracts/src/entities/profile/profile.types.js.map +1 -1
  46. package/contracts/src/entities/role-permission/index.d.ts +1 -0
  47. package/contracts/src/entities/role-permission/index.js +5 -0
  48. package/contracts/src/entities/role-permission/index.js.map +1 -0
  49. package/contracts/src/entities/role-permission/role-permission.entity.d.ts +2 -0
  50. package/contracts/src/entities/role-permission/role-permission.entity.js +163 -0
  51. package/contracts/src/entities/role-permission/role-permission.entity.js.map +1 -0
  52. package/contracts/src/entities/role-permission/role-permission.types.d.ts +11 -0
  53. package/contracts/src/entities/role-permission/role-permission.types.js +5 -0
  54. package/contracts/src/entities/role-permission/role-permission.types.js.map +1 -0
  55. package/contracts/src/entities/roles/index.d.ts +0 -1
  56. package/contracts/src/entities/roles/index.js +0 -1
  57. package/contracts/src/entities/roles/index.js.map +1 -1
  58. package/contracts/src/entities/roles/roles.entity.js +73 -144
  59. package/contracts/src/entities/roles/roles.entity.js.map +1 -1
  60. package/contracts/src/entities/roles/roles.types.d.ts +4 -1
  61. package/contracts/src/entities/roles/roles.types.js.map +1 -1
  62. package/contracts/src/entities/user-role/index.d.ts +1 -0
  63. package/{src/lib/seed/tenant → contracts/src/entities/user-role}/index.js +1 -1
  64. package/contracts/src/entities/user-role/index.js.map +1 -0
  65. package/contracts/src/entities/user-role/user-role.entity.d.ts +2 -0
  66. package/contracts/src/entities/user-role/user-role.entity.js +164 -0
  67. package/contracts/src/entities/user-role/user-role.entity.js.map +1 -0
  68. package/contracts/src/entities/user-role/user-role.types.d.ts +11 -0
  69. package/contracts/src/entities/user-role/user-role.types.js +5 -0
  70. package/contracts/src/entities/user-role/user-role.types.js.map +1 -0
  71. package/contracts/src/entities/user-two-factor/index.d.ts +2 -0
  72. package/contracts/src/entities/user-two-factor/index.js +8 -0
  73. package/contracts/src/entities/user-two-factor/index.js.map +1 -0
  74. package/contracts/src/entities/user-two-factor/user-two-factor.entity.d.ts +6 -0
  75. package/contracts/src/entities/user-two-factor/user-two-factor.entity.js +103 -0
  76. package/contracts/src/entities/user-two-factor/user-two-factor.entity.js.map +1 -0
  77. package/contracts/src/entities/user-two-factor/user-two-factor.types.d.ts +24 -0
  78. package/contracts/src/entities/user-two-factor/user-two-factor.types.js +4 -0
  79. package/contracts/src/entities/user-two-factor/user-two-factor.types.js.map +1 -0
  80. package/contracts/src/entities/users/index.d.ts +1 -1
  81. package/contracts/src/entities/users/index.js +1 -1
  82. package/contracts/src/entities/users/index.js.map +1 -1
  83. package/contracts/src/entities/users/user-provisioning-list-actions.d.ts +8 -0
  84. package/contracts/src/entities/users/user-provisioning-list-actions.js +95 -0
  85. package/contracts/src/entities/users/user-provisioning-list-actions.js.map +1 -0
  86. package/contracts/src/entities/users/users.entity.js +244 -83
  87. package/contracts/src/entities/users/users.entity.js.map +1 -1
  88. package/contracts/src/entities/users/users.types.d.ts +15 -0
  89. package/contracts/src/entities/users/users.types.js.map +1 -1
  90. package/contracts/src/entity-catalog.d.ts +7 -0
  91. package/contracts/src/entity-catalog.js +28 -0
  92. package/contracts/src/entity-catalog.js.map +1 -0
  93. package/contracts/src/entity-entry.device-sessions.d.ts +1 -0
  94. package/contracts/src/entity-entry.device-sessions.js +6 -0
  95. package/contracts/src/entity-entry.device-sessions.js.map +1 -0
  96. package/contracts/src/entity-entry.identity-provider.d.ts +1 -0
  97. package/contracts/src/entity-entry.identity-provider.js +6 -0
  98. package/contracts/src/entity-entry.identity-provider.js.map +1 -0
  99. package/contracts/src/entity-entry.policy.d.ts +1 -0
  100. package/contracts/src/entity-entry.policy.js +6 -0
  101. package/contracts/src/entity-entry.policy.js.map +1 -0
  102. package/contracts/src/entity-entry.profile.d.ts +1 -0
  103. package/contracts/src/entity-entry.profile.js +6 -0
  104. package/contracts/src/entity-entry.profile.js.map +1 -0
  105. package/contracts/src/entity-entry.role-permission.d.ts +1 -0
  106. package/contracts/src/entity-entry.role-permission.js +6 -0
  107. package/contracts/src/entity-entry.role-permission.js.map +1 -0
  108. package/contracts/src/entity-entry.roles.d.ts +1 -0
  109. package/contracts/src/entity-entry.roles.js +6 -0
  110. package/contracts/src/entity-entry.roles.js.map +1 -0
  111. package/contracts/src/entity-entry.user-role.d.ts +1 -0
  112. package/contracts/src/entity-entry.user-role.js +6 -0
  113. package/contracts/src/entity-entry.user-role.js.map +1 -0
  114. package/contracts/src/entity-entry.user-two-factor.d.ts +1 -0
  115. package/contracts/src/entity-entry.user-two-factor.js +6 -0
  116. package/contracts/src/entity-entry.user-two-factor.js.map +1 -0
  117. package/contracts/src/entity-entry.users.d.ts +1 -0
  118. package/contracts/src/entity-entry.users.js +6 -0
  119. package/contracts/src/entity-entry.users.js.map +1 -0
  120. package/contracts/src/features.keys.d.ts +4 -0
  121. package/contracts/src/features.keys.js +4 -0
  122. package/contracts/src/features.keys.js.map +1 -1
  123. package/contracts/src/index.d.ts +10 -1
  124. package/contracts/src/index.js +10 -1
  125. package/contracts/src/index.js.map +1 -1
  126. package/contracts/src/invite-application-role-rows.util.d.ts +16 -0
  127. package/contracts/src/invite-application-role-rows.util.js +68 -0
  128. package/contracts/src/invite-application-role-rows.util.js.map +1 -0
  129. package/contracts/src/invite-assignable-roles.util.d.ts +34 -0
  130. package/contracts/src/invite-assignable-roles.util.js +75 -0
  131. package/contracts/src/invite-assignable-roles.util.js.map +1 -0
  132. package/contracts/src/lib/context.definitions.d.ts +2 -0
  133. package/contracts/src/lib/context.definitions.js +15 -0
  134. package/contracts/src/lib/context.definitions.js.map +1 -0
  135. package/contracts/src/manifest.d.ts +6 -0
  136. package/contracts/src/manifest.js +24 -0
  137. package/contracts/src/manifest.js.map +1 -0
  138. package/contracts/src/menu.keys.d.ts +1 -0
  139. package/contracts/src/menu.keys.js +1 -0
  140. package/contracts/src/menu.keys.js.map +1 -1
  141. package/contracts/src/permission.keys.d.ts +48 -18
  142. package/contracts/src/permission.keys.js +49 -21
  143. package/contracts/src/permission.keys.js.map +1 -1
  144. package/contracts/src/resolve-user-effective-state.js.map +1 -1
  145. package/contracts/src/root-config.d.ts +33 -0
  146. package/contracts/src/root-config.js +33 -0
  147. package/contracts/src/root-config.js.map +1 -1
  148. package/contracts/src/server-commands.d.ts +322 -0
  149. package/contracts/src/server-commands.js +77 -1
  150. package/contracts/src/server-commands.js.map +1 -1
  151. package/contracts/src/settings.keys.d.ts +16 -0
  152. package/contracts/src/settings.keys.js +21 -0
  153. package/contracts/src/settings.keys.js.map +1 -0
  154. package/contracts/src/user-access-state.js.map +1 -1
  155. package/contracts/src/user-effective-state.js.map +1 -1
  156. package/contracts/src/user-invitation.d.ts +41 -0
  157. package/contracts/src/user-invitation.js +18 -0
  158. package/contracts/src/user-invitation.js.map +1 -0
  159. package/contracts/src/user-password-reset.js.map +1 -1
  160. package/package.json +16 -18
  161. package/server/src/index.d.ts +3 -0
  162. package/server/src/index.js +11 -0
  163. package/server/src/index.js.map +1 -0
  164. package/server/src/lib/effective-access-history/effective-access-history.service.d.ts +35 -0
  165. package/server/src/lib/effective-access-history/effective-access-history.service.js +486 -0
  166. package/server/src/lib/effective-access-history/effective-access-history.service.js.map +1 -0
  167. package/server/src/lib/effective-access-history/effective-access-history.types.d.ts +64 -0
  168. package/server/src/lib/effective-access-history/effective-access-history.types.js +5 -0
  169. package/server/src/lib/effective-access-history/effective-access-history.types.js.map +1 -0
  170. package/server/src/lib/effective-access-history/version-as-of.util.d.ts +37 -0
  171. package/server/src/lib/effective-access-history/version-as-of.util.js +167 -0
  172. package/server/src/lib/effective-access-history/version-as-of.util.js.map +1 -0
  173. package/server/src/lib/entities/index.d.ts +1 -0
  174. package/server/src/lib/entities/index.js +5 -0
  175. package/{src/lib/seed/tenant → server/src/lib/entities}/index.js.map +1 -1
  176. package/server/src/lib/entities/security-management.entity-catalog.d.ts +1 -0
  177. package/server/src/lib/entities/security-management.entity-catalog.js +12 -0
  178. package/server/src/lib/entities/security-management.entity-catalog.js.map +1 -0
  179. package/server/src/lib/handlers/security-report.handlers.d.ts +36 -0
  180. package/server/src/lib/handlers/security-report.handlers.js +164 -0
  181. package/server/src/lib/handlers/security-report.handlers.js.map +1 -0
  182. package/server/src/lib/identity-provider/auth-oauth-clients.constants.d.ts +5 -0
  183. package/server/src/lib/identity-provider/auth-oauth-clients.constants.js +11 -0
  184. package/server/src/lib/identity-provider/auth-oauth-clients.constants.js.map +1 -0
  185. package/server/src/lib/identity-provider/identity-provider-catalog.service.d.ts +20 -0
  186. package/server/src/lib/identity-provider/identity-provider-catalog.service.js +169 -0
  187. package/server/src/lib/identity-provider/identity-provider-catalog.service.js.map +1 -0
  188. package/server/src/lib/identity-provider/identity-provider-ids.constants.d.ts +8 -0
  189. package/server/src/lib/identity-provider/identity-provider-ids.constants.js +19 -0
  190. package/server/src/lib/identity-provider/identity-provider-ids.constants.js.map +1 -0
  191. package/server/src/lib/identity-provider/identity-provider-stub.bootstrap.d.ts +12 -0
  192. package/server/src/lib/identity-provider/identity-provider-stub.bootstrap.js +48 -0
  193. package/server/src/lib/identity-provider/identity-provider-stub.bootstrap.js.map +1 -0
  194. package/server/src/lib/identity-provider/identity-provider.constants.d.ts +1 -0
  195. package/server/src/lib/identity-provider/identity-provider.constants.js +7 -0
  196. package/server/src/lib/identity-provider/identity-provider.constants.js.map +1 -0
  197. package/server/src/lib/middlewares/device-sessions-active.middleware.d.ts +15 -0
  198. package/server/src/lib/middlewares/device-sessions-active.middleware.js +76 -0
  199. package/server/src/lib/middlewares/device-sessions-active.middleware.js.map +1 -0
  200. package/server/src/lib/middlewares/device-sessions-app-scope.middleware.d.ts +29 -0
  201. package/server/src/lib/middlewares/device-sessions-app-scope.middleware.js +137 -0
  202. package/server/src/lib/middlewares/device-sessions-app-scope.middleware.js.map +1 -0
  203. package/server/src/lib/middlewares/device-sessions-app-scope.util.d.ts +41 -0
  204. package/server/src/lib/middlewares/device-sessions-app-scope.util.js +69 -0
  205. package/server/src/lib/middlewares/device-sessions-app-scope.util.js.map +1 -0
  206. package/server/src/lib/middlewares/device-sessions-token-revoke.middleware.d.ts +18 -0
  207. package/server/src/lib/middlewares/device-sessions-token-revoke.middleware.js +90 -0
  208. package/server/src/lib/middlewares/device-sessions-token-revoke.middleware.js.map +1 -0
  209. package/server/src/lib/middlewares/user-assigned-roles.middleware.d.ts +36 -0
  210. package/server/src/lib/middlewares/user-assigned-roles.middleware.js +359 -0
  211. package/server/src/lib/middlewares/user-assigned-roles.middleware.js.map +1 -0
  212. package/{src → server/src}/lib/middlewares/user-effective-state.middleware.js +1 -1
  213. package/server/src/lib/middlewares/user-effective-state.middleware.js.map +1 -0
  214. package/server/src/lib/middlewares/user-invitation-list.middleware.d.ts +32 -0
  215. package/server/src/lib/middlewares/user-invitation-list.middleware.js +250 -0
  216. package/server/src/lib/middlewares/user-invitation-list.middleware.js.map +1 -0
  217. package/server/src/lib/middlewares/user-profile-write.middleware.d.ts +18 -0
  218. package/server/src/lib/middlewares/user-profile-write.middleware.js +206 -0
  219. package/server/src/lib/middlewares/user-profile-write.middleware.js.map +1 -0
  220. package/server/src/lib/password-reset/change-own-password.command.d.ts +8 -0
  221. package/server/src/lib/password-reset/change-own-password.command.js +38 -0
  222. package/server/src/lib/password-reset/change-own-password.command.js.map +1 -0
  223. package/{src → server/src}/lib/password-reset/complete-password-reset.command.d.ts +3 -4
  224. package/{src → server/src}/lib/password-reset/complete-password-reset.command.js +8 -12
  225. package/server/src/lib/password-reset/complete-password-reset.command.js.map +1 -0
  226. package/server/src/lib/password-reset/get-own-password-status.command.d.ts +8 -0
  227. package/server/src/lib/password-reset/get-own-password-status.command.js +31 -0
  228. package/server/src/lib/password-reset/get-own-password-status.command.js.map +1 -0
  229. package/{src → server/src}/lib/password-reset/send-password-reset-email.command.d.ts +12 -13
  230. package/{src → server/src}/lib/password-reset/send-password-reset-email.command.js +10 -15
  231. package/server/src/lib/password-reset/send-password-reset-email.command.js.map +1 -0
  232. package/server/src/lib/password-reset/user-change-password.service.d.ts +24 -0
  233. package/server/src/lib/password-reset/user-change-password.service.js +92 -0
  234. package/server/src/lib/password-reset/user-change-password.service.js.map +1 -0
  235. package/{src → server/src}/lib/password-reset/user-password-reset.service.d.ts +2 -7
  236. package/{src → server/src}/lib/password-reset/user-password-reset.service.js +29 -90
  237. package/server/src/lib/password-reset/user-password-reset.service.js.map +1 -0
  238. package/server/src/lib/queries/get-permission-holders-history.query.d.ts +4 -0
  239. package/server/src/lib/queries/get-permission-holders-history.query.definition.d.ts +5 -0
  240. package/server/src/lib/queries/get-permission-holders-history.query.definition.js +38 -0
  241. package/server/src/lib/queries/get-permission-holders-history.query.definition.js.map +1 -0
  242. package/server/src/lib/queries/get-permission-holders-history.query.js +25 -0
  243. package/server/src/lib/queries/get-permission-holders-history.query.js.map +1 -0
  244. package/server/src/lib/queries/get-role-holders-history.query.d.ts +4 -0
  245. package/server/src/lib/queries/get-role-holders-history.query.definition.d.ts +5 -0
  246. package/server/src/lib/queries/get-role-holders-history.query.definition.js +38 -0
  247. package/server/src/lib/queries/get-role-holders-history.query.definition.js.map +1 -0
  248. package/server/src/lib/queries/get-role-holders-history.query.js +25 -0
  249. package/server/src/lib/queries/get-role-holders-history.query.js.map +1 -0
  250. package/server/src/lib/queries/get-user-effective-permissions-history.query.d.ts +4 -0
  251. package/server/src/lib/queries/get-user-effective-permissions-history.query.definition.d.ts +5 -0
  252. package/server/src/lib/queries/get-user-effective-permissions-history.query.definition.js +35 -0
  253. package/server/src/lib/queries/get-user-effective-permissions-history.query.definition.js.map +1 -0
  254. package/server/src/lib/queries/get-user-effective-permissions-history.query.js +26 -0
  255. package/server/src/lib/queries/get-user-effective-permissions-history.query.js.map +1 -0
  256. package/server/src/lib/queries/get-user-effective-roles-history.query.d.ts +4 -0
  257. package/server/src/lib/queries/get-user-effective-roles-history.query.definition.d.ts +5 -0
  258. package/server/src/lib/queries/get-user-effective-roles-history.query.definition.js +36 -0
  259. package/server/src/lib/queries/get-user-effective-roles-history.query.definition.js.map +1 -0
  260. package/server/src/lib/queries/get-user-effective-roles-history.query.js +25 -0
  261. package/server/src/lib/queries/get-user-effective-roles-history.query.js.map +1 -0
  262. package/server/src/lib/queries/get-user-password-change-history.query.d.ts +4 -0
  263. package/server/src/lib/queries/get-user-password-change-history.query.definition.d.ts +5 -0
  264. package/server/src/lib/queries/get-user-password-change-history.query.definition.js +33 -0
  265. package/server/src/lib/queries/get-user-password-change-history.query.definition.js.map +1 -0
  266. package/server/src/lib/queries/get-user-password-change-history.query.js +23 -0
  267. package/server/src/lib/queries/get-user-password-change-history.query.js.map +1 -0
  268. package/server/src/lib/queries/security-query.helpers.d.ts +47 -0
  269. package/server/src/lib/queries/security-query.helpers.js +184 -0
  270. package/server/src/lib/queries/security-query.helpers.js.map +1 -0
  271. package/server/src/lib/reports/password-change-history.service.d.ts +14 -0
  272. package/server/src/lib/reports/password-change-history.service.js +74 -0
  273. package/server/src/lib/reports/password-change-history.service.js.map +1 -0
  274. package/server/src/lib/reports/permission-display-catalog.d.ts +7 -0
  275. package/server/src/lib/reports/permission-display-catalog.js +101 -0
  276. package/server/src/lib/reports/permission-display-catalog.js.map +1 -0
  277. package/server/src/lib/reports/security-report-definition.provider.d.ts +5 -0
  278. package/server/src/lib/reports/security-report-definition.provider.js +23 -0
  279. package/server/src/lib/reports/security-report-definition.provider.js.map +1 -0
  280. package/server/src/lib/reports/security-report-parameter-groups.d.ts +343 -0
  281. package/server/src/lib/reports/security-report-parameter-groups.js +167 -0
  282. package/server/src/lib/reports/security-report-parameter-groups.js.map +1 -0
  283. package/server/src/lib/reports/security-report-scope.constants.d.ts +5 -0
  284. package/server/src/lib/reports/security-report-scope.constants.js +11 -0
  285. package/server/src/lib/reports/security-report-scope.constants.js.map +1 -0
  286. package/server/src/lib/reports/security-report.definitions.d.ts +12 -0
  287. package/server/src/lib/reports/security-report.definitions.js +386 -0
  288. package/server/src/lib/reports/security-report.definitions.js.map +1 -0
  289. package/server/src/lib/security-management-entity-storage.bootstrap.d.ts +26 -0
  290. package/server/src/lib/security-management-entity-storage.bootstrap.js +56 -0
  291. package/server/src/lib/security-management-entity-storage.bootstrap.js.map +1 -0
  292. package/server/src/lib/security-management-server.module.d.ts +7 -0
  293. package/server/src/lib/security-management-server.module.js +190 -0
  294. package/server/src/lib/security-management-server.module.js.map +1 -0
  295. package/server/src/lib/two-factor/admin-reset-two-factor.command.d.ts +8 -0
  296. package/server/src/lib/two-factor/admin-reset-two-factor.command.js +35 -0
  297. package/server/src/lib/two-factor/admin-reset-two-factor.command.js.map +1 -0
  298. package/server/src/lib/two-factor/confirm-two-factor-enrollment.command.d.ts +8 -0
  299. package/server/src/lib/two-factor/confirm-two-factor-enrollment.command.js +34 -0
  300. package/server/src/lib/two-factor/confirm-two-factor-enrollment.command.js.map +1 -0
  301. package/server/src/lib/two-factor/disable-two-factor.command.d.ts +8 -0
  302. package/server/src/lib/two-factor/disable-two-factor.command.js +31 -0
  303. package/server/src/lib/two-factor/disable-two-factor.command.js.map +1 -0
  304. package/server/src/lib/two-factor/generate-two-factor-recovery-codes.command.d.ts +8 -0
  305. package/server/src/lib/two-factor/generate-two-factor-recovery-codes.command.js +34 -0
  306. package/server/src/lib/two-factor/generate-two-factor-recovery-codes.command.js.map +1 -0
  307. package/server/src/lib/two-factor/get-two-factor-status.command.d.ts +8 -0
  308. package/server/src/lib/two-factor/get-two-factor-status.command.js +31 -0
  309. package/server/src/lib/two-factor/get-two-factor-status.command.js.map +1 -0
  310. package/server/src/lib/two-factor/recovery-codes.util.d.ts +11 -0
  311. package/server/src/lib/two-factor/recovery-codes.util.js +73 -0
  312. package/server/src/lib/two-factor/recovery-codes.util.js.map +1 -0
  313. package/server/src/lib/two-factor/start-two-factor-enrollment.command.d.ts +8 -0
  314. package/server/src/lib/two-factor/start-two-factor-enrollment.command.js +31 -0
  315. package/server/src/lib/two-factor/start-two-factor-enrollment.command.js.map +1 -0
  316. package/server/src/lib/two-factor/totp.util.d.ts +32 -0
  317. package/server/src/lib/two-factor/totp.util.js +128 -0
  318. package/server/src/lib/two-factor/totp.util.js.map +1 -0
  319. package/server/src/lib/two-factor/two-factor-encryption.util.d.ts +25 -0
  320. package/server/src/lib/two-factor/two-factor-encryption.util.js +123 -0
  321. package/server/src/lib/two-factor/two-factor-encryption.util.js.map +1 -0
  322. package/server/src/lib/two-factor/two-factor-gate.bootstrap.d.ts +9 -0
  323. package/server/src/lib/two-factor/two-factor-gate.bootstrap.js +65 -0
  324. package/server/src/lib/two-factor/two-factor-gate.bootstrap.js.map +1 -0
  325. package/server/src/lib/two-factor/two-factor-redis.store.d.ts +63 -0
  326. package/server/src/lib/two-factor/two-factor-redis.store.js +321 -0
  327. package/server/src/lib/two-factor/two-factor-redis.store.js.map +1 -0
  328. package/server/src/lib/two-factor/user-two-factor.service.d.ts +62 -0
  329. package/server/src/lib/two-factor/user-two-factor.service.js +573 -0
  330. package/server/src/lib/two-factor/user-two-factor.service.js.map +1 -0
  331. package/server/src/lib/two-factor/verify-two-factor-login.command.d.ts +18 -0
  332. package/server/src/lib/two-factor/verify-two-factor-login.command.js +54 -0
  333. package/server/src/lib/two-factor/verify-two-factor-login.command.js.map +1 -0
  334. package/server/src/lib/user-invitation/accept-invitation.command.d.ts +8 -0
  335. package/server/src/lib/user-invitation/accept-invitation.command.js +41 -0
  336. package/server/src/lib/user-invitation/accept-invitation.command.js.map +1 -0
  337. package/server/src/lib/user-invitation/accept-my-invitation.command.d.ts +8 -0
  338. package/server/src/lib/user-invitation/accept-my-invitation.command.js +40 -0
  339. package/server/src/lib/user-invitation/accept-my-invitation.command.js.map +1 -0
  340. package/server/src/lib/user-invitation/approve-join-request.command.d.ts +8 -0
  341. package/server/src/lib/user-invitation/approve-join-request.command.js +41 -0
  342. package/server/src/lib/user-invitation/approve-join-request.command.js.map +1 -0
  343. package/server/src/lib/user-invitation/cancel-invitation.command.d.ts +8 -0
  344. package/server/src/lib/user-invitation/cancel-invitation.command.js +37 -0
  345. package/server/src/lib/user-invitation/cancel-invitation.command.js.map +1 -0
  346. package/server/src/lib/user-invitation/cancel-my-join-request.command.d.ts +8 -0
  347. package/server/src/lib/user-invitation/cancel-my-join-request.command.js +40 -0
  348. package/server/src/lib/user-invitation/cancel-my-join-request.command.js.map +1 -0
  349. package/server/src/lib/user-invitation/create-user-in-tenant.command.d.ts +8 -0
  350. package/server/src/lib/user-invitation/create-user-in-tenant.command.js +37 -0
  351. package/server/src/lib/user-invitation/create-user-in-tenant.command.js.map +1 -0
  352. package/server/src/lib/user-invitation/decline-invitation.command.d.ts +8 -0
  353. package/server/src/lib/user-invitation/decline-invitation.command.js +37 -0
  354. package/server/src/lib/user-invitation/decline-invitation.command.js.map +1 -0
  355. package/server/src/lib/user-invitation/invite-user.command.d.ts +8 -0
  356. package/server/src/lib/user-invitation/invite-user.command.js +37 -0
  357. package/server/src/lib/user-invitation/invite-user.command.js.map +1 -0
  358. package/server/src/lib/user-invitation/list-invite-assignable-roles.command.d.ts +8 -0
  359. package/server/src/lib/user-invitation/list-invite-assignable-roles.command.js +41 -0
  360. package/server/src/lib/user-invitation/list-invite-assignable-roles.command.js.map +1 -0
  361. package/server/src/lib/user-invitation/list-my-join-requests.command.d.ts +8 -0
  362. package/server/src/lib/user-invitation/list-my-join-requests.command.js +40 -0
  363. package/server/src/lib/user-invitation/list-my-join-requests.command.js.map +1 -0
  364. package/server/src/lib/user-invitation/list-my-pending-invitations.command.d.ts +8 -0
  365. package/server/src/lib/user-invitation/list-my-pending-invitations.command.js +37 -0
  366. package/server/src/lib/user-invitation/list-my-pending-invitations.command.js.map +1 -0
  367. package/server/src/lib/user-invitation/list-tenant-entitled-applications.command.d.ts +8 -0
  368. package/server/src/lib/user-invitation/list-tenant-entitled-applications.command.js +41 -0
  369. package/server/src/lib/user-invitation/list-tenant-entitled-applications.command.js.map +1 -0
  370. package/server/src/lib/user-invitation/lookup-tenant-by-unique-name.command.d.ts +8 -0
  371. package/server/src/lib/user-invitation/lookup-tenant-by-unique-name.command.js +40 -0
  372. package/server/src/lib/user-invitation/lookup-tenant-by-unique-name.command.js.map +1 -0
  373. package/server/src/lib/user-invitation/reject-join-request.command.d.ts +8 -0
  374. package/server/src/lib/user-invitation/reject-join-request.command.js +41 -0
  375. package/server/src/lib/user-invitation/reject-join-request.command.js.map +1 -0
  376. package/server/src/lib/user-invitation/request-tenant-membership.command.d.ts +8 -0
  377. package/server/src/lib/user-invitation/request-tenant-membership.command.js +40 -0
  378. package/server/src/lib/user-invitation/request-tenant-membership.command.js.map +1 -0
  379. package/server/src/lib/user-invitation/resend-invitation.command.d.ts +12 -0
  380. package/server/src/lib/user-invitation/resend-invitation.command.js +37 -0
  381. package/server/src/lib/user-invitation/resend-invitation.command.js.map +1 -0
  382. package/server/src/lib/user-invitation/user-invitation-application-access.util.d.ts +25 -0
  383. package/server/src/lib/user-invitation/user-invitation-application-access.util.js +121 -0
  384. package/server/src/lib/user-invitation/user-invitation-application-access.util.js.map +1 -0
  385. package/server/src/lib/user-invitation/user-invitation.service.d.ts +162 -0
  386. package/server/src/lib/user-invitation/user-invitation.service.js +1658 -0
  387. package/server/src/lib/user-invitation/user-invitation.service.js.map +1 -0
  388. package/contracts/src/datasource.keys.d.ts +0 -4
  389. package/contracts/src/datasource.keys.js +0 -10
  390. package/contracts/src/datasource.keys.js.map +0 -1
  391. package/src/index.d.ts +0 -5
  392. package/src/index.js +0 -13
  393. package/src/index.js.map +0 -1
  394. package/src/lib/middlewares/user-effective-state.middleware.js.map +0 -1
  395. package/src/lib/password-reset/complete-password-reset.command.js.map +0 -1
  396. package/src/lib/password-reset/send-password-reset-email.command.js.map +0 -1
  397. package/src/lib/password-reset/user-password-reset.service.js.map +0 -1
  398. package/src/lib/security-management-server.module.d.ts +0 -2
  399. package/src/lib/security-management-server.module.js +0 -48
  400. package/src/lib/security-management-server.module.js.map +0 -1
  401. package/src/lib/seed/index.d.ts +0 -22
  402. package/src/lib/seed/index.js +0 -24
  403. package/src/lib/seed/index.js.map +0 -1
  404. package/src/lib/seed/policy/index.d.ts +0 -2
  405. package/src/lib/seed/policy/index.js +0 -6
  406. package/src/lib/seed/policy/index.js.map +0 -1
  407. package/src/lib/seed/policy/policy.mock.d.ts +0 -7
  408. package/src/lib/seed/policy/policy.mock.js +0 -40
  409. package/src/lib/seed/policy/policy.mock.js.map +0 -1
  410. package/src/lib/seed/policy/policy.seed.d.ts +0 -5
  411. package/src/lib/seed/policy/policy.seed.js +0 -31
  412. package/src/lib/seed/policy/policy.seed.js.map +0 -1
  413. package/src/lib/seed/role/index.d.ts +0 -4
  414. package/src/lib/seed/role/index.js +0 -8
  415. package/src/lib/seed/role/index.js.map +0 -1
  416. package/src/lib/seed/role/role-ids.constants.d.ts +0 -14
  417. package/src/lib/seed/role/role-ids.constants.js +0 -20
  418. package/src/lib/seed/role/role-ids.constants.js.map +0 -1
  419. package/src/lib/seed/role/role-permission-keys.constants.d.ts +0 -578
  420. package/src/lib/seed/role/role-permission-keys.constants.js +0 -620
  421. package/src/lib/seed/role/role-permission-keys.constants.js.map +0 -1
  422. package/src/lib/seed/role/role.mock.d.ts +0 -4
  423. package/src/lib/seed/role/role.mock.js +0 -321
  424. package/src/lib/seed/role/role.mock.js.map +0 -1
  425. package/src/lib/seed/role/role.seed.d.ts +0 -5
  426. package/src/lib/seed/role/role.seed.js +0 -31
  427. package/src/lib/seed/role/role.seed.js.map +0 -1
  428. package/src/lib/seed/security-management-seed.provider.d.ts +0 -4
  429. package/src/lib/seed/security-management-seed.provider.js +0 -18
  430. package/src/lib/seed/security-management-seed.provider.js.map +0 -1
  431. package/src/lib/seed/security-management-seed.tokens.d.ts +0 -1
  432. package/src/lib/seed/security-management-seed.tokens.js +0 -7
  433. package/src/lib/seed/security-management-seed.tokens.js.map +0 -1
  434. package/src/lib/seed/security-management.seed-catalog.d.ts +0 -2
  435. package/src/lib/seed/security-management.seed-catalog.js +0 -17
  436. package/src/lib/seed/security-management.seed-catalog.js.map +0 -1
  437. package/src/lib/seed/tenant/index.d.ts +0 -1
  438. package/src/lib/seed/tenant/tenant-ids.constants.d.ts +0 -11
  439. package/src/lib/seed/tenant/tenant-ids.constants.js +0 -17
  440. package/src/lib/seed/tenant/tenant-ids.constants.js.map +0 -1
  441. package/src/lib/seed/user/index.d.ts +0 -4
  442. package/src/lib/seed/user/index.js +0 -13
  443. package/src/lib/seed/user/index.js.map +0 -1
  444. package/src/lib/seed/user/resolve-user-effective-state.util.d.ts +0 -4
  445. package/src/lib/seed/user/resolve-user-effective-state.util.js +0 -10
  446. package/src/lib/seed/user/resolve-user-effective-state.util.js.map +0 -1
  447. package/src/lib/seed/user/user.mock.d.ts +0 -21
  448. package/src/lib/seed/user/user.mock.js +0 -338
  449. package/src/lib/seed/user/user.mock.js.map +0 -1
  450. package/src/lib/seed/user/user.seed.d.ts +0 -5
  451. package/src/lib/seed/user/user.seed.js +0 -31
  452. package/src/lib/seed/user/user.seed.js.map +0 -1
  453. /package/{src → server/src}/lib/middlewares/user-effective-state.middleware.d.ts +0 -0
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StartTwoFactorEnrollmentCommand = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const abstract_1 = require("@acorex-platform/framework-server/domain/abstract");
7
+ const module_security_management_contracts_1 = require("@acorex-platform/module-security-management-client/contracts");
8
+ const user_two_factor_service_1 = require("./user-two-factor.service");
9
+ //#region ----- Start two-factor enrollment command -----
10
+ let StartTwoFactorEnrollmentCommand = class StartTwoFactorEnrollmentCommand {
11
+ constructor(twoFactor) {
12
+ this.twoFactor = twoFactor;
13
+ }
14
+ execute() {
15
+ return tslib_1.__awaiter(this, arguments, void 0, function* (input = { password: '' }) {
16
+ const result = yield this.twoFactor.startEnrollment(input);
17
+ if (!result.success) {
18
+ return { success: false, message: { code: result.code } };
19
+ }
20
+ return { success: true, kind: 'object', data: result.data };
21
+ });
22
+ }
23
+ };
24
+ exports.StartTwoFactorEnrollmentCommand = StartTwoFactorEnrollmentCommand;
25
+ exports.StartTwoFactorEnrollmentCommand = StartTwoFactorEnrollmentCommand = tslib_1.__decorate([
26
+ (0, abstract_1.ServerHandler)({ key: module_security_management_contracts_1.AXMSecurityManagementServerCommands.StartTwoFactorEnrollment, auth: 'session' }),
27
+ (0, common_1.Injectable)(),
28
+ tslib_1.__metadata("design:paramtypes", [user_two_factor_service_1.UserTwoFactorService])
29
+ ], StartTwoFactorEnrollmentCommand);
30
+ //#endregion
31
+ //# sourceMappingURL=start-two-factor-enrollment.command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start-two-factor-enrollment.command.js","sourceRoot":"","sources":["../../../../../../../libs/modules/security-management/server/src/lib/two-factor/start-two-factor-enrollment.command.ts"],"names":[],"mappings":";;;;AAAA,2CAA4C;AAE5C,gFAAkF;AAClF,gHAI+D;AAE/D,uEAAiE;AAEjE,yDAAyD;AAIlD,IAAM,+BAA+B,GAArC,MAAM,+BAA+B;IAG1C,YAA6B,SAA+B;QAA/B,cAAS,GAAT,SAAS,CAAsB;IAAG,CAAC;IAE1D,OAAO;qEACX,QAA0C,EAAE,QAAQ,EAAE,EAAE,EAAE;YAE1D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;YAC3D,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;YAC5D,CAAC;YACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;QAC9D,CAAC;KAAA;CACF,CAAA;AAdY,0EAA+B;0CAA/B,+BAA+B;IAF3C,IAAA,wBAAa,EAAC,EAAE,GAAG,EAAE,0EAAmC,CAAC,wBAAwB,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;IACrG,IAAA,mBAAU,GAAE;6CAI6B,8CAAoB;GAHjD,+BAA+B,CAc3C;AAED,YAAY"}
@@ -0,0 +1,32 @@
1
+ export declare const TOTP_DIGITS = 6;
2
+ export declare const TOTP_PERIOD_SECONDS = 30;
3
+ export declare const TOTP_WINDOW = 1;
4
+ export declare const TOTP_SECRET_BYTES = 20;
5
+ export declare function base32Encode(bytes: Buffer): string;
6
+ export declare function base32Decode(input: string): Buffer;
7
+ /** RFC 4226 HOTP (HMAC-SHA1). */
8
+ export declare function hotp(secret: Buffer, counter: number, digits?: number): string;
9
+ export declare function totpTimeStep(unixSeconds: number, period?: number): number;
10
+ export declare function generateTotp(secret: Buffer, unixSeconds?: number, digits?: number, period?: number): string;
11
+ export interface TotpVerifyResult {
12
+ valid: boolean;
13
+ /** Matched time-step when valid. */
14
+ step?: number;
15
+ }
16
+ /**
17
+ * Verifies TOTP with ±window steps. Caller must reject when `step` was already consumed.
18
+ */
19
+ export declare function verifyTotp(secret: Buffer, code: string, options?: {
20
+ unixSeconds?: number;
21
+ window?: number;
22
+ digits?: number;
23
+ period?: number;
24
+ }): TotpVerifyResult;
25
+ export declare function generateTotpSecretBytes(byteLength?: number): Buffer;
26
+ export declare function buildOtpAuthUri(params: {
27
+ secretBase32: string;
28
+ accountName: string;
29
+ issuer: string;
30
+ digits?: number;
31
+ period?: number;
32
+ }): string;
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TOTP_SECRET_BYTES = exports.TOTP_WINDOW = exports.TOTP_PERIOD_SECONDS = exports.TOTP_DIGITS = void 0;
4
+ exports.base32Encode = base32Encode;
5
+ exports.base32Decode = base32Decode;
6
+ exports.hotp = hotp;
7
+ exports.totpTimeStep = totpTimeStep;
8
+ exports.generateTotp = generateTotp;
9
+ exports.verifyTotp = verifyTotp;
10
+ exports.generateTotpSecretBytes = generateTotpSecretBytes;
11
+ exports.buildOtpAuthUri = buildOtpAuthUri;
12
+ const crypto_1 = require("crypto");
13
+ //#region ----- Constants -----
14
+ const BASE32_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
15
+ exports.TOTP_DIGITS = 6;
16
+ exports.TOTP_PERIOD_SECONDS = 30;
17
+ exports.TOTP_WINDOW = 1;
18
+ exports.TOTP_SECRET_BYTES = 20;
19
+ //#endregion
20
+ //#region ----- Base32 -----
21
+ function base32Encode(bytes) {
22
+ let bits = 0;
23
+ let value = 0;
24
+ let output = '';
25
+ for (const byte of bytes) {
26
+ value = (value << 8) | byte;
27
+ bits += 8;
28
+ while (bits >= 5) {
29
+ output += BASE32_ALPHABET[(value >>> (bits - 5)) & 31];
30
+ bits -= 5;
31
+ }
32
+ }
33
+ if (bits > 0) {
34
+ output += BASE32_ALPHABET[(value << (5 - bits)) & 31];
35
+ }
36
+ return output;
37
+ }
38
+ function base32Decode(input) {
39
+ const cleaned = input.replace(/=+$/g, '').replace(/\s+/g, '').toUpperCase();
40
+ let bits = 0;
41
+ let value = 0;
42
+ const bytes = [];
43
+ for (const char of cleaned) {
44
+ const idx = BASE32_ALPHABET.indexOf(char);
45
+ if (idx < 0) {
46
+ throw new Error('Invalid Base32 character');
47
+ }
48
+ value = (value << 5) | idx;
49
+ bits += 5;
50
+ if (bits >= 8) {
51
+ bytes.push((value >>> (bits - 8)) & 0xff);
52
+ bits -= 8;
53
+ }
54
+ }
55
+ return Buffer.from(bytes);
56
+ }
57
+ //#endregion
58
+ //#region ----- HOTP / TOTP -----
59
+ function counterToBuffer(counter) {
60
+ const buf = Buffer.alloc(8);
61
+ let c = counter;
62
+ for (let i = 7; i >= 0; i -= 1) {
63
+ buf[i] = c & 0xff;
64
+ c = Math.floor(c / 256);
65
+ }
66
+ return buf;
67
+ }
68
+ /** RFC 4226 HOTP (HMAC-SHA1). */
69
+ function hotp(secret, counter, digits = exports.TOTP_DIGITS) {
70
+ const hmac = (0, crypto_1.createHmac)('sha1', secret).update(counterToBuffer(counter)).digest();
71
+ const offset = hmac[hmac.length - 1] & 0x0f;
72
+ const binary = ((hmac[offset] & 0x7f) << 24) |
73
+ ((hmac[offset + 1] & 0xff) << 16) |
74
+ ((hmac[offset + 2] & 0xff) << 8) |
75
+ (hmac[offset + 3] & 0xff);
76
+ const otp = binary % Math.pow(10, digits);
77
+ return String(otp).padStart(digits, '0');
78
+ }
79
+ function totpTimeStep(unixSeconds, period = exports.TOTP_PERIOD_SECONDS) {
80
+ return Math.floor(unixSeconds / period);
81
+ }
82
+ function generateTotp(secret, unixSeconds = Math.floor(Date.now() / 1000), digits = exports.TOTP_DIGITS, period = exports.TOTP_PERIOD_SECONDS) {
83
+ return hotp(secret, totpTimeStep(unixSeconds, period), digits);
84
+ }
85
+ /**
86
+ * Verifies TOTP with ±window steps. Caller must reject when `step` was already consumed.
87
+ */
88
+ function verifyTotp(secret, code, options) {
89
+ var _a, _b, _c, _d;
90
+ const normalized = String(code !== null && code !== void 0 ? code : '').replace(/\s+/g, '');
91
+ const digits = (_a = options === null || options === void 0 ? void 0 : options.digits) !== null && _a !== void 0 ? _a : exports.TOTP_DIGITS;
92
+ const period = (_b = options === null || options === void 0 ? void 0 : options.period) !== null && _b !== void 0 ? _b : exports.TOTP_PERIOD_SECONDS;
93
+ const window = (_c = options === null || options === void 0 ? void 0 : options.window) !== null && _c !== void 0 ? _c : exports.TOTP_WINDOW;
94
+ const unixSeconds = (_d = options === null || options === void 0 ? void 0 : options.unixSeconds) !== null && _d !== void 0 ? _d : Math.floor(Date.now() / 1000);
95
+ if (!/^\d+$/.test(normalized) || normalized.length !== digits) {
96
+ return { valid: false };
97
+ }
98
+ const expectedBuf = Buffer.from(normalized);
99
+ const center = totpTimeStep(unixSeconds, period);
100
+ for (let delta = -window; delta <= window; delta += 1) {
101
+ const step = center + delta;
102
+ if (step < 0) {
103
+ continue;
104
+ }
105
+ const candidate = Buffer.from(hotp(secret, step, digits));
106
+ if (candidate.length === expectedBuf.length && (0, crypto_1.timingSafeEqual)(candidate, expectedBuf)) {
107
+ return { valid: true, step };
108
+ }
109
+ }
110
+ return { valid: false };
111
+ }
112
+ function generateTotpSecretBytes(byteLength = exports.TOTP_SECRET_BYTES) {
113
+ return (0, crypto_1.randomBytes)(byteLength);
114
+ }
115
+ function buildOtpAuthUri(params) {
116
+ var _a, _b;
117
+ const label = encodeURIComponent(`${params.issuer}:${params.accountName}`);
118
+ const query = new URLSearchParams({
119
+ secret: params.secretBase32,
120
+ issuer: params.issuer,
121
+ algorithm: 'SHA1',
122
+ digits: String((_a = params.digits) !== null && _a !== void 0 ? _a : exports.TOTP_DIGITS),
123
+ period: String((_b = params.period) !== null && _b !== void 0 ? _b : exports.TOTP_PERIOD_SECONDS),
124
+ });
125
+ return `otpauth://totp/${label}?${query.toString()}`;
126
+ }
127
+ //#endregion
128
+ //# sourceMappingURL=totp.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"totp.util.js","sourceRoot":"","sources":["../../../../../../../libs/modules/security-management/server/src/lib/two-factor/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I,IAAA,wBAAe,EAAC,SAAS,EAAE,WAAW,CAAC,EAAE,CAAC;YACvF,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QAC/B,CAAC;IACH,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC1B,CAAC;AAED,SAAgB,uBAAuB,CAAC,UAAU,GAAG,yBAAiB;IACpE,OAAO,IAAA,oBAAW,EAAC,UAAU,CAAC,CAAC;AACjC,CAAC;AAED,SAAgB,eAAe,CAAC,MAM/B;;IACC,MAAM,KAAK,GAAG,kBAAkB,CAAC,GAAG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;IAC3E,MAAM,KAAK,GAAG,IAAI,eAAe,CAAC;QAChC,MAAM,EAAE,MAAM,CAAC,YAAY;QAC3B,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,SAAS,EAAE,MAAM;QACjB,MAAM,EAAE,MAAM,CAAC,MAAA,MAAM,CAAC,MAAM,mCAAI,mBAAW,CAAC;QAC5C,MAAM,EAAE,MAAM,CAAC,MAAA,MAAM,CAAC,MAAM,mCAAI,2BAAmB,CAAC;KACrD,CAAC,CAAC;IACH,OAAO,kBAAkB,KAAK,IAAI,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC;AACvD,CAAC;AAED,YAAY"}
@@ -0,0 +1,25 @@
1
+ export interface AXMTwoFactorEncryptedSecret {
2
+ encryptedSecret: string;
3
+ iv: string;
4
+ authTag: string;
5
+ keyVersion: number;
6
+ }
7
+ /**
8
+ * Loads 2FA-only versioned keys from env.
9
+ * `AUTH_2FA_ENCRYPTION_KEYS` JSON object: `{ "1": "<key>", "2": "<key>" }`
10
+ * or colon map `1=<key>;2=<key>`.
11
+ */
12
+ export declare function loadTwoFactorEncryptionKeyring(): {
13
+ keys: Map<number, Buffer>;
14
+ currentVersion: number;
15
+ };
16
+ export declare function encryptTwoFactorSecret(plaintextSecret: Buffer, keyring?: {
17
+ keys: Map<number, Buffer>;
18
+ currentVersion: number;
19
+ }): AXMTwoFactorEncryptedSecret;
20
+ export declare function decryptTwoFactorSecret(envelope: Pick<AXMTwoFactorEncryptedSecret, 'encryptedSecret' | 'iv' | 'authTag' | 'keyVersion'>, keyring?: {
21
+ keys: Map<number, Buffer>;
22
+ currentVersion: number;
23
+ }): Buffer;
24
+ /** Constant-time compare for equal-length buffers. */
25
+ export declare function timingSafeEqualBuffers(a: Buffer, b: Buffer): boolean;
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadTwoFactorEncryptionKeyring = loadTwoFactorEncryptionKeyring;
4
+ exports.encryptTwoFactorSecret = encryptTwoFactorSecret;
5
+ exports.decryptTwoFactorSecret = decryptTwoFactorSecret;
6
+ exports.timingSafeEqualBuffers = timingSafeEqualBuffers;
7
+ const crypto_1 = require("crypto");
8
+ //#endregion
9
+ //#region ----- Constants -----
10
+ const ALGORITHM = 'aes-256-gcm';
11
+ const IV_BYTES = 12;
12
+ const KEYS_ENV = 'AUTH_2FA_ENCRYPTION_KEYS';
13
+ const CURRENT_VERSION_ENV = 'AUTH_2FA_ENCRYPTION_KEY_CURRENT_VERSION';
14
+ //#endregion
15
+ //#region ----- Keyring -----
16
+ function parseKeyMaterial(raw) {
17
+ const trimmed = raw.trim();
18
+ if (/^[0-9a-fA-F]{64}$/.test(trimmed)) {
19
+ return Buffer.from(trimmed, 'hex');
20
+ }
21
+ try {
22
+ const fromBase64 = Buffer.from(trimmed, 'base64');
23
+ if (fromBase64.length === 32) {
24
+ return fromBase64;
25
+ }
26
+ }
27
+ catch (_a) {
28
+ // fall through
29
+ }
30
+ return (0, crypto_1.createHash)('sha256').update(trimmed, 'utf8').digest();
31
+ }
32
+ /**
33
+ * Loads 2FA-only versioned keys from env.
34
+ * `AUTH_2FA_ENCRYPTION_KEYS` JSON object: `{ "1": "<key>", "2": "<key>" }`
35
+ * or colon map `1=<key>;2=<key>`.
36
+ */
37
+ function loadTwoFactorEncryptionKeyring() {
38
+ var _a, _b;
39
+ const isProduction = process.env['NODE_ENV'] === 'production';
40
+ const rawKeys = (_a = process.env[KEYS_ENV]) === null || _a === void 0 ? void 0 : _a.trim();
41
+ const rawVersion = (_b = process.env[CURRENT_VERSION_ENV]) === null || _b === void 0 ? void 0 : _b.trim();
42
+ const keys = new Map();
43
+ if (rawKeys) {
44
+ if (rawKeys.startsWith('{')) {
45
+ const parsed = JSON.parse(rawKeys);
46
+ for (const [version, material] of Object.entries(parsed)) {
47
+ const v = Number(version);
48
+ if (!Number.isInteger(v) || v < 1 || typeof material !== 'string' || !material.trim()) {
49
+ throw new Error(`${KEYS_ENV} entry "${version}" is invalid`);
50
+ }
51
+ keys.set(v, parseKeyMaterial(material));
52
+ }
53
+ }
54
+ else {
55
+ for (const part of rawKeys.split(/[;,]/).map((p) => p.trim()).filter(Boolean)) {
56
+ const eq = part.indexOf('=');
57
+ if (eq <= 0) {
58
+ throw new Error(`${KEYS_ENV} must be JSON or version=key pairs`);
59
+ }
60
+ const v = Number(part.slice(0, eq).trim());
61
+ const material = part.slice(eq + 1).trim();
62
+ if (!Number.isInteger(v) || v < 1 || !material) {
63
+ throw new Error(`${KEYS_ENV} entry "${part}" is invalid`);
64
+ }
65
+ keys.set(v, parseKeyMaterial(material));
66
+ }
67
+ }
68
+ }
69
+ let currentVersion = rawVersion ? Number(rawVersion) : 1;
70
+ if (!Number.isInteger(currentVersion) || currentVersion < 1) {
71
+ throw new Error(`${CURRENT_VERSION_ENV} must be a positive integer`);
72
+ }
73
+ if (keys.size === 0) {
74
+ if (isProduction) {
75
+ throw new Error(`${KEYS_ENV} is required in production`);
76
+ }
77
+ keys.set(1, (0, crypto_1.createHash)('sha256').update('acorex-auth-2fa-dev-only', 'utf8').digest());
78
+ currentVersion = 1;
79
+ }
80
+ if (!keys.has(currentVersion)) {
81
+ throw new Error(`${CURRENT_VERSION_ENV}=${currentVersion} is missing from ${KEYS_ENV}`);
82
+ }
83
+ return { keys, currentVersion };
84
+ }
85
+ //#endregion
86
+ //#region ----- Encrypt / decrypt -----
87
+ function encryptTwoFactorSecret(plaintextSecret, keyring = loadTwoFactorEncryptionKeyring()) {
88
+ const key = keyring.keys.get(keyring.currentVersion);
89
+ if (!key) {
90
+ throw new Error('2FA encryption current key is unavailable');
91
+ }
92
+ const iv = (0, crypto_1.randomBytes)(IV_BYTES);
93
+ const cipher = (0, crypto_1.createCipheriv)(ALGORITHM, key, iv);
94
+ const encrypted = Buffer.concat([cipher.update(plaintextSecret), cipher.final()]);
95
+ const authTag = cipher.getAuthTag();
96
+ return {
97
+ encryptedSecret: encrypted.toString('base64'),
98
+ iv: iv.toString('base64'),
99
+ authTag: authTag.toString('base64'),
100
+ keyVersion: keyring.currentVersion,
101
+ };
102
+ }
103
+ function decryptTwoFactorSecret(envelope, keyring = loadTwoFactorEncryptionKeyring()) {
104
+ const key = keyring.keys.get(envelope.keyVersion);
105
+ if (!key) {
106
+ throw new Error(`2FA encryption key version ${envelope.keyVersion} is unavailable`);
107
+ }
108
+ const iv = Buffer.from(envelope.iv, 'base64');
109
+ const authTag = Buffer.from(envelope.authTag, 'base64');
110
+ const encrypted = Buffer.from(envelope.encryptedSecret, 'base64');
111
+ const decipher = (0, crypto_1.createDecipheriv)(ALGORITHM, key, iv);
112
+ decipher.setAuthTag(authTag);
113
+ return Buffer.concat([decipher.update(encrypted), decipher.final()]);
114
+ }
115
+ /** Constant-time compare for equal-length buffers. */
116
+ function timingSafeEqualBuffers(a, b) {
117
+ if (a.length !== b.length) {
118
+ return false;
119
+ }
120
+ return (0, crypto_1.timingSafeEqual)(a, b);
121
+ }
122
+ //#endregion
123
+ //# sourceMappingURL=two-factor-encryption.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"two-factor-encryption.util.js","sourceRoot":"","sources":["../../../../../../../libs/modules/security-management/server/src/lib/two-factor/two-factor-encryption.util.ts"],"names":[],"mappings":";;AA6CA,wEAsD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AG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACxD,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;IAClE,MAAM,QAAQ,GAAG,IAAA,yBAAgB,EAAC,SAAS,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;IACtD,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAC7B,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;AACvE,CAAC;AAED,sDAAsD;AACtD,SAAgB,sBAAsB,CAAC,CAAS,EAAE,CAAS;IACzD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAA,wBAAe,EAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC/B,CAAC;AAED,YAAY"}
@@ -0,0 +1,9 @@
1
+ import { type OnModuleInit } from '@nestjs/common';
2
+ import { UserTwoFactorService } from './user-two-factor.service';
3
+ export declare class TwoFactorGateBootstrap implements OnModuleInit {
4
+ private readonly twoFactor;
5
+ constructor(twoFactor: UserTwoFactorService);
6
+ onModuleInit(): void;
7
+ private afterPassword;
8
+ private verify;
9
+ }
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TwoFactorGateBootstrap = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const security_1 = require("@acorex-platform/framework-server/security");
7
+ const module_security_management_contracts_1 = require("@acorex-platform/module-security-management-client/contracts");
8
+ const user_two_factor_service_1 = require("./user-two-factor.service");
9
+ //#region ----- Two-factor gate bootstrap -----
10
+ let TwoFactorGateBootstrap = class TwoFactorGateBootstrap {
11
+ constructor(twoFactor) {
12
+ this.twoFactor = twoFactor;
13
+ }
14
+ onModuleInit() {
15
+ (0, security_1.configureAuthTwoFactorGate)({
16
+ afterPasswordAuthenticated: (user, options) => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.afterPassword(user, options); }),
17
+ verifyChallenge: (challengeId, code) => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.verify(challengeId, code); }),
18
+ });
19
+ }
20
+ afterPassword(user, options) {
21
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
22
+ var _a;
23
+ try {
24
+ const challenge = yield this.twoFactor.createLoginChallengeAfterPassword(user, options);
25
+ if (!challenge) {
26
+ return { requiresTwoFactor: false };
27
+ }
28
+ return challenge;
29
+ }
30
+ catch (error) {
31
+ const code = error && typeof error === 'object' && 'code' in error
32
+ ? String((_a = error.code) !== null && _a !== void 0 ? _a : '')
33
+ : '';
34
+ if (code === module_security_management_contracts_1.AXM_TWO_FACTOR_ERROR_CODES.InvalidConfiguration) {
35
+ return {
36
+ requiresTwoFactor: true,
37
+ blocked: true,
38
+ code: module_security_management_contracts_1.AXM_TWO_FACTOR_ERROR_CODES.InvalidConfiguration,
39
+ };
40
+ }
41
+ throw error;
42
+ }
43
+ });
44
+ }
45
+ verify(challengeId, code) {
46
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
47
+ const result = yield this.twoFactor.verifyLoginChallenge(challengeId, code);
48
+ if (!result.success) {
49
+ return { success: false, code: result.code };
50
+ }
51
+ return {
52
+ success: true,
53
+ userId: result.data.userId,
54
+ rememberMe: result.data.rememberMe,
55
+ };
56
+ });
57
+ }
58
+ };
59
+ exports.TwoFactorGateBootstrap = TwoFactorGateBootstrap;
60
+ exports.TwoFactorGateBootstrap = TwoFactorGateBootstrap = tslib_1.__decorate([
61
+ (0, common_1.Injectable)(),
62
+ tslib_1.__metadata("design:paramtypes", [user_two_factor_service_1.UserTwoFactorService])
63
+ ], TwoFactorGateBootstrap);
64
+ //#endregion
65
+ //# sourceMappingURL=two-factor-gate.bootstrap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"two-factor-gate.bootstrap.js","sourceRoot":"","sources":["../../../../../../../libs/modules/security-management/server/src/lib/two-factor/two-factor-gate.bootstrap.ts"],"names":[],"mappings":";;;;AAAA,2CAA+D;AAC/D,yEAGoD;AAEpD,gHAAmG;AAEnG,uEAAiE;AAEjE,+CAA+C;AAGxC,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IACjC,YAA6B,SAA+B;QAA/B,cAAS,GAAT,SAAS,CAAsB;IAAG,CAAC;IAEhE,YAAY;QACV,IAAA,qCAA0B,EAAC;YACzB,0BAA0B,EAAE,CAAO,IAAI,EAAE,OAAO,EAAE,EAAE,wDAAC,OAAA,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA,GAAA;YACtF,eAAe,EAAE,CAAO,WAAW,EAAE,IAAI,EAAE,EAAE,wDAAC,OAAA,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA,GAAA;SAC7E,CAAC,CAAC;IACL,CAAC;IAEa,aAAa,CACzB,IAAkC,EAClC,OAAkC;;;YAElC,IAAI,CAAC;gBACH,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,iCAAiC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;gBACxF,IAAI,CAAC,SAAS,EAAE,CAAC;oBACf,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC;gBACtC,CAAC;gBACD,OAAO,SAAS,CAAC;YACnB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,GACR,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,IAAI,KAAK;oBACnD,CAAC,CAAC,MAAM,CAAC,MAAC,KAA2B,CAAC,IAAI,mCAAI,EAAE,CAAC;oBACjD,CAAC,CAAC,EAAE,CAAC;gBACT,IAAI,IAAI,KAAK,iEAA0B,CAAC,oBAAoB,EAAE,CAAC;oBAC7D,OAAO;wBACL,iBAAiB,EAAE,IAAI;wBACvB,OAAO,EAAE,IAAI;wBACb,IAAI,EAAE,iEAA0B,CAAC,oBAAoB;qBACtD,CAAC;gBACJ,CAAC;gBACD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;KAAA;IAEa,MAAM,CAClB,WAAmB,EACnB,IAAY;;YAEZ,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;YAC5E,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;YAC/C,CAAC;YACD,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM;gBAC1B,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,UAAU;aACnC,CAAC;QACJ,CAAC;KAAA;CACF,CAAA;AAlDY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,mBAAU,GAAE;6CAE6B,8CAAoB;GADjD,sBAAsB,CAkDlC;AAED,YAAY"}
@@ -0,0 +1,63 @@
1
+ import { OnModuleDestroy } from '@nestjs/common';
2
+ import type { AXMTwoFactorEncryptedSecret } from './two-factor-encryption.util';
3
+ export interface TwoFactorEnrollmentRecord {
4
+ userId: string;
5
+ /** AES-GCM envelope for temporary TOTP secret (never plaintext in Redis). */
6
+ secret: AXMTwoFactorEncryptedSecret;
7
+ createdAt: string;
8
+ expiresAt: string;
9
+ }
10
+ export interface TwoFactorLoginChallengeRecord {
11
+ userId: string;
12
+ username?: string;
13
+ rememberMe?: boolean;
14
+ createdAt: string;
15
+ expiresAt: string;
16
+ }
17
+ export declare const TWO_FACTOR_TTL_MS: number;
18
+ export declare class TwoFactorRedisStore implements OnModuleDestroy {
19
+ private readonly logger;
20
+ private readonly redis;
21
+ private readonly local;
22
+ constructor();
23
+ private enrollKey;
24
+ private challengeKey;
25
+ private challengeAttemptsKey;
26
+ private userAttemptsKey;
27
+ private userChallengesIndexKey;
28
+ private stepLockKey;
29
+ private recoveryLockKey;
30
+ saveEnrollment(enrollmentId: string, record: TwoFactorEnrollmentRecord, ttlMs?: number): Promise<void>;
31
+ getEnrollment(enrollmentId: string): Promise<TwoFactorEnrollmentRecord | null>;
32
+ consumeEnrollment(enrollmentId: string): Promise<TwoFactorEnrollmentRecord | null>;
33
+ deleteEnrollment(enrollmentId: string): Promise<void>;
34
+ saveLoginChallenge(challengeId: string, record: TwoFactorLoginChallengeRecord, ttlMs?: number): Promise<void>;
35
+ getLoginChallenge(challengeId: string): Promise<TwoFactorLoginChallengeRecord | null>;
36
+ consumeLoginChallenge(challengeId: string): Promise<TwoFactorLoginChallengeRecord | null>;
37
+ invalidateChallengesForUser(userId: string): Promise<void>;
38
+ incrementAttemptCounters(challengeId: string, userId: string, ttlMs?: number): Promise<{
39
+ challengeAttempts: number;
40
+ userAttempts: number;
41
+ }>;
42
+ getAttemptCounters(challengeId: string, userId: string): Promise<{
43
+ challengeAttempts: number;
44
+ userAttempts: number;
45
+ }>;
46
+ clearAttemptCounters(challengeId: string, userId: string): Promise<void>;
47
+ /** Returns true when this process acquired the step lock (first consumer). */
48
+ tryAcquireStepLock(userId: string, step: number, ttlMs: number): Promise<boolean>;
49
+ /** One-shot lock so concurrent recovery-code use allows only one success. */
50
+ tryAcquireRecoveryLock(userId: string, normalizedCode: string, ttlMs: number): Promise<boolean>;
51
+ onModuleDestroy(): Promise<void>;
52
+ private tryAcquireLock;
53
+ private purgeExpiredLocal;
54
+ private setJson;
55
+ private getJson;
56
+ private consumeJson;
57
+ private del;
58
+ private incrWithTtl;
59
+ private getInt;
60
+ private addToSet;
61
+ private removeFromSet;
62
+ private getSetMembers;
63
+ }