@venizia/ignis 0.4.8-0 → 0.4.8-10

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 (275) hide show
  1. package/README.md +7 -14
  2. package/dist/esm/base/applications/base.d.ts +19 -0
  3. package/dist/esm/base/applications/base.js +19 -0
  4. package/dist/esm/base/applications/base.js.map +1 -1
  5. package/dist/esm/base/applications/boot-steps.d.ts +1 -0
  6. package/dist/esm/base/applications/boot-steps.js.map +1 -1
  7. package/dist/esm/base/applications/common/types.d.ts +21 -4
  8. package/dist/esm/base/applications/common/types.js.map +1 -1
  9. package/dist/esm/base/applications/server.d.ts +12 -0
  10. package/dist/esm/base/applications/server.js +11 -0
  11. package/dist/esm/base/applications/server.js.map +1 -1
  12. package/dist/esm/base/metadata/request-context.d.ts +1 -0
  13. package/dist/esm/base/metadata/request-context.js +1 -0
  14. package/dist/esm/base/metadata/request-context.js.map +1 -1
  15. package/dist/esm/base/middlewares/request-spy/request-spy.middleware.d.ts +1 -0
  16. package/dist/esm/base/middlewares/request-spy/request-spy.middleware.js +9 -2
  17. package/dist/esm/base/middlewares/request-spy/request-spy.middleware.js.map +1 -1
  18. package/dist/esm/components/api-reference/common/constants.d.ts +1 -0
  19. package/dist/esm/components/api-reference/common/constants.js +1 -0
  20. package/dist/esm/components/api-reference/common/constants.js.map +1 -1
  21. package/dist/esm/components/api-reference/common/keys.d.ts +1 -0
  22. package/dist/esm/components/api-reference/common/keys.js +1 -0
  23. package/dist/esm/components/api-reference/common/keys.js.map +1 -1
  24. package/dist/esm/components/api-reference/common/types.d.ts +18 -1
  25. package/dist/esm/components/api-reference/common/types.js.map +1 -1
  26. package/dist/esm/components/api-reference/component.d.ts +14 -0
  27. package/dist/esm/components/api-reference/component.js +14 -0
  28. package/dist/esm/components/api-reference/component.js.map +1 -1
  29. package/dist/esm/components/api-reference/ui/factory.d.ts +1 -0
  30. package/dist/esm/components/api-reference/ui/factory.js +1 -0
  31. package/dist/esm/components/api-reference/ui/factory.js.map +1 -1
  32. package/dist/esm/components/api-reference/ui/scalar.d.ts +1 -0
  33. package/dist/esm/components/api-reference/ui/scalar.js +1 -0
  34. package/dist/esm/components/api-reference/ui/scalar.js.map +1 -1
  35. package/dist/esm/components/api-reference/ui/swagger.d.ts +1 -0
  36. package/dist/esm/components/api-reference/ui/swagger.js +1 -0
  37. package/dist/esm/components/api-reference/ui/swagger.js.map +1 -1
  38. package/dist/esm/components/auth/authenticate/component.d.ts +1 -0
  39. package/dist/esm/components/auth/authenticate/component.js +38 -1
  40. package/dist/esm/components/auth/authenticate/component.js.map +1 -1
  41. package/dist/esm/components/auth/authenticate/controllers/factory.d.ts +2 -0
  42. package/dist/esm/components/auth/authenticate/controllers/factory.js +1 -0
  43. package/dist/esm/components/auth/authenticate/controllers/factory.js.map +1 -1
  44. package/dist/esm/components/auth/authenticate/controllers/jwks/controller.d.ts +1 -0
  45. package/dist/esm/components/auth/authenticate/controllers/jwks/controller.js +1 -0
  46. package/dist/esm/components/auth/authenticate/controllers/jwks/controller.js.map +1 -1
  47. package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.d.ts +56 -5
  48. package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.js +115 -11
  49. package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.js.map +1 -1
  50. package/dist/esm/components/auth/authenticate/services/bearer/jwks/issuer.service.d.ts +1 -0
  51. package/dist/esm/components/auth/authenticate/services/bearer/jwks/issuer.service.js +3 -2
  52. package/dist/esm/components/auth/authenticate/services/bearer/jwks/issuer.service.js.map +1 -1
  53. package/dist/esm/components/auth/authenticate/services/bearer/jwks/verifier.service.d.ts +1 -0
  54. package/dist/esm/components/auth/authenticate/services/bearer/jwks/verifier.service.js +11 -3
  55. package/dist/esm/components/auth/authenticate/services/bearer/jwks/verifier.service.js.map +1 -1
  56. package/dist/esm/components/auth/authenticate/services/bearer/jws.service.d.ts +11 -0
  57. package/dist/esm/components/auth/authenticate/services/bearer/jws.service.js +25 -3
  58. package/dist/esm/components/auth/authenticate/services/bearer/jws.service.js.map +1 -1
  59. package/dist/esm/components/auth/authenticate/services/index.d.ts +1 -0
  60. package/dist/esm/components/auth/authenticate/services/index.js +1 -0
  61. package/dist/esm/components/auth/authenticate/services/index.js.map +1 -1
  62. package/dist/esm/components/auth/authenticate/services/jwks-url-policy.d.ts +42 -0
  63. package/dist/esm/components/auth/authenticate/services/jwks-url-policy.js +162 -0
  64. package/dist/esm/components/auth/authenticate/services/jwks-url-policy.js.map +1 -0
  65. package/dist/esm/components/auth/authenticate/services/service/verifier.service.js +7 -1
  66. package/dist/esm/components/auth/authenticate/services/service/verifier.service.js.map +1 -1
  67. package/dist/esm/components/auth/authenticate/strategies/jwks/issuer.d.ts +1 -0
  68. package/dist/esm/components/auth/authenticate/strategies/jwks/issuer.js +1 -0
  69. package/dist/esm/components/auth/authenticate/strategies/jwks/issuer.js.map +1 -1
  70. package/dist/esm/components/auth/authenticate/strategies/jwks/verifier.d.ts +1 -0
  71. package/dist/esm/components/auth/authenticate/strategies/jwks/verifier.js +1 -0
  72. package/dist/esm/components/auth/authenticate/strategies/jwks/verifier.js.map +1 -1
  73. package/dist/esm/components/auth/authenticate/strategies/jws.strategy.d.ts +1 -0
  74. package/dist/esm/components/auth/authenticate/strategies/jws.strategy.js +1 -0
  75. package/dist/esm/components/auth/authenticate/strategies/jws.strategy.js.map +1 -1
  76. package/dist/esm/components/auth/authenticate/strategies/service.strategy.js +2 -4
  77. package/dist/esm/components/auth/authenticate/strategies/service.strategy.js.map +1 -1
  78. package/dist/esm/components/auth/authorize/adapters/base-filtered.d.ts +1 -1
  79. package/dist/esm/components/auth/authorize/adapters/base-filtered.js +3 -2
  80. package/dist/esm/components/auth/authorize/adapters/base-filtered.js.map +1 -1
  81. package/dist/esm/components/auth/authorize/adapters/common/types.d.ts +2 -0
  82. package/dist/esm/components/auth/authorize/adapters/common/types.js.map +1 -1
  83. package/dist/esm/components/auth/authorize/adapters/connector.d.ts +2 -2
  84. package/dist/esm/components/auth/authorize/adapters/connector.js +3 -2
  85. package/dist/esm/components/auth/authorize/adapters/connector.js.map +1 -1
  86. package/dist/esm/components/auth/authorize/adapters/custom-grant-expander.js +1 -1
  87. package/dist/esm/components/auth/authorize/adapters/custom-grant-expander.js.map +1 -1
  88. package/dist/esm/components/auth/authorize/adapters/scoped-casbin/common/types.d.ts +2 -0
  89. package/dist/esm/components/auth/authorize/adapters/scoped-casbin/common/types.js.map +1 -1
  90. package/dist/esm/components/auth/authorize/adapters/scoped-casbin/policy-edges.d.ts +1 -0
  91. package/dist/esm/components/auth/authorize/adapters/scoped-casbin/policy-edges.js +1 -0
  92. package/dist/esm/components/auth/authorize/adapters/scoped-casbin/policy-edges.js.map +1 -1
  93. package/dist/esm/components/auth/authorize/component.d.ts +1 -0
  94. package/dist/esm/components/auth/authorize/component.js +1 -0
  95. package/dist/esm/components/auth/authorize/component.js.map +1 -1
  96. package/dist/esm/components/auth/authorize/enforcers/casbin.enforcer.d.ts +1 -0
  97. package/dist/esm/components/auth/authorize/enforcers/casbin.enforcer.js +1 -0
  98. package/dist/esm/components/auth/authorize/enforcers/casbin.enforcer.js.map +1 -1
  99. package/dist/esm/components/auth/models/entities/columns.d.ts +1 -0
  100. package/dist/esm/components/auth/models/entities/columns.js.map +1 -1
  101. package/dist/esm/components/auth/models/entities/permission.model.d.ts +2 -0
  102. package/dist/esm/components/auth/models/entities/permission.model.js.map +1 -1
  103. package/dist/esm/components/auth/models/entities/policy-definition.model.d.ts +1 -0
  104. package/dist/esm/components/auth/models/entities/policy-definition.model.js.map +1 -1
  105. package/dist/esm/components/controller/grpc/common/types.d.ts +2 -0
  106. package/dist/esm/components/controller/grpc/common/types.js +1 -0
  107. package/dist/esm/components/controller/grpc/common/types.js.map +1 -1
  108. package/dist/esm/components/controller/grpc/grpc.component.d.ts +1 -0
  109. package/dist/esm/components/controller/grpc/grpc.component.js +1 -0
  110. package/dist/esm/components/controller/grpc/grpc.component.js.map +1 -1
  111. package/dist/esm/components/health-check/common/constants.d.ts +1 -0
  112. package/dist/esm/components/health-check/common/constants.js +1 -0
  113. package/dist/esm/components/health-check/common/constants.js.map +1 -1
  114. package/dist/esm/components/health-check/common/keys.d.ts +1 -0
  115. package/dist/esm/components/health-check/common/keys.js +1 -0
  116. package/dist/esm/components/health-check/common/keys.js.map +1 -1
  117. package/dist/esm/components/health-check/common/rest-paths.d.ts +1 -0
  118. package/dist/esm/components/health-check/common/rest-paths.js +1 -0
  119. package/dist/esm/components/health-check/common/rest-paths.js.map +1 -1
  120. package/dist/esm/components/health-check/common/types.d.ts +24 -3
  121. package/dist/esm/components/health-check/common/types.js.map +1 -1
  122. package/dist/esm/components/health-check/component.d.ts +15 -0
  123. package/dist/esm/components/health-check/component.js +15 -0
  124. package/dist/esm/components/health-check/component.js.map +1 -1
  125. package/dist/esm/components/health-check/controller.d.ts +1 -0
  126. package/dist/esm/components/health-check/controller.js +1 -0
  127. package/dist/esm/components/health-check/controller.js.map +1 -1
  128. package/dist/esm/components/health-check/reporter.js +2 -2
  129. package/dist/esm/components/health-check/reporter.js.map +1 -1
  130. package/dist/esm/components/index.d.ts +1 -0
  131. package/dist/esm/components/index.js +1 -0
  132. package/dist/esm/components/index.js.map +1 -1
  133. package/dist/esm/components/mail/common/constants.d.ts +6 -0
  134. package/dist/esm/components/mail/common/constants.js +5 -0
  135. package/dist/esm/components/mail/common/constants.js.map +1 -1
  136. package/dist/esm/components/mail/common/keys.d.ts +1 -0
  137. package/dist/esm/components/mail/common/keys.js +1 -0
  138. package/dist/esm/components/mail/common/keys.js.map +1 -1
  139. package/dist/esm/components/mail/common/types/message.d.ts +10 -0
  140. package/dist/esm/components/mail/common/types/message.js.map +1 -1
  141. package/dist/esm/components/mail/common/types/options.d.ts +22 -1
  142. package/dist/esm/components/mail/common/types/options.js.map +1 -1
  143. package/dist/esm/components/mail/common/types/queue.d.ts +7 -0
  144. package/dist/esm/components/mail/common/types/queue.js.map +1 -1
  145. package/dist/esm/components/mail/common/types/template.d.ts +2 -0
  146. package/dist/esm/components/mail/common/types/template.js.map +1 -1
  147. package/dist/esm/components/mail/common/types/verification.d.ts +6 -0
  148. package/dist/esm/components/mail/common/types/verification.js.map +1 -1
  149. package/dist/esm/components/mail/component.d.ts +1 -0
  150. package/dist/esm/components/mail/component.js +1 -0
  151. package/dist/esm/components/mail/component.js.map +1 -1
  152. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.d.ts +1 -0
  153. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js +1 -0
  154. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js.map +1 -1
  155. package/dist/esm/components/mail/helpers/executors/direct-executor.helper.d.ts +1 -0
  156. package/dist/esm/components/mail/helpers/executors/direct-executor.helper.js +1 -0
  157. package/dist/esm/components/mail/helpers/executors/direct-executor.helper.js.map +1 -1
  158. package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.d.ts +1 -0
  159. package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.js +1 -0
  160. package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.js.map +1 -1
  161. package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.d.ts +1 -0
  162. package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js +1 -0
  163. package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js.map +1 -1
  164. package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.d.ts +1 -0
  165. package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.js +1 -0
  166. package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.js.map +1 -1
  167. package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.d.ts +1 -0
  168. package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.js +1 -0
  169. package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.js.map +1 -1
  170. package/dist/esm/components/mail/providers/mail-queue-executor.provider.d.ts +2 -0
  171. package/dist/esm/components/mail/providers/mail-queue-executor.provider.js +1 -0
  172. package/dist/esm/components/mail/providers/mail-queue-executor.provider.js.map +1 -1
  173. package/dist/esm/components/mail/providers/mail-transporter.provider.d.ts +2 -0
  174. package/dist/esm/components/mail/providers/mail-transporter.provider.js +1 -0
  175. package/dist/esm/components/mail/providers/mail-transporter.provider.js.map +1 -1
  176. package/dist/esm/components/mail/services/generators/numeric-code.d.ts +1 -5
  177. package/dist/esm/components/mail/services/generators/numeric-code.js +3 -30
  178. package/dist/esm/components/mail/services/generators/numeric-code.js.map +1 -1
  179. package/dist/esm/components/mail/services/generators/random-token.d.ts +4 -0
  180. package/dist/esm/components/mail/services/generators/random-token.js +9 -5
  181. package/dist/esm/components/mail/services/generators/random-token.js.map +1 -1
  182. package/dist/esm/components/mail/services/generators/verification-data.d.ts +1 -0
  183. package/dist/esm/components/mail/services/generators/verification-data.js +1 -0
  184. package/dist/esm/components/mail/services/generators/verification-data.js.map +1 -1
  185. package/dist/esm/components/mail/services/mail.service.d.ts +1 -0
  186. package/dist/esm/components/mail/services/mail.service.js +1 -0
  187. package/dist/esm/components/mail/services/mail.service.js.map +1 -1
  188. package/dist/esm/components/mail/services/template.service.d.ts +1 -0
  189. package/dist/esm/components/mail/services/template.service.js +1 -0
  190. package/dist/esm/components/mail/services/template.service.js.map +1 -1
  191. package/dist/esm/components/mail/utilities/address.utility.d.ts +1 -0
  192. package/dist/esm/components/mail/utilities/address.utility.js +1 -0
  193. package/dist/esm/components/mail/utilities/address.utility.js.map +1 -1
  194. package/dist/esm/components/mail/utilities/mime.utility.d.ts +1 -0
  195. package/dist/esm/components/mail/utilities/mime.utility.js +5 -4
  196. package/dist/esm/components/mail/utilities/mime.utility.js.map +1 -1
  197. package/dist/esm/components/mail/utilities/verification.utility.d.ts +1 -0
  198. package/dist/esm/components/mail/utilities/verification.utility.js +1 -0
  199. package/dist/esm/components/mail/utilities/verification.utility.js.map +1 -1
  200. package/dist/esm/components/request-tracker/component.d.ts +1 -0
  201. package/dist/esm/components/request-tracker/component.js +1 -0
  202. package/dist/esm/components/request-tracker/component.js.map +1 -1
  203. package/dist/esm/components/server-info/common/constants.d.ts +6 -0
  204. package/dist/esm/components/server-info/common/constants.js +6 -0
  205. package/dist/esm/components/server-info/common/constants.js.map +1 -0
  206. package/dist/esm/components/server-info/common/index.d.ts +5 -0
  207. package/dist/esm/components/server-info/common/index.js +5 -0
  208. package/dist/esm/components/server-info/common/index.js.map +1 -0
  209. package/dist/esm/components/server-info/common/keys.d.ts +5 -0
  210. package/dist/esm/components/server-info/common/keys.js +5 -0
  211. package/dist/esm/components/server-info/common/keys.js.map +1 -0
  212. package/dist/esm/components/server-info/common/rest-paths.d.ts +5 -0
  213. package/dist/esm/components/server-info/common/rest-paths.js +5 -0
  214. package/dist/esm/components/server-info/common/rest-paths.js.map +1 -0
  215. package/dist/esm/components/server-info/common/types.d.ts +68 -0
  216. package/dist/esm/components/server-info/common/types.js +2 -0
  217. package/dist/esm/components/server-info/common/types.js.map +1 -0
  218. package/dist/esm/components/server-info/component.d.ts +31 -0
  219. package/dist/esm/components/server-info/component.js +87 -0
  220. package/dist/esm/components/server-info/component.js.map +1 -0
  221. package/dist/esm/components/server-info/controller.d.ts +14 -0
  222. package/dist/esm/components/server-info/controller.js +68 -0
  223. package/dist/esm/components/server-info/controller.js.map +1 -0
  224. package/dist/esm/components/server-info/index.d.ts +5 -0
  225. package/dist/esm/components/server-info/index.js +5 -0
  226. package/dist/esm/components/server-info/index.js.map +1 -0
  227. package/dist/esm/components/server-info/reporter.d.ts +25 -0
  228. package/dist/esm/components/server-info/reporter.js +68 -0
  229. package/dist/esm/components/server-info/reporter.js.map +1 -0
  230. package/dist/esm/components/socket-io/common/keys.d.ts +1 -0
  231. package/dist/esm/components/socket-io/common/keys.js +1 -0
  232. package/dist/esm/components/socket-io/common/keys.js.map +1 -1
  233. package/dist/esm/components/socket-io/component.d.ts +1 -0
  234. package/dist/esm/components/socket-io/component.js +1 -0
  235. package/dist/esm/components/socket-io/component.js.map +1 -1
  236. package/dist/esm/components/static-asset/common/constants.d.ts +5 -0
  237. package/dist/esm/components/static-asset/common/constants.js +3 -0
  238. package/dist/esm/components/static-asset/common/constants.js.map +1 -1
  239. package/dist/esm/components/static-asset/common/keys.d.ts +1 -0
  240. package/dist/esm/components/static-asset/common/keys.js +1 -0
  241. package/dist/esm/components/static-asset/common/keys.js.map +1 -1
  242. package/dist/esm/components/static-asset/common/types.d.ts +48 -6
  243. package/dist/esm/components/static-asset/common/types.js.map +1 -1
  244. package/dist/esm/components/static-asset/controller/base.definition.d.ts +2 -0
  245. package/dist/esm/components/static-asset/controller/base.definition.js +6 -4
  246. package/dist/esm/components/static-asset/controller/base.definition.js.map +1 -1
  247. package/dist/esm/components/static-asset/controller/factory.d.ts +3 -0
  248. package/dist/esm/components/static-asset/controller/factory.js +18 -9
  249. package/dist/esm/components/static-asset/controller/factory.js.map +1 -1
  250. package/dist/esm/components/static-asset/controller/meta-link.js +1 -1
  251. package/dist/esm/components/static-asset/controller/meta-link.js.map +1 -1
  252. package/dist/esm/components/static-asset/controller/route-options.d.ts +9 -0
  253. package/dist/esm/components/static-asset/controller/route-options.js +16 -3
  254. package/dist/esm/components/static-asset/controller/route-options.js.map +1 -1
  255. package/dist/esm/components/static-asset/ingest.d.ts +7 -3
  256. package/dist/esm/components/static-asset/ingest.js +2 -2
  257. package/dist/esm/components/static-asset/ingest.js.map +1 -1
  258. package/dist/esm/components/static-asset/models/base.model.d.ts +2 -0
  259. package/dist/esm/components/static-asset/models/base.model.js.map +1 -1
  260. package/dist/esm/components/websocket/common/keys.d.ts +1 -0
  261. package/dist/esm/components/websocket/common/keys.js +1 -0
  262. package/dist/esm/components/websocket/common/keys.js.map +1 -1
  263. package/dist/esm/components/websocket/component.d.ts +1 -0
  264. package/dist/esm/components/websocket/component.js +1 -0
  265. package/dist/esm/components/websocket/component.js.map +1 -1
  266. package/dist/esm/testing/assert-application-boots.d.ts +48 -8
  267. package/dist/esm/testing/assert-application-boots.js +25 -1
  268. package/dist/esm/testing/assert-application-boots.js.map +1 -1
  269. package/dist/esm/utilities/drizzle-result.utility.d.ts +1 -0
  270. package/dist/esm/utilities/drizzle-result.utility.js +1 -0
  271. package/dist/esm/utilities/drizzle-result.utility.js.map +1 -1
  272. package/dist/presets/app/preset.json +4 -4
  273. package/dist/presets/lib/preset.json +3 -3
  274. package/dist/presets/shared/preset.json +1 -1
  275. package/package.json +8 -8
@@ -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,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\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,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,cAAc,GAGf,MAAM,uBAAuB,CA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,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 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,6 +1,7 @@
1
1
  import { BaseRestController } from '@venizia/ignis-kernel';
2
2
  import { type ValueOrPromise } from '@venizia/ignis-helpers/common';
3
3
  import { JWKSIssuerTokenService } from '../../services/index.js';
4
+ /** 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`. */
4
5
  export declare class JWKSController extends BaseRestController {
5
6
  private jwksService;
6
7
  constructor(jwksService: JWKSIssuerTokenService);
@@ -18,6 +18,7 @@ import { HTTP } from '@venizia/ignis-helpers/common';
18
18
  import { BindingKeys } from '@venizia/ignis-inversion';
19
19
  import { JWKSIssuerTokenService } from '../../services/index.js';
20
20
  import { RouteConfigs } from './definitions.js';
21
+ /** 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`. */
21
22
  let JWKSController = JWKSController_1 = class JWKSController extends BaseRestController {
22
23
  constructor(jwksService) {
23
24
  super({
@@ -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,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\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,C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port { 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,10 +1,24 @@
1
1
  import type { AESAlgorithmType } from '@venizia/ignis-helpers';
2
2
  import { AES } from '@venizia/ignis-helpers';
3
3
  import type { ValueOrPromise } from '@venizia/ignis-helpers/common';
4
- import type { IJWTIssueClaims, IJWTSignOptions, IJWTTokenPayload, IPayloadFieldCodec, TContext, TGetTokenExpiresFn } from '@venizia/ignis-kernel';
4
+ import type { IJWTClaimsOptions, IJWTIssueClaims, IJWTTokenPayload, IPayloadFieldCodec, TContext, TGetTokenExpiresFn } from '@venizia/ignis-kernel';
5
5
  import { BaseService } from '@venizia/ignis-kernel';
6
6
  import type { Env } from 'hono';
7
- import type { JWTPayload, JWTVerifyResult, SignJWT } from 'jose';
7
+ import type { JWTPayload, JWTVerifyOptions, JWTVerifyResult, SignJWT } from 'jose';
8
+ /** What a token service is configured with for claims: the required `claims`, the `verify` checks, and the removed `sign` it refuses. */
9
+ export interface IClaimsConfigSource {
10
+ claims?: unknown;
11
+ verify?: unknown;
12
+ /** Removed: refused with a message that points to `claims`. */
13
+ sign?: unknown;
14
+ }
15
+ /** What {@link AbstractBearerTokenService.resolveClaimsConfig} answers: the validated claims and the verify options jose receives. */
16
+ export interface IResolvedClaimsConfig {
17
+ claims: IJWTClaimsOptions;
18
+ verify: JWTVerifyOptions & {
19
+ algorithms: string[];
20
+ };
21
+ }
8
22
  /** Abstract base for Bearer-token services (JWS, JWKS) with optional AES payload encryption. */
9
23
  export declare abstract class AbstractBearerTokenService<E extends Env = Env> extends BaseService {
10
24
  /** Standard JWT fields that are never encrypted. */
@@ -12,14 +26,36 @@ export declare abstract class AbstractBearerTokenService<E extends Env = Env> ex
12
26
  protected aes: AES | null;
13
27
  protected applicationSecret: string | null;
14
28
  protected fieldCodecs: Map<string, IPayloadFieldCodec>;
15
- /** Configured `iss` / `aud`. Authoritative over anything the payload carries. */
16
- protected signOptions: IJWTSignOptions | null;
29
+ /** Configured `iss` / `aud`: stamped on every issued token, authoritative over anything the payload carries, and required on every verified one. */
30
+ protected claimOptions: IJWTClaimsOptions | null;
31
+ /** What jose verifies against: the claims, the algorithm pin and the `verify` checks. */
32
+ protected verifyOptions: JWTVerifyOptions | null;
33
+ /** The keys a `claims` object may hold. */
34
+ static readonly CLAIM_KEYS: ReadonlyArray<string>;
35
+ /**
36
+ * Validates the claims configuration of a token service and answers what the service uses. It throws, naming the
37
+ * key, when `claims.issuer` is missing or empty, when `claims.audience` is present but not a non-empty string or a
38
+ * non-empty list of them, when `claims` holds another key, when the removed `sign` or `verify.issuer` /
39
+ * `verify.audience` is still passed, and when no algorithm is pinned. `claims.audience` is optional: without it
40
+ * no `aud` is stamped and none is checked.
41
+ * `pinnedAlgorithms` is what the service signs with; a verifier has none and requires `verify.algorithms`.
42
+ * The component calls it at boot, and a service calls it when it is built, so neither can start without them.
43
+ */
44
+ static resolveClaimsConfig(opts: {
45
+ scope: string;
46
+ options: IClaimsConfigSource;
47
+ pinnedAlgorithms?: string[];
48
+ }): IResolvedClaimsConfig;
49
+ /** Validates the claims configuration (see {@link AbstractBearerTokenService.resolveClaimsConfig}) and keeps the result. */
50
+ protected configureClaims(opts: {
51
+ options: IClaimsConfigSource;
52
+ pinnedAlgorithms?: string[];
53
+ }): void;
17
54
  /** Configures AES payload encryption and field codecs. Both aesAlgorithm and applicationSecret required to activate encryption. */
18
55
  protected configurePayloadEncryption(opts: {
19
56
  aesAlgorithm?: AESAlgorithmType;
20
57
  applicationSecret?: string;
21
58
  fieldCodecs?: IPayloadFieldCodec[];
22
- sign?: IJWTSignOptions;
23
59
  }): void;
24
60
  extractCredentials(context: TContext<E, string>): {
25
61
  type: string;
@@ -29,17 +65,32 @@ export declare abstract class AbstractBearerTokenService<E extends Env = Env> ex
29
65
  type: string;
30
66
  token: string;
31
67
  }): Promise<IJWTTokenPayload>;
68
+ /**
69
+ * A service assertion (`typ: svc+jwt`) is not a user token. When a JWKS issuer shares the key of the service
70
+ * assertions and the names collide, an assertion would otherwise verify here, so the user-token path refuses it.
71
+ */
72
+ protected assertNotServiceAssertion(opts: {
73
+ token: string;
74
+ }): Promise<void>;
32
75
  generate(opts: {
33
76
  payload: IJWTTokenPayload;
34
77
  getTokenExpiresFn?: TGetTokenExpiresFn;
35
78
  /** Per-token registered claims. The supported way to vary `aud` / `sub`; the payload is not. */
36
79
  claims?: IJWTIssueClaims;
37
80
  }): Promise<string>;
81
+ /** A `null` is written as `null` whatever the field's codec is: a codec converts a value, and `null` is none. */
38
82
  protected serializeField(opts: {
39
83
  key: string;
40
84
  value: any;
41
85
  }): string;
86
+ /**
87
+ * With `applicationSecret` set, AES-encrypts the key and the value of every claim outside `JWT_COMMON_FIELDS`;
88
+ * without it, returns the payload as is. A `null` claim is encrypted like any other value and decodes as `null`,
89
+ * so the token decodes to the same payload with encryption on or off and `null` stays distinct from absent. An
90
+ * `undefined` claim is skipped, as JSON drops it.
91
+ */
42
92
  encryptPayload(payload: IJWTTokenPayload): Promise<Record<string, any>>;
93
+ /** The text `null` reads as `null` before any codec sees it, the other half of {@link serializeField}. */
43
94
  protected deserializeField(opts: {
44
95
  key: string;
45
96
  value: string;
@@ -1,7 +1,8 @@
1
1
  import { AES } from '@venizia/ignis-helpers';
2
2
  import { HTTP } from '@venizia/ignis-helpers/common';
3
- import { getError } from '@venizia/ignis-helpers/core';
4
- import { Authentication, AuthenticationErrors, BaseService } from '@venizia/ignis-kernel';
3
+ import { getError, RecordUtility } from '@venizia/ignis-helpers/core';
4
+ import { Authentication, AuthenticationErrors, BaseService, ServiceAssertion, } from '@venizia/ignis-kernel';
5
+ import { JoseLoader } from '../jose-loader.js';
5
6
  /** Abstract base for Bearer-token services (JWS, JWKS) with optional AES payload encryption. */
6
7
  export class AbstractBearerTokenService extends BaseService {
7
8
  constructor() {
@@ -9,8 +10,10 @@ export class AbstractBearerTokenService extends BaseService {
9
10
  this.aes = null;
10
11
  this.applicationSecret = null;
11
12
  this.fieldCodecs = new Map();
12
- /** Configured `iss` / `aud`. Authoritative over anything the payload carries. */
13
- this.signOptions = null;
13
+ /** Configured `iss` / `aud`: stamped on every issued token, authoritative over anything the payload carries, and required on every verified one. */
14
+ this.claimOptions = null;
15
+ /** What jose verifies against: the claims, the algorithm pin and the `verify` checks. */
16
+ this.verifyOptions = null;
14
17
  }
15
18
  /** Standard JWT fields that are never encrypted. */
16
19
  static { this.JWT_COMMON_FIELDS = new Set([
@@ -22,10 +25,85 @@ export class AbstractBearerTokenService extends BaseService {
22
25
  'exp',
23
26
  'iat',
24
27
  ]); }
28
+ /** The keys a `claims` object may hold. */
29
+ static { this.CLAIM_KEYS = ['issuer', 'audience']; }
30
+ /**
31
+ * Validates the claims configuration of a token service and answers what the service uses. It throws, naming the
32
+ * key, when `claims.issuer` is missing or empty, when `claims.audience` is present but not a non-empty string or a
33
+ * non-empty list of them, when `claims` holds another key, when the removed `sign` or `verify.issuer` /
34
+ * `verify.audience` is still passed, and when no algorithm is pinned. `claims.audience` is optional: without it
35
+ * no `aud` is stamped and none is checked.
36
+ * `pinnedAlgorithms` is what the service signs with; a verifier has none and requires `verify.algorithms`.
37
+ * The component calls it at boot, and a service calls it when it is built, so neither can start without them.
38
+ */
39
+ static resolveClaimsConfig(opts) {
40
+ const { scope, options, pinnedAlgorithms } = opts;
41
+ const fail = (detail) => getError({
42
+ statusCode: HTTP.ResultCodes.RS_5.InternalServerError,
43
+ message: `[${scope}] ${detail}`,
44
+ });
45
+ if (options.sign !== undefined) {
46
+ throw fail('`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');
47
+ }
48
+ if (options.verify !== undefined && !RecordUtility.isPlainRecord(options.verify)) {
49
+ throw fail('verify must be an object | its checks (maxTokenAge, subject, ...) would be dropped silently');
50
+ }
51
+ const verify = RecordUtility.isPlainRecord(options.verify) ? options.verify : {};
52
+ for (const key of AbstractBearerTokenService.CLAIM_KEYS) {
53
+ if (key in verify) {
54
+ throw fail(`verify.${key} was removed | set claims.${key}: it is stamped on every token and required on every verified one`);
55
+ }
56
+ }
57
+ const { claims } = options;
58
+ if (!RecordUtility.isPlainRecord(claims)) {
59
+ throw fail('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');
60
+ }
61
+ const unknown = Object.keys(claims).filter((key) => !AbstractBearerTokenService.CLAIM_KEYS.includes(key));
62
+ if (unknown.length > 0) {
63
+ throw fail(`claims holds unknown keys ${JSON.stringify(unknown)} | accepted: ${AbstractBearerTokenService.CLAIM_KEYS.join(', ')}`);
64
+ }
65
+ const { issuer, audience } = claims;
66
+ const isName = (value) => typeof value === 'string' && value.trim().length > 0;
67
+ if (!isName(issuer)) {
68
+ throw fail('claims.issuer is required | a non-empty string');
69
+ }
70
+ // Optional, but a present value is checked: `null`, `''` and `[]` are mistakes, not "no audience".
71
+ if (audience !== undefined &&
72
+ !isName(audience) &&
73
+ !(Array.isArray(audience) && audience.length > 0 && audience.every(isName))) {
74
+ throw fail('claims.audience must be a non-empty string or a non-empty list of them | or leave it out');
75
+ }
76
+ const resolvedAudience = Array.isArray(audience) ? [...audience] : audience;
77
+ const algorithms = verify.algorithms ?? pinnedAlgorithms;
78
+ if (!Array.isArray(algorithms) || algorithms.length === 0 || !algorithms.every(isName)) {
79
+ throw fail("verify.algorithms is required | the accepted JWS algorithms, for example ['RS256']: a verifier cannot know what the issuer signs with");
80
+ }
81
+ if (algorithms.some((algorithm) => algorithm.trim().toLowerCase() === 'none')) {
82
+ throw fail("the algorithm 'none' is refused | a token with no signature verifies nothing");
83
+ }
84
+ return {
85
+ claims: { issuer, ...(resolvedAudience === undefined ? {} : { audience: resolvedAudience }) },
86
+ verify: {
87
+ ...verify,
88
+ issuer,
89
+ ...(resolvedAudience === undefined ? {} : { audience: resolvedAudience }),
90
+ algorithms: [...algorithms],
91
+ },
92
+ };
93
+ }
94
+ /** Validates the claims configuration (see {@link AbstractBearerTokenService.resolveClaimsConfig}) and keeps the result. */
95
+ configureClaims(opts) {
96
+ const resolved = AbstractBearerTokenService.resolveClaimsConfig({
97
+ scope: this.scope,
98
+ options: opts.options,
99
+ pinnedAlgorithms: opts.pinnedAlgorithms,
100
+ });
101
+ this.claimOptions = resolved.claims;
102
+ this.verifyOptions = resolved.verify;
103
+ }
25
104
  /** Configures AES payload encryption and field codecs. Both aesAlgorithm and applicationSecret required to activate encryption. */
26
105
  configurePayloadEncryption(opts) {
27
- const { aesAlgorithm = 'aes-256-cbc', applicationSecret, fieldCodecs, sign } = opts;
28
- this.signOptions = sign ?? null;
106
+ const { aesAlgorithm = 'aes-256-cbc', applicationSecret, fieldCodecs } = opts;
29
107
  if (fieldCodecs) {
30
108
  for (const codec of fieldCodecs) {
31
109
  this.fieldCodecs.set(codec.key, codec);
@@ -72,6 +150,7 @@ export class AbstractBearerTokenService extends BaseService {
72
150
  });
73
151
  }
74
152
  try {
153
+ await this.assertNotServiceAssertion({ token });
75
154
  const result = await this.doVerify(token);
76
155
  return result;
77
156
  }
@@ -85,6 +164,21 @@ export class AbstractBearerTokenService extends BaseService {
85
164
  });
86
165
  }
87
166
  }
167
+ /**
168
+ * A service assertion (`typ: svc+jwt`) is not a user token. When a JWKS issuer shares the key of the service
169
+ * assertions and the names collide, an assertion would otherwise verify here, so the user-token path refuses it.
170
+ */
171
+ async assertNotServiceAssertion(opts) {
172
+ const { decodeProtectedHeader } = await JoseLoader.load();
173
+ const { typ } = decodeProtectedHeader(opts.token);
174
+ const kind = typeof typ === 'string' ? typ.toLowerCase().replace(/^application\//, '') : '';
175
+ if (kind === ServiceAssertion.TYP) {
176
+ throw getError({
177
+ error: AuthenticationErrors.TOKEN_INVALID,
178
+ message: '[verify] A service assertion is not a user token',
179
+ });
180
+ }
181
+ }
88
182
  async generate(opts) {
89
183
  const { payload, claims, getTokenExpiresFn = this.getDefaultTokenExpiresFn() } = opts;
90
184
  if (!payload) {
@@ -107,14 +201,21 @@ export class AbstractBearerTokenService extends BaseService {
107
201
  });
108
202
  }
109
203
  }
204
+ /** A `null` is written as `null` whatever the field's codec is: a codec converts a value, and `null` is none. */
110
205
  serializeField(opts) {
111
206
  const { key, value } = opts;
112
- const codec = this.fieldCodecs.get(key);
207
+ const codec = value === null ? undefined : this.fieldCodecs.get(key);
113
208
  if (codec) {
114
209
  return codec.serialize({ value });
115
210
  }
116
211
  return JSON.stringify(value);
117
212
  }
213
+ /**
214
+ * With `applicationSecret` set, AES-encrypts the key and the value of every claim outside `JWT_COMMON_FIELDS`;
215
+ * without it, returns the payload as is. A `null` claim is encrypted like any other value and decodes as `null`,
216
+ * so the token decodes to the same payload with encryption on or off and `null` stays distinct from absent. An
217
+ * `undefined` claim is skipped, as JSON drops it.
218
+ */
118
219
  async encryptPayload(payload) {
119
220
  if (!this.aes || !this.applicationSecret) {
120
221
  return payload;
@@ -127,8 +228,10 @@ export class AbstractBearerTokenService extends BaseService {
127
228
  rs[key] = value;
128
229
  continue;
129
230
  }
130
- // NOTE: Skip undefined or null values because they cannot be encrypted
131
- if (value === undefined || value === null) {
231
+ // Only `undefined` is skipped: JSON drops it too, so the claim is absent either way. `null` is a value, and
232
+ // `serializeField` writes it as `null`, which `deserializeField` reads back, so an encrypted token decodes the
233
+ // same payload as a plain one.
234
+ if (value === undefined) {
132
235
  continue;
133
236
  }
134
237
  const encryptedKey = await this.aes.encrypt({
@@ -144,9 +247,10 @@ export class AbstractBearerTokenService extends BaseService {
144
247
  }
145
248
  return rs;
146
249
  }
250
+ /** The text `null` reads as `null` before any codec sees it, the other half of {@link serializeField}. */
147
251
  deserializeField(opts) {
148
252
  const { key, value } = opts;
149
- const codec = this.fieldCodecs.get(key);
253
+ const codec = value === 'null' ? undefined : this.fieldCodecs.get(key);
150
254
  if (codec) {
151
255
  return codec.deserialize({ raw: value });
152
256
  }
@@ -165,7 +269,7 @@ export class AbstractBearerTokenService extends BaseService {
165
269
  */
166
270
  applySignClaims(opts) {
167
271
  const { signer, payload, claims } = opts;
168
- const configured = this.signOptions;
272
+ const configured = this.claimOptions;
169
273
  const issuer = claims?.issuer ?? configured?.issuer;
170
274
  const audience = claims?.audience ?? configured?.audience;
171
275
  const logger = this.logger.for(this.applySignClaims.name);
@@ -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,MAAM,6BAA6B,CAAC;AASvD,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAI1F,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,iF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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 } from '@venizia/ignis-helpers/core';\nimport type {\n IJWTIssueClaims,\n IJWTSignOptions,\n IJWTTokenPayload,\n IPayloadFieldCodec,\n TContext,\n TGetTokenExpiresFn,\n} from '@venizia/ignis-kernel';\nimport { Authentication, AuthenticationErrors, BaseService } from '@venizia/ignis-kernel';\nimport type { Env } from 'hono';\nimport type { JWTPayload, JWTVerifyResult, SignJWT } from 'jose';\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`. Authoritative over anything the payload carries. */\n protected signOptions: IJWTSignOptions | null = null;\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 sign?: IJWTSignOptions;\n }): void {\n const { aesAlgorithm = 'aes-256-cbc', applicationSecret, fieldCodecs, sign } = opts;\n\n this.signOptions = sign ?? null;\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 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 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 protected serializeField(opts: { key: string; value: any }): string {\n const { key, value } = opts;\n const codec = this.fieldCodecs.get(key);\n\n if (codec) {\n return codec.serialize({ value });\n }\n\n return JSON.stringify(value);\n }\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 // NOTE: Skip undefined or null values because they cannot be encrypted\n if (value === undefined || value === null) {\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 protected deserializeField(opts: { key: string; value: string }) {\n const { key, value } = opts;\n const codec = 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.signOptions;\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;IA4a1D,CAAC;IA/bC,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,CAQ9B;IAYH,2CAA2C;aAC3B,eAAU,GAA0B,CAAC,QAAQ,EAAE,UAAU,CAAC,AAAhD,CAAiD;IAE3E;;;;;;;;OAQG;IACH,MAAM,CAAC,mBAAmB,CAAC,IAI1B;QACC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC;QAClD,MAAM,IAAI,GAAG,CAAC,MAAc,EAAE,EAAE,CAC9B,QAAQ,CAAC;YACP,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mB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C,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"]}
@@ -3,6 +3,7 @@ import { type IJWKSIssuerOptions, type IJWTIssueClaims, type IJWTTokenPayload, t
3
3
  import { type Env } from 'hono';
4
4
  import type { CryptoKey, JWK } from 'jose';
5
5
  import { AbstractJWKSTokenService } from './abstract.service.js';
6
+ /** Signs tokens with a private key loaded from `IJWKSIssuerOptions` and exposes the matching public keys as a JWKS via `getJWKSAsync()`. */
6
7
  export declare class JWKSIssuerTokenService<E extends Env = Env> extends AbstractJWKSTokenService<E> {
7
8
  protected options: IJWKSIssuerOptions;
8
9
  protected privateKey: TNullable<CryptoKey | Uint8Array>;
@@ -17,6 +17,7 @@ import { AuthenticateBindingKeys, inject, JWKSKeyDrivers, JWKSKeyFormats, } from
17
17
  import { readFile } from 'node:fs/promises';
18
18
  import { JoseLoader } from '../../jose-loader.js';
19
19
  import { AbstractJWKSTokenService } from './abstract.service.js';
20
+ /** Signs tokens with a private key loaded from `IJWKSIssuerOptions` and exposes the matching public keys as a JWKS via `getJWKSAsync()`. */
20
21
  let JWKSIssuerTokenService = JWKSIssuerTokenService_1 = class JWKSIssuerTokenService extends AbstractJWKSTokenService {
21
22
  constructor(options) {
22
23
  super({ scope: JWKSIssuerTokenService_1.name });
@@ -24,11 +25,11 @@ let JWKSIssuerTokenService = JWKSIssuerTokenService_1 = class JWKSIssuerTokenSer
24
25
  this.privateKey = null;
25
26
  this.publicKey = null;
26
27
  this.jwks = null;
28
+ this.configureClaims({ options: this.options, pinnedAlgorithms: [this.options.algorithm] });
27
29
  this.configurePayloadEncryption({
28
30
  aesAlgorithm: this.options.aesAlgorithm,
29
31
  applicationSecret: this.options.applicationSecret,
30
32
  fieldCodecs: this.options.fieldCodecs,
31
- sign: this.options.sign,
32
33
  });
33
34
  }
34
35
  async initialize() {
@@ -153,7 +154,7 @@ let JWKSIssuerTokenService = JWKSIssuerTokenService_1 = class JWKSIssuerTokenSer
153
154
  async doVerify(token) {
154
155
  await this.ensureInitialized();
155
156
  const { jwtVerify } = await JoseLoader.load();
156
- const result = await jwtVerify(token, this.publicKey, this.options.verify);
157
+ const result = await jwtVerify(token, this.publicKey, this.verifyOptions);
157
158
  return this.decryptPayload({ result });
158
159
  }
159
160
  async getSigner(opts) {