@venizia/ignis 0.4.8-9 → 0.5.0-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 (265) hide show
  1. package/dist/esm/base/applications/base.js +5 -2
  2. package/dist/esm/base/applications/base.js.map +1 -1
  3. package/dist/esm/base/middlewares/request-spy/request-spy.middleware.js +1 -1
  4. package/dist/esm/base/middlewares/request-spy/request-spy.middleware.js.map +1 -1
  5. package/dist/esm/components/api-reference/common/keys.d.ts +2 -1
  6. package/dist/esm/components/api-reference/common/keys.js +4 -1
  7. package/dist/esm/components/api-reference/common/keys.js.map +1 -1
  8. package/dist/esm/components/api-reference/common/types.d.ts +7 -4
  9. package/dist/esm/components/api-reference/common/types.js.map +1 -1
  10. package/dist/esm/components/api-reference/component.js +8 -3
  11. package/dist/esm/components/api-reference/component.js.map +1 -1
  12. package/dist/esm/components/auth/authenticate/component.js +13 -18
  13. package/dist/esm/components/auth/authenticate/component.js.map +1 -1
  14. package/dist/esm/components/auth/authenticate/controllers/factory.d.ts +3 -3
  15. package/dist/esm/components/auth/authenticate/controllers/factory.js +1 -1
  16. package/dist/esm/components/auth/authenticate/controllers/factory.js.map +1 -1
  17. package/dist/esm/components/auth/authenticate/controllers/jwks/controller.js.map +1 -1
  18. package/dist/esm/components/auth/authenticate/controllers/jwks/definitions.d.ts +2 -2
  19. package/dist/esm/components/auth/authenticate/controllers/service-certs/controller.js.map +1 -1
  20. package/dist/esm/components/auth/authenticate/controllers/service-certs/definitions.d.ts +2 -2
  21. package/dist/esm/components/auth/authenticate/services/basic/service.js +1 -1
  22. package/dist/esm/components/auth/authenticate/services/basic/service.js.map +1 -1
  23. package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.d.ts +5 -3
  24. package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.js +19 -2
  25. package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.js.map +1 -1
  26. package/dist/esm/components/auth/authenticate/services/bearer/jwks/issuer.service.d.ts +3 -3
  27. package/dist/esm/components/auth/authenticate/services/bearer/jwks/issuer.service.js +1 -1
  28. package/dist/esm/components/auth/authenticate/services/bearer/jwks/issuer.service.js.map +1 -1
  29. package/dist/esm/components/auth/authenticate/services/bearer/jwks/verifier.service.d.ts +3 -3
  30. package/dist/esm/components/auth/authenticate/services/bearer/jwks/verifier.service.js +2 -2
  31. package/dist/esm/components/auth/authenticate/services/bearer/jwks/verifier.service.js.map +1 -1
  32. package/dist/esm/components/auth/authenticate/services/bearer/jws.service.d.ts +3 -3
  33. package/dist/esm/components/auth/authenticate/services/bearer/jws.service.js +1 -1
  34. package/dist/esm/components/auth/authenticate/services/bearer/jws.service.js.map +1 -1
  35. package/dist/esm/components/auth/authenticate/services/jwks-url-policy.d.ts +10 -22
  36. package/dist/esm/components/auth/authenticate/services/jwks-url-policy.js +16 -112
  37. package/dist/esm/components/auth/authenticate/services/jwks-url-policy.js.map +1 -1
  38. package/dist/esm/components/auth/authenticate/services/service/signer.service.d.ts +11 -0
  39. package/dist/esm/components/auth/authenticate/services/service/signer.service.js +18 -0
  40. package/dist/esm/components/auth/authenticate/services/service/signer.service.js.map +1 -1
  41. package/dist/esm/components/auth/authenticate/services/service/verifier.service.js +1 -1
  42. package/dist/esm/components/auth/authenticate/services/service/verifier.service.js.map +1 -1
  43. package/dist/esm/components/auth/authenticate/strategies/basic.strategy.js.map +1 -1
  44. package/dist/esm/components/auth/authenticate/strategies/jwks/issuer.js.map +1 -1
  45. package/dist/esm/components/auth/authenticate/strategies/jwks/verifier.js.map +1 -1
  46. package/dist/esm/components/auth/authenticate/strategies/jws.strategy.js.map +1 -1
  47. package/dist/esm/components/auth/authenticate/strategies/service.strategy.js.map +1 -1
  48. package/dist/esm/components/auth/authorize/adapters/common/types.d.ts +1 -2
  49. package/dist/esm/components/auth/authorize/adapters/common/types.js.map +1 -1
  50. package/dist/esm/components/auth/authorize/component.js.map +1 -1
  51. package/dist/esm/components/controller/grpc/common/types.d.ts +1 -1
  52. package/dist/esm/components/controller/grpc/common/types.js +4 -1
  53. package/dist/esm/components/controller/grpc/common/types.js.map +1 -1
  54. package/dist/esm/components/controller/grpc/grpc.component.js.map +1 -1
  55. package/dist/esm/components/health-check/common/keys.d.ts +4 -2
  56. package/dist/esm/components/health-check/common/keys.js +7 -2
  57. package/dist/esm/components/health-check/common/keys.js.map +1 -1
  58. package/dist/esm/components/health-check/common/types.d.ts +1 -1
  59. package/dist/esm/components/health-check/common/types.js.map +1 -1
  60. package/dist/esm/components/health-check/component.js +1 -3
  61. package/dist/esm/components/health-check/component.js.map +1 -1
  62. package/dist/esm/components/mail/common/constants.d.ts +32 -14
  63. package/dist/esm/components/mail/common/constants.js +25 -32
  64. package/dist/esm/components/mail/common/constants.js.map +1 -1
  65. package/dist/esm/components/mail/common/errors.d.ts +19 -1
  66. package/dist/esm/components/mail/common/errors.js +13 -1
  67. package/dist/esm/components/mail/common/errors.js.map +1 -1
  68. package/dist/esm/components/mail/common/keys.d.ts +14 -11
  69. package/dist/esm/components/mail/common/keys.js +34 -11
  70. package/dist/esm/components/mail/common/keys.js.map +1 -1
  71. package/dist/esm/components/mail/common/types/message.d.ts +7 -4
  72. package/dist/esm/components/mail/common/types/message.js.map +1 -1
  73. package/dist/esm/components/mail/common/types/options.d.ts +54 -10
  74. package/dist/esm/components/mail/common/types/options.js.map +1 -1
  75. package/dist/esm/components/mail/common/types/queue.d.ts +25 -12
  76. package/dist/esm/components/mail/common/types/queue.js.map +1 -1
  77. package/dist/esm/components/mail/common/types/template.d.ts +8 -4
  78. package/dist/esm/components/mail/common/types/template.js.map +1 -1
  79. package/dist/esm/components/mail/common/types/verification.d.ts +1 -0
  80. package/dist/esm/components/mail/common/types/verification.js.map +1 -1
  81. package/dist/esm/components/mail/component.js +11 -2
  82. package/dist/esm/components/mail/component.js.map +1 -1
  83. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.d.ts +3 -1
  84. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js +27 -33
  85. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js.map +1 -1
  86. package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.d.ts +2 -0
  87. package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.js +17 -10
  88. package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.js.map +1 -1
  89. package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js +11 -6
  90. package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js.map +1 -1
  91. package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.d.ts +2 -3
  92. package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.js +15 -6
  93. package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.js.map +1 -1
  94. package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.d.ts +2 -3
  95. package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.js +2 -2
  96. package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.js.map +1 -1
  97. package/dist/esm/components/mail/providers/mail-queue-executor.provider.d.ts +2 -2
  98. package/dist/esm/components/mail/providers/mail-queue-executor.provider.js +7 -9
  99. package/dist/esm/components/mail/providers/mail-queue-executor.provider.js.map +1 -1
  100. package/dist/esm/components/mail/providers/mail-transporter.provider.js +7 -7
  101. package/dist/esm/components/mail/providers/mail-transporter.provider.js.map +1 -1
  102. package/dist/esm/components/mail/services/generators/numeric-code.d.ts +1 -6
  103. package/dist/esm/components/mail/services/generators/numeric-code.js +3 -31
  104. package/dist/esm/components/mail/services/generators/numeric-code.js.map +1 -1
  105. package/dist/esm/components/mail/services/generators/random-token.d.ts +4 -1
  106. package/dist/esm/components/mail/services/generators/random-token.js +9 -6
  107. package/dist/esm/components/mail/services/generators/random-token.js.map +1 -1
  108. package/dist/esm/components/mail/services/mail.service.d.ts +1 -2
  109. package/dist/esm/components/mail/services/mail.service.js +22 -19
  110. package/dist/esm/components/mail/services/mail.service.js.map +1 -1
  111. package/dist/esm/components/mail/services/template.service.d.ts +8 -6
  112. package/dist/esm/components/mail/services/template.service.js +34 -33
  113. package/dist/esm/components/mail/services/template.service.js.map +1 -1
  114. package/dist/esm/components/mail/utilities/attachment.utility.js +8 -6
  115. package/dist/esm/components/mail/utilities/attachment.utility.js.map +1 -1
  116. package/dist/esm/components/mail/utilities/header.utility.d.ts +14 -0
  117. package/dist/esm/components/mail/utilities/header.utility.js +44 -0
  118. package/dist/esm/components/mail/utilities/header.utility.js.map +1 -0
  119. package/dist/esm/components/mail/utilities/index.d.ts +2 -0
  120. package/dist/esm/components/mail/utilities/index.js +2 -0
  121. package/dist/esm/components/mail/utilities/index.js.map +1 -1
  122. package/dist/esm/components/mail/utilities/mime.utility.d.ts +5 -1
  123. package/dist/esm/components/mail/utilities/mime.utility.js +12 -58
  124. package/dist/esm/components/mail/utilities/mime.utility.js.map +1 -1
  125. package/dist/esm/components/mail/utilities/template-renderer.utility.d.ts +31 -0
  126. package/dist/esm/components/mail/utilities/template-renderer.utility.js +184 -0
  127. package/dist/esm/components/mail/utilities/template-renderer.utility.js.map +1 -0
  128. package/dist/esm/components/mail/utilities/type.utility.d.ts +2 -3
  129. package/dist/esm/components/mail/utilities/type.utility.js +6 -7
  130. package/dist/esm/components/mail/utilities/type.utility.js.map +1 -1
  131. package/dist/esm/components/request-tracker/component.d.ts +2 -1
  132. package/dist/esm/components/request-tracker/component.js +5 -5
  133. package/dist/esm/components/request-tracker/component.js.map +1 -1
  134. package/dist/esm/components/server-info/common/keys.d.ts +2 -1
  135. package/dist/esm/components/server-info/common/keys.js +4 -1
  136. package/dist/esm/components/server-info/common/keys.js.map +1 -1
  137. package/dist/esm/components/server-info/common/types.d.ts +1 -1
  138. package/dist/esm/components/server-info/common/types.js.map +1 -1
  139. package/dist/esm/components/server-info/component.js +1 -3
  140. package/dist/esm/components/server-info/component.js.map +1 -1
  141. package/dist/esm/components/socket-io/common/keys.d.ts +9 -6
  142. package/dist/esm/components/socket-io/common/keys.js +19 -6
  143. package/dist/esm/components/socket-io/common/keys.js.map +1 -1
  144. package/dist/esm/components/socket-io/component.js +1 -1
  145. package/dist/esm/components/socket-io/component.js.map +1 -1
  146. package/dist/esm/components/socket-io/handlers/bun.handler.d.ts +13 -3
  147. package/dist/esm/components/socket-io/handlers/bun.handler.js.map +1 -1
  148. package/dist/esm/components/static-asset/common/constants.d.ts +51 -24
  149. package/dist/esm/components/static-asset/common/constants.js +75 -47
  150. package/dist/esm/components/static-asset/common/constants.js.map +1 -1
  151. package/dist/esm/components/static-asset/common/errors.d.ts +30 -35
  152. package/dist/esm/components/static-asset/common/errors.js +31 -33
  153. package/dist/esm/components/static-asset/common/errors.js.map +1 -1
  154. package/dist/esm/components/static-asset/common/index.d.ts +1 -1
  155. package/dist/esm/components/static-asset/common/index.js +1 -1
  156. package/dist/esm/components/static-asset/common/index.js.map +1 -1
  157. package/dist/esm/components/static-asset/common/keys.d.ts +14 -2
  158. package/dist/esm/components/static-asset/common/keys.js +17 -2
  159. package/dist/esm/components/static-asset/common/keys.js.map +1 -1
  160. package/dist/esm/components/static-asset/common/types.d.ts +267 -147
  161. package/dist/esm/components/static-asset/common/types.js.map +1 -1
  162. package/dist/esm/components/static-asset/common/validation.d.ts +10 -0
  163. package/dist/esm/components/static-asset/common/validation.js +8 -0
  164. package/dist/esm/components/static-asset/common/validation.js.map +1 -0
  165. package/dist/esm/components/static-asset/component.d.ts +4 -2
  166. package/dist/esm/components/static-asset/component.js +27 -31
  167. package/dist/esm/components/static-asset/component.js.map +1 -1
  168. package/dist/esm/components/static-asset/controller/factory.d.ts +37 -79
  169. package/dist/esm/components/static-asset/controller/factory.js +26 -917
  170. package/dist/esm/components/static-asset/controller/factory.js.map +1 -1
  171. package/dist/esm/components/static-asset/controller/index.d.ts +1 -0
  172. package/dist/esm/components/static-asset/controller/index.js +1 -0
  173. package/dist/esm/components/static-asset/controller/index.js.map +1 -1
  174. package/dist/esm/components/static-asset/controller/routes/context.d.ts +62 -0
  175. package/dist/esm/components/static-asset/controller/routes/context.js +45 -0
  176. package/dist/esm/components/static-asset/controller/routes/context.js.map +1 -0
  177. package/dist/esm/components/static-asset/controller/routes/definition.d.ts +40 -0
  178. package/dist/esm/components/static-asset/controller/routes/definition.js +83 -0
  179. package/dist/esm/components/static-asset/controller/routes/definition.js.map +1 -0
  180. package/dist/esm/components/static-asset/controller/routes/direct-upload.d.ts +3 -0
  181. package/dist/esm/components/static-asset/controller/routes/direct-upload.js +153 -0
  182. package/dist/esm/components/static-asset/controller/routes/direct-upload.js.map +1 -0
  183. package/dist/esm/components/static-asset/controller/routes/labels.d.ts +16 -0
  184. package/dist/esm/components/static-asset/controller/routes/labels.js +19 -0
  185. package/dist/esm/components/static-asset/controller/routes/labels.js.map +1 -0
  186. package/dist/esm/components/static-asset/controller/routes/objects.d.ts +7 -0
  187. package/dist/esm/components/static-asset/controller/routes/objects.js +193 -0
  188. package/dist/esm/components/static-asset/controller/routes/objects.js.map +1 -0
  189. package/dist/esm/components/static-asset/controller/routes/serve.d.ts +29 -0
  190. package/dist/esm/components/static-asset/controller/routes/serve.js +152 -0
  191. package/dist/esm/components/static-asset/controller/routes/serve.js.map +1 -0
  192. package/dist/esm/components/static-asset/controller/routes/table.d.ts +12 -0
  193. package/dist/esm/components/static-asset/controller/routes/table.js +52 -0
  194. package/dist/esm/components/static-asset/controller/routes/table.js.map +1 -0
  195. package/dist/esm/components/static-asset/controller/routes/upload.d.ts +10 -0
  196. package/dist/esm/components/static-asset/controller/routes/upload.js +175 -0
  197. package/dist/esm/components/static-asset/controller/routes/upload.js.map +1 -0
  198. package/dist/esm/components/static-asset/index.d.ts +2 -1
  199. package/dist/esm/components/static-asset/index.js +2 -1
  200. package/dist/esm/components/static-asset/index.js.map +1 -1
  201. package/dist/esm/components/static-asset/models/base.model.d.ts +4 -4
  202. package/dist/esm/components/static-asset/models/base.model.js.map +1 -1
  203. package/dist/esm/components/static-asset/services/commitment.service.d.ts +103 -0
  204. package/dist/esm/components/static-asset/services/commitment.service.js +252 -0
  205. package/dist/esm/components/static-asset/services/commitment.service.js.map +1 -0
  206. package/dist/esm/components/static-asset/services/index.d.ts +3 -0
  207. package/dist/esm/components/static-asset/services/index.js +3 -0
  208. package/dist/esm/components/static-asset/services/index.js.map +1 -0
  209. package/dist/esm/components/static-asset/services/policy.service.d.ts +45 -0
  210. package/dist/esm/components/static-asset/services/policy.service.js +104 -0
  211. package/dist/esm/components/static-asset/services/policy.service.js.map +1 -0
  212. package/dist/esm/components/static-asset/utilities/commit-token.utility.d.ts +28 -0
  213. package/dist/esm/components/static-asset/utilities/commit-token.utility.js +112 -0
  214. package/dist/esm/components/static-asset/utilities/commit-token.utility.js.map +1 -0
  215. package/dist/esm/components/static-asset/utilities/entry.utility.d.ts +69 -0
  216. package/dist/esm/components/static-asset/utilities/entry.utility.js +160 -0
  217. package/dist/esm/components/static-asset/utilities/entry.utility.js.map +1 -0
  218. package/dist/esm/components/static-asset/utilities/index.d.ts +6 -0
  219. package/dist/esm/components/static-asset/utilities/index.js +6 -0
  220. package/dist/esm/components/static-asset/utilities/index.js.map +1 -0
  221. package/dist/esm/components/static-asset/{ingest.d.ts → utilities/ingest.utility.d.ts} +8 -8
  222. package/dist/esm/components/static-asset/{ingest.js → utilities/ingest.utility.js} +21 -23
  223. package/dist/esm/components/static-asset/utilities/ingest.utility.js.map +1 -0
  224. package/dist/esm/components/static-asset/{controller/key-scope.d.ts → utilities/key-scope.utility.d.ts} +21 -2
  225. package/dist/esm/components/static-asset/utilities/key-scope.utility.js +74 -0
  226. package/dist/esm/components/static-asset/utilities/key-scope.utility.js.map +1 -0
  227. package/dist/esm/components/static-asset/{controller/meta-link.d.ts → utilities/meta-link.utility.d.ts} +9 -9
  228. package/dist/esm/components/static-asset/{controller/meta-link.js → utilities/meta-link.utility.js} +10 -10
  229. package/dist/esm/components/static-asset/utilities/meta-link.utility.js.map +1 -0
  230. package/dist/esm/components/static-asset/utilities/object-link.utility.d.ts +16 -0
  231. package/dist/esm/components/static-asset/utilities/object-link.utility.js +20 -0
  232. package/dist/esm/components/static-asset/utilities/object-link.utility.js.map +1 -0
  233. package/dist/esm/components/static-asset/utilities/pinned-file.utility.d.ts +39 -0
  234. package/dist/esm/components/static-asset/utilities/pinned-file.utility.js +53 -0
  235. package/dist/esm/components/static-asset/utilities/pinned-file.utility.js.map +1 -0
  236. package/dist/esm/components/static-asset/utilities/route-options.utility.d.ts +43 -0
  237. package/dist/esm/components/static-asset/utilities/route-options.utility.js +71 -0
  238. package/dist/esm/components/static-asset/utilities/route-options.utility.js.map +1 -0
  239. package/dist/esm/components/static-asset/utilities/toggle.utility.d.ts +5 -0
  240. package/dist/esm/components/static-asset/utilities/toggle.utility.js +5 -0
  241. package/dist/esm/components/static-asset/utilities/toggle.utility.js.map +1 -0
  242. package/dist/esm/components/websocket/common/keys.d.ts +12 -10
  243. package/dist/esm/components/websocket/common/keys.js +31 -10
  244. package/dist/esm/components/websocket/common/keys.js.map +1 -1
  245. package/dist/esm/components/websocket/component.js.map +1 -1
  246. package/dist/esm/testing/assert-application-boots.d.ts +2 -2
  247. package/dist/esm/testing/assert-application-boots.js +6 -2
  248. package/dist/esm/testing/assert-application-boots.js.map +1 -1
  249. package/dist/presets/app/preset.json +4 -4
  250. package/dist/presets/lib/preset.json +3 -3
  251. package/dist/presets/shared/preset.json +1 -1
  252. package/package.json +8 -8
  253. package/dist/esm/components/static-asset/common/commit-token.d.ts +0 -28
  254. package/dist/esm/components/static-asset/common/commit-token.js +0 -48
  255. package/dist/esm/components/static-asset/common/commit-token.js.map +0 -1
  256. package/dist/esm/components/static-asset/controller/base.definition.d.ts +0 -30
  257. package/dist/esm/components/static-asset/controller/base.definition.js +0 -307
  258. package/dist/esm/components/static-asset/controller/base.definition.js.map +0 -1
  259. package/dist/esm/components/static-asset/controller/key-scope.js +0 -41
  260. package/dist/esm/components/static-asset/controller/key-scope.js.map +0 -1
  261. package/dist/esm/components/static-asset/controller/meta-link.js.map +0 -1
  262. package/dist/esm/components/static-asset/controller/route-options.d.ts +0 -29
  263. package/dist/esm/components/static-asset/controller/route-options.js +0 -47
  264. package/dist/esm/components/static-asset/controller/route-options.js.map +0 -1
  265. package/dist/esm/components/static-asset/ingest.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"component.js","sourceRoot":"","sources":["../../../../../src/components/auth/authenticate/component.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,8BAA8B,EAC9B,aAAa,EACb,UAAU,EACV,YAAY,EAKZ,MAAM,EAEN,aAAa,EACb,cAAc,EACd,SAAS,EACT,gBAAgB,GAKjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EACL,0BAA0B,EAC1B,iBAAiB,EACjB,sBAAsB,EACtB,wBAAwB,EACxB,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AAClF,OAAO,EAAE,+BAA+B,EAAE,MAAM,qCAAqC,CAAC;AACtF,OAAO,EAAE,6BAA6B,EAAE,MAAM,+BAA+B,CAAC;AAE9E,MAAM,cAAc,GAAG,gBAAgB,CAAC;AAExC,6LAA6L;AAC7L,IAAa,qBAAqB,6BAAlC,MAAa,qBAAsB,SAAQ,aAAa;IACtD,YAC8D,WAA4B;QAExF,KAAK,CAAC;YACJ,KAAK,EAAE,uBAAqB,CAAC,IAAI;YACjC,WAAW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AM,cAAc,GAAG,qBAAqB,CAAC,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;QAChF,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;QAE5C,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;IAClF,CAAC;IAED,YAAY;QACV,wBAAwB;IAC1B,CAAC;CACF,CAAA;AA7VY,qBAAqB;IAE7B,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,oBAAoB,EAAE,CAAC,CAAA;;GAF1C,qBAAqB,CA6VjC","sourcesContent":["import type { BaseApplication } from '@/base/applications/base';\nimport { type ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { Binding } from '@venizia/ignis-inversion';\nimport {\n AuthenticateBindingKeys,\n Authentication,\n AuthenticationStrategyRegistry,\n BaseComponent,\n controller,\n CoreBindings,\n type IAuthenticateOptions,\n type IJWKSIssuerOptions,\n type IJWKSVerifierOptions,\n type IJWSTokenServiceOptions,\n inject,\n type IServiceAuthOptions,\n JOSEStandards,\n JWKSKeyFormats,\n JWKSModes,\n ServiceAssertion,\n type TAuthenticationRestOptions,\n type TBasicTokenServiceOptions,\n type TJWKSTokenServiceOptions,\n type TJWTTokenServiceOptions,\n} from '@venizia/ignis-kernel';\nimport { AuthControllerFactory, JWKSController } from './controllers';\nimport { ServiceCertsController } from './controllers/service-certs';\nimport {\n AbstractBearerTokenService,\n BasicTokenService,\n JWKSIssuerTokenService,\n JWKSVerifierTokenService,\n JWSTokenService,\n} from './services';\nimport { JoseLoader } from './services/jose-loader';\nimport { JWKSUrlPolicy } from './services/jwks-url-policy';\nimport { ServiceAssertionSignerService } from './services/service/signer.service';\nimport { ServiceAssertionVerifierService } from './services/service/verifier.service';\nimport { ServiceAuthenticationStrategy } from './strategies/service.strategy';\n\nconst DEFAULT_SECRET = 'unknown_secret';\n\n/** Registers the authentication services and strategies from the options bound under `AuthenticateBindingKeys`. Throws at binding time unless JWT, basic or service options are provided. */\nexport class AuthenticateComponent extends BaseComponent {\n constructor(\n @inject({ key: CoreBindings.APPLICATION_INSTANCE }) private application: BaseApplication,\n ) {\n super({\n scope: AuthenticateComponent.name,\n initDefault: { enable: true, container: application },\n bindings: {\n [AuthenticateBindingKeys.REST_OPTIONS]: Binding.bind<TAuthenticationRestOptions>({\n key: AuthenticateBindingKeys.REST_OPTIONS,\n }).toValue({ useAuthController: false }),\n },\n });\n }\n\n override binding(): ValueOrPromise<void> {\n const jwtOptions = this.application.get<TJWTTokenServiceOptions>({\n key: AuthenticateBindingKeys.JWT_OPTIONS,\n isOptional: true,\n });\n const basicOptions = this.application.get<TBasicTokenServiceOptions>({\n key: AuthenticateBindingKeys.BASIC_OPTIONS,\n isOptional: true,\n });\n const restOptions = this.application.get<TAuthenticationRestOptions>({\n key: AuthenticateBindingKeys.REST_OPTIONS,\n isOptional: true,\n });\n const serviceOptions = this.application.get<IServiceAuthOptions>({\n key: AuthenticateBindingKeys.SERVICE_OPTIONS,\n isOptional: true,\n });\n\n // A service that only VERIFIES assertions needs neither jwt nor basic - and that application,\n // an IGNIS app consuming no user tokens at all, is exactly what the service strategy is for.\n if (!jwtOptions && !basicOptions && !serviceOptions) {\n throw getError({\n message:\n '[AuthenticateComponent] At least one of jwtOptions, basicOptions or serviceOptions must be provided',\n });\n }\n\n const options: IAuthenticateOptions = { restOptions, jwtOptions, basicOptions, serviceOptions };\n\n if (jwtOptions) {\n switch (jwtOptions.standard) {\n case JOSEStandards.JWS: {\n this.defineJWSAuth({ options: jwtOptions.options });\n break;\n }\n case JOSEStandards.JWKS: {\n this.defineJWKSAuth({ options: jwtOptions.options });\n break;\n }\n default: {\n throw getError({\n message: `[AuthenticateComponent] Unknown JOSE standard: ${(jwtOptions as any).standard}`,\n });\n }\n }\n }\n\n this.defineBasicAuth({ basicOptions });\n this.defineServiceAuth({ serviceOptions });\n\n this.defineControllers({ options });\n\n this.defineOAuth2();\n\n return this.preloadJose({ options });\n }\n\n /**\n * Loads `jose` at boot when a configured service signs or verifies with it, so a missing or broken\n * install fails the boot instead of answering every token check with a 401.\n */\n private async preloadJose(opts: { options: IAuthenticateOptions }): Promise<void> {\n const { jwtOptions, serviceOptions } = opts.options;\n\n if (!jwtOptions && !serviceOptions) {\n return;\n }\n\n try {\n await JoseLoader.load();\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n this.logger.for(this.preloadJose.name).error(\"Failed to load 'jose' | Error: %s\", reason);\n\n throw getError({\n message: `[AuthenticateComponent] Cannot load 'jose', which JWT and service authentication need. Please install it | Error: ${reason}`,\n cause: error,\n });\n }\n }\n\n private defineJWSAuth(opts: { options: IJWSTokenServiceOptions }): void {\n const { options: jwsOptions } = opts;\n\n const { jwtSecret, getTokenExpiresFn } = jwsOptions;\n\n if (!jwtSecret || jwtSecret === DEFAULT_SECRET) {\n throw getError({\n message: `[defineJWSAuth] Invalid jwtSecret | Provided: ${jwtSecret}`,\n });\n }\n\n if (!getTokenExpiresFn) {\n throw getError({\n message: '[defineJWSAuth] getTokenExpiresFn is required',\n });\n }\n\n // The boot refuses a configuration without claims, and a service refuses the same when built.\n AbstractBearerTokenService.resolveClaimsConfig({\n scope: 'defineJWSAuth',\n options: jwsOptions,\n pinnedAlgorithms: [jwsOptions.headerAlgorithm ?? 'HS256'],\n });\n\n JWSTokenService.assertSecretStrength({ scope: 'defineJWSAuth', secret: jwtSecret });\n\n this.application\n .bind<IJWSTokenServiceOptions>({ key: AuthenticateBindingKeys.JWT_OPTIONS })\n .toValue(jwsOptions);\n this.application.service(JWSTokenService);\n\n this.logger.for(this.defineJWSAuth.name).info('JWS authentication configured');\n }\n\n private defineJWKSAuth(opts: { options: TJWKSTokenServiceOptions }): void {\n const { options: jwksOptions } = opts;\n\n switch (jwksOptions.mode) {\n case JWKSModes.ISSUER: {\n const issuerOpts = jwksOptions;\n\n if (!issuerOpts.keys?.private || !issuerOpts.keys?.public) {\n throw getError({\n message: '[defineJWKSAuth] keys.private and keys.public are required for issuer mode',\n });\n }\n\n if (!issuerOpts.keys?.format || !JWKSKeyFormats.isValid(issuerOpts.keys.format)) {\n throw getError({\n message: `[defineJWKSAuth] keys.format is required and must be one of: ${[...JWKSKeyFormats.SCHEME_SET].join(', ')}`,\n });\n }\n\n if (!issuerOpts.kid) {\n throw getError({ message: '[defineJWKSAuth] kid is required for issuer mode' });\n }\n\n if (!issuerOpts.getTokenExpiresFn) {\n throw getError({\n message: '[defineJWKSAuth] getTokenExpiresFn is required for issuer mode',\n });\n }\n\n AbstractBearerTokenService.resolveClaimsConfig({\n scope: 'defineJWKSAuth',\n options: issuerOpts,\n pinnedAlgorithms: [issuerOpts.algorithm],\n });\n\n this.application\n .bind<IJWKSIssuerOptions>({ key: AuthenticateBindingKeys.JWKS_OPTIONS })\n .toValue(issuerOpts);\n this.application.service(JWKSIssuerTokenService);\n\n // Path depends on a runtime option, so @controller can't be applied statically — decorate here instead.\n Reflect.decorate(\n [controller({ path: issuerOpts?.rest?.path ?? '/certs' })],\n JWKSController,\n );\n this.application.controller(JWKSController);\n\n this.logger\n .for(this.defineJWKSAuth.name)\n .info('JWKS issuer configured with /certs endpoint');\n break;\n }\n\n case JWKSModes.VERIFIER: {\n const verifierOpts = jwksOptions;\n\n if (!verifierOpts.jwksUrl) {\n throw getError({ message: '[defineJWKSAuth] jwksUrl is required for verifier mode' });\n }\n\n AbstractBearerTokenService.resolveClaimsConfig({\n scope: 'defineJWKSAuth',\n options: verifierOpts,\n });\n\n JWKSUrlPolicy.assertUrl({\n scope: 'defineJWKSAuth',\n label: 'jwksUrl',\n url: verifierOpts.jwksUrl,\n hosts: verifierOpts.jwks?.hosts?.http,\n });\n\n this.application\n .bind<IJWKSVerifierOptions>({ key: AuthenticateBindingKeys.JWKS_OPTIONS })\n .toValue(verifierOpts);\n this.application.service(JWKSVerifierTokenService);\n\n this.logger.for(this.defineJWKSAuth.name).info('JWKS verifier configured');\n break;\n }\n\n default: {\n // Same exhaustive-switch-narrows-to-never situation as the JOSE standard default above.\n throw getError({\n message: `[defineJWKSAuth] Invalid JWKS mode: ${(jwksOptions as { mode?: unknown }).mode}`,\n });\n }\n }\n }\n\n /**\n * Service-to-service authentication. Absent options mean no strategy is registered and no route is\n * mounted, so an application that never sets them is byte-identical to today.\n *\n * The certs route is mounted only when SIGNING keys are present. Most services are called and\n * never call; publishing a key set for a service that signs nothing advertises a capability it\n * does not have.\n */\n private defineServiceAuth(opts: { serviceOptions?: IServiceAuthOptions }): void {\n const { serviceOptions } = opts;\n\n if (!serviceOptions) {\n this.logger\n .for(this.defineServiceAuth.name)\n .debug('serviceOptions not provided, skipping service authentication');\n\n return;\n }\n\n if (!serviceOptions.name) {\n throw getError({\n message:\n '[defineServiceAuth] name is required | it is the issuer this service stamps and the audience it demands',\n });\n }\n\n if (!serviceOptions.resolvePrincipal) {\n throw getError({\n message:\n '[defineServiceAuth] resolvePrincipal is required | the framework proves WHICH SERVICE called, the application decides who that acts as',\n });\n }\n\n // A caller's key set decides who may call: https, loopback, or a host listed in jwks.hosts.http. Checked at boot, so a bad URL never waits for its first request.\n JWKSUrlPolicy.resolveHttpHosts({\n scope: 'defineServiceAuth',\n hosts: serviceOptions.jwks?.hosts?.http,\n });\n\n for (const [caller, entry] of Object.entries(serviceOptions.callers ?? {})) {\n JWKSUrlPolicy.assertUrl({\n scope: 'defineServiceAuth',\n label: `callers[${JSON.stringify(caller)}].jwksUrl`,\n url: typeof entry === 'string' ? entry : entry.jwksUrl,\n hosts: serviceOptions.jwks?.hosts?.http,\n });\n }\n\n this.application.service(ServiceAssertionVerifierService);\n\n if (serviceOptions.keys) {\n this.application.service(ServiceAssertionSignerService);\n\n const restPath = serviceOptions.rest?.path ?? ServiceAssertion.DEFAULT_REST_PATH;\n this.application\n .bind<string>({ key: AuthenticateBindingKeys.SERVICE_CERTS_PATH })\n .toValue(restPath);\n\n // Path depends on a runtime option, so @controller cannot be applied statically.\n Reflect.decorate([controller({ path: restPath })], ServiceCertsController);\n this.application.controller(ServiceCertsController);\n }\n\n AuthenticationStrategyRegistry.getInstance().register({\n container: this.application,\n strategies: [\n { name: Authentication.STRATEGY_SERVICE, strategy: ServiceAuthenticationStrategy },\n ],\n });\n\n this.logger\n .for(this.defineServiceAuth.name)\n .info(\n 'Service authentication configured | name: %s | signs: %s | callers: %s',\n serviceOptions.name,\n Boolean(serviceOptions.keys),\n Object.keys(serviceOptions.callers ?? {}).join(', ') || 'none',\n );\n }\n\n private defineBasicAuth(opts: { basicOptions?: TBasicTokenServiceOptions }): void {\n const { basicOptions } = opts;\n\n if (!basicOptions) {\n this.logger\n .for(this.defineBasicAuth.name)\n .debug('basicOptions not provided, skipping Basic configuration');\n\n return;\n }\n\n if (!basicOptions.verifyCredentials) {\n throw getError({\n message: '[defineBasicAuth] verifyCredentials function is required',\n });\n }\n\n this.application\n .bind<TBasicTokenServiceOptions>({ key: AuthenticateBindingKeys.BASIC_OPTIONS })\n .toValue(basicOptions);\n this.application.service(BasicTokenService);\n\n this.logger.for(this.defineBasicAuth.name).info('Basic authentication configured');\n }\n\n private defineControllers(opts: { options: IAuthenticateOptions }): void {\n const { restOptions, jwtOptions } = opts.options;\n\n if (!restOptions?.useAuthController) {\n this.logger.for(this.defineControllers.name).debug('Auth controller disabled');\n\n return;\n }\n\n if (!jwtOptions) {\n throw getError({\n message: '[defineControllers] Auth controller requires jwtOptions to be configured',\n });\n }\n\n const AuthController = AuthControllerFactory.define(restOptions.controllerOpts);\n this.application.controller(AuthController);\n\n this.logger.for(this.defineControllers.name).info('Auth controller registered');\n }\n\n defineOAuth2() {\n // TODO Implement OAuth2\n }\n}\n"]}
1
+ {"version":3,"file":"component.js","sourceRoot":"","sources":["../../../../../src/components/auth/authenticate/component.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;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IAE7B,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,oBAAoB,EAAE,CAAC,CAAA;;GAF1C,qBAAqB,CAyVjC","sourcesContent":["import type { BaseApplication } from '@/base/applications/base';\nimport { type ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { Binding } from '@venizia/ignis-inversion';\nimport {\n AuthenticateBindingKeys,\n Authentication,\n AuthenticationStrategyRegistry,\n BaseComponent,\n controller,\n CoreBindings,\n type IAuthenticateOptions,\n type IJWSTokenServiceOptions,\n inject,\n type IServiceAuthOptions,\n JOSEStandards,\n JWKSKeyFormats,\n JWKSModes,\n ServiceAssertion,\n type TBasicTokenServiceOptions,\n type TJWKSTokenServiceOptions,\n} from '@venizia/ignis-kernel';\nimport { AuthControllerFactory, JWKSController } from './controllers';\nimport { ServiceCertsController } from './controllers/service-certs';\nimport {\n AbstractBearerTokenService,\n BasicTokenService,\n JWKSIssuerTokenService,\n JWKSVerifierTokenService,\n JWSTokenService,\n} from './services';\nimport { JoseLoader } from './services/jose-loader';\nimport { JWKSUrlPolicy } from './services/jwks-url-policy';\nimport { ServiceAssertionSignerService } from './services/service/signer.service';\nimport { ServiceAssertionVerifierService } from './services/service/verifier.service';\nimport { ServiceAuthenticationStrategy } from './strategies/service.strategy';\n\nconst DEFAULT_SECRET = 'unknown_secret';\n\n/** Registers the authentication services and strategies from the options bound under `AuthenticateBindingKeys`. Throws at binding time unless JWT, basic or service options are provided. */\nexport class AuthenticateComponent extends BaseComponent {\n constructor(\n @inject({ key: CoreBindings.APPLICATION_INSTANCE }) private application: BaseApplication,\n ) {\n super({\n scope: AuthenticateComponent.name,\n initDefault: { enable: true, container: application },\n bindings: {\n [AuthenticateBindingKeys.REST_OPTIONS]: Binding.bind({\n key: AuthenticateBindingKeys.REST_OPTIONS,\n }).toValue({ useAuthController: false }),\n },\n });\n }\n\n override binding(): ValueOrPromise<void> {\n const jwtOptions = this.application.get({\n key: AuthenticateBindingKeys.JWT_OPTIONS,\n isOptional: true,\n });\n const basicOptions = this.application.get({\n key: AuthenticateBindingKeys.BASIC_OPTIONS,\n isOptional: true,\n });\n const restOptions = this.application.get({\n key: AuthenticateBindingKeys.REST_OPTIONS,\n isOptional: true,\n });\n const serviceOptions = this.application.get({\n key: AuthenticateBindingKeys.SERVICE_OPTIONS,\n isOptional: true,\n });\n\n // A service that only VERIFIES assertions needs neither jwt nor basic - and that application,\n // an IGNIS app consuming no user tokens at all, is exactly what the service strategy is for.\n if (!jwtOptions && !basicOptions && !serviceOptions) {\n throw getError({\n message:\n '[AuthenticateComponent] At least one of jwtOptions, basicOptions or serviceOptions must be provided',\n });\n }\n\n const options: IAuthenticateOptions = { restOptions, jwtOptions, basicOptions, serviceOptions };\n\n if (jwtOptions) {\n const standard: string = jwtOptions.standard;\n\n switch (jwtOptions.standard) {\n case JOSEStandards.JWS: {\n this.defineJWSAuth({ options: jwtOptions.options });\n break;\n }\n case JOSEStandards.JWKS: {\n this.defineJWKSAuth({ options: jwtOptions.options });\n break;\n }\n default: {\n throw getError({\n message: `[AuthenticateComponent] Unknown JOSE standard: ${standard}`,\n });\n }\n }\n }\n\n this.defineBasicAuth({ basicOptions });\n this.defineServiceAuth({ serviceOptions });\n\n this.defineControllers({ options });\n\n this.defineOAuth2();\n\n return this.preloadJose({ options });\n }\n\n /**\n * Loads `jose` at boot when a configured service signs or verifies with it, so a missing or broken\n * install fails the boot instead of answering every token check with a 401.\n */\n private async preloadJose(opts: { options: IAuthenticateOptions }): Promise<void> {\n const { jwtOptions, serviceOptions } = opts.options;\n\n if (!jwtOptions && !serviceOptions) {\n return;\n }\n\n try {\n await JoseLoader.load();\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n this.logger.for(this.preloadJose.name).error(\"Failed to load 'jose' | Error: %s\", reason);\n\n throw getError({\n message: `[AuthenticateComponent] Cannot load 'jose', which JWT and service authentication need. Please install it | Error: ${reason}`,\n cause: error,\n });\n }\n }\n\n private defineJWSAuth(opts: { options: IJWSTokenServiceOptions }): void {\n const { options: jwsOptions } = opts;\n\n const { jwtSecret, getTokenExpiresFn } = jwsOptions;\n\n if (!jwtSecret || jwtSecret === DEFAULT_SECRET) {\n throw getError({\n message: `[defineJWSAuth] Invalid jwtSecret | Provided: ${jwtSecret}`,\n });\n }\n\n if (!getTokenExpiresFn) {\n throw getError({\n message: '[defineJWSAuth] getTokenExpiresFn is required',\n });\n }\n\n // The boot refuses a configuration without claims, and a service refuses the same when built.\n AbstractBearerTokenService.resolveClaimsConfig({\n scope: 'defineJWSAuth',\n options: jwsOptions,\n pinnedAlgorithms: [jwsOptions.headerAlgorithm ?? 'HS256'],\n });\n\n JWSTokenService.assertSecretStrength({ scope: 'defineJWSAuth', secret: jwtSecret });\n\n this.application.bind({ key: AuthenticateBindingKeys.JWS_OPTIONS }).toValue(jwsOptions);\n this.application.service(JWSTokenService);\n\n this.logger.for(this.defineJWSAuth.name).info('JWS authentication configured');\n }\n\n private defineJWKSAuth(opts: { options: TJWKSTokenServiceOptions }): void {\n const { options: jwksOptions } = opts;\n\n switch (jwksOptions.mode) {\n case JWKSModes.ISSUER: {\n const issuerOpts = jwksOptions;\n\n if (!issuerOpts.keys?.private || !issuerOpts.keys?.public) {\n throw getError({\n message: '[defineJWKSAuth] keys.private and keys.public are required for issuer mode',\n });\n }\n\n if (!issuerOpts.keys?.format || !JWKSKeyFormats.isValid(issuerOpts.keys.format)) {\n throw getError({\n message: `[defineJWKSAuth] keys.format is required and must be one of: ${[...JWKSKeyFormats.SCHEME_SET].join(', ')}`,\n });\n }\n\n if (!issuerOpts.kid) {\n throw getError({ message: '[defineJWKSAuth] kid is required for issuer mode' });\n }\n\n if (!issuerOpts.getTokenExpiresFn) {\n throw getError({\n message: '[defineJWKSAuth] getTokenExpiresFn is required for issuer mode',\n });\n }\n\n AbstractBearerTokenService.resolveClaimsConfig({\n scope: 'defineJWKSAuth',\n options: issuerOpts,\n pinnedAlgorithms: [issuerOpts.algorithm],\n });\n\n this.application\n .bind({ key: AuthenticateBindingKeys.JWKS_ISSUER_OPTIONS })\n .toValue(issuerOpts);\n this.application.service(JWKSIssuerTokenService);\n\n // Path depends on a runtime option, so @controller can't be applied statically — decorate here instead.\n Reflect.decorate(\n [controller({ path: issuerOpts?.rest?.path ?? '/certs' })],\n JWKSController,\n );\n this.application.controller(JWKSController);\n\n this.logger\n .for(this.defineJWKSAuth.name)\n .info('JWKS issuer configured with /certs endpoint');\n break;\n }\n\n case JWKSModes.VERIFIER: {\n const verifierOpts = jwksOptions;\n\n if (!verifierOpts.jwksUrl) {\n throw getError({ message: '[defineJWKSAuth] jwksUrl is required for verifier mode' });\n }\n\n AbstractBearerTokenService.resolveClaimsConfig({\n scope: 'defineJWKSAuth',\n options: verifierOpts,\n });\n\n JWKSUrlPolicy.assertUrl({\n scope: 'defineJWKSAuth',\n label: 'jwksUrl',\n url: verifierOpts.jwksUrl,\n trusted: verifierOpts.jwks?.trusted,\n });\n\n this.application\n .bind({ key: AuthenticateBindingKeys.JWKS_VERIFIER_OPTIONS })\n .toValue(verifierOpts);\n this.application.service(JWKSVerifierTokenService);\n\n this.logger.for(this.defineJWKSAuth.name).info('JWKS verifier configured');\n break;\n }\n\n default: {\n // Same exhaustive-switch-narrows-to-never situation as the JOSE standard default above.\n throw getError({\n message: `[defineJWKSAuth] Invalid JWKS mode: ${(jwksOptions as { mode?: unknown }).mode}`,\n });\n }\n }\n }\n\n /**\n * Service-to-service authentication. Absent options mean no strategy is registered and no route is\n * mounted, so an application that never sets them is byte-identical to today.\n *\n * The certs route is mounted only when SIGNING keys are present. Most services are called and\n * never call; publishing a key set for a service that signs nothing advertises a capability it\n * does not have.\n */\n private defineServiceAuth(opts: { serviceOptions?: IServiceAuthOptions }): void {\n const { serviceOptions } = opts;\n\n if (!serviceOptions) {\n this.logger\n .for(this.defineServiceAuth.name)\n .debug('serviceOptions not provided, skipping service authentication');\n\n return;\n }\n\n if (!serviceOptions.name) {\n throw getError({\n message:\n '[defineServiceAuth] name is required | it is the issuer this service stamps and the audience it demands',\n });\n }\n\n if (!serviceOptions.resolvePrincipal) {\n throw getError({\n message:\n '[defineServiceAuth] resolvePrincipal is required | the framework proves WHICH SERVICE called, the application decides who that acts as',\n });\n }\n\n // A caller's key set decides who may call: https, loopback, or an origin listed in jwks.trusted. Checked at boot, so a bad URL never waits for its first request.\n JWKSUrlPolicy.resolveTrustedOrigins({\n scope: 'defineServiceAuth',\n trusted: serviceOptions.jwks?.trusted,\n });\n\n for (const [caller, entry] of Object.entries(serviceOptions.callers ?? {})) {\n JWKSUrlPolicy.assertUrl({\n scope: 'defineServiceAuth',\n label: `callers[${JSON.stringify(caller)}].jwksUrl`,\n url: typeof entry === 'string' ? entry : entry.jwksUrl,\n trusted: serviceOptions.jwks?.trusted,\n });\n }\n\n this.application.service(ServiceAssertionVerifierService);\n\n if (serviceOptions.keys) {\n this.application.service(ServiceAssertionSignerService);\n\n const restPath = serviceOptions.rest?.path ?? ServiceAssertion.DEFAULT_REST_PATH;\n this.application.bind({ key: AuthenticateBindingKeys.SERVICE_CERTS_PATH }).toValue(restPath);\n\n // Path depends on a runtime option, so @controller cannot be applied statically.\n Reflect.decorate([controller({ path: restPath })], ServiceCertsController);\n this.application.controller(ServiceCertsController);\n }\n\n AuthenticationStrategyRegistry.getInstance().register({\n container: this.application,\n strategies: [\n { name: Authentication.STRATEGY_SERVICE, strategy: ServiceAuthenticationStrategy },\n ],\n });\n\n this.logger\n .for(this.defineServiceAuth.name)\n .info(\n 'Service authentication configured | name: %s | signs: %s | callers: %s',\n serviceOptions.name,\n Boolean(serviceOptions.keys),\n Object.keys(serviceOptions.callers ?? {}).join(', ') || 'none',\n );\n }\n\n private defineBasicAuth(opts: { basicOptions?: TBasicTokenServiceOptions }): void {\n const { basicOptions } = opts;\n\n if (!basicOptions) {\n this.logger\n .for(this.defineBasicAuth.name)\n .debug('basicOptions not provided, skipping Basic configuration');\n\n return;\n }\n\n if (!basicOptions.verifyCredentials) {\n throw getError({\n message: '[defineBasicAuth] verifyCredentials function is required',\n });\n }\n\n this.application.bind({ key: AuthenticateBindingKeys.BASIC_OPTIONS }).toValue(basicOptions);\n this.application.service(BasicTokenService);\n\n this.logger.for(this.defineBasicAuth.name).info('Basic authentication configured');\n }\n\n private defineControllers(opts: { options: IAuthenticateOptions }): void {\n const { restOptions, jwtOptions } = opts.options;\n\n if (!restOptions?.useAuthController) {\n this.logger.for(this.defineControllers.name).debug('Auth controller disabled');\n\n return;\n }\n\n if (!jwtOptions) {\n throw getError({\n message: '[defineControllers] Auth controller requires jwtOptions to be configured',\n });\n }\n\n const AuthController = AuthControllerFactory.build(restOptions.controllerOpts);\n this.application.controller(AuthController);\n\n this.logger.for(this.defineControllers.name).info('Auth controller registered');\n }\n\n defineOAuth2() {\n // TODO Implement OAuth2\n }\n}\n"]}
@@ -15,7 +15,7 @@ export declare const JWTTokenPayloadSchema: z.ZodObject<{
15
15
  }, z.core.$strip>;
16
16
  /** Builds the decorated REST controller of the authentication routes (sign-in, sign-up, change-password, who-am-i). */
17
17
  export declare class AuthControllerFactory {
18
- static define(opts: TDefineAuthControllerOpts): {
18
+ static build(opts: TDefineAuthControllerOpts): {
19
19
  new (authService: IAuthService): {
20
20
  service: IAuthService;
21
21
  binding(): ValueOrPromise<void>;
@@ -23,8 +23,8 @@ export declare class AuthControllerFactory {
23
23
  scope: string;
24
24
  args: unknown;
25
25
  task: () => Promise<R>;
26
- }): Promise<any>;
27
- normalizeCountData<ResponseSchema extends unknown, RequestContext extends import("@venizia/ignis-kernel").TRouteContext<import("hono").Env> = import("@venizia/ignis-kernel").TRouteContext<import("hono").Env>, ResponseData extends {
26
+ }): Promise<R>;
27
+ normalizeCountData<ResponseSchema, RequestContext extends import("@venizia/ignis-kernel").TRouteContext<import("hono").Env> = import("@venizia/ignis-kernel").TRouteContext<import("hono").Env>, ResponseData extends {
28
28
  count: number;
29
29
  data?: import("@venizia/ignis-helpers").TNullable<ResponseSchema>;
30
30
  } = {
@@ -33,7 +33,7 @@ export const JWTTokenPayloadSchema = z.object({
33
33
  });
34
34
  /** Builds the decorated REST controller of the authentication routes (sign-in, sign-up, change-password, who-am-i). */
35
35
  export class AuthControllerFactory {
36
- static define(opts) {
36
+ static build(opts) {
37
37
  const { restPath = '/auth', serviceKey, requireAuthenticatedSignUp = false, payload = {}, } = opts;
38
38
  let AuthController = AuthController_1 = class AuthController extends BaseRestController {
39
39
  constructor(authService) {
@@ -1 +1 @@
1
- {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../../../src/components/auth/authenticate/controllers/factory.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,IAAI,EAAuB,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,cAAc,GAGf,MAAM,uBAAuB,CAAC;AAE/B,+IAA+I;AAC/I,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IACjC,KAAK,EAAE,CAAC,CAAC,KAAK,CACZ,CAAC,CAAC,MAAM,CAAC;Q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,EAAE,EAAE,CAAC,CAAC;wBAE9D,OAAO,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;oBACpD,CAAC;iBACF,CAAC,CAAC;YACL,CAAC;SACF,CAAA;QAjNK,cAAc;YADnB,UAAU,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;WACzB,cAAc,CAiNnB;QAED,MAAM,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,CAAC,cAAc,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;QAE1D,OAAO,cAAc,CAAC;IACxB,CAAC;CACF","sourcesContent":["import { BaseRestController } from '@venizia/ignis-kernel';\nimport { inject } from '@venizia/ignis-kernel';\nimport { controller } from '@venizia/ignis-kernel';\nimport { OpenApiResponses } from '@venizia/ignis-kernel';\nimport { NotSupportedUtility } from '@venizia/ignis-kernel';\nimport { AnyObjectSchema } from '@venizia/ignis-kernel';\nimport { z } from '@hono/zod-openapi';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { HTTP, type ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport {\n ChangePasswordRequestSchema,\n SignInRequestSchema,\n SignUpRequestSchema,\n} from '@venizia/ignis-kernel';\nimport {\n Authentication,\n type IAuthService,\n type TDefineAuthControllerOpts,\n} from '@venizia/ignis-kernel';\n\n/** Zod schema of the JWT payload: `userId`, the `roles` (id, identifier, integer priority) and optional `clientId`, `provider` and `email`. */\nexport const JWTTokenPayloadSchema = z.object({\n userId: z.string().or(z.number()),\n roles: z.array(\n z.object({\n id: z.string().or(z.number()),\n identifier: z.string(),\n priority: z.number().int(),\n }),\n ),\n clientId: z.string().optional(),\n provider: z.string().optional(),\n email: z.email().optional(),\n});\n\n/** Builds the decorated REST controller of the authentication routes (sign-in, sign-up, change-password, who-am-i). */\nexport class AuthControllerFactory {\n static define(opts: TDefineAuthControllerOpts) {\n const {\n restPath = '/auth',\n serviceKey,\n requireAuthenticatedSignUp = false,\n payload = {},\n } = opts;\n\n @controller({ path: restPath })\n class AuthController extends BaseRestController {\n service: IAuthService;\n\n constructor(authService: IAuthService) {\n super({\n scope: AuthController.name,\n path: restPath,\n isStrict: true,\n });\n\n if (!authService) {\n throw getError({\n message:\n '[AuthController] Failed to init auth controller | Invalid injectable authentication service!',\n });\n }\n\n this.service = authService;\n }\n\n override binding(): ValueOrPromise<void> {\n this.defineRoute({\n configs: {\n description: 'Sign In',\n path: '/sign-in',\n method: HTTP.Methods.POST,\n request: {\n body: OpenApiResponses.jsonContent({\n description: 'Sign-in request body',\n required: true,\n schema: payload?.signIn?.request?.schema ?? SignInRequestSchema,\n }),\n },\n responses: OpenApiResponses.jsonResponse({\n schema: payload?.signIn?.response?.schema ?? AnyObjectSchema,\n description: 'Success Response',\n }),\n },\n handler: async (context) => {\n const body = await context.req.json();\n const rs = await this.service.signIn(context, body);\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n },\n });\n\n this.defineRoute({\n configs: {\n description: 'Sign Up',\n path: '/sign-up',\n method: HTTP.Methods.POST,\n authenticate: {\n strategies: !requireAuthenticatedSignUp ? [] : [Authentication.STRATEGY_JWT],\n },\n request: {\n body: OpenApiResponses.jsonContent({\n description: 'Sign-up request body',\n required: true,\n schema: payload?.signUp?.request?.schema ?? SignUpRequestSchema,\n }),\n },\n responses: OpenApiResponses.jsonResponse({\n schema: payload?.signUp?.response?.schema ?? AnyObjectSchema,\n description: 'Success Response',\n }),\n },\n handler: async (context) => {\n const body = await context.req.json();\n const rs = await this.service.signUp(context, body);\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n },\n });\n\n this.defineRoute({\n configs: {\n description: 'Change password',\n path: '/change-password',\n method: HTTP.Methods.POST,\n request: {\n body: OpenApiResponses.jsonContent({\n description: 'Change password request body',\n required: true,\n schema: payload?.changePassword?.request?.schema ?? ChangePasswordRequestSchema,\n }),\n },\n responses: OpenApiResponses.jsonResponse({\n schema: payload?.changePassword?.response?.schema ?? AnyObjectSchema,\n description: 'Success Response',\n }),\n authenticate: { strategies: [Authentication.STRATEGY_JWT] },\n },\n handler: async (context) => {\n const body = await context.req.json();\n const rs = await this.service.changePassword(context, body);\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n },\n });\n\n // Re-issues an access token using the caller's currently valid JWT — no separate refresh token. Implementers must enforce their own rotation/revocation policy if needed.\n this.defineRoute({\n configs: {\n description: 'Refresh access token',\n path: '/token/refresh',\n method: HTTP.Methods.POST,\n responses: OpenApiResponses.jsonResponse({\n schema: payload?.refreshToken?.response?.schema ?? AnyObjectSchema,\n description: 'Success Response',\n }),\n authenticate: { strategies: [Authentication.STRATEGY_JWT] },\n },\n handler: async (context) => {\n if (!this.service.refreshToken) {\n return NotSupportedUtility.throwNotSupported({\n scope: AuthController.name,\n feature: 'refreshToken',\n logger: this.logger,\n });\n }\n\n const rs = await this.service.refreshToken(context);\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n },\n });\n\n this.defineRoute({\n configs: {\n path: '/who-am-i',\n method: HTTP.Methods.GET,\n request: {\n query: z.object({\n withUserInformation: z\n .enum(['true', 'false', '1', '0'])\n .transform((value) => value === 'true' || value === '1')\n .optional()\n .openapi({\n description: 'Whether to attach user information to currentUser',\n }),\n }),\n },\n responses: {\n [HTTP.ResultCodes.RS_2.Ok]: OpenApiResponses.jsonContent({\n description: 'Success Response',\n schema: JWTTokenPayloadSchema.extend({\n userInformation: (\n payload?.getUserInformation?.response?.schema ?? AnyObjectSchema\n )\n .optional()\n .openapi({\n description: 'Attached when withUserInformation is truthy',\n }),\n }),\n }),\n },\n authenticate: { strategies: [Authentication.STRATEGY_JWT] },\n },\n handler: async (context) => {\n const { withUserInformation = false } = context.req.valid<{\n withUserInformation?: boolean;\n }>('query');\n\n const currentUser = context.get(Authentication.CURRENT_USER);\n let rs = currentUser;\n\n if (withUserInformation) {\n if (!this.service.getUserInformation) {\n return NotSupportedUtility.throwNotSupported({\n scope: AuthController.name,\n feature: 'getUserInformation',\n logger: this.logger,\n });\n }\n\n const userInformation = await this.service.getUserInformation(context, {});\n rs = Object.assign({}, currentUser, { userInformation });\n }\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n },\n });\n\n this.defineRoute({\n configs: {\n description: 'Get current user information',\n path: '/me',\n method: HTTP.Methods.GET,\n responses: OpenApiResponses.jsonResponse({\n schema: payload?.getUserInformation?.response?.schema ?? AnyObjectSchema,\n description: 'Success Response',\n }),\n authenticate: { strategies: [Authentication.STRATEGY_JWT] },\n },\n handler: async (context) => {\n if (!this.service.getUserInformation) {\n return NotSupportedUtility.throwNotSupported({\n scope: AuthController.name,\n feature: 'getUserInformation',\n logger: this.logger,\n });\n }\n\n const rs = await this.service.getUserInformation(context, {});\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n },\n });\n }\n }\n\n inject({ key: serviceKey })(AuthController, undefined, 0);\n\n return AuthController;\n }\n}\n"]}
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../../../src/components/auth/authenticate/controllers/factory.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,IAAI,EAAuB,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,mBAAmB,GACp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,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC;4BACrC,OAAO,mBAAmB,CAAC,iBAAiB,CAAC;gCAC3C,KAAK,EAAE,gBAAc,CAAC,IAAI;gCAC1B,OAAO,EAAE,oBAAoB;gCAC7B,MAAM,EAAE,IAAI,CAAC,MAAM;6BACpB,CAAC,CAAC;wBACL,CAAC;wBAED,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;wBAE9D,OAAO,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;oBACpD,CAAC;iBACF,CAAC,CAAC;YACL,CAAC;SACF,CAAA;QAjNK,cAAc;YADnB,UAAU,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;WACzB,cAAc,CAiNnB;QAED,MAAM,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,CAAC,cAAc,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;QAE1D,OAAO,cAAc,CAAC;IACxB,CAAC;CACF","sourcesContent":["import { BaseRestController } from '@venizia/ignis-kernel';\nimport { inject } from '@venizia/ignis-kernel';\nimport { controller } from '@venizia/ignis-kernel';\nimport { OpenApiResponses } from '@venizia/ignis-kernel';\nimport { NotSupportedUtility } from '@venizia/ignis-kernel';\nimport { AnyObjectSchema } from '@venizia/ignis-kernel';\nimport { z } from '@hono/zod-openapi';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { HTTP, type ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport {\n ChangePasswordRequestSchema,\n SignInRequestSchema,\n SignUpRequestSchema,\n} from '@venizia/ignis-kernel';\nimport {\n Authentication,\n type IAuthService,\n type TDefineAuthControllerOpts,\n} from '@venizia/ignis-kernel';\n\n/** Zod schema of the JWT payload: `userId`, the `roles` (id, identifier, integer priority) and optional `clientId`, `provider` and `email`. */\nexport const JWTTokenPayloadSchema = z.object({\n userId: z.string().or(z.number()),\n roles: z.array(\n z.object({\n id: z.string().or(z.number()),\n identifier: z.string(),\n priority: z.number().int(),\n }),\n ),\n clientId: z.string().optional(),\n provider: z.string().optional(),\n email: z.email().optional(),\n});\n\n/** Builds the decorated REST controller of the authentication routes (sign-in, sign-up, change-password, who-am-i). */\nexport class AuthControllerFactory {\n static build(opts: TDefineAuthControllerOpts) {\n const {\n restPath = '/auth',\n serviceKey,\n requireAuthenticatedSignUp = false,\n payload = {},\n } = opts;\n\n @controller({ path: restPath })\n class AuthController extends BaseRestController {\n service: IAuthService;\n\n constructor(authService: IAuthService) {\n super({\n scope: AuthController.name,\n path: restPath,\n isStrict: true,\n });\n\n if (!authService) {\n throw getError({\n message:\n '[AuthController] Failed to init auth controller | Invalid injectable authentication service!',\n });\n }\n\n this.service = authService;\n }\n\n override binding(): ValueOrPromise<void> {\n this.defineRoute({\n configs: {\n description: 'Sign In',\n path: '/sign-in',\n method: HTTP.Methods.POST,\n request: {\n body: OpenApiResponses.jsonContent({\n description: 'Sign-in request body',\n required: true,\n schema: payload?.signIn?.request?.schema ?? SignInRequestSchema,\n }),\n },\n responses: OpenApiResponses.jsonResponse({\n schema: payload?.signIn?.response?.schema ?? AnyObjectSchema,\n description: 'Success Response',\n }),\n },\n handler: async (context) => {\n const body = await context.req.json();\n const rs = await this.service.signIn(context, body);\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n },\n });\n\n this.defineRoute({\n configs: {\n description: 'Sign Up',\n path: '/sign-up',\n method: HTTP.Methods.POST,\n authenticate: {\n strategies: !requireAuthenticatedSignUp ? [] : [Authentication.STRATEGY_JWT],\n },\n request: {\n body: OpenApiResponses.jsonContent({\n description: 'Sign-up request body',\n required: true,\n schema: payload?.signUp?.request?.schema ?? SignUpRequestSchema,\n }),\n },\n responses: OpenApiResponses.jsonResponse({\n schema: payload?.signUp?.response?.schema ?? AnyObjectSchema,\n description: 'Success Response',\n }),\n },\n handler: async (context) => {\n const body = await context.req.json();\n const rs = await this.service.signUp(context, body);\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n },\n });\n\n this.defineRoute({\n configs: {\n description: 'Change password',\n path: '/change-password',\n method: HTTP.Methods.POST,\n request: {\n body: OpenApiResponses.jsonContent({\n description: 'Change password request body',\n required: true,\n schema: payload?.changePassword?.request?.schema ?? ChangePasswordRequestSchema,\n }),\n },\n responses: OpenApiResponses.jsonResponse({\n schema: payload?.changePassword?.response?.schema ?? AnyObjectSchema,\n description: 'Success Response',\n }),\n authenticate: { strategies: [Authentication.STRATEGY_JWT] },\n },\n handler: async (context) => {\n const body = await context.req.json();\n const rs = await this.service.changePassword(context, body);\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n },\n });\n\n // Re-issues an access token using the caller's currently valid JWT — no separate refresh token. Implementers must enforce their own rotation/revocation policy if needed.\n this.defineRoute({\n configs: {\n description: 'Refresh access token',\n path: '/token/refresh',\n method: HTTP.Methods.POST,\n responses: OpenApiResponses.jsonResponse({\n schema: payload?.refreshToken?.response?.schema ?? AnyObjectSchema,\n description: 'Success Response',\n }),\n authenticate: { strategies: [Authentication.STRATEGY_JWT] },\n },\n handler: async (context) => {\n if (!this.service.refreshToken) {\n return NotSupportedUtility.throwNotSupported({\n scope: AuthController.name,\n feature: 'refreshToken',\n logger: this.logger,\n });\n }\n\n const rs = await this.service.refreshToken(context);\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n },\n });\n\n this.defineRoute({\n configs: {\n path: '/who-am-i',\n method: HTTP.Methods.GET,\n request: {\n query: z.object({\n withUserInformation: z\n .enum(['true', 'false', '1', '0'])\n .transform((value) => value === 'true' || value === '1')\n .optional()\n .openapi({\n description: 'Whether to attach user information to currentUser',\n }),\n }),\n },\n responses: {\n [HTTP.ResultCodes.RS_2.Ok]: OpenApiResponses.jsonContent({\n description: 'Success Response',\n schema: JWTTokenPayloadSchema.extend({\n userInformation: (\n payload?.getUserInformation?.response?.schema ?? AnyObjectSchema\n )\n .optional()\n .openapi({\n description: 'Attached when withUserInformation is truthy',\n }),\n }),\n }),\n },\n authenticate: { strategies: [Authentication.STRATEGY_JWT] },\n },\n handler: async (context) => {\n const { withUserInformation = false } = context.req.valid<{\n withUserInformation?: boolean;\n }>('query');\n\n const currentUser = context.get(Authentication.CURRENT_USER);\n let rs = currentUser;\n\n if (withUserInformation) {\n if (!this.service.getUserInformation) {\n return NotSupportedUtility.throwNotSupported({\n scope: AuthController.name,\n feature: 'getUserInformation',\n logger: this.logger,\n });\n }\n\n const userInformation = await this.service.getUserInformation(context, {});\n rs = Object.assign({}, currentUser, { userInformation });\n }\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n },\n });\n\n this.defineRoute({\n configs: {\n description: 'Get current user information',\n path: '/me',\n method: HTTP.Methods.GET,\n responses: OpenApiResponses.jsonResponse({\n schema: payload?.getUserInformation?.response?.schema ?? AnyObjectSchema,\n description: 'Success Response',\n }),\n authenticate: { strategies: [Authentication.STRATEGY_JWT] },\n },\n handler: async (context) => {\n if (!this.service.getUserInformation) {\n return NotSupportedUtility.throwNotSupported({\n scope: AuthController.name,\n feature: 'getUserInformation',\n logger: this.logger,\n });\n }\n\n const rs = await this.service.getUserInformation(context, {});\n\n return context.json(rs, HTTP.ResultCodes.RS_2.Ok);\n },\n });\n }\n }\n\n inject({ key: serviceKey })(AuthController, undefined, 0);\n\n return AuthController;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authenticate/controllers/jwks/controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAuB,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,2LAA2L;AAC3L,IAAa,cAAc,sBAA3B,MAAa,cAAe,SAAQ,kBAAkB;IACpD,YAOU,WAAmC;QAE3C,KAAK,CAAC;YACJ,KAAK,EAAE,gBAAc,CAAC,IAAI;YAC1B,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;SACf,CAAC,CAAC;QANK,gBAAW,GAAX,WAAW,CAAwB;IAO7C,CAAC;IAEQ,OAAO;QACd,IAAI,CAAC,WAAW,CAAC;YACf,OAAO,EAAE,YAAY,CAAC,cAAc;YACpC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;gBACzB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC;gBACnD,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,oDAAoD,CAAC,CAAC;gBAEtF,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACtD,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA5BY,cAAc;IAEtB,WAAA,MAAM,CAAC;QACN,GAAG,EAAE,WAAW,CAAC,KAAK,CAAC;YACrB,SAAS,EAAE,iBAAiB,CAAC,OAAO;YACpC,GAAG,EAAE,sBAAsB,CAAC,IAAI;SACjC,CAAC;KACH,CAAC,CAAA;qCACmB,sBAAsB;GARlC,cAAc,CA4B1B","sourcesContent":["import { BaseRestController } from '@venizia/ignis-kernel';\nimport { inject } from '@venizia/ignis-kernel';\nimport { BindingNamespaces } from '@venizia/ignis-kernel';\nimport { HTTP, type ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { BindingKeys } from '@venizia/ignis-inversion';\nimport { JWKSIssuerTokenService } from '../../services';\nimport { RouteConfigs } from './definitions';\n\n/** Serves the public JWKS from `JWKSIssuerTokenService` for external verifiers, with a one-hour `Cache-Control` max-age. Mounted at `/certs` unless the issuer options set `rest.path`. */\nexport class JWKSController extends BaseRestController {\n constructor(\n @inject({\n key: BindingKeys.build({\n namespace: BindingNamespaces.SERVICE,\n key: JWKSIssuerTokenService.name,\n }),\n })\n private jwksService: JWKSIssuerTokenService,\n ) {\n super({\n scope: JWKSController.name,\n path: '/certs',\n isStrict: true,\n });\n }\n\n override binding(): ValueOrPromise<void> {\n this.defineRoute({\n configs: RouteConfigs.GET_JWKS_CERTS,\n handler: async (context) => {\n const jwks = await this.jwksService.getJWKSAsync();\n context.header('Cache-Control', 'public, max-age=3600, stale-while-revalidate=86400');\n\n return context.json(jwks, HTTP.ResultCodes.RS_2.Ok);\n },\n });\n }\n}\n"]}
1
+ {"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authenticate/controllers/jwks/controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAuB,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,2LAA2L;AAC3L,IAAa,cAAc,sBAA3B,MAAa,cAAe,SAAQ,kBAAkB;IACpD,YAOU,WAAmC;QAE3C,KAAK,CAAC;YACJ,KAAK,EAAE,gBAAc,CAAC,IAAI;YAC1B,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;SACf,CAAC,CAAC;QANK,gBAAW,GAAX,WAAW,CAAwB;IAO7C,CAAC;IAEQ,OAAO;QACd,IAAI,CAAC,WAAW,CAAC;YACf,OAAO,EAAE,YAAY,CAAC,cAAc;YACpC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;gBACzB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC;gBACnD,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,oDAAoD,CAAC,CAAC;gBAEtF,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACtD,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA5BY,cAAc;IAEtB,WAAA,MAAM,CAAC;QACN,GAAG,EAAE,WAAW,CAAC,KAAK,CAAyB;YAC7C,SAAS,EAAE,iBAAiB,CAAC,OAAO;YACpC,GAAG,EAAE,sBAAsB,CAAC,IAAI;SACjC,CAAC;KACH,CAAC,CAAA;qCACmB,sBAAsB;GARlC,cAAc,CA4B1B","sourcesContent":["import { BaseRestController } from '@venizia/ignis-kernel';\nimport { inject } from '@venizia/ignis-kernel';\nimport { BindingNamespaces } from '@venizia/ignis-kernel';\nimport { HTTP, type ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { BindingKeys } from '@venizia/ignis-inversion';\nimport { JWKSIssuerTokenService } from '../../services';\nimport { RouteConfigs } from './definitions';\n\n/** Serves the public JWKS from `JWKSIssuerTokenService` for external verifiers, with a one-hour `Cache-Control` max-age. Mounted at `/certs` unless the issuer options set `rest.path`. */\nexport class JWKSController extends BaseRestController {\n constructor(\n @inject({\n key: BindingKeys.build<JWKSIssuerTokenService>({\n namespace: BindingNamespaces.SERVICE,\n key: JWKSIssuerTokenService.name,\n }),\n })\n private jwksService: JWKSIssuerTokenService,\n ) {\n super({\n scope: JWKSController.name,\n path: '/certs',\n isStrict: true,\n });\n }\n\n override binding(): ValueOrPromise<void> {\n this.defineRoute({\n configs: RouteConfigs.GET_JWKS_CERTS,\n handler: async (context) => {\n const jwks = await this.jwksService.getJWKSAsync();\n context.header('Cache-Control', 'public, max-age=3600, stale-while-revalidate=86400');\n\n return context.json(jwks, HTTP.ResultCodes.RS_2.Ok);\n },\n });\n }\n}\n"]}
@@ -47,7 +47,7 @@ export declare const RouteConfigs: {
47
47
  200: {
48
48
  description: string;
49
49
  content: {
50
- 'application/json': {
50
+ "application/json": {
51
51
  schema: z.ZodObject<{
52
52
  keys: z.ZodArray<z.ZodObject<{
53
53
  kty: z.ZodString;
@@ -68,7 +68,7 @@ export declare const RouteConfigs: {
68
68
  headers: never;
69
69
  description: string;
70
70
  content: {
71
- 'application/json': {
71
+ "application/json": {
72
72
  schema: z.ZodObject<{
73
73
  keys: z.ZodArray<z.ZodObject<{
74
74
  kty: z.ZodString;
@@ -1 +1 @@
1
- {"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authenticate/controllers/service-certs/controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EAClB,iBAAiB,EACjB,MAAM,GACP,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAuB,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,6BAA6B,EAAE,MAAM,uCAAuC,CAAC;AACtF,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAEzD,4GAA4G;AAC5G,IAAa,sBAAsB,8BAAnC,MAAa,sBAAuB,SAAQ,kBAAkB;IAC5D,YAOmB,MAAqC,EAEtD,IAAY;QAEZ,KAAK,CAAC,EAAE,KAAK,EAAE,wBAAsB,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;QAJnD,WAAM,GAAN,MAAM,CAA+B;IAKxD,CAAC;IAEQ,OAAO;QACd,IAAI,CAAC,WAAW,CAAC;YACf,OAAO,EAAE,wBAAwB,CAAC,iBAAiB;YACnD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;gBACzB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;gBAC/C,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,mDAAmD,CAAC,CAAC;gBAErF,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACtD,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA1BY,sBAAsB;IAE9B,WAAA,MAAM,CAAC;QACN,GAAG,EAAE,WAAW,CAAC,KAAK,CAAC;YACrB,SAAS,EAAE,iBAAiB,CAAC,OAAO;YACpC,GAAG,EAAE,6BAA6B,CAAC,IAAI;SACxC,CAAC;KACH,CAAC,CAAA;IAED,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,uBAAuB,CAAC,kBAAkB,EAAE,CAAC,CAAA;qCADnC,6BAA6B;GAR7C,sBAAsB,CA0BlC","sourcesContent":["import {\n AuthenticateBindingKeys,\n BaseRestController,\n BindingNamespaces,\n inject,\n} from '@venizia/ignis-kernel';\nimport { HTTP, type ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { BindingKeys } from '@venizia/ignis-inversion';\nimport { ServiceAssertionSignerService } from '../../services/service/signer.service';\nimport { ServiceCertsRouteConfigs } from './definitions';\n\n/** Publishes this service's assertion-signing public key. Mounted only when signing keys are configured. */\nexport class ServiceCertsController extends BaseRestController {\n constructor(\n @inject({\n key: BindingKeys.build({\n namespace: BindingNamespaces.SERVICE,\n key: ServiceAssertionSignerService.name,\n }),\n })\n private readonly signer: ServiceAssertionSignerService,\n @inject({ key: AuthenticateBindingKeys.SERVICE_CERTS_PATH })\n path: string,\n ) {\n super({ scope: ServiceCertsController.name, path, isStrict: true });\n }\n\n override binding(): ValueOrPromise<void> {\n this.defineRoute({\n configs: ServiceCertsRouteConfigs.GET_SERVICE_CERTS,\n handler: async (context) => {\n const jwks = await this.signer.getPublicJWKS();\n context.header('Cache-Control', 'public, max-age=600, stale-while-revalidate=86400');\n\n return context.json(jwks, HTTP.ResultCodes.RS_2.Ok);\n },\n });\n }\n}\n"]}
1
+ {"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authenticate/controllers/service-certs/controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EAClB,iBAAiB,EACjB,MAAM,GACP,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAuB,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,6BAA6B,EAAE,MAAM,uCAAuC,CAAC;AACtF,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAEzD,4GAA4G;AAC5G,IAAa,sBAAsB,8BAAnC,MAAa,sBAAuB,SAAQ,kBAAkB;IAC5D,YAOmB,MAAqC,EAEtD,IAAY;QAEZ,KAAK,CAAC,EAAE,KAAK,EAAE,wBAAsB,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;QAJnD,WAAM,GAAN,MAAM,CAA+B;IAKxD,CAAC;IAEQ,OAAO;QACd,IAAI,CAAC,WAAW,CAAC;YACf,OAAO,EAAE,wBAAwB,CAAC,iBAAiB;YACnD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;gBACzB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;gBAC/C,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,mDAAmD,CAAC,CAAC;gBAErF,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACtD,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA1BY,sBAAsB;IAE9B,WAAA,MAAM,CAAC;QACN,GAAG,EAAE,WAAW,CAAC,KAAK,CAAgC;YACpD,SAAS,EAAE,iBAAiB,CAAC,OAAO;YACpC,GAAG,EAAE,6BAA6B,CAAC,IAAI;SACxC,CAAC;KACH,CAAC,CAAA;IAED,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,uBAAuB,CAAC,kBAAkB,EAAE,CAAC,CAAA;qCADnC,6BAA6B;GAR7C,sBAAsB,CA0BlC","sourcesContent":["import {\n AuthenticateBindingKeys,\n BaseRestController,\n BindingNamespaces,\n inject,\n} from '@venizia/ignis-kernel';\nimport { HTTP, type ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { BindingKeys } from '@venizia/ignis-inversion';\nimport { ServiceAssertionSignerService } from '../../services/service/signer.service';\nimport { ServiceCertsRouteConfigs } from './definitions';\n\n/** Publishes this service's assertion-signing public key. Mounted only when signing keys are configured. */\nexport class ServiceCertsController extends BaseRestController {\n constructor(\n @inject({\n key: BindingKeys.build<ServiceAssertionSignerService>({\n namespace: BindingNamespaces.SERVICE,\n key: ServiceAssertionSignerService.name,\n }),\n })\n private readonly signer: ServiceAssertionSignerService,\n @inject({ key: AuthenticateBindingKeys.SERVICE_CERTS_PATH })\n path: string,\n ) {\n super({ scope: ServiceCertsController.name, path, isStrict: true });\n }\n\n override binding(): ValueOrPromise<void> {\n this.defineRoute({\n configs: ServiceCertsRouteConfigs.GET_SERVICE_CERTS,\n handler: async (context) => {\n const jwks = await this.signer.getPublicJWKS();\n context.header('Cache-Control', 'public, max-age=600, stale-while-revalidate=86400');\n\n return context.json(jwks, HTTP.ResultCodes.RS_2.Ok);\n },\n });\n }\n}\n"]}
@@ -54,7 +54,7 @@ export declare const ServiceCertsRouteConfigs: {
54
54
  200: {
55
55
  description: string;
56
56
  content: {
57
- 'application/json': {
57
+ "application/json": {
58
58
  schema: z.ZodObject<{
59
59
  keys: z.ZodArray<z.ZodObject<{
60
60
  kty: z.ZodString;
@@ -72,7 +72,7 @@ export declare const ServiceCertsRouteConfigs: {
72
72
  headers: never;
73
73
  description: string;
74
74
  content: {
75
- 'application/json': {
75
+ "application/json": {
76
76
  schema: z.ZodObject<{
77
77
  keys: z.ZodArray<z.ZodObject<{
78
78
  kty: z.ZodString;
@@ -31,7 +31,7 @@ let BasicTokenService = BasicTokenService_1 = class BasicTokenService extends Ba
31
31
  }
32
32
  /** Extracts username:password from Base64-encoded Authorization header. */
33
33
  extractCredentials(context) {
34
- const authHeaderValue = context.req.header('Authorization');
34
+ const authHeaderValue = context.req.header(HTTP.Headers.AUTHORIZATION);
35
35
  if (!authHeaderValue) {
36
36
  throw getError({
37
37
  error: AuthenticationErrors.HEADER_MISSING,
@@ -1 +1 @@
1
- {"version":3,"file":"service.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authenticate/services/basic/service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAErD,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,uBAAuB,GAGxB,MAAM,uBAAuB,CAAC;AAE/B,kFAAkF;AAClF,IAAa,iBAAiB,yBAA9B,MAAa,iBAAuC,SAAQ,WAAW;IAGrE,YAEY,OAAqC;QAE/C,KAAK,CAAC,EAAE,KAAK,EAAE,mBAAiB,CAAC,IAAI,EAAE,CAAC,CAAC;QAF/B,YAAO,GAAP,OAAO,CAA8B;QAI/C,IAAI,CAAC,OAAO,EAAE,iBAAiB,EAAE,CAAC;YAChC,M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4CAA4C;aACtD,CAAC,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAxGY,iBAAiB;IAIzB,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,uBAAuB,CAAC,aAAa,EAAE,CAAC,CAAA;;GAJ9C,iBAAiB,CAwG7B","sourcesContent":["import { type TContext } from '@venizia/ignis-kernel';\nimport { inject } from '@venizia/ignis-kernel';\nimport { BaseService } from '@venizia/ignis-kernel';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport { type Env } from 'hono';\nimport {\n Authentication,\n AuthenticationErrors,\n AuthenticateBindingKeys,\n type IAuthUser,\n type TBasicTokenServiceOptions,\n} from '@venizia/ignis-kernel';\n\n/** Extracts and verifies Basic auth credentials from the Authorization header. */\nexport class BasicTokenService<E extends Env = Env> extends BaseService {\n protected verifyCredentials: TBasicTokenServiceOptions<E>['verifyCredentials'];\n\n constructor(\n @inject({ key: AuthenticateBindingKeys.BASIC_OPTIONS })\n protected options: TBasicTokenServiceOptions<E>,\n ) {\n super({ scope: BasicTokenService.name });\n\n if (!options?.verifyCredentials) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[BasicTokenService] Invalid verifyCredentials function',\n });\n }\n\n this.verifyCredentials = options.verifyCredentials;\n }\n\n /** Extracts username:password from Base64-encoded Authorization header. */\n extractCredentials(context: TContext<E, string>): { username: string; password: string } {\n const authHeaderValue = context.req.header('Authorization');\n\n if (!authHeaderValue) {\n throw getError({\n error: AuthenticationErrors.HEADER_MISSING,\n message: 'Unauthorized! Missing authorization header',\n });\n }\n\n if (!authHeaderValue.startsWith(Authentication.TYPE_BASIC)) {\n throw getError({\n error: AuthenticationErrors.SCHEME_INVALID,\n message: 'Unauthorized! Invalid authorization schema, expected Basic',\n });\n }\n\n const parts = authHeaderValue.split(' ');\n\n if (parts.length !== 2) {\n throw getError({\n error: AuthenticationErrors.HEADER_MALFORMED,\n message: 'Unauthorized! Invalid authorization header format',\n });\n }\n\n const [, base64Credentials] = parts;\n\n // The rejection reason stays in the LOG, never in the response: telling a caller which half of its credential was malformed is a probing oracle.\n const reject = (reason: string): never => {\n this.logger\n .for(this.extractCredentials.name)\n .debug('Failed to decode credentials | Reason: %s', reason);\n\n throw getError({\n error: AuthenticationErrors.CREDENTIALS_MALFORMED,\n message: 'Unauthorized! Invalid base64 credentials format',\n });\n };\n\n let decoded: string;\n\n try {\n decoded = Buffer.from(base64Credentials, 'base64').toString('utf-8');\n } catch (error) {\n return reject(`Base64 decode failed | Error: ${error}`);\n }\n\n const colonIndex = decoded.indexOf(':');\n\n if (colonIndex === -1) {\n return reject('Missing colon separator');\n }\n\n const username = decoded.substring(0, colonIndex);\n const password = decoded.substring(colonIndex + 1);\n\n if (!username) {\n return reject('Empty username');\n }\n\n return { username, password };\n }\n\n /** Verifies credentials via the user-provided verification function. */\n async verify(opts: {\n credentials: { username: string; password: string };\n context: TContext<E, string>;\n }): Promise<IAuthUser> {\n const user = await this.verifyCredentials(opts);\n\n if (!user) {\n this.logger\n .for(this.verify.name)\n .debug('Invalid credentials for username: %s', opts.credentials.username);\n\n throw getError({\n error: AuthenticationErrors.CREDENTIALS_INVALID,\n message: 'Unauthorized! Invalid username or password',\n });\n }\n\n return user;\n }\n}\n"]}
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authenticate/services/basic/service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAErD,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,uBAAuB,GAGxB,MAAM,uBAAuB,CAAC;AAE/B,kFAAkF;A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,CAAC,IAAI,EAAE,CAAC;YACV,IAAI,CAAC,MAAM;iBACR,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;iBACrB,KAAK,CAAC,sCAAsC,EAAE,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;YAE5E,MAAM,QAAQ,CAAC;gBACb,KAAK,EAAE,oBAAoB,CAAC,mBAAmB;gBAC/C,OAAO,EAAE,4CAA4C;aACtD,CAAC,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAxGY,iBAAiB;IAIzB,WAAA,MAAM,CAAC,EAAE,GAAG,EAAE,uBAAuB,CAAC,aAAa,EAAE,CAAC,CAAA;;GAJ9C,iBAAiB,CAwG7B","sourcesContent":["import { type TContext } from '@venizia/ignis-kernel';\nimport { inject } from '@venizia/ignis-kernel';\nimport { BaseService } from '@venizia/ignis-kernel';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport { type Env } from 'hono';\nimport {\n Authentication,\n AuthenticationErrors,\n AuthenticateBindingKeys,\n type IAuthUser,\n type TBasicTokenServiceOptions,\n} from '@venizia/ignis-kernel';\n\n/** Extracts and verifies Basic auth credentials from the Authorization header. */\nexport class BasicTokenService<E extends Env = Env> extends BaseService {\n protected verifyCredentials: TBasicTokenServiceOptions<E>['verifyCredentials'];\n\n constructor(\n @inject({ key: AuthenticateBindingKeys.BASIC_OPTIONS })\n protected options: TBasicTokenServiceOptions<E>,\n ) {\n super({ scope: BasicTokenService.name });\n\n if (!options?.verifyCredentials) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[BasicTokenService] Invalid verifyCredentials function',\n });\n }\n\n this.verifyCredentials = options.verifyCredentials;\n }\n\n /** Extracts username:password from Base64-encoded Authorization header. */\n extractCredentials(context: TContext<E, string>): { username: string; password: string } {\n const authHeaderValue = context.req.header(HTTP.Headers.AUTHORIZATION);\n\n if (!authHeaderValue) {\n throw getError({\n error: AuthenticationErrors.HEADER_MISSING,\n message: 'Unauthorized! Missing authorization header',\n });\n }\n\n if (!authHeaderValue.startsWith(Authentication.TYPE_BASIC)) {\n throw getError({\n error: AuthenticationErrors.SCHEME_INVALID,\n message: 'Unauthorized! Invalid authorization schema, expected Basic',\n });\n }\n\n const parts = authHeaderValue.split(' ');\n\n if (parts.length !== 2) {\n throw getError({\n error: AuthenticationErrors.HEADER_MALFORMED,\n message: 'Unauthorized! Invalid authorization header format',\n });\n }\n\n const [, base64Credentials] = parts;\n\n // The rejection reason stays in the LOG, never in the response: telling a caller which half of its credential was malformed is a probing oracle.\n const reject = (reason: string): never => {\n this.logger\n .for(this.extractCredentials.name)\n .debug('Failed to decode credentials | Reason: %s', reason);\n\n throw getError({\n error: AuthenticationErrors.CREDENTIALS_MALFORMED,\n message: 'Unauthorized! Invalid base64 credentials format',\n });\n };\n\n let decoded: string;\n\n try {\n decoded = Buffer.from(base64Credentials, 'base64').toString('utf-8');\n } catch (error) {\n return reject(`Base64 decode failed | Error: ${error}`);\n }\n\n const colonIndex = decoded.indexOf(':');\n\n if (colonIndex === -1) {\n return reject('Missing colon separator');\n }\n\n const username = decoded.substring(0, colonIndex);\n const password = decoded.substring(colonIndex + 1);\n\n if (!username) {\n return reject('Empty username');\n }\n\n return { username, password };\n }\n\n /** Verifies credentials via the user-provided verification function. */\n async verify(opts: {\n credentials: { username: string; password: string };\n context: TContext<E, string>;\n }): Promise<IAuthUser> {\n const user = await this.verifyCredentials(opts);\n\n if (!user) {\n this.logger\n .for(this.verify.name)\n .debug('Invalid credentials for username: %s', opts.credentials.username);\n\n throw getError({\n error: AuthenticationErrors.CREDENTIALS_INVALID,\n message: 'Unauthorized! Invalid username or password',\n });\n }\n\n return user;\n }\n}\n"]}
@@ -81,7 +81,7 @@ export declare abstract class AbstractBearerTokenService<E extends Env = Env> ex
81
81
  /** A `null` is written as `null` whatever the field's codec is: a codec converts a value, and `null` is none. */
82
82
  protected serializeField(opts: {
83
83
  key: string;
84
- value: any;
84
+ value: unknown;
85
85
  }): string;
86
86
  /**
87
87
  * With `applicationSecret` set, AES-encrypts the key and the value of every claim outside `JWT_COMMON_FIELDS`;
@@ -89,7 +89,7 @@ export declare abstract class AbstractBearerTokenService<E extends Env = Env> ex
89
89
  * so the token decodes to the same payload with encryption on or off and `null` stays distinct from absent. An
90
90
  * `undefined` claim is skipped, as JSON drops it.
91
91
  */
92
- encryptPayload(payload: IJWTTokenPayload): Promise<Record<string, any>>;
92
+ encryptPayload(payload: IJWTTokenPayload): Promise<Record<string, unknown>>;
93
93
  /** The text `null` reads as `null` before any codec sees it, the other half of {@link serializeField}. */
94
94
  protected deserializeField(opts: {
95
95
  key: string;
@@ -108,12 +108,14 @@ export declare abstract class AbstractBearerTokenService<E extends Env = Env> ex
108
108
  */
109
109
  protected applySignClaims(opts: {
110
110
  signer: SignJWT;
111
- payload: Record<string, any>;
111
+ payload: Record<string, unknown>;
112
112
  claims?: IJWTIssueClaims;
113
113
  }): SignJWT;
114
114
  decryptPayload(opts: {
115
115
  result: JWTVerifyResult<IJWTTokenPayload>;
116
116
  }): Promise<IJWTTokenPayload>;
117
+ /** A decrypted claim set is a payload only if it names its user. */
118
+ private static isTokenPayload;
117
119
  protected abstract doVerify(token: string): Promise<IJWTTokenPayload>;
118
120
  abstract getSigner(opts: {
119
121
  payload: IJWTTokenPayload;
@@ -117,7 +117,7 @@ export class AbstractBearerTokenService extends BaseService {
117
117
  }
118
118
  extractCredentials(context) {
119
119
  const request = context.req;
120
- const authHeaderValue = request.header('Authorization');
120
+ const authHeaderValue = request.header(HTTP.Headers.AUTHORIZATION);
121
121
  if (!authHeaderValue) {
122
122
  throw getError({
123
123
  error: AuthenticationErrors.HEADER_MISSING,
@@ -311,13 +311,30 @@ export class AbstractBearerTokenService extends BaseService {
311
311
  message: key,
312
312
  secret: this.applicationSecret,
313
313
  });
314
+ const encryptedValue = payload[key];
315
+ if (typeof encryptedValue !== 'string') {
316
+ throw getError({
317
+ statusCode: HTTP.ResultCodes.RS_4.Unauthorized,
318
+ message: '[decryptPayload] An encrypted claim is not a string',
319
+ });
320
+ }
314
321
  const decryptedValue = await this.aes.decrypt({
315
- message: payload[key],
322
+ message: encryptedValue,
316
323
  secret: this.applicationSecret,
317
324
  });
318
325
  rs[decryptedKey] = this.deserializeField({ key: decryptedKey, value: decryptedValue });
319
326
  }
327
+ if (!AbstractBearerTokenService.isTokenPayload(rs)) {
328
+ throw getError({
329
+ statusCode: HTTP.ResultCodes.RS_4.Unauthorized,
330
+ message: '[decryptPayload] The decrypted claims carry no userId',
331
+ });
332
+ }
320
333
  return rs;
321
334
  }
335
+ /** A decrypted claim set is a payload only if it names its user. */
336
+ static isTokenPayload(value) {
337
+ return 'userId' in value && value.userId !== undefined;
338
+ }
322
339
  }
323
340
  //# sourceMappingURL=abstract.service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"abstract.service.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authenticate/services/bearer/abstract.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAUtE,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,WAAW,EACX,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAiB5C,gGAAgG;AAChG,MAAM,OAAgB,0BAAgD,SAAQ,WAAW;IAAzF;;QAYY,QAAG,GAAe,IAAI,CAAC;QACvB,sBAAiB,GAAkB,IAAI,CAAC;QACxC,gBAAW,GAAoC,IAAI,GAAG,EAAE,CAAC;QAEnE,oJAAoJ;QAC1I,iBAAY,GAA6B,IAAI,CAAC;QAExD,yFAAyF;QAC/E,kBAAa,GAA4B,IAAI,CAA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,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC1D,EAAE,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;gBACvB,SAAS;YACX,CAAC;YAED,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;gBAC1C,OAAO,EAAE,GAAG;gBACZ,MAAM,EAAE,IAAI,CAAC,iBAAiB;aAC/B,CAAC,CAAC;YACH,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;gBAC5C,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC;gBACrB,MAAM,EAAE,IAAI,CAAC,iBAAiB;aAC/B,CAAC,CAAC;YAEH,EAAE,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,gBAAgB,CAAC,EAAE,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC;QACzF,CAAC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC","sourcesContent":["import type { AESAlgorithmType } from '@venizia/ignis-helpers';\nimport { AES } from '@venizia/ignis-helpers';\nimport type { ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport { getError, RecordUtility } from '@venizia/ignis-helpers/core';\nimport type {\n IJWTClaimsOptions,\n IJWTIssueClaims,\n IJWTTokenPayload,\n IJWTVerifyOptions,\n IPayloadFieldCodec,\n TContext,\n TGetTokenExpiresFn,\n} from '@venizia/ignis-kernel';\nimport {\n Authentication,\n AuthenticationErrors,\n BaseService,\n ServiceAssertion,\n} from '@venizia/ignis-kernel';\nimport type { Env } from 'hono';\nimport { JoseLoader } from '../jose-loader';\nimport type { JWTPayload, JWTVerifyOptions, JWTVerifyResult, SignJWT } from 'jose';\n\n/** What a token service is configured with for claims: the required `claims`, the `verify` checks, and the removed `sign` it refuses. */\nexport interface IClaimsConfigSource {\n claims?: unknown;\n verify?: unknown;\n /** Removed: refused with a message that points to `claims`. */\n sign?: unknown;\n}\n\n/** What {@link AbstractBearerTokenService.resolveClaimsConfig} answers: the validated claims and the verify options jose receives. */\nexport interface IResolvedClaimsConfig {\n claims: IJWTClaimsOptions;\n verify: JWTVerifyOptions & { algorithms: string[] };\n}\n\n/** Abstract base for Bearer-token services (JWS, JWKS) with optional AES payload encryption. */\nexport abstract class AbstractBearerTokenService<E extends Env = Env> extends BaseService {\n /** Standard JWT fields that are never encrypted. */\n static readonly JWT_COMMON_FIELDS = new Set<keyof JWTPayload>([\n 'iss',\n 'sub',\n 'aud',\n 'jti',\n 'nbf',\n 'exp',\n 'iat',\n ]);\n\n protected aes: AES | null = null;\n protected applicationSecret: string | null = null;\n protected fieldCodecs: Map<string, IPayloadFieldCodec> = new Map();\n\n /** Configured `iss` / `aud`: stamped on every issued token, authoritative over anything the payload carries, and required on every verified one. */\n protected claimOptions: IJWTClaimsOptions | null = null;\n\n /** What jose verifies against: the claims, the algorithm pin and the `verify` checks. */\n protected verifyOptions: JWTVerifyOptions | null = null;\n\n /** The keys a `claims` object may hold. */\n static readonly CLAIM_KEYS: ReadonlyArray<string> = ['issuer', 'audience'];\n\n /**\n * Validates the claims configuration of a token service and answers what the service uses. It throws, naming the\n * key, when `claims.issuer` is missing or empty, when `claims.audience` is present but not a non-empty string or a\n * non-empty list of them, when `claims` holds another key, when the removed `sign` or `verify.issuer` /\n * `verify.audience` is still passed, and when no algorithm is pinned. `claims.audience` is optional: without it\n * no `aud` is stamped and none is checked.\n * `pinnedAlgorithms` is what the service signs with; a verifier has none and requires `verify.algorithms`.\n * The component calls it at boot, and a service calls it when it is built, so neither can start without them.\n */\n static resolveClaimsConfig(opts: {\n scope: string;\n options: IClaimsConfigSource;\n pinnedAlgorithms?: string[];\n }): IResolvedClaimsConfig {\n const { scope, options, pinnedAlgorithms } = opts;\n const fail = (detail: string) =>\n getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] ${detail}`,\n });\n\n if (options.sign !== undefined) {\n throw fail(\n '`sign` was removed | put the issuer and the audience in `claims: { issuer, audience }`: they are stamped on every token and required on every verified one',\n );\n }\n\n if (options.verify !== undefined && !RecordUtility.isPlainRecord(options.verify)) {\n throw fail(\n 'verify must be an object | its checks (maxTokenAge, subject, ...) would be dropped silently',\n );\n }\n\n const verify = RecordUtility.isPlainRecord(options.verify) ? options.verify : {};\n\n for (const key of AbstractBearerTokenService.CLAIM_KEYS) {\n if (key in verify) {\n throw fail(\n `verify.${key} was removed | set claims.${key}: it is stamped on every token and required on every verified one`,\n );\n }\n }\n\n const { claims } = options;\n\n if (!RecordUtility.isPlainRecord(claims)) {\n throw fail(\n 'claims is required | pass claims: { issuer: string, audience: string | string[] }: a token signed with the same key for another purpose must not authenticate a request',\n );\n }\n\n const unknown = Object.keys(claims).filter(\n (key) => !AbstractBearerTokenService.CLAIM_KEYS.includes(key),\n );\n\n if (unknown.length > 0) {\n throw fail(\n `claims holds unknown keys ${JSON.stringify(unknown)} | accepted: ${AbstractBearerTokenService.CLAIM_KEYS.join(', ')}`,\n );\n }\n\n const { issuer, audience } = claims;\n const isName = (value: unknown): value is string =>\n typeof value === 'string' && value.trim().length > 0;\n\n if (!isName(issuer)) {\n throw fail('claims.issuer is required | a non-empty string');\n }\n\n // Optional, but a present value is checked: `null`, `''` and `[]` are mistakes, not \"no audience\".\n if (\n audience !== undefined &&\n !isName(audience) &&\n !(Array.isArray(audience) && audience.length > 0 && audience.every(isName))\n ) {\n throw fail(\n 'claims.audience must be a non-empty string or a non-empty list of them | or leave it out',\n );\n }\n\n const resolvedAudience = Array.isArray(audience) ? [...audience] : audience;\n\n const algorithms = verify.algorithms ?? pinnedAlgorithms;\n\n if (!Array.isArray(algorithms) || algorithms.length === 0 || !algorithms.every(isName)) {\n throw fail(\n \"verify.algorithms is required | the accepted JWS algorithms, for example ['RS256']: a verifier cannot know what the issuer signs with\",\n );\n }\n\n if (algorithms.some((algorithm) => algorithm.trim().toLowerCase() === 'none')) {\n throw fail(\"the algorithm 'none' is refused | a token with no signature verifies nothing\");\n }\n\n return {\n claims: { issuer, ...(resolvedAudience === undefined ? {} : { audience: resolvedAudience }) },\n verify: {\n ...(verify as IJWTVerifyOptions),\n issuer,\n ...(resolvedAudience === undefined ? {} : { audience: resolvedAudience }),\n algorithms: [...algorithms],\n },\n };\n }\n\n /** Validates the claims configuration (see {@link AbstractBearerTokenService.resolveClaimsConfig}) and keeps the result. */\n protected configureClaims(opts: {\n options: IClaimsConfigSource;\n pinnedAlgorithms?: string[];\n }): void {\n const resolved = AbstractBearerTokenService.resolveClaimsConfig({\n scope: this.scope,\n options: opts.options,\n pinnedAlgorithms: opts.pinnedAlgorithms,\n });\n\n this.claimOptions = resolved.claims;\n this.verifyOptions = resolved.verify;\n }\n\n /** Configures AES payload encryption and field codecs. Both aesAlgorithm and applicationSecret required to activate encryption. */\n protected configurePayloadEncryption(opts: {\n aesAlgorithm?: AESAlgorithmType;\n applicationSecret?: string;\n fieldCodecs?: IPayloadFieldCodec[];\n }): void {\n const { aesAlgorithm = 'aes-256-cbc', applicationSecret, fieldCodecs } = opts;\n\n if (fieldCodecs) {\n for (const codec of fieldCodecs) {\n this.fieldCodecs.set(codec.key, codec);\n }\n }\n\n if (!applicationSecret) {\n return;\n }\n\n this.aes = AES.withAlgorithm(aesAlgorithm);\n this.applicationSecret = applicationSecret;\n }\n\n extractCredentials(context: TContext<E, string>): { type: string; token: string } {\n const request = context.req;\n\n const authHeaderValue = request.header('Authorization');\n\n if (!authHeaderValue) {\n throw getError({\n error: AuthenticationErrors.HEADER_MISSING,\n message: 'Unauthorized user! Missing authorization header',\n });\n }\n\n if (!authHeaderValue.startsWith(Authentication.TYPE_BEARER)) {\n throw getError({\n error: AuthenticationErrors.SCHEME_INVALID,\n message: 'Unauthorized user! Invalid schema of request token!',\n });\n }\n\n const parts = authHeaderValue.split(' ');\n\n if (parts.length !== 2) {\n throw getError({\n error: AuthenticationErrors.HEADER_MALFORMED,\n message: `Authorization header value is invalid format. It must follow the pattern: 'Bearer xx.yy.zz' where xx.yy.zz is a valid JWT token.`,\n });\n }\n\n const [tokenType, tokenValue] = parts;\n\n return { type: tokenType, token: tokenValue };\n }\n\n async verify(opts: { type: string; token: string }): Promise<IJWTTokenPayload> {\n const { token } = opts;\n\n if (!token) {\n this.logger.for(this.verify.name).error('Missing token for validating request!');\n throw getError({\n error: AuthenticationErrors.TOKEN_MISSING,\n message: '[verify] Invalid request token!',\n });\n }\n\n try {\n await this.assertNotServiceAssertion({ token });\n const result = await this.doVerify(token);\n\n return result;\n } catch (error) {\n // No log here - `cause` carries the reason (JWTExpired, signature mismatch) to the error handler, which logs the request once. An expired token is the caller's problem, hence `warn`.\n throw getError({\n error: AuthenticationErrors.TOKEN_INVALID,\n message: '[verify] Invalid or expired token',\n logLevel: 'warn',\n cause: error,\n });\n }\n }\n\n /**\n * A service assertion (`typ: svc+jwt`) is not a user token. When a JWKS issuer shares the key of the service\n * assertions and the names collide, an assertion would otherwise verify here, so the user-token path refuses it.\n */\n protected async assertNotServiceAssertion(opts: { token: string }): Promise<void> {\n const { decodeProtectedHeader } = await JoseLoader.load();\n const { typ } = decodeProtectedHeader(opts.token);\n const kind = typeof typ === 'string' ? typ.toLowerCase().replace(/^application\\//, '') : '';\n\n if (kind === ServiceAssertion.TYP) {\n throw getError({\n error: AuthenticationErrors.TOKEN_INVALID,\n message: '[verify] A service assertion is not a user token',\n });\n }\n }\n\n async generate(opts: {\n payload: IJWTTokenPayload;\n getTokenExpiresFn?: TGetTokenExpiresFn;\n /** Per-token registered claims. The supported way to vary `aud` / `sub`; the payload is not. */\n claims?: IJWTIssueClaims;\n }): Promise<string> {\n const { payload, claims, getTokenExpiresFn = this.getDefaultTokenExpiresFn() } = opts;\n\n if (!payload) {\n throw getError({\n error: AuthenticationErrors.TOKEN_PAYLOAD_INVALID,\n message: '[generate] Invalid token payload!',\n });\n }\n\n const signer = await this.getSigner({ payload, getTokenExpiresFn, claims });\n\n try {\n const result = await this.getSigningKey();\n const rs = await signer.sign(result);\n\n return rs;\n } catch (error) {\n this.logger.for(this.generate.name).error('Failed to generate token | Error: %s', error);\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[generate] Failed to generate token',\n });\n }\n }\n\n /** A `null` is written as `null` whatever the field's codec is: a codec converts a value, and `null` is none. */\n protected serializeField(opts: { key: string; value: any }): string {\n const { key, value } = opts;\n const codec = value === null ? undefined : this.fieldCodecs.get(key);\n\n if (codec) {\n return codec.serialize({ value });\n }\n\n return JSON.stringify(value);\n }\n\n /**\n * With `applicationSecret` set, AES-encrypts the key and the value of every claim outside `JWT_COMMON_FIELDS`;\n * without it, returns the payload as is. A `null` claim is encrypted like any other value and decodes as `null`,\n * so the token decodes to the same payload with encryption on or off and `null` stays distinct from absent. An\n * `undefined` claim is skipped, as JSON drops it.\n */\n async encryptPayload(payload: IJWTTokenPayload): Promise<Record<string, any>> {\n if (!this.aes || !this.applicationSecret) {\n return payload;\n }\n\n const rs: Record<string, string> = {};\n\n const keys = Object.keys(payload);\n\n for (const key of keys) {\n const value = payload[key];\n\n if (AbstractBearerTokenService.JWT_COMMON_FIELDS.has(key)) {\n rs[key] = value;\n continue;\n }\n\n // Only `undefined` is skipped: JSON drops it too, so the claim is absent either way. `null` is a value, and\n // `serializeField` writes it as `null`, which `deserializeField` reads back, so an encrypted token decodes the\n // same payload as a plain one.\n if (value === undefined) {\n continue;\n }\n\n const encryptedKey = await this.aes.encrypt({\n message: key,\n secret: this.applicationSecret,\n });\n\n const serialized = this.serializeField({ key, value });\n\n const encryptedValue = await this.aes.encrypt({\n message: serialized,\n secret: this.applicationSecret,\n });\n rs[encryptedKey] = encryptedValue;\n }\n\n return rs;\n }\n\n /** The text `null` reads as `null` before any codec sees it, the other half of {@link serializeField}. */\n protected deserializeField(opts: { key: string; value: string }) {\n const { key, value } = opts;\n const codec = value === 'null' ? undefined : this.fieldCodecs.get(key);\n\n if (codec) {\n return codec.deserialize({ raw: value });\n }\n\n return JSON.parse(value);\n }\n\n /**\n * Stamps the configured `iss` / `aud` onto a signer, plus any per-token claims the caller passed.\n *\n * The configured value is AUTHORITATIVE. `iss` and `aud` are in `JWT_COMMON_FIELDS`, so they ride\n * through the AES envelope in the clear and an application-shaped payload can carry them - an\n * issuer identity any payload could overwrite would not be an identity. A conflicting payload\n * claim is overwritten and reported.\n *\n * Per-token audience is an explicit argument rather than a smuggled payload key, so the caller\n * that legitimately needs one says so.\n */\n protected applySignClaims(opts: {\n signer: SignJWT;\n payload: Record<string, any>;\n claims?: IJWTIssueClaims;\n }): SignJWT {\n const { signer, payload, claims } = opts;\n const configured = this.claimOptions;\n\n const issuer = claims?.issuer ?? configured?.issuer;\n const audience = claims?.audience ?? configured?.audience;\n\n const logger = this.logger.for(this.applySignClaims.name);\n\n if (issuer !== undefined) {\n if (payload.iss !== undefined && payload.iss !== issuer) {\n logger.warn(\n 'Payload iss overridden by the configured issuer | payload: %s | configured: %s',\n payload.iss,\n issuer,\n );\n }\n\n signer.setIssuer(issuer);\n }\n\n if (audience !== undefined) {\n if (payload.aud !== undefined) {\n logger.warn('Payload aud overridden | payload: %j | applied: %j', payload.aud, audience);\n }\n\n signer.setAudience(audience);\n }\n\n if (claims?.subject !== undefined) {\n signer.setSubject(claims.subject);\n }\n\n if (claims?.jwtId !== undefined) {\n signer.setJti(claims.jwtId);\n }\n\n return signer;\n }\n\n async decryptPayload(opts: {\n result: JWTVerifyResult<IJWTTokenPayload>;\n }): Promise<IJWTTokenPayload> {\n const { payload, protectedHeader } = opts.result;\n\n if (!this.aes || !this.applicationSecret) {\n return payload as IJWTTokenPayload;\n }\n\n this.logger\n .for(this.decryptPayload.name)\n .debug('JWT Token | payload: %j | header: %j', payload, protectedHeader);\n\n const rs: any = {};\n\n for (const key in payload) {\n if (AbstractBearerTokenService.JWT_COMMON_FIELDS.has(key)) {\n rs[key] = payload[key];\n continue;\n }\n\n const decryptedKey = await this.aes.decrypt({\n message: key,\n secret: this.applicationSecret,\n });\n const decryptedValue = await this.aes.decrypt({\n message: payload[key],\n secret: this.applicationSecret,\n });\n\n rs[decryptedKey] = this.deserializeField({ key: decryptedKey, value: decryptedValue });\n }\n\n return rs;\n }\n\n protected abstract doVerify(token: string): Promise<IJWTTokenPayload>;\n\n abstract getSigner(opts: {\n payload: IJWTTokenPayload;\n getTokenExpiresFn: TGetTokenExpiresFn;\n claims?: IJWTIssueClaims;\n }): Promise<SignJWT>;\n\n protected abstract getSigningKey(): ValueOrPromise<Uint8Array | CryptoKey>;\n\n protected abstract getDefaultTokenExpiresFn(): TGetTokenExpiresFn;\n}\n"]}
1
+ {"version":3,"file":"abstract.service.js","sourceRoot":"","sources":["../../../../../../../src/components/auth/authenticate/services/bearer/abstract.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAUtE,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,WAAW,EACX,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAiB5C,gGAAgG;AAChG,MAAM,OAAgB,0BAAgD,SAAQ,WAAW;IAAzF;;QAYY,QAAG,GAAe,IAAI,CAAC;QACvB,sBAAiB,GAAkB,IAAI,CAAC;QACxC,gBAAW,GAAoC,IAAI,GAAG,EAAE,CAAC;QAEnE,oJAAoJ;QAC1I,iBAAY,GAA6B,IAAI,CAAC;QAExD,yFAAyF;QAC/E,kBAAa,GAA4B,IAAI,CAAC;IAic1D,CAAC;IApdC,oDAAoD;aACpC,sBAAiB,GAAG,IAAI,GAAG,CAAmB;QAC5D,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;KACN,CAAC,AAR+B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ACX,CAAC;YAED,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;gBAC1C,OAAO,EAAE,GAAG;gBACZ,MAAM,EAAE,IAAI,CAAC,iBAAiB;aAC/B,CAAC,CAAC;YACH,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;YAEpC,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE,CAAC;gBACvC,MAAM,QAAQ,CAAC;oBACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY;oBAC9C,OAAO,EAAE,qDAAqD;iBAC/D,CAAC,CAAC;YACL,CAAC;YAED,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;gBAC5C,OAAO,EAAE,cAAc;gBACvB,MAAM,EAAE,IAAI,CAAC,iBAAiB;aAC/B,CAAC,CAAC;YAEH,EAAE,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,gBAAgB,CAAC,EAAE,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC;QACzF,CAAC;QAED,IAAI,CAAC,0BAA0B,CAAC,cAAc,CAAC,EAAE,CAAC,EAAE,CAAC;YACnD,MAAM,QAAQ,CAAC;gBACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY;gBAC9C,OAAO,EAAE,uDAAuD;aACjE,CAAC,CAAC;QACL,CAAC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,oEAAoE;IAC5D,MAAM,CAAC,cAAc,CAAC,KAA8B;QAC1D,OAAO,QAAQ,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,CAAC;IACzD,CAAC","sourcesContent":["import type { AESAlgorithmType } from '@venizia/ignis-helpers';\nimport { AES } from '@venizia/ignis-helpers';\nimport type { ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport { getError, RecordUtility } from '@venizia/ignis-helpers/core';\nimport type {\n IJWTClaimsOptions,\n IJWTIssueClaims,\n IJWTTokenPayload,\n IJWTVerifyOptions,\n IPayloadFieldCodec,\n TContext,\n TGetTokenExpiresFn,\n} from '@venizia/ignis-kernel';\nimport {\n Authentication,\n AuthenticationErrors,\n BaseService,\n ServiceAssertion,\n} from '@venizia/ignis-kernel';\nimport type { Env } from 'hono';\nimport { JoseLoader } from '../jose-loader';\nimport type { JWTPayload, JWTVerifyOptions, JWTVerifyResult, SignJWT } from 'jose';\n\n/** What a token service is configured with for claims: the required `claims`, the `verify` checks, and the removed `sign` it refuses. */\nexport interface IClaimsConfigSource {\n claims?: unknown;\n verify?: unknown;\n /** Removed: refused with a message that points to `claims`. */\n sign?: unknown;\n}\n\n/** What {@link AbstractBearerTokenService.resolveClaimsConfig} answers: the validated claims and the verify options jose receives. */\nexport interface IResolvedClaimsConfig {\n claims: IJWTClaimsOptions;\n verify: JWTVerifyOptions & { algorithms: string[] };\n}\n\n/** Abstract base for Bearer-token services (JWS, JWKS) with optional AES payload encryption. */\nexport abstract class AbstractBearerTokenService<E extends Env = Env> extends BaseService {\n /** Standard JWT fields that are never encrypted. */\n static readonly JWT_COMMON_FIELDS = new Set<keyof JWTPayload>([\n 'iss',\n 'sub',\n 'aud',\n 'jti',\n 'nbf',\n 'exp',\n 'iat',\n ]);\n\n protected aes: AES | null = null;\n protected applicationSecret: string | null = null;\n protected fieldCodecs: Map<string, IPayloadFieldCodec> = new Map();\n\n /** Configured `iss` / `aud`: stamped on every issued token, authoritative over anything the payload carries, and required on every verified one. */\n protected claimOptions: IJWTClaimsOptions | null = null;\n\n /** What jose verifies against: the claims, the algorithm pin and the `verify` checks. */\n protected verifyOptions: JWTVerifyOptions | null = null;\n\n /** The keys a `claims` object may hold. */\n static readonly CLAIM_KEYS: ReadonlyArray<string> = ['issuer', 'audience'];\n\n /**\n * Validates the claims configuration of a token service and answers what the service uses. It throws, naming the\n * key, when `claims.issuer` is missing or empty, when `claims.audience` is present but not a non-empty string or a\n * non-empty list of them, when `claims` holds another key, when the removed `sign` or `verify.issuer` /\n * `verify.audience` is still passed, and when no algorithm is pinned. `claims.audience` is optional: without it\n * no `aud` is stamped and none is checked.\n * `pinnedAlgorithms` is what the service signs with; a verifier has none and requires `verify.algorithms`.\n * The component calls it at boot, and a service calls it when it is built, so neither can start without them.\n */\n static resolveClaimsConfig(opts: {\n scope: string;\n options: IClaimsConfigSource;\n pinnedAlgorithms?: string[];\n }): IResolvedClaimsConfig {\n const { scope, options, pinnedAlgorithms } = opts;\n const fail = (detail: string) =>\n getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${scope}] ${detail}`,\n });\n\n if (options.sign !== undefined) {\n throw fail(\n '`sign` was removed | put the issuer and the audience in `claims: { issuer, audience }`: they are stamped on every token and required on every verified one',\n );\n }\n\n if (options.verify !== undefined && !RecordUtility.isPlainRecord(options.verify)) {\n throw fail(\n 'verify must be an object | its checks (maxTokenAge, subject, ...) would be dropped silently',\n );\n }\n\n const verify = RecordUtility.isPlainRecord(options.verify) ? options.verify : {};\n\n for (const key of AbstractBearerTokenService.CLAIM_KEYS) {\n if (key in verify) {\n throw fail(\n `verify.${key} was removed | set claims.${key}: it is stamped on every token and required on every verified one`,\n );\n }\n }\n\n const { claims } = options;\n\n if (!RecordUtility.isPlainRecord(claims)) {\n throw fail(\n 'claims is required | pass claims: { issuer: string, audience: string | string[] }: a token signed with the same key for another purpose must not authenticate a request',\n );\n }\n\n const unknown = Object.keys(claims).filter(\n (key) => !AbstractBearerTokenService.CLAIM_KEYS.includes(key),\n );\n\n if (unknown.length > 0) {\n throw fail(\n `claims holds unknown keys ${JSON.stringify(unknown)} | accepted: ${AbstractBearerTokenService.CLAIM_KEYS.join(', ')}`,\n );\n }\n\n const { issuer, audience } = claims;\n const isName = (value: unknown): value is string =>\n typeof value === 'string' && value.trim().length > 0;\n\n if (!isName(issuer)) {\n throw fail('claims.issuer is required | a non-empty string');\n }\n\n // Optional, but a present value is checked: `null`, `''` and `[]` are mistakes, not \"no audience\".\n if (\n audience !== undefined &&\n !isName(audience) &&\n !(Array.isArray(audience) && audience.length > 0 && audience.every(isName))\n ) {\n throw fail(\n 'claims.audience must be a non-empty string or a non-empty list of them | or leave it out',\n );\n }\n\n const resolvedAudience = Array.isArray(audience) ? [...audience] : audience;\n\n const algorithms = verify.algorithms ?? pinnedAlgorithms;\n\n if (!Array.isArray(algorithms) || algorithms.length === 0 || !algorithms.every(isName)) {\n throw fail(\n \"verify.algorithms is required | the accepted JWS algorithms, for example ['RS256']: a verifier cannot know what the issuer signs with\",\n );\n }\n\n if (algorithms.some((algorithm) => algorithm.trim().toLowerCase() === 'none')) {\n throw fail(\"the algorithm 'none' is refused | a token with no signature verifies nothing\");\n }\n\n return {\n claims: { issuer, ...(resolvedAudience === undefined ? {} : { audience: resolvedAudience }) },\n verify: {\n ...(verify as IJWTVerifyOptions),\n issuer,\n ...(resolvedAudience === undefined ? {} : { audience: resolvedAudience }),\n algorithms: [...algorithms],\n },\n };\n }\n\n /** Validates the claims configuration (see {@link AbstractBearerTokenService.resolveClaimsConfig}) and keeps the result. */\n protected configureClaims(opts: {\n options: IClaimsConfigSource;\n pinnedAlgorithms?: string[];\n }): void {\n const resolved = AbstractBearerTokenService.resolveClaimsConfig({\n scope: this.scope,\n options: opts.options,\n pinnedAlgorithms: opts.pinnedAlgorithms,\n });\n\n this.claimOptions = resolved.claims;\n this.verifyOptions = resolved.verify;\n }\n\n /** Configures AES payload encryption and field codecs. Both aesAlgorithm and applicationSecret required to activate encryption. */\n protected configurePayloadEncryption(opts: {\n aesAlgorithm?: AESAlgorithmType;\n applicationSecret?: string;\n fieldCodecs?: IPayloadFieldCodec[];\n }): void {\n const { aesAlgorithm = 'aes-256-cbc', applicationSecret, fieldCodecs } = opts;\n\n if (fieldCodecs) {\n for (const codec of fieldCodecs) {\n this.fieldCodecs.set(codec.key, codec);\n }\n }\n\n if (!applicationSecret) {\n return;\n }\n\n this.aes = AES.withAlgorithm(aesAlgorithm);\n this.applicationSecret = applicationSecret;\n }\n\n extractCredentials(context: TContext<E, string>): { type: string; token: string } {\n const request = context.req;\n\n const authHeaderValue = request.header(HTTP.Headers.AUTHORIZATION);\n\n if (!authHeaderValue) {\n throw getError({\n error: AuthenticationErrors.HEADER_MISSING,\n message: 'Unauthorized user! Missing authorization header',\n });\n }\n\n if (!authHeaderValue.startsWith(Authentication.TYPE_BEARER)) {\n throw getError({\n error: AuthenticationErrors.SCHEME_INVALID,\n message: 'Unauthorized user! Invalid schema of request token!',\n });\n }\n\n const parts = authHeaderValue.split(' ');\n\n if (parts.length !== 2) {\n throw getError({\n error: AuthenticationErrors.HEADER_MALFORMED,\n message: `Authorization header value is invalid format. It must follow the pattern: 'Bearer xx.yy.zz' where xx.yy.zz is a valid JWT token.`,\n });\n }\n\n const [tokenType, tokenValue] = parts;\n\n return { type: tokenType, token: tokenValue };\n }\n\n async verify(opts: { type: string; token: string }): Promise<IJWTTokenPayload> {\n const { token } = opts;\n\n if (!token) {\n this.logger.for(this.verify.name).error('Missing token for validating request!');\n throw getError({\n error: AuthenticationErrors.TOKEN_MISSING,\n message: '[verify] Invalid request token!',\n });\n }\n\n try {\n await this.assertNotServiceAssertion({ token });\n const result = await this.doVerify(token);\n\n return result;\n } catch (error) {\n // No log here - `cause` carries the reason (JWTExpired, signature mismatch) to the error handler, which logs the request once. An expired token is the caller's problem, hence `warn`.\n throw getError({\n error: AuthenticationErrors.TOKEN_INVALID,\n message: '[verify] Invalid or expired token',\n logLevel: 'warn',\n cause: error,\n });\n }\n }\n\n /**\n * A service assertion (`typ: svc+jwt`) is not a user token. When a JWKS issuer shares the key of the service\n * assertions and the names collide, an assertion would otherwise verify here, so the user-token path refuses it.\n */\n protected async assertNotServiceAssertion(opts: { token: string }): Promise<void> {\n const { decodeProtectedHeader } = await JoseLoader.load();\n const { typ } = decodeProtectedHeader(opts.token);\n const kind = typeof typ === 'string' ? typ.toLowerCase().replace(/^application\\//, '') : '';\n\n if (kind === ServiceAssertion.TYP) {\n throw getError({\n error: AuthenticationErrors.TOKEN_INVALID,\n message: '[verify] A service assertion is not a user token',\n });\n }\n }\n\n async generate(opts: {\n payload: IJWTTokenPayload;\n getTokenExpiresFn?: TGetTokenExpiresFn;\n /** Per-token registered claims. The supported way to vary `aud` / `sub`; the payload is not. */\n claims?: IJWTIssueClaims;\n }): Promise<string> {\n const { payload, claims, getTokenExpiresFn = this.getDefaultTokenExpiresFn() } = opts;\n\n if (!payload) {\n throw getError({\n error: AuthenticationErrors.TOKEN_PAYLOAD_INVALID,\n message: '[generate] Invalid token payload!',\n });\n }\n\n const signer = await this.getSigner({ payload, getTokenExpiresFn, claims });\n\n try {\n const result = await this.getSigningKey();\n const rs = await signer.sign(result);\n\n return rs;\n } catch (error) {\n this.logger.for(this.generate.name).error('Failed to generate token | Error: %s', error);\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[generate] Failed to generate token',\n });\n }\n }\n\n /** A `null` is written as `null` whatever the field's codec is: a codec converts a value, and `null` is none. */\n protected serializeField(opts: { key: string; value: unknown }): string {\n const { key, value } = opts;\n const codec = value === null ? undefined : this.fieldCodecs.get(key);\n\n if (codec) {\n return codec.serialize({ value });\n }\n\n return JSON.stringify(value);\n }\n\n /**\n * With `applicationSecret` set, AES-encrypts the key and the value of every claim outside `JWT_COMMON_FIELDS`;\n * without it, returns the payload as is. A `null` claim is encrypted like any other value and decodes as `null`,\n * so the token decodes to the same payload with encryption on or off and `null` stays distinct from absent. An\n * `undefined` claim is skipped, as JSON drops it.\n */\n async encryptPayload(payload: IJWTTokenPayload): Promise<Record<string, unknown>> {\n if (!this.aes || !this.applicationSecret) {\n return payload;\n }\n\n const rs: Record<string, unknown> = {};\n\n const keys = Object.keys(payload);\n\n for (const key of keys) {\n const value = payload[key];\n\n if (AbstractBearerTokenService.JWT_COMMON_FIELDS.has(key)) {\n rs[key] = value;\n continue;\n }\n\n // Only `undefined` is skipped: JSON drops it too, so the claim is absent either way. `null` is a value, and\n // `serializeField` writes it as `null`, which `deserializeField` reads back, so an encrypted token decodes the\n // same payload as a plain one.\n if (value === undefined) {\n continue;\n }\n\n const encryptedKey = await this.aes.encrypt({\n message: key,\n secret: this.applicationSecret,\n });\n\n const serialized = this.serializeField({ key, value });\n\n const encryptedValue = await this.aes.encrypt({\n message: serialized,\n secret: this.applicationSecret,\n });\n rs[encryptedKey] = encryptedValue;\n }\n\n return rs;\n }\n\n /** The text `null` reads as `null` before any codec sees it, the other half of {@link serializeField}. */\n protected deserializeField(opts: { key: string; value: string }) {\n const { key, value } = opts;\n const codec = value === 'null' ? undefined : this.fieldCodecs.get(key);\n\n if (codec) {\n return codec.deserialize({ raw: value });\n }\n\n return JSON.parse(value);\n }\n\n /**\n * Stamps the configured `iss` / `aud` onto a signer, plus any per-token claims the caller passed.\n *\n * The configured value is AUTHORITATIVE. `iss` and `aud` are in `JWT_COMMON_FIELDS`, so they ride\n * through the AES envelope in the clear and an application-shaped payload can carry them - an\n * issuer identity any payload could overwrite would not be an identity. A conflicting payload\n * claim is overwritten and reported.\n *\n * Per-token audience is an explicit argument rather than a smuggled payload key, so the caller\n * that legitimately needs one says so.\n */\n protected applySignClaims(opts: {\n signer: SignJWT;\n payload: Record<string, unknown>;\n claims?: IJWTIssueClaims;\n }): SignJWT {\n const { signer, payload, claims } = opts;\n const configured = this.claimOptions;\n\n const issuer = claims?.issuer ?? configured?.issuer;\n const audience = claims?.audience ?? configured?.audience;\n\n const logger = this.logger.for(this.applySignClaims.name);\n\n if (issuer !== undefined) {\n if (payload.iss !== undefined && payload.iss !== issuer) {\n logger.warn(\n 'Payload iss overridden by the configured issuer | payload: %s | configured: %s',\n payload.iss,\n issuer,\n );\n }\n\n signer.setIssuer(issuer);\n }\n\n if (audience !== undefined) {\n if (payload.aud !== undefined) {\n logger.warn('Payload aud overridden | payload: %j | applied: %j', payload.aud, audience);\n }\n\n signer.setAudience(audience);\n }\n\n if (claims?.subject !== undefined) {\n signer.setSubject(claims.subject);\n }\n\n if (claims?.jwtId !== undefined) {\n signer.setJti(claims.jwtId);\n }\n\n return signer;\n }\n\n async decryptPayload(opts: {\n result: JWTVerifyResult<IJWTTokenPayload>;\n }): Promise<IJWTTokenPayload> {\n const { payload, protectedHeader } = opts.result;\n\n if (!this.aes || !this.applicationSecret) {\n return payload as IJWTTokenPayload;\n }\n\n this.logger\n .for(this.decryptPayload.name)\n .debug('JWT Token | payload: %j | header: %j', payload, protectedHeader);\n\n const rs: Record<string, unknown> = {};\n\n for (const key in payload) {\n if (AbstractBearerTokenService.JWT_COMMON_FIELDS.has(key)) {\n rs[key] = payload[key];\n continue;\n }\n\n const decryptedKey = await this.aes.decrypt({\n message: key,\n secret: this.applicationSecret,\n });\n const encryptedValue = payload[key];\n\n if (typeof encryptedValue !== 'string') {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_4.Unauthorized,\n message: '[decryptPayload] An encrypted claim is not a string',\n });\n }\n\n const decryptedValue = await this.aes.decrypt({\n message: encryptedValue,\n secret: this.applicationSecret,\n });\n\n rs[decryptedKey] = this.deserializeField({ key: decryptedKey, value: decryptedValue });\n }\n\n if (!AbstractBearerTokenService.isTokenPayload(rs)) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_4.Unauthorized,\n message: '[decryptPayload] The decrypted claims carry no userId',\n });\n }\n\n return rs;\n }\n\n /** A decrypted claim set is a payload only if it names its user. */\n private static isTokenPayload(value: Record<string, unknown>): value is IJWTTokenPayload {\n return 'userId' in value && value.userId !== undefined;\n }\n\n protected abstract doVerify(token: string): Promise<IJWTTokenPayload>;\n\n abstract getSigner(opts: {\n payload: IJWTTokenPayload;\n getTokenExpiresFn: TGetTokenExpiresFn;\n claims?: IJWTIssueClaims;\n }): Promise<SignJWT>;\n\n protected abstract getSigningKey(): ValueOrPromise<Uint8Array | CryptoKey>;\n\n protected abstract getDefaultTokenExpiresFn(): TGetTokenExpiresFn;\n}\n"]}
@@ -1,17 +1,17 @@
1
1
  import { type TNullable, type ValueOrPromise } from '@venizia/ignis-helpers/common';
2
- import { type IJWKSIssuerOptions, type IJWTIssueClaims, type IJWTTokenPayload, type TGetTokenExpiresFn } from '@venizia/ignis-kernel';
2
+ import { AuthenticateBindingKeys, type IJWKSIssuerOptions, type IJWTIssueClaims, type IJWTTokenPayload, type TBindingKeyValue, type TGetTokenExpiresFn } from '@venizia/ignis-kernel';
3
3
  import { type Env } from 'hono';
4
4
  import type { CryptoKey, JWK } from 'jose';
5
5
  import { AbstractJWKSTokenService } from './abstract.service.js';
6
6
  /** Signs tokens with a private key loaded from `IJWKSIssuerOptions` and exposes the matching public keys as a JWKS via `getJWKSAsync()`. */
7
7
  export declare class JWKSIssuerTokenService<E extends Env = Env> extends AbstractJWKSTokenService<E> {
8
- protected options: IJWKSIssuerOptions;
8
+ protected options: TBindingKeyValue<typeof AuthenticateBindingKeys.JWKS_ISSUER_OPTIONS>;
9
9
  protected privateKey: TNullable<CryptoKey | Uint8Array>;
10
10
  protected publicKey: TNullable<CryptoKey | Uint8Array>;
11
11
  protected jwks: {
12
12
  keys: JWK[];
13
13
  } | null;
14
- constructor(options: IJWKSIssuerOptions);
14
+ constructor(options: TBindingKeyValue<typeof AuthenticateBindingKeys.JWKS_ISSUER_OPTIONS>);
15
15
  protected initialize(): Promise<void>;
16
16
  protected resolveKeyContent(opts: {
17
17
  keys: IJWKSIssuerOptions['keys'];
@@ -194,7 +194,7 @@ let JWKSIssuerTokenService = JWKSIssuerTokenService_1 = class JWKSIssuerTokenSer
194
194
  }
195
195
  };
196
196
  JWKSIssuerTokenService = JWKSIssuerTokenService_1 = __decorate([
197
- __param(0, inject({ key: AuthenticateBindingKeys.JWKS_OPTIONS })),
197
+ __param(0, inject({ key: AuthenticateBindingKeys.JWKS_ISSUER_OPTIONS })),
198
198
  __metadata("design:paramtypes", [Object])
199
199
  ], JWKSIssuerTokenService);
200
200
  export { JWKSIssuerTokenService };