@blazedpath/commons 0.2.2 → 0.3.1

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 (626) hide show
  1. package/README.md +4 -1
  2. package/dist/blz-base/health/index.d.ts +1 -0
  3. package/dist/blz-base/health/index.js +1 -0
  4. package/dist/blz-base/index.d.ts +108 -0
  5. package/dist/blz-base/index.js +1 -0
  6. package/dist/blz-cache/LruCache.d.ts +31 -0
  7. package/dist/blz-cache/LruCache.js +1 -0
  8. package/dist/blz-cache/index.d.ts +2 -0
  9. package/dist/blz-cache/index.js +1 -0
  10. package/dist/blz-config/index.d.ts +16 -0
  11. package/dist/blz-config/index.js +1 -0
  12. package/dist/blz-core/index.d.ts +32 -0
  13. package/dist/blz-core/index.js +1 -0
  14. package/dist/blz-cryptography/index.d.ts +2 -0
  15. package/dist/blz-cryptography/index.js +1 -0
  16. package/dist/blz-datetimes/index.d.ts +35 -0
  17. package/dist/blz-datetimes/index.js +1 -0
  18. package/dist/blz-file/fileService.d.ts +25 -0
  19. package/dist/blz-file/fileService.js +1 -0
  20. package/dist/blz-file/index.d.ts +2 -0
  21. package/dist/blz-file/index.js +1 -0
  22. package/dist/blz-file/index.test.js +1 -0
  23. package/dist/blz-file/lab.js +1 -0
  24. package/dist/blz-hazelcast/index.d.ts +25 -0
  25. package/dist/blz-hazelcast/index.js +1 -0
  26. package/dist/blz-hazelcast/lib/credentials.d.ts +10 -0
  27. package/dist/blz-hazelcast/lib/credentials.js +1 -0
  28. package/dist/blz-hazelcast/lib/credentialsFactory.d.ts +1 -0
  29. package/dist/blz-hazelcast/lib/credentialsFactory.js +1 -0
  30. package/dist/blz-hazelcast/lib/hazelcastCache.d.ts +27 -0
  31. package/dist/blz-hazelcast/lib/hazelcastCache.js +1 -0
  32. package/dist/blz-iterable/index.d.ts +49 -0
  33. package/dist/blz-iterable/index.js +1 -0
  34. package/dist/blz-json-schema/index.d.ts +1 -0
  35. package/dist/blz-json-schema/index.js +1 -0
  36. package/dist/blz-jwt/index.d.ts +12 -0
  37. package/dist/blz-jwt/index.js +1 -0
  38. package/dist/blz-kafka/index.d.ts +9 -0
  39. package/dist/blz-kafka/index.js +1 -0
  40. package/dist/blz-math/index.d.ts +22 -0
  41. package/dist/blz-math/index.js +1 -0
  42. package/dist/blz-mongodb/index.d.ts +28 -0
  43. package/dist/blz-mongodb/index.js +1 -0
  44. package/dist/blz-rds/__test__/scape.test.js +1 -0
  45. package/dist/blz-rds/blz-rds-executor.d.ts +4 -0
  46. package/dist/blz-rds/blz-rds-executor.js +1 -0
  47. package/dist/blz-rds/blz-rds-helper.d.ts +5 -0
  48. package/dist/blz-rds/blz-rds-helper.js +1 -0
  49. package/dist/blz-rds/commands/core/add.d.ts +2 -0
  50. package/dist/blz-rds/commands/core/add.js +1 -0
  51. package/dist/blz-rds/commands/core/and.d.ts +3 -0
  52. package/dist/blz-rds/commands/core/and.js +1 -0
  53. package/dist/blz-rds/commands/core/asc.d.ts +2 -0
  54. package/dist/blz-rds/commands/core/asc.js +1 -0
  55. package/dist/blz-rds/commands/core/avg.d.ts +2 -0
  56. package/dist/blz-rds/commands/core/avg.js +1 -0
  57. package/dist/blz-rds/commands/core/column-ref.d.ts +2 -0
  58. package/dist/blz-rds/commands/core/column-ref.js +1 -0
  59. package/dist/blz-rds/commands/core/count-distinct.d.ts +2 -0
  60. package/dist/blz-rds/commands/core/count-distinct.js +1 -0
  61. package/dist/blz-rds/commands/core/count.d.ts +2 -0
  62. package/dist/blz-rds/commands/core/count.js +1 -0
  63. package/dist/blz-rds/commands/core/decimal.d.ts +2 -0
  64. package/dist/blz-rds/commands/core/decimal.js +1 -0
  65. package/dist/blz-rds/commands/core/desc.d.ts +2 -0
  66. package/dist/blz-rds/commands/core/desc.js +1 -0
  67. package/dist/blz-rds/commands/core/distinct.d.ts +2 -0
  68. package/dist/blz-rds/commands/core/distinct.js +1 -0
  69. package/dist/blz-rds/commands/core/divide.d.ts +2 -0
  70. package/dist/blz-rds/commands/core/divide.js +1 -0
  71. package/dist/blz-rds/commands/core/embedded-exists.d.ts +3 -0
  72. package/dist/blz-rds/commands/core/embedded-exists.js +1 -0
  73. package/dist/blz-rds/commands/core/embedded-select.d.ts +2 -0
  74. package/dist/blz-rds/commands/core/embedded-select.js +1 -0
  75. package/dist/blz-rds/commands/core/equals.d.ts +3 -0
  76. package/dist/blz-rds/commands/core/equals.js +1 -0
  77. package/dist/blz-rds/commands/core/false.d.ts +2 -0
  78. package/dist/blz-rds/commands/core/false.js +1 -0
  79. package/dist/blz-rds/commands/core/greater-or-equal.d.ts +3 -0
  80. package/dist/blz-rds/commands/core/greater-or-equal.js +1 -0
  81. package/dist/blz-rds/commands/core/greater.d.ts +3 -0
  82. package/dist/blz-rds/commands/core/greater.js +1 -0
  83. package/dist/blz-rds/commands/core/in.d.ts +3 -0
  84. package/dist/blz-rds/commands/core/in.js +1 -0
  85. package/dist/blz-rds/commands/core/integer.d.ts +2 -0
  86. package/dist/blz-rds/commands/core/integer.js +1 -0
  87. package/dist/blz-rds/commands/core/is-not-null.d.ts +3 -0
  88. package/dist/blz-rds/commands/core/is-not-null.js +1 -0
  89. package/dist/blz-rds/commands/core/is-null-or-value.d.ts +3 -0
  90. package/dist/blz-rds/commands/core/is-null-or-value.js +1 -0
  91. package/dist/blz-rds/commands/core/is-null.d.ts +3 -0
  92. package/dist/blz-rds/commands/core/is-null.js +1 -0
  93. package/dist/blz-rds/commands/core/less-or-equal.d.ts +3 -0
  94. package/dist/blz-rds/commands/core/less-or-equal.js +1 -0
  95. package/dist/blz-rds/commands/core/less-unary.d.ts +2 -0
  96. package/dist/blz-rds/commands/core/less-unary.js +1 -0
  97. package/dist/blz-rds/commands/core/less.d.ts +3 -0
  98. package/dist/blz-rds/commands/core/less.js +1 -0
  99. package/dist/blz-rds/commands/core/like.d.ts +3 -0
  100. package/dist/blz-rds/commands/core/like.js +1 -0
  101. package/dist/blz-rds/commands/core/max.d.ts +2 -0
  102. package/dist/blz-rds/commands/core/max.js +1 -0
  103. package/dist/blz-rds/commands/core/min.d.ts +2 -0
  104. package/dist/blz-rds/commands/core/min.js +1 -0
  105. package/dist/blz-rds/commands/core/multiply.d.ts +2 -0
  106. package/dist/blz-rds/commands/core/multiply.js +1 -0
  107. package/dist/blz-rds/commands/core/not-equals.d.ts +3 -0
  108. package/dist/blz-rds/commands/core/not-equals.js +1 -0
  109. package/dist/blz-rds/commands/core/not-in.d.ts +3 -0
  110. package/dist/blz-rds/commands/core/not-in.js +1 -0
  111. package/dist/blz-rds/commands/core/not.d.ts +3 -0
  112. package/dist/blz-rds/commands/core/not.js +1 -0
  113. package/dist/blz-rds/commands/core/null.d.ts +2 -0
  114. package/dist/blz-rds/commands/core/null.js +1 -0
  115. package/dist/blz-rds/commands/core/nvl.d.ts +2 -0
  116. package/dist/blz-rds/commands/core/nvl.js +1 -0
  117. package/dist/blz-rds/commands/core/or.d.ts +3 -0
  118. package/dist/blz-rds/commands/core/or.js +1 -0
  119. package/dist/blz-rds/commands/core/parameter.d.ts +2 -0
  120. package/dist/blz-rds/commands/core/parameter.js +1 -0
  121. package/dist/blz-rds/commands/core/remainder.d.ts +2 -0
  122. package/dist/blz-rds/commands/core/remainder.js +1 -0
  123. package/dist/blz-rds/commands/core/string.d.ts +2 -0
  124. package/dist/blz-rds/commands/core/string.js +1 -0
  125. package/dist/blz-rds/commands/core/subtract.d.ts +2 -0
  126. package/dist/blz-rds/commands/core/subtract.js +1 -0
  127. package/dist/blz-rds/commands/core/sum.d.ts +2 -0
  128. package/dist/blz-rds/commands/core/sum.js +1 -0
  129. package/dist/blz-rds/commands/core/true.d.ts +2 -0
  130. package/dist/blz-rds/commands/core/true.js +1 -0
  131. package/dist/blz-rds/commands/core/tuple.d.ts +2 -0
  132. package/dist/blz-rds/commands/core/tuple.js +1 -0
  133. package/dist/blz-rds/commands/datetimes/add-days.d.ts +2 -0
  134. package/dist/blz-rds/commands/datetimes/add-days.js +1 -0
  135. package/dist/blz-rds/commands/datetimes/add-hours.d.ts +2 -0
  136. package/dist/blz-rds/commands/datetimes/add-hours.js +1 -0
  137. package/dist/blz-rds/commands/datetimes/add-milliseconds.d.ts +2 -0
  138. package/dist/blz-rds/commands/datetimes/add-milliseconds.js +1 -0
  139. package/dist/blz-rds/commands/datetimes/add-minutes.d.ts +2 -0
  140. package/dist/blz-rds/commands/datetimes/add-minutes.js +1 -0
  141. package/dist/blz-rds/commands/datetimes/add-months.d.ts +2 -0
  142. package/dist/blz-rds/commands/datetimes/add-months.js +1 -0
  143. package/dist/blz-rds/commands/datetimes/add-seconds.d.ts +2 -0
  144. package/dist/blz-rds/commands/datetimes/add-seconds.js +1 -0
  145. package/dist/blz-rds/commands/datetimes/add-years.d.ts +2 -0
  146. package/dist/blz-rds/commands/datetimes/add-years.js +1 -0
  147. package/dist/blz-rds/commands/datetimes/date-diff.d.ts +2 -0
  148. package/dist/blz-rds/commands/datetimes/date-diff.js +1 -0
  149. package/dist/blz-rds/commands/datetimes/date.d.ts +2 -0
  150. package/dist/blz-rds/commands/datetimes/date.js +1 -0
  151. package/dist/blz-rds/commands/datetimes/datetime-diff.d.ts +2 -0
  152. package/dist/blz-rds/commands/datetimes/datetime-diff.js +1 -0
  153. package/dist/blz-rds/commands/datetimes/datetime.d.ts +2 -0
  154. package/dist/blz-rds/commands/datetimes/datetime.js +1 -0
  155. package/dist/blz-rds/commands/datetimes/day.d.ts +2 -0
  156. package/dist/blz-rds/commands/datetimes/day.js +1 -0
  157. package/dist/blz-rds/commands/datetimes/hour.d.ts +2 -0
  158. package/dist/blz-rds/commands/datetimes/hour.js +1 -0
  159. package/dist/blz-rds/commands/datetimes/millisecond.d.ts +2 -0
  160. package/dist/blz-rds/commands/datetimes/millisecond.js +1 -0
  161. package/dist/blz-rds/commands/datetimes/minute.d.ts +2 -0
  162. package/dist/blz-rds/commands/datetimes/minute.js +1 -0
  163. package/dist/blz-rds/commands/datetimes/month-text.d.ts +2 -0
  164. package/dist/blz-rds/commands/datetimes/month-text.js +1 -0
  165. package/dist/blz-rds/commands/datetimes/month.d.ts +2 -0
  166. package/dist/blz-rds/commands/datetimes/month.js +1 -0
  167. package/dist/blz-rds/commands/datetimes/now.d.ts +2 -0
  168. package/dist/blz-rds/commands/datetimes/now.js +1 -0
  169. package/dist/blz-rds/commands/datetimes/second.d.ts +2 -0
  170. package/dist/blz-rds/commands/datetimes/second.js +1 -0
  171. package/dist/blz-rds/commands/datetimes/subtract-days.d.ts +2 -0
  172. package/dist/blz-rds/commands/datetimes/subtract-days.js +1 -0
  173. package/dist/blz-rds/commands/datetimes/subtract-hours.d.ts +2 -0
  174. package/dist/blz-rds/commands/datetimes/subtract-hours.js +1 -0
  175. package/dist/blz-rds/commands/datetimes/subtract-milliseconds.d.ts +2 -0
  176. package/dist/blz-rds/commands/datetimes/subtract-milliseconds.js +1 -0
  177. package/dist/blz-rds/commands/datetimes/subtract-minutes.d.ts +2 -0
  178. package/dist/blz-rds/commands/datetimes/subtract-minutes.js +1 -0
  179. package/dist/blz-rds/commands/datetimes/subtract-seconds.d.ts +2 -0
  180. package/dist/blz-rds/commands/datetimes/subtract-seconds.js +1 -0
  181. package/dist/blz-rds/commands/datetimes/time-diff.d.ts +2 -0
  182. package/dist/blz-rds/commands/datetimes/time-diff.js +1 -0
  183. package/dist/blz-rds/commands/datetimes/time.d.ts +2 -0
  184. package/dist/blz-rds/commands/datetimes/time.js +1 -0
  185. package/dist/blz-rds/commands/datetimes/today.d.ts +2 -0
  186. package/dist/blz-rds/commands/datetimes/today.js +1 -0
  187. package/dist/blz-rds/commands/datetimes/week-day-text.d.ts +2 -0
  188. package/dist/blz-rds/commands/datetimes/week-day-text.js +1 -0
  189. package/dist/blz-rds/commands/datetimes/week-day.d.ts +2 -0
  190. package/dist/blz-rds/commands/datetimes/week-day.js +1 -0
  191. package/dist/blz-rds/commands/datetimes/week.d.ts +2 -0
  192. package/dist/blz-rds/commands/datetimes/week.js +1 -0
  193. package/dist/blz-rds/commands/datetimes/year.d.ts +2 -0
  194. package/dist/blz-rds/commands/datetimes/year.js +1 -0
  195. package/dist/blz-rds/commands/math/abs.d.ts +2 -0
  196. package/dist/blz-rds/commands/math/abs.js +1 -0
  197. package/dist/blz-rds/commands/math/acos.d.ts +2 -0
  198. package/dist/blz-rds/commands/math/acos.js +1 -0
  199. package/dist/blz-rds/commands/math/asin.d.ts +2 -0
  200. package/dist/blz-rds/commands/math/asin.js +1 -0
  201. package/dist/blz-rds/commands/math/atan.d.ts +2 -0
  202. package/dist/blz-rds/commands/math/atan.js +1 -0
  203. package/dist/blz-rds/commands/math/atan2.d.ts +2 -0
  204. package/dist/blz-rds/commands/math/atan2.js +1 -0
  205. package/dist/blz-rds/commands/math/ceil.d.ts +2 -0
  206. package/dist/blz-rds/commands/math/ceil.js +1 -0
  207. package/dist/blz-rds/commands/math/cos.d.ts +2 -0
  208. package/dist/blz-rds/commands/math/cos.js +1 -0
  209. package/dist/blz-rds/commands/math/cosh.d.ts +2 -0
  210. package/dist/blz-rds/commands/math/cosh.js +1 -0
  211. package/dist/blz-rds/commands/math/exp.d.ts +2 -0
  212. package/dist/blz-rds/commands/math/exp.js +1 -0
  213. package/dist/blz-rds/commands/math/floor.d.ts +2 -0
  214. package/dist/blz-rds/commands/math/floor.js +1 -0
  215. package/dist/blz-rds/commands/math/log.d.ts +2 -0
  216. package/dist/blz-rds/commands/math/log.js +1 -0
  217. package/dist/blz-rds/commands/math/log10.d.ts +2 -0
  218. package/dist/blz-rds/commands/math/log10.js +1 -0
  219. package/dist/blz-rds/commands/math/pow.d.ts +2 -0
  220. package/dist/blz-rds/commands/math/pow.js +1 -0
  221. package/dist/blz-rds/commands/math/random.d.ts +2 -0
  222. package/dist/blz-rds/commands/math/random.js +1 -0
  223. package/dist/blz-rds/commands/math/round.d.ts +2 -0
  224. package/dist/blz-rds/commands/math/round.js +1 -0
  225. package/dist/blz-rds/commands/math/sign.d.ts +2 -0
  226. package/dist/blz-rds/commands/math/sign.js +1 -0
  227. package/dist/blz-rds/commands/math/sin.d.ts +2 -0
  228. package/dist/blz-rds/commands/math/sin.js +1 -0
  229. package/dist/blz-rds/commands/math/sinh.d.ts +2 -0
  230. package/dist/blz-rds/commands/math/sinh.js +1 -0
  231. package/dist/blz-rds/commands/math/sqrt.d.ts +2 -0
  232. package/dist/blz-rds/commands/math/sqrt.js +1 -0
  233. package/dist/blz-rds/commands/math/tan.d.ts +2 -0
  234. package/dist/blz-rds/commands/math/tan.js +1 -0
  235. package/dist/blz-rds/commands/math/tanh.d.ts +2 -0
  236. package/dist/blz-rds/commands/math/tanh.js +1 -0
  237. package/dist/blz-rds/commands/math/trunc.d.ts +2 -0
  238. package/dist/blz-rds/commands/math/trunc.js +1 -0
  239. package/dist/blz-rds/commands/strings/concat.d.ts +2 -0
  240. package/dist/blz-rds/commands/strings/concat.js +1 -0
  241. package/dist/blz-rds/commands/strings/contains.d.ts +3 -0
  242. package/dist/blz-rds/commands/strings/contains.js +1 -0
  243. package/dist/blz-rds/commands/strings/ends-with.d.ts +3 -0
  244. package/dist/blz-rds/commands/strings/ends-with.js +1 -0
  245. package/dist/blz-rds/commands/strings/index-of.d.ts +2 -0
  246. package/dist/blz-rds/commands/strings/index-of.js +1 -0
  247. package/dist/blz-rds/commands/strings/is-null-or-empty.d.ts +3 -0
  248. package/dist/blz-rds/commands/strings/is-null-or-empty.js +1 -0
  249. package/dist/blz-rds/commands/strings/is-null-or-white-space.d.ts +3 -0
  250. package/dist/blz-rds/commands/strings/is-null-or-white-space.js +1 -0
  251. package/dist/blz-rds/commands/strings/join.d.ts +2 -0
  252. package/dist/blz-rds/commands/strings/join.js +1 -0
  253. package/dist/blz-rds/commands/strings/last-index-of.d.ts +2 -0
  254. package/dist/blz-rds/commands/strings/last-index-of.js +1 -0
  255. package/dist/blz-rds/commands/strings/length.d.ts +2 -0
  256. package/dist/blz-rds/commands/strings/length.js +1 -0
  257. package/dist/blz-rds/commands/strings/pad-left.d.ts +2 -0
  258. package/dist/blz-rds/commands/strings/pad-left.js +1 -0
  259. package/dist/blz-rds/commands/strings/pad-right.d.ts +2 -0
  260. package/dist/blz-rds/commands/strings/pad-right.js +1 -0
  261. package/dist/blz-rds/commands/strings/replace.d.ts +2 -0
  262. package/dist/blz-rds/commands/strings/replace.js +1 -0
  263. package/dist/blz-rds/commands/strings/starts-with.d.ts +3 -0
  264. package/dist/blz-rds/commands/strings/starts-with.js +1 -0
  265. package/dist/blz-rds/commands/strings/substring.d.ts +2 -0
  266. package/dist/blz-rds/commands/strings/substring.js +1 -0
  267. package/dist/blz-rds/commands/strings/to-lower.d.ts +2 -0
  268. package/dist/blz-rds/commands/strings/to-lower.js +1 -0
  269. package/dist/blz-rds/commands/strings/to-upper.d.ts +2 -0
  270. package/dist/blz-rds/commands/strings/to-upper.js +1 -0
  271. package/dist/blz-rds/commands/strings/trim-end.d.ts +2 -0
  272. package/dist/blz-rds/commands/strings/trim-end.js +1 -0
  273. package/dist/blz-rds/commands/strings/trim-start.d.ts +2 -0
  274. package/dist/blz-rds/commands/strings/trim-start.js +1 -0
  275. package/dist/blz-rds/commands/strings/trim.d.ts +2 -0
  276. package/dist/blz-rds/commands/strings/trim.js +1 -0
  277. package/dist/blz-rds/index.d.ts +53 -0
  278. package/dist/blz-rds/index.js +1 -0
  279. package/dist/blz-rds-mysql/base.d.ts +83 -0
  280. package/dist/blz-rds-mysql/base.js +1 -0
  281. package/dist/blz-rds-mysql/connection-manager.d.ts +8 -0
  282. package/dist/blz-rds-mysql/connection-manager.js +1 -0
  283. package/dist/blz-rds-mysql/execute-bulk-insert.d.ts +2 -0
  284. package/dist/blz-rds-mysql/execute-bulk-insert.js +1 -0
  285. package/dist/blz-rds-mysql/execute-bulk-merge.d.ts +2 -0
  286. package/dist/blz-rds-mysql/execute-bulk-merge.js +1 -0
  287. package/dist/blz-rds-mysql/execute-non-query.d.ts +14 -0
  288. package/dist/blz-rds-mysql/execute-non-query.js +1 -0
  289. package/dist/blz-rds-mysql/execute-query.d.ts +11 -0
  290. package/dist/blz-rds-mysql/execute-query.js +1 -0
  291. package/dist/blz-rds-mysql/index.d.ts +9 -0
  292. package/dist/blz-rds-mysql/index.js +1 -0
  293. package/dist/blz-rds-mysql/stored-procedure.d.ts +19 -0
  294. package/dist/blz-rds-mysql/stored-procedure.js +1 -0
  295. package/dist/blz-rds-mysqlx/base.d.ts +83 -0
  296. package/dist/blz-rds-mysqlx/base.js +1 -0
  297. package/dist/blz-rds-mysqlx/connection-manager.d.ts +6 -0
  298. package/dist/blz-rds-mysqlx/connection-manager.js +1 -0
  299. package/dist/blz-rds-mysqlx/execute-bulk-insert.d.ts +2 -0
  300. package/dist/blz-rds-mysqlx/execute-bulk-insert.js +1 -0
  301. package/dist/blz-rds-mysqlx/execute-bulk-merge.d.ts +2 -0
  302. package/dist/blz-rds-mysqlx/execute-bulk-merge.js +1 -0
  303. package/dist/blz-rds-mysqlx/execute-non-query.d.ts +4 -0
  304. package/dist/blz-rds-mysqlx/execute-non-query.js +1 -0
  305. package/dist/blz-rds-mysqlx/execute-query.d.ts +7 -0
  306. package/dist/blz-rds-mysqlx/execute-query.js +1 -0
  307. package/dist/blz-rds-mysqlx/index.d.ts +9 -0
  308. package/dist/blz-rds-mysqlx/index.js +1 -0
  309. package/dist/blz-rds-mysqlx/stored-procedure.d.ts +20 -0
  310. package/dist/blz-rds-mysqlx/stored-procedure.js +1 -0
  311. package/dist/blz-rds-oracle/index.d.ts +25 -0
  312. package/dist/blz-rds-oracle/index.js +1 -0
  313. package/dist/blz-rds-postgres/base.d.ts +94 -0
  314. package/dist/blz-rds-postgres/base.js +1 -0
  315. package/dist/blz-rds-postgres/connection-manager.d.ts +6 -0
  316. package/dist/blz-rds-postgres/connection-manager.js +1 -0
  317. package/dist/blz-rds-postgres/execute-bulk-insert.d.ts +5 -0
  318. package/dist/blz-rds-postgres/execute-bulk-insert.js +1 -0
  319. package/dist/blz-rds-postgres/execute-bulk-merge.d.ts +4 -0
  320. package/dist/blz-rds-postgres/execute-bulk-merge.js +1 -0
  321. package/dist/blz-rds-postgres/execute-non-query.d.ts +12 -0
  322. package/dist/blz-rds-postgres/execute-non-query.js +1 -0
  323. package/dist/blz-rds-postgres/execute-query.d.ts +4 -0
  324. package/dist/blz-rds-postgres/execute-query.js +1 -0
  325. package/dist/blz-rds-postgres/index.d.ts +9 -0
  326. package/dist/blz-rds-postgres/index.js +1 -0
  327. package/dist/blz-rds-postgres/result-set.js +1 -0
  328. package/dist/blz-rds-postgres/stored-procedure.d.ts +19 -0
  329. package/dist/blz-rds-postgres/stored-procedure.js +1 -0
  330. package/dist/blz-redis/index.d.ts +31 -0
  331. package/dist/blz-redis/index.js +1 -0
  332. package/dist/blz-redis/lib/redisCache.d.ts +33 -0
  333. package/dist/blz-redis/lib/redisCache.js +1 -0
  334. package/dist/blz-regex/index.d.ts +3 -0
  335. package/dist/blz-regex/index.js +1 -0
  336. package/dist/blz-security/__test__/autorization.test.js +1 -0
  337. package/dist/blz-security/__test__/autorizationKpn.test.js +1 -0
  338. package/dist/blz-security/__test__/orderManagement.test.js +1 -0
  339. package/dist/blz-security/__test__/secureUrl.test.js +1 -0
  340. package/dist/blz-security/__test__/solveMergeRule.test.js +1 -0
  341. package/dist/blz-security/__test__/sqlInjectionGuard.test.js +1 -0
  342. package/dist/blz-security/__test__/xssGuard.test.js +1 -0
  343. package/dist/blz-security/authorizationService.d.ts +42 -0
  344. package/dist/blz-security/authorizationService.js +2 -0
  345. package/dist/blz-security/config/global.js +1 -0
  346. package/dist/blz-security/filescanner/index.d.ts +24 -0
  347. package/dist/blz-security/filescanner/index.js +1 -0
  348. package/dist/blz-security/helpers/consts.d.ts +28 -0
  349. package/dist/blz-security/helpers/consts.js +1 -0
  350. package/dist/blz-security/helpers/utils.d.ts +82 -0
  351. package/dist/blz-security/helpers/utils.js +1 -0
  352. package/dist/blz-security/implementations/cache.d.ts +58 -0
  353. package/dist/blz-security/implementations/cache.js +1 -0
  354. package/dist/blz-security/implementations/oidc.d.ts +100 -0
  355. package/dist/blz-security/implementations/oidc.js +1 -0
  356. package/dist/blz-security/implementations/pkceCacheStore.d.ts +2 -0
  357. package/dist/blz-security/implementations/pkceCacheStore.js +1 -0
  358. package/dist/blz-security/implementations/saml.js +1 -0
  359. package/dist/blz-security/implementations/uma.d.ts +31 -0
  360. package/dist/blz-security/implementations/uma.js +1 -0
  361. package/dist/blz-security/implementations/webAuthn.js +1 -0
  362. package/dist/blz-security/implementations/wstg.js +1 -0
  363. package/dist/blz-security/index.d.ts +4 -0
  364. package/dist/blz-security/index.js +2 -0
  365. package/dist/blz-security/lab/index.js +1 -0
  366. package/dist/blz-security/middleware/HapiServerAzureAd.d.ts +26 -0
  367. package/dist/blz-security/middleware/HapiServerAzureAd.js +1 -0
  368. package/dist/blz-security/middleware/HapiServerKeycloak.d.ts +47 -0
  369. package/dist/blz-security/middleware/HapiServerKeycloak.js +1 -0
  370. package/dist/blz-security/middleware/HapiServerSimToken.d.ts +13 -0
  371. package/dist/blz-security/middleware/HapiServerSimToken.js +1 -0
  372. package/dist/blz-security/middleware/hapi.d.ts +14 -0
  373. package/dist/blz-security/middleware/hapi.js +1 -0
  374. package/dist/blz-security/middleware/hapiServer.js +1 -0
  375. package/dist/blz-security/navigationMemoryRepository.d.ts +6 -0
  376. package/dist/blz-security/navigationMemoryRepository.js +1 -0
  377. package/dist/blz-security/navigationMongoDbRepository.d.ts +15 -0
  378. package/dist/blz-security/navigationMongoDbRepository.js +1 -0
  379. package/dist/blz-security/secureUrlService.d.ts +7 -0
  380. package/dist/blz-security/secureUrlService.js +1 -0
  381. package/dist/blz-security/securityService.d.ts +72 -0
  382. package/dist/blz-security/securityService.js +1 -0
  383. package/dist/blz-security/sqlInjectionGuard.d.ts +37 -0
  384. package/dist/blz-security/sqlInjectionGuard.js +1 -0
  385. package/dist/blz-security/xssGuard.d.ts +14 -0
  386. package/dist/blz-security/xssGuard.js +1 -0
  387. package/dist/blz-strings/index.d.ts +42 -0
  388. package/dist/blz-strings/index.js +1 -0
  389. package/dist/blz-uuid/index.d.ts +1 -0
  390. package/dist/blz-uuid/index.js +1 -0
  391. package/dist/blz-yaml/index.d.ts +2 -0
  392. package/dist/blz-yaml/index.js +1 -0
  393. package/dist/index.d.ts +34 -0
  394. package/dist/index.js +1 -0
  395. package/dist/process-managers/index.d.ts +25 -0
  396. package/dist/process-managers/index.js +1 -0
  397. package/package.json +52 -41
  398. package/blz-base/health/index.js +0 -215
  399. package/blz-base/index.js +0 -1466
  400. package/blz-cache/LruCache.js +0 -44
  401. package/blz-cache/index.js +0 -29
  402. package/blz-config/index.js +0 -434
  403. package/blz-core/index.js +0 -364
  404. package/blz-cryptography/index.js +0 -54
  405. package/blz-datetimes/index.js +0 -356
  406. package/blz-file/example.dat +0 -2545
  407. package/blz-file/fileService.js +0 -205
  408. package/blz-file/index.js +0 -94
  409. package/blz-file/index.test.js +0 -31
  410. package/blz-file/lab.js +0 -33
  411. package/blz-hazelcast/index.js +0 -189
  412. package/blz-hazelcast/lib/credentials.js +0 -25
  413. package/blz-hazelcast/lib/credentialsFactory.js +0 -12
  414. package/blz-hazelcast/lib/hazelcastCache.js +0 -234
  415. package/blz-iterable/index.js +0 -446
  416. package/blz-json-schema/index.js +0 -11
  417. package/blz-jwt/index.js +0 -121
  418. package/blz-kafka/index.js +0 -522
  419. package/blz-math/index.js +0 -131
  420. package/blz-mongodb/index.js +0 -326
  421. package/blz-rds/__test__/scape.test.js +0 -58
  422. package/blz-rds/blz-rds-executor.js +0 -578
  423. package/blz-rds/blz-rds-helper.js +0 -310
  424. package/blz-rds/commands/core/add.js +0 -13
  425. package/blz-rds/commands/core/and.js +0 -18
  426. package/blz-rds/commands/core/asc.js +0 -10
  427. package/blz-rds/commands/core/avg.js +0 -10
  428. package/blz-rds/commands/core/column-ref.js +0 -8
  429. package/blz-rds/commands/core/count-distinct.js +0 -10
  430. package/blz-rds/commands/core/count.js +0 -10
  431. package/blz-rds/commands/core/decimal.js +0 -8
  432. package/blz-rds/commands/core/desc.js +0 -10
  433. package/blz-rds/commands/core/distinct.js +0 -10
  434. package/blz-rds/commands/core/divide.js +0 -11
  435. package/blz-rds/commands/core/embedded-exists.js +0 -17
  436. package/blz-rds/commands/core/embedded-select.js +0 -17
  437. package/blz-rds/commands/core/equals.js +0 -9
  438. package/blz-rds/commands/core/false.js +0 -8
  439. package/blz-rds/commands/core/greater-or-equal.js +0 -9
  440. package/blz-rds/commands/core/greater.js +0 -9
  441. package/blz-rds/commands/core/in.js +0 -9
  442. package/blz-rds/commands/core/integer.js +0 -8
  443. package/blz-rds/commands/core/is-not-null.js +0 -11
  444. package/blz-rds/commands/core/is-null-or-value.js +0 -10
  445. package/blz-rds/commands/core/is-null.js +0 -11
  446. package/blz-rds/commands/core/less-or-equal.js +0 -9
  447. package/blz-rds/commands/core/less-unary.js +0 -12
  448. package/blz-rds/commands/core/less.js +0 -9
  449. package/blz-rds/commands/core/like.js +0 -12
  450. package/blz-rds/commands/core/max.js +0 -10
  451. package/blz-rds/commands/core/min.js +0 -10
  452. package/blz-rds/commands/core/multiply.js +0 -13
  453. package/blz-rds/commands/core/not-equals.js +0 -9
  454. package/blz-rds/commands/core/not-in.js +0 -9
  455. package/blz-rds/commands/core/not.js +0 -13
  456. package/blz-rds/commands/core/null.js +0 -8
  457. package/blz-rds/commands/core/nvl.js +0 -11
  458. package/blz-rds/commands/core/or.js +0 -13
  459. package/blz-rds/commands/core/parameter.js +0 -34
  460. package/blz-rds/commands/core/remainder.js +0 -16
  461. package/blz-rds/commands/core/string.js +0 -8
  462. package/blz-rds/commands/core/subtract.js +0 -13
  463. package/blz-rds/commands/core/sum.js +0 -10
  464. package/blz-rds/commands/core/true.js +0 -8
  465. package/blz-rds/commands/core/tuple.js +0 -13
  466. package/blz-rds/commands/datetimes/add-days.js +0 -11
  467. package/blz-rds/commands/datetimes/add-hours.js +0 -11
  468. package/blz-rds/commands/datetimes/add-milliseconds.js +0 -11
  469. package/blz-rds/commands/datetimes/add-minutes.js +0 -11
  470. package/blz-rds/commands/datetimes/add-months.js +0 -11
  471. package/blz-rds/commands/datetimes/add-seconds.js +0 -11
  472. package/blz-rds/commands/datetimes/add-years.js +0 -11
  473. package/blz-rds/commands/datetimes/date-diff.js +0 -11
  474. package/blz-rds/commands/datetimes/date.js +0 -12
  475. package/blz-rds/commands/datetimes/datetime-diff.js +0 -11
  476. package/blz-rds/commands/datetimes/datetime.js +0 -15
  477. package/blz-rds/commands/datetimes/day.js +0 -10
  478. package/blz-rds/commands/datetimes/hour.js +0 -10
  479. package/blz-rds/commands/datetimes/millisecond.js +0 -10
  480. package/blz-rds/commands/datetimes/minute.js +0 -10
  481. package/blz-rds/commands/datetimes/month-text.js +0 -10
  482. package/blz-rds/commands/datetimes/month.js +0 -10
  483. package/blz-rds/commands/datetimes/now.js +0 -9
  484. package/blz-rds/commands/datetimes/second.js +0 -10
  485. package/blz-rds/commands/datetimes/subtract-days.js +0 -11
  486. package/blz-rds/commands/datetimes/subtract-hours.js +0 -11
  487. package/blz-rds/commands/datetimes/subtract-milliseconds.js +0 -11
  488. package/blz-rds/commands/datetimes/subtract-minutes.js +0 -11
  489. package/blz-rds/commands/datetimes/subtract-seconds.js +0 -11
  490. package/blz-rds/commands/datetimes/time-diff.js +0 -11
  491. package/blz-rds/commands/datetimes/time.js +0 -13
  492. package/blz-rds/commands/datetimes/today.js +0 -9
  493. package/blz-rds/commands/datetimes/week-day-text.js +0 -10
  494. package/blz-rds/commands/datetimes/week-day.js +0 -10
  495. package/blz-rds/commands/datetimes/week.js +0 -10
  496. package/blz-rds/commands/datetimes/year.js +0 -10
  497. package/blz-rds/commands/math/abs.js +0 -10
  498. package/blz-rds/commands/math/acos.js +0 -10
  499. package/blz-rds/commands/math/asin.js +0 -10
  500. package/blz-rds/commands/math/atan.js +0 -10
  501. package/blz-rds/commands/math/atan2.js +0 -11
  502. package/blz-rds/commands/math/ceil.js +0 -10
  503. package/blz-rds/commands/math/cos.js +0 -10
  504. package/blz-rds/commands/math/cosh.js +0 -10
  505. package/blz-rds/commands/math/exp.js +0 -10
  506. package/blz-rds/commands/math/floor.js +0 -10
  507. package/blz-rds/commands/math/log.js +0 -18
  508. package/blz-rds/commands/math/log10.js +0 -10
  509. package/blz-rds/commands/math/pow.js +0 -11
  510. package/blz-rds/commands/math/random.js +0 -9
  511. package/blz-rds/commands/math/round.js +0 -18
  512. package/blz-rds/commands/math/sign.js +0 -10
  513. package/blz-rds/commands/math/sin.js +0 -10
  514. package/blz-rds/commands/math/sinh.js +0 -10
  515. package/blz-rds/commands/math/sqrt.js +0 -10
  516. package/blz-rds/commands/math/tan.js +0 -10
  517. package/blz-rds/commands/math/tanh.js +0 -10
  518. package/blz-rds/commands/math/trunc.js +0 -18
  519. package/blz-rds/commands/strings/concat.js +0 -20
  520. package/blz-rds/commands/strings/contains.js +0 -12
  521. package/blz-rds/commands/strings/ends-with.js +0 -12
  522. package/blz-rds/commands/strings/index-of.js +0 -11
  523. package/blz-rds/commands/strings/is-null-or-empty.js +0 -11
  524. package/blz-rds/commands/strings/is-null-or-white-space.js +0 -11
  525. package/blz-rds/commands/strings/join.js +0 -22
  526. package/blz-rds/commands/strings/last-index-of.js +0 -11
  527. package/blz-rds/commands/strings/length.js +0 -10
  528. package/blz-rds/commands/strings/pad-left.js +0 -20
  529. package/blz-rds/commands/strings/pad-right.js +0 -20
  530. package/blz-rds/commands/strings/replace.js +0 -12
  531. package/blz-rds/commands/strings/starts-with.js +0 -12
  532. package/blz-rds/commands/strings/substring.js +0 -12
  533. package/blz-rds/commands/strings/to-lower.js +0 -10
  534. package/blz-rds/commands/strings/to-upper.js +0 -10
  535. package/blz-rds/commands/strings/trim-end.js +0 -10
  536. package/blz-rds/commands/strings/trim-start.js +0 -10
  537. package/blz-rds/commands/strings/trim.js +0 -10
  538. package/blz-rds/index.js +0 -744
  539. package/blz-rds-mysql/base.js +0 -857
  540. package/blz-rds-mysql/connection-manager.js +0 -129
  541. package/blz-rds-mysql/execute-bulk-insert.js +0 -35
  542. package/blz-rds-mysql/execute-bulk-merge.js +0 -45
  543. package/blz-rds-mysql/execute-non-query.js +0 -34
  544. package/blz-rds-mysql/execute-query.js +0 -50
  545. package/blz-rds-mysql/index.js +0 -41
  546. package/blz-rds-mysql/stored-procedure.js +0 -207
  547. package/blz-rds-mysqlx/base.js +0 -846
  548. package/blz-rds-mysqlx/connection-manager.js +0 -141
  549. package/blz-rds-mysqlx/execute-bulk-insert.js +0 -35
  550. package/blz-rds-mysqlx/execute-bulk-merge.js +0 -45
  551. package/blz-rds-mysqlx/execute-non-query.js +0 -29
  552. package/blz-rds-mysqlx/execute-query.js +0 -39
  553. package/blz-rds-mysqlx/index.js +0 -41
  554. package/blz-rds-mysqlx/stored-procedure.js +0 -179
  555. package/blz-rds-oracle/index.js +0 -539
  556. package/blz-rds-postgres/base.js +0 -861
  557. package/blz-rds-postgres/connection-manager.js +0 -225
  558. package/blz-rds-postgres/execute-bulk-insert.js +0 -81
  559. package/blz-rds-postgres/execute-bulk-merge.js +0 -93
  560. package/blz-rds-postgres/execute-non-query.js +0 -23
  561. package/blz-rds-postgres/execute-query.js +0 -37
  562. package/blz-rds-postgres/index.js +0 -41
  563. package/blz-rds-postgres/result-set.js +0 -51
  564. package/blz-rds-postgres/stored-procedure.js +0 -116
  565. package/blz-redis/index.js +0 -217
  566. package/blz-redis/lib/redisCache.js +0 -265
  567. package/blz-regex/index.js +0 -25
  568. package/blz-security/.eslintrc.js +0 -15
  569. package/blz-security/__test__/AuthorizationKpn.yaml +0 -1149
  570. package/blz-security/__test__/FinancingSetting.yaml +0 -177
  571. package/blz-security/__test__/KpnConfigPortal.yaml +0 -330
  572. package/blz-security/__test__/OrderManagement.yaml +0 -5190
  573. package/blz-security/__test__/Security.yaml +0 -128
  574. package/blz-security/__test__/autorization.test.js +0 -105
  575. package/blz-security/__test__/autorizationKpn.test.js +0 -42
  576. package/blz-security/__test__/orderManagement.test.js +0 -26
  577. package/blz-security/__test__/secureUrl.test.js +0 -79
  578. package/blz-security/__test__/solveMergeRule.test.js +0 -109
  579. package/blz-security/__test__/sqlInjectionGuard.test.js +0 -203
  580. package/blz-security/__test__/xssGuard.test.js +0 -204
  581. package/blz-security/authorizationService.js +0 -537
  582. package/blz-security/config/global.js +0 -8
  583. package/blz-security/config/welcome +0 -8
  584. package/blz-security/doc/README.md +0 -75
  585. package/blz-security/filescanner/index.js +0 -46
  586. package/blz-security/helpers/consts.js +0 -229
  587. package/blz-security/helpers/utils.js +0 -267
  588. package/blz-security/implementations/cache.js +0 -90
  589. package/blz-security/implementations/oidc.js +0 -404
  590. package/blz-security/implementations/pkceCacheStore.js +0 -23
  591. package/blz-security/implementations/saml.js +0 -10
  592. package/blz-security/implementations/uma.js +0 -63
  593. package/blz-security/implementations/webAuthn.js +0 -9
  594. package/blz-security/implementations/wstg.js +0 -72
  595. package/blz-security/index.js +0 -77
  596. package/blz-security/lab/index.js +0 -43
  597. package/blz-security/middleware/HapiServerAzureAd.js +0 -681
  598. package/blz-security/middleware/HapiServerKeycloak.js +0 -876
  599. package/blz-security/middleware/HapiServerSimToken.js +0 -286
  600. package/blz-security/middleware/hapi.js +0 -555
  601. package/blz-security/middleware/hapiServer.js +0 -1008
  602. package/blz-security/navigationMemoryRepository.js +0 -15
  603. package/blz-security/navigationMongoDbRepository.js +0 -73
  604. package/blz-security/secureUrlService.js +0 -47
  605. package/blz-security/securityService.js +0 -413
  606. package/blz-security/sqlInjectionGuard.js +0 -162
  607. package/blz-security/templates/forbidden.html +0 -0
  608. package/blz-security/templates/session-iframe-azure-ad.html +0 -7
  609. package/blz-security/templates/session-iframe.html +0 -73
  610. package/blz-security/templates/unauthorized.html +0 -1
  611. package/blz-security/xssGuard.js +0 -87
  612. package/blz-strings/index.js +0 -167
  613. package/blz-uuid/index.js +0 -7
  614. package/blz-yaml/index.js +0 -19
  615. package/index.js +0 -84
  616. package/process-managers/index.js +0 -422
  617. /package/{blz-rds-mysql → dist/blz-rds-mysql}/syntaxis.json +0 -0
  618. /package/{blz-rds-mysqlx → dist/blz-rds-mysqlx}/syntaxis.json +0 -0
  619. /package/{blz-rds-oracle → dist/blz-rds-oracle}/syntaxis.json +0 -0
  620. /package/{blz-rds-postgres → dist/blz-rds-postgres}/syntaxis.json +0 -0
  621. /package/{blz-security → dist/blz-security}/lab/ConfigurationAdmin.agent.json +0 -0
  622. /package/{blz-security → dist/blz-security}/lab/frontend.json +0 -0
  623. /package/{blz-security → dist/blz-security}/lab/result.json +0 -0
  624. /package/{blz-security → dist/blz-security}/lab/resultOnWeb.json +0 -0
  625. /package/{blz-security → dist/blz-security}/lab/rules.json +0 -0
  626. /package/{blz-security → dist/blz-security}/lab/securityRules.json +0 -0
@@ -1,1008 +0,0 @@
1
- /**
2
- * @author Blazedpath Team
3
- * @implements Protecting all resources through hapi middleware
4
- * @description Hapi.js (derived from Http-API) is an open-source Node.js
5
- * framework used to build powerful and scalable web applications.
6
- * @see https://hapi.dev/api/
7
- */
8
- const Uma = require('../implementations/uma')
9
- const Jsonwebtoken = require('jsonwebtoken') // Implementations of JSON Web Tokens.
10
- const {
11
- Exception,
12
- getFullUrl,
13
- getHost,
14
- getProtocol,
15
- getPathname,
16
- getTemplate,
17
- getTokenTolerance,
18
- trace,
19
- errorResponse
20
- } = require('../helpers/utils')
21
- // HapiServer Modules
22
- const hapiYar = require('@hapi/yar');
23
- const hapiJwt = require('@hapi/jwt');
24
- const hapiCookie = require('@hapi/cookie')
25
- // Quick Http Fetch using axios
26
- const axios = require('axios');
27
- // Crypto for code_verifier in token exchange
28
- const crypto = require('crypto');
29
- var jwkToPem = require('jwk-to-pem');
30
- // Uses Issue to cache manage and logout (generators/customs not sure why yet)
31
- const { Issuer, generators, custom } = require('openid-client') // OpenID Certified Relying Party.
32
- const { METADATA } = require('../helpers/consts')
33
- // Azure AD rotates keys, so we jwk used to routinly fetch them
34
- const jwksClient = require('jwks-rsa') // Retrieve RSA public keys from a JWKS.
35
- // MS authenticator library
36
- const { ConfidentialClientApplication } = require('@azure/msal-node');
37
-
38
- let contextConfig = {}
39
- let securityService = null
40
-
41
- class HapiServer {
42
- constructor (openIdConnect, cookiesName, cache) {
43
- this.openIdConnect = openIdConnect
44
- this.COOKIE_NAMES = cookiesName
45
- this.activateTraceApiMethod = false
46
- this.queryStringLimit = null;
47
- this.securityLoginTokenExpToleranceSeconds = 3600 * 5; // Default 5 hours
48
- this.authServerConfig = null;
49
- this.authServerFullLoginUrl = null;
50
- // This cache stores locally the jwt token set for refresh and logout.
51
- this.cache = cache;
52
- // To terminate sessions
53
- this.clientOidc = null;
54
- // This client keeps a refresh of the rotating keys
55
- this.clientJwk = null;
56
- this.publicKeyFetch = null;
57
- }
58
-
59
- async connect (_securityService, hapiServer, config) {
60
- contextConfig = config
61
- this.authServerConfig = contextConfig;
62
- securityService = _securityService
63
- const { authServer, accessTokenSimulation, activateTraceApiMethod } = config
64
- if (activateTraceApiMethod) {
65
- this.activateTraceApiMethod = activateTraceApiMethod
66
- }
67
- let oidcConfiguration = {}
68
- const stateOption = {
69
- clearInvalid: true,
70
- encoding: 'base64',
71
- isSecure: true,
72
- isHttpOnly: true,
73
- isSameSite: 'Lax',
74
- path: '/',
75
- strictHeader: true
76
- }
77
- if (accessTokenSimulation && !authServer) {
78
- hapiServer.config = config
79
- hapiServer.state(this.COOKIE_NAMES.ACCESS_TOKEN, stateOption)
80
- this.authServerSimulation(context)
81
- } else {
82
- try {
83
- if (authServer.sessionCookiesDomain) {
84
- stateOption.domain = authServer.sessionCookiesDomain
85
- }
86
- const isHttpOnlyForSessionState = authServer.isHttpOnlyForSessionState !== undefined ? authServer.isHttpOnlyForSessionState : false
87
- // hapiServer.state(this.COOKIE_NAMES.SID, stateOption)
88
- // stateOption.encoding = 'none'
89
- // stateOption.strictHeader = false
90
- // stateOption.isHttpOnly = isHttpOnlyForSessionState
91
- hapiServer.state(this.COOKIE_NAMES.SESSION_STATE, stateOption)
92
- oidcConfiguration = await this.configuration(authServer)
93
- if (oidcConfiguration.clientOidc) {
94
- this.clientOidc = oidcConfiguration.clientOidc;
95
- }
96
- if (!authServer.scope || !authServer.scope.split(' ').some((reg) => reg === 'openid')) {
97
- authServer.scope = `openid ${authServer.scope || ''}`
98
- }
99
- if (authServer.tokenEndpoint && !authServer.tokenEndpoint.match(/https.*/)) {
100
- hapiServer.states.cookies[this.COOKIE_NAMES.SID].isSecure = false
101
- hapiServer.states.cookies[this.COOKIE_NAMES.SESSION_STATE].isSecure = false
102
- }
103
- trace('INFO', 'The following configuration was initialized')
104
- const securityConfiguration = Object.fromEntries(Object.entries(authServer).filter((entry) => !['clientSecret', 'PrivateKey', 'PublicKey'].includes(entry[0])))
105
- trace('INFO', oidcConfiguration.tokenEndpoint ? oidcConfiguration : securityConfiguration)
106
- } catch (err) {
107
- trace('ERROR', `Exception ${err.message}`)
108
- trace('ERROR', err.stack)
109
- }
110
-
111
- this.prepareMemoryValues();
112
- // Add Plugins
113
- this.configurePlugins(hapiServer);
114
- // onPreAuth: Here we check if the jwtToken is stored in the yar, refresh, and recompose the authorization header before hapi jwt module auth.
115
- // Http protocol does not redirect all headers on a 3XX code.
116
- hapiServer.ext('onPreAuth', async (request, h) => {
117
- // Retrieve the token from the yar storage, second parameter absent so that the token is not lost on read
118
- let tokenInfo = request.yar.get('jwtToken');
119
- if(tokenInfo) {
120
- // check if token is about to be expired, if expired, update
121
- let aboutToExpire = await me.tokenAboutToExpire(tokenInfo.token, 10);
122
- if (aboutToExpire) {
123
- if (me.authServerConfig.authServer.msalClient) {
124
- // Get session name from yar storage: should be in request.yar.get('jwtToken')
125
-
126
- // To refresh the tokens, Azure uses a silent re authentication
127
- const silentRereshTokenResponse = await me.authServerConfig.authServer.msalClient.acquireTokenSilent({
128
- account: tokenInfo.account, // Use stored account details
129
- scopes: ["User.Read"], // Adjust scopes as needed
130
- });
131
- //let refreshedTokens = await this.silentAuthenticationAzure({redirectUri: me.getBaseUrl(request), idToken: tokenInfo.token})
132
- // Check that all the needed data comes in the silent Authentication, if not send to relog
133
- if (silentRereshTokenResponse && silentRereshTokenResponse.idToken) {
134
- // Update the session with the new access token
135
- const session = request.yar.get('session');
136
- request.yar.set('session', {
137
- ...session,
138
- token: silentRereshTokenResponse.accessToken
139
- });
140
- const obtainedTokens = {};
141
- obtainedTokens.tokenType = 'Bearer';
142
- obtainedTokens.token = silentRereshTokenResponse.idToken;
143
- obtainedTokens.tokenSubType = 'id_token';
144
- obtainedTokens.account = silentRereshTokenResponse.account;
145
- request.yar.set('jwtToken', obtainedTokens );
146
- // let refreshedTokenInfo = { tokenType: 'Bearer', token: refreshedTokens.id_token, tokenSubType: 'id_token'};
147
- // request.yar.set('jwtToken', refreshedTokenInfo);
148
- // tokenInfo = refreshedTokenInfo;
149
- await request.yar.commit(h);
150
- } else {
151
- // no valid set of tokens has returned, clear the yar storage and continue
152
- request.yar.get('jwtToken', true);
153
- await request.yar.commit(h);
154
- delete request.headers.authorization; // Remove the authorization header
155
- return h.continue;
156
- }
157
- } else {
158
- // If Provider is Keycloak, execute this block
159
- // If refresh token is expired as well, then the user MUST re-login
160
- let isRefreshTokenExpired = await this.isRefreshTokenExpired(tokenInfo.refreshToken);
161
- let refreshTokenPresent = 'refreshToken' in tokenInfo;
162
- if (isRefreshTokenExpired && refreshTokenPresent) {
163
- // clear token from cookies and exit
164
- request.yar.get('jwtToken', true);
165
- delete request.headers.authorization; // Remove the authorization header
166
- await request.yar.commit(h);
167
- return h.continue;
168
- } else {
169
- // If refresh token is present and not expired, attempt refresh
170
- let refreshedTokens = await this.refreshToken(tokenInfo.refreshToken);
171
- // Check that this method returned a valid set of tokens
172
- if (refreshedTokens && refreshedTokens.token_type &&
173
- refreshedTokens.id_token && refreshedTokens.session_state &&
174
- refreshedTokens.access_token && refreshedTokens.refresh_token ) {
175
- let refreshedTokenInfo = { tokenType: 'Bearer', token: refreshedTokens.id_token, tokenSubType: 'id_token', refreshToken: refreshedTokens.refresh_token };
176
- request.yar.set('jwtToken', refreshedTokenInfo);
177
- await request.yar.commit(h);
178
- tokenInfo = refreshedTokenInfo;
179
- } else {
180
- // Refresh token failed, clear and continue
181
- request.yar.get('jwtToken', true);
182
- delete request.headers.authorization;
183
- await request.yar.commit(h);
184
- return h.continue;
185
- }
186
- }
187
- }
188
- }
189
- switch(tokenInfo.tokenType) {
190
- case 'Bearer':
191
- case 'bearer': {
192
- request.headers.authorization = `Bearer ${tokenInfo.token}`;
193
- break;
194
- }
195
- default:
196
- break;
197
- }
198
- }
199
- return h.continue;
200
- });
201
- hapiServer.ext('onPreResponse', async (request, h) => {
202
- const response = request.response;
203
-
204
- let authError = request.yar.get('authError', true);
205
- // By this point, token refresh was already attempted in onPreAuth event, so it redirects to login on unauthorized
206
- if (response.isBoom && response.output.statusCode === 401 && !request.path.startsWith('/auth/callback') && !authError) {
207
- if (this.authServerConfig.authServer.provider=== 'ad-azure') {
208
- return h.redirect('/login').takeover();
209
- }
210
- // Create the url query string parameters. with a random code verifier, store in yar and get the codeChallenge
211
- const codeVerifier = crypto.randomBytes(32).toString('base64url');
212
- request.yar.set('code_verifier', codeVerifier); // For PKCE auth flow
213
- request.yar.set('originalUrlPathName', me.getFullUrl(request)); // For redirect after login
214
- await request.yar.commit(h);
215
-
216
- const codeChallenge = crypto.createHash('sha256').update(codeVerifier).digest('base64url');
217
- const responseType = 'code'; // Authorization code grant
218
- const redirectUri = me.getBaseUrl(request) + 'auth/callback';
219
- const codeChallengeMethod = 'S256'; // PKCE method
220
- const scope = (authServer.scope) ? authServer.scope.replace(/\s+/g, '%20') : 'openid';
221
-
222
- const authLoginUrlWithParams = new URL(authServer.authorizationEndpoint);
223
- authLoginUrlWithParams.searchParams.set('client_id', me.authServerConfig.authServer.clientId);
224
- authLoginUrlWithParams.searchParams.set('response_type', responseType);
225
- authLoginUrlWithParams.searchParams.set('redirect_uri', redirectUri);
226
- authLoginUrlWithParams.searchParams.set('scope', scope);
227
- authLoginUrlWithParams.searchParams.set('code_challenge', codeChallenge);
228
- authLoginUrlWithParams.searchParams.set('code_challenge_method', codeChallengeMethod);
229
-
230
- // Redirect to Keycloak
231
- return h.redirect(authLoginUrlWithParams.toString()).takeover();
232
- }
233
- return h.continue;
234
- });
235
- // /login so that i can redirect my user to a login.
236
- hapiServer.route({
237
- method: 'GET',
238
- path: '/login',
239
- options: {
240
- auth: false, // Disable authentication for this route
241
- },
242
- handler: async (request, h) => {
243
- const authUrl = await me.authServerConfig.authServer.msalClient.getAuthCodeUrl({
244
- redirectUri: me.getBaseUrl(request) + 'auth/callback',
245
- scopes: ['user.read'],
246
- });
247
-
248
- return h.redirect(authUrl);
249
- }
250
- });
251
- // /auth/callback
252
- // Resolves the jwt token on a callback after the login (keycloak/azure)
253
- hapiServer.route({
254
- method: 'GET',
255
- path: '/auth/callback',
256
- options: {
257
- auth: false, // Disable authentication for this route
258
- },
259
- handler: async (request, h) => {
260
- const authCode = request.query.code;
261
- if (!authCode) {
262
- return h.response('Authorization code missing').code(400);
263
- }
264
- try {
265
- let obtainedTokens = {};
266
- // If we have azure-AD use that lifecycle
267
- if (me.authServerConfig.authServer.msalClient) {
268
- if (!authCode) {
269
- return h.response('Missing authorization code').code(400);
270
- }
271
-
272
- try {
273
- const tokenResponse = await me.authServerConfig.authServer.msalClient.acquireTokenByCode({
274
- code: authCode,
275
- redirectUri: me.getBaseUrl(request) + 'auth/callback',
276
- scopes: ['user.read'],
277
- });
278
-
279
- request.yar.set('session', { token: tokenResponse.accessToken, user: tokenResponse.account });
280
- obtainedTokens.tokenType = 'Bearer';
281
- obtainedTokens.token = tokenResponse.idToken;
282
- obtainedTokens.tokenSubType = 'id_token';
283
- obtainedTokens.account = tokenResponse.account;
284
- //return h.redirect('/');
285
- } catch (error) {
286
- console.error('Auth error:', error);
287
- return h.response('Authentication failed').code(500);
288
- }
289
- } else {
290
- // This code-block is for keycloak or other oauth0 for now
291
- // Grab the code verifier
292
- let codeVerifier = request.yar.get('code_verifier', true);
293
- tokenResponse = await axios.post(
294
- me.authServerConfig.authServer.tokenEndpoint,
295
- new URLSearchParams({
296
- grant_type: 'authorization_code',
297
- client_id: me.authServerConfig.authServer.clientId,
298
- client_secret: me.authServerConfig.authServer.clientSecret, // If required
299
- code: authCode,
300
- redirect_uri: me.getRedirectUri(request),
301
- code_verifier: codeVerifier
302
- }).toString(),
303
- {
304
- headers: {
305
- 'Content-Type': 'application/x-www-form-urlencoded',
306
- },
307
- }
308
- );
309
- if (!tokenResponse.statusText =='OK') {
310
- throw new Error('Failed to exchange code for tokens');
311
- }
312
- obtainedTokens.tokenType = 'Bearer';
313
- obtainedTokens.token = tokenResponse.data.id_token;
314
- obtainedTokens.tokenSubType = 'id_token';
315
- obtainedTokens.refreshToken = tokenResponse.data.refresh_token;
316
- }
317
- let originalUrlPathName = request.yar.get('originalUrlPathName') ?? '/'
318
- // Set session state
319
- const sessionState = request.query.session_state;
320
- h.state(this.COOKIE_NAMES.SESSION_STATE, sessionState);
321
-
322
- // Store the JWT token in the `Authorization` header or a cookie
323
- switch (obtainedTokens.tokenType){
324
- case 'Bearer':
325
- case 'bearer': {
326
- request.yar.set('jwtToken', obtainedTokens);
327
- await request.yar.commit(h);
328
- return h.redirect(originalUrlPathName).takeover();
329
- }
330
- default: {
331
- break;
332
-
333
- }
334
- }
335
- return h.continue; // Continue in case no token_type -> no auth header configured
336
- } catch (error) {
337
- request.yar.set('authError', true);
338
- await request.yar.commit(h);
339
- console.error('Failed to exchange code for token:', error.response?.data || error.message);
340
- return h.response('Failed to authenticate').code(500).takeover();
341
- }
342
- },
343
- });
344
- const me = this
345
- // /get-authorization
346
- hapiServer.route({
347
- method: 'GET',
348
- path: '/get-authorization',
349
- handler: async (request, h) => {
350
- try {
351
- const { session_state: ckSessionState } = request.state
352
- if (!ckSessionState) {
353
-
354
- throw new Exception("Hapi get-authorization: Session cookie doesn't exist.", 'CookiesError', 404)
355
- }
356
- const tokenSet = await me.openIdConnect.tokenSet()
357
- const tokens = await tokenSet.tokens(ckSessionState)
358
- const uma = await Uma.permission()
359
- const token = await uma.ticket({ tokenUrl: authServer.tokenEndpoint || authServer.tokenUrl, token: tokens.access_token, audience: authServer.clientId })
360
- const sourceData = Jsonwebtoken.decode(token.access_token)
361
- return h.response(JSON.stringify(sourceData.authorization)).takeover()
362
- } catch (err) {
363
- return errorResponse(h, err, 401)
364
- }
365
- }
366
- })
367
- // /get-security-rules
368
- hapiServer.route({
369
- method: 'GET',
370
- path: '/get-security-rules',
371
- handler: async (request, h) => {
372
- try {
373
- const securityRules = await securityService.getFrontendSecurityRules(request)
374
- return h.response(JSON.stringify(securityRules)).takeover()
375
- } catch (err) {
376
- return errorResponse(h, err, 401)
377
- }
378
- }
379
- })
380
- // /get-permissions
381
- hapiServer.route({
382
- method: 'GET',
383
- path: '/get-permissions',
384
- handler: async (request, h) => {
385
- try {
386
- const permissions = await securityService.getPermissions()
387
- return h.response(JSON.stringify(permissions)).takeover()
388
- } catch (err) {
389
- return errorResponse(h, err, 401)
390
- }
391
- }
392
- })
393
-
394
- context.route({
395
- method: 'GET',
396
- path: '/check-authorize',
397
- handler: async (request, h) => {
398
- try {
399
- const resourcePath = request.query.path;
400
- const action = request.query.action;
401
- const roles = request.query.roles;
402
- const domains = request.query.domains;
403
- let parsedRoles;
404
- if (Array.isArray(roles)) {
405
- parsedRoles = roles;
406
- } else if (typeof roles === 'string') {
407
- parsedRoles = roles.split(',').map(r => r.trim());
408
- } else {
409
- parsedRoles = [];
410
- }
411
- let parsedDomains;
412
- if (Array.isArray(domains)) {
413
- parsedDomains = domains;
414
- } else if (typeof domains === 'string') {
415
- parsedDomains = domains.split(',').map(d => d.trim());
416
- } else {
417
- parsedDomains = [];
418
- }
419
- const result = await securityService.checkAuthorize(
420
- resourcePath,
421
- action,
422
- parsedRoles,
423
- parsedDomains
424
- );
425
- return h.response(JSON.stringify(result)).takeover()
426
- } catch (err) {
427
- return errorResponse(h, err, 401)
428
- }
429
- }
430
- })
431
-
432
- // /get-user-info
433
- hapiServer.route({
434
- method: 'GET',
435
- path: '/get-user-info',
436
- handler: async (request, h) => {
437
- try {
438
- const userInfo = await securityService.getUserInfo(request)
439
- return h
440
- .response(JSON.stringify(userInfo))
441
- .takeover()
442
- } catch (err) {
443
- return errorResponse(h, err, 500)
444
- }
445
- }
446
- })
447
- // /logout
448
- hapiServer.route({
449
- path: '/logout',
450
- method: 'GET',
451
- handler: async (request, h) => {
452
- try {
453
- const ckSessionState = request.state[this.COOKIE_NAMES.SESSION_STATE]
454
- request.yar.clear('jwtToken');
455
- await request.yar.commit(h);
456
- let endSessionUrl = await me.endSessionUrl(me.getRedirectUri(request), me.clientOidc);
457
- return h
458
- .response()
459
- .unstate(this.COOKIE_NAMES.SID)
460
- .unstate(this.COOKIE_NAMES.SESSION_STATE)
461
- .unstate(this.COOKIE_NAMES.AUTH_TOKEN)
462
- .redirect(endSessionUrl)
463
- .takeover()
464
- } catch (err) {
465
- return errorResponse(h, err, 500)
466
- }
467
- }
468
- })
469
- // /invalid-session
470
- hapiServer.route({
471
- path: '/invalid-session',
472
- method: 'GET',
473
- handler: async (request, h) => {
474
- try {
475
- const endSessionUrl = await me.openIdConnect.endSessionUrl({
476
- redirectUri: this.getRedirectUri(request),
477
- sessionState: request.state[this.COOKIE_NAMES.SESSION_STATE]
478
- })
479
- return h
480
- .response()
481
- .unstate(this.COOKIE_NAMES.SID)
482
- .unstate(this.COOKIE_NAMES.SESSION_STATE)
483
- .redirect(endSessionUrl)
484
- .takeover()
485
- } catch (err) {
486
- return errorResponse(h, err, 500)
487
- }
488
- }
489
- })
490
- // /check-session-iframe.html
491
- hapiServer.route({
492
- path: '/check-session-iframe.html',
493
- method: 'GET',
494
- handler: async (_request, h) => {
495
- try {
496
- let content = '<html/>'
497
- if (authServer && authServer.checkSessionIframe) {
498
- const { checkSessionIframe: sessionIframeUrl, clientId, sessionCookiesPrefix } = authServer
499
- if (sessionIframeUrl && sessionIframeUrl.includes('https://')) {
500
- trace('INFO', `Session management url: ${sessionIframeUrl}`)
501
- content = getTemplate('session-iframe', {
502
- sessionIframeUrl,
503
- clientId,
504
- sessionCookiesPrefix: sessionCookiesPrefix || ''
505
- })
506
- } else {
507
- trace('WARN', 'For session management, it is necessary to get the value from a cookie called session_state, and as a good practice, it should have reached a secure context [TLS].')
508
- }
509
- }
510
- return h
511
- .response(content)
512
- .header('Content-Type', 'text/html')
513
- } catch (err) {
514
- return errorResponse(h, err, 500)
515
- }
516
- }
517
- });
518
- }
519
- }
520
-
521
- authServerSimulation (context) {
522
- if (!context.config || !context.config.accessTokenSimulation) {
523
- throw new Exception('Error parsing metadata for simulation', 'ConfigurationError', 404)
524
- }
525
- let { algorithm, payload, secret } = context.config.accessTokenSimulation
526
- const me = this
527
- context.ext('onPreAuth', async function (request, h) {
528
- if (request.state && request.state[me.COOKIE_NAMES.ACCESS_TOKEN]) {
529
- return h.continue
530
- } else {
531
- switch (algorithm) {
532
- case 'HMAC-SHA384': {
533
- algorithm = 'HS384'
534
- break
535
- }
536
- case 'HMAC-SHA512': {
537
- algorithm = 'HS512'
538
- break
539
- }
540
- default: {
541
- algorithm = 'HS256'
542
- }
543
- }
544
- const jwt = me.openIdConnect.jwt().sign({ payload, secret, algorithm })
545
- return h
546
- .response()
547
- .state(me.COOKIE_NAMES.ACCESS_TOKEN, jwt)
548
- .redirect(me.getRedirectUri(request))
549
- .takeover()
550
- }
551
- })
552
- // /get-authorization
553
- context.route({
554
- path: '/get-authorization',
555
- method: 'GET',
556
- handler: async function (_request, h) {
557
- return h
558
- .response('[]')
559
- .code(200)
560
- }
561
- })
562
- // /get-security-rules
563
- context.route({
564
- path: '/get-security-rules',
565
- method: 'GET',
566
- handler: async function (_request, h) {
567
- let securityRules = []
568
- if (securityService && context.config.accessTokenSimulation.playload) {
569
- const groups = securityService.getGroups(context.config.accessTokenSimulation.playload)
570
- securityRules = securityService.getFrontendSecurityRules([groups])
571
- }
572
- return h
573
- .response(JSON.stringify(securityRules))
574
- .code(200)
575
- }
576
- })
577
- // /get-permissions
578
- context.route({
579
- path: '/get-permissions',
580
- method: 'GET',
581
- handler: async function (_request, h) {
582
- const permissions = (securityService) ? securityService.getPermissions() : []
583
- return h
584
- .response(JSON.stringify(permissions))
585
- .code(200)
586
- }
587
- })
588
- // /get-user-info
589
- context.route({
590
- path: '/get-user-info',
591
- method: 'GET',
592
- handler: async function (_request, h) {
593
- return h
594
- .response(JSON.stringify(payload))
595
- .code(200)
596
- }
597
- })
598
- // /logout
599
- context.route({
600
- path: '/logout',
601
- method: 'GET',
602
- handler: async function (_request, h) {
603
- return h
604
- .response()
605
- .unstate(this.COOKIE_NAMES.ACCESS_TOKEN)
606
- .takeover()
607
- }
608
- })
609
- }
610
-
611
- getRedirectUri (request) {
612
- return contextConfig.authServer.redirectUri || getFullUrl(request)
613
- }
614
- getFullUrl (request) {
615
- return `${getProtocol(request)}://${getHost(request)}${getPathname(request)}`
616
- }
617
- getBaseUrl (request) {
618
- return `${getProtocol(request)}://${getHost(request)}/`
619
- }
620
- async authenticate (h, scope) {
621
- const { request } = h
622
- const pkceCode = await this.openIdConnect.pkceCode()
623
- const requestUrl = getFullUrl(request)
624
- let oidcMetadata = await this.openIdConnect.oidcMetadata()
625
- if (!oidcMetadata || !oidcMetadata.openid_configuration) {
626
- oidcMetadata = await this.configuration(contextConfig.authServer)
627
- }
628
- if (requestUrl.match(new RegExp(/^(https?:\/{2}.*):?(\d*)/.source + getHost(request) + /\/?$/.source))) {
629
- const authorizationUrl = await this.openIdConnect.authorizationUrl({ scope, redirectUri: this.getRedirectUri(request), pkceCode })
630
- trace('INFO', `Authenticate redirecting to ${authorizationUrl}`)
631
- return h
632
- .response()
633
- .state(this.COOKIE_NAMES.SID, pkceCode)
634
- .redirect(authorizationUrl)
635
- .takeover()
636
- } else if (getPathname(request) === '/logout') {
637
- return h.continue
638
- } else {
639
- const tokenSet = await this.openIdConnect.tokenSet()
640
- const { state } = request
641
- if (tokenSet && state && state[this.COOKIE_NAMES.SESSION_STATE]) {
642
- const tokens = await tokenSet.tokens(state[this.COOKIE_NAMES.SESSION_STATE])
643
- if (!tokens || tokens.refresh_expires_in <= getTokenTolerance(0)) {
644
- throw new Exception('Error when getting token', 'ExpirationError', 403)
645
- }
646
- return h.continue
647
- } else {
648
- return h
649
- .response()
650
- .code(401)
651
- .takeover()
652
- }
653
- }
654
- }
655
-
656
- async configurePlugins (server) {
657
- // Add Yar to save info in the cookies across session calls
658
- const hapiYarPassword = process.env.blz_hapiYarPassword || 'your-super-secure-yar-atleast-32-bytes-password';
659
- await server.register({
660
- plugin: hapiYar,
661
- options: {
662
- cookieOptions: {
663
- password: hapiYarPassword,
664
- isSecure: true, // Use true in production
665
- isHttpOnly: true,
666
- isSameSite: 'Lax', // 'Strict', 'Lax', or 'None'
667
- clearInvalid: true,
668
- ignoreErrors: true
669
- },
670
- storeBlank: false, // Prevent saving blank sessions
671
- maxCookieSize: 0 // Use server-side storage for larger payloads
672
- }
673
- });
674
- // Register @hapi/jwt plugin
675
- await server.register(hapiJwt);
676
-
677
- // Check for static certificate or rotating.
678
- let keysFetch = true;
679
- if (true) {
680
- // Azure rotating certificates, prepare for the hapi jwt module
681
- this.startupJwksClient();
682
- // set up the function in this.publickKeyFetch
683
- this.startupPublickKeyFetch();
684
- keysFetch = this.publicKeyFetch;
685
- } else {
686
- // Esto es para un certificado estatico. Keycloak lo permite
687
- const response = await axios.get(this.authServerConfig.authServer.jwksUri);
688
- const jwks = response.data; // JWKS data is directly accessible from response.data
689
- const kidValue = this.authServerConfig.authServer.oAuthKid; // Kid from keycloak/azure, in realm settings
690
- const key = jwks.keys.find(k => k.kid === kidValue);
691
- if (!key) throw new Error(`Key with ID ${kid} not found`);
692
- const pemPublicKey = jwkToPem(key);
693
- this.authServerConfig.authServer.PublicKey = pemPublicKey;
694
- keysFetch = {
695
- key: pemPublicKey,
696
- algorithms: ['RS256'],
697
- kid: kidValue
698
- };
699
- }
700
- if (this.authServerConfig.authServer.provider=== 'ad-azure') {
701
- const tenant_id = this.authServerConfig.authServer.issuer.match(/login\.microsoftonline\.com\/([^/]+)/)?.[1]
702
- this.authServerConfig.authServer.msalConfig = {
703
- auth: {
704
- clientId: this.authServerConfig.authServer.clientId,
705
- authority: `https://login.microsoftonline.com/${tenant_id}`,
706
- clientSecret: this.authServerConfig.authServer.clientSecret,
707
- },
708
- };
709
- const msalClient = new ConfidentialClientApplication(this.authServerConfig.authServer.msalConfig);
710
- this.authServerConfig.authServer.msalClient = msalClient;
711
- }
712
-
713
-
714
- // Define the auth strategy
715
- server.auth.strategy('jwtAuth', 'jwt', {
716
- keys: keysFetch,
717
- verify: {
718
- aud: this.authServerConfig.authServer.clientId,
719
- iss: this.authServerConfig.authServer.issuer,
720
- exp: true, // validate expiration
721
- sub: false
722
- },
723
- validate: false
724
- // validate: async (artifacts, request, h) => {
725
- // // Validate the token payload (you can perform additional checks here if needed)
726
- // const { exp } = artifacts.decoded.payload;
727
-
728
- // if (Date.now() >= exp * 1000) {
729
- // throw h.unauthorized('Token expired', { redirectToLogin: true });
730
- // }
731
-
732
- // return { isValid: true, credentials: artifacts.decoded.payload };
733
- // }
734
- });
735
-
736
- // Register the @hapi/cookie plugin
737
- await server.register(hapiCookie);
738
-
739
- const hapiCookiePassword = process.env.blz_hapiCookiePassword || 'supersecretpasswordmustbeatleast32characterslong';
740
- // Define the cookie-based auth strategy
741
- server.auth.strategy('cookieAuth', 'cookie', {
742
- cookie: {
743
- name: 'sid', // Primary session cookie
744
- password: hapiCookiePassword, // Encryption key
745
- isSecure: true, // Should be true in production
746
- isHttpOnly: true, // Prevents client-side JavaScript access
747
- isSameSite: 'Lax', // Protects against CSRF
748
- },
749
- keepAlive: true, // automatically sets the session cookie after validation to extend the current session for a new ttl duration. Defaults to false.
750
- redirectTo: false, //function(request) {}, // Redirect if authentication fails
751
- });
752
- // Set default auth strategy to try both JWT and cookies
753
- server.auth.default({
754
- strategies: ['jwtAuth', 'cookieAuth'], // Try JWT first, then Cookie
755
- });
756
- }
757
-
758
- async configuration (authServer) {
759
- if (!authServer) {
760
- throw new Exception('Error when getting configuration attributes ')
761
- }
762
- const { clientId, clientSecret } = authServer
763
- await this.openIdConnect.client({ clientId, clientSecret })
764
- if (authServer.openIdConfigurationEndpoint) {
765
- return await this.openIdConnect.configuration(authServer.openIdConfigurationEndpoint)
766
- } else {
767
- // If configuration uri does not exist but the auth server form has been filled in.
768
- return await this.openIdConnect.configuration({
769
- issuer: authServer.issuer,
770
- authorization_endpoint: authServer.authorizationEndpoint,
771
- token_endpoint: authServer.tokenEndpoint,
772
- userinfo_endpoint: authServer.userinfoEndpoint,
773
- end_session_endpoint: authServer.endSessionEndpoint,
774
- jwks_uri: authServer.jwksUri
775
- })
776
- }
777
- }
778
- async prepareMemoryValues(){
779
- //this.authServerFullLoginUrl = ;
780
- }
781
- async endSessionUrl (redirectUri, clientOidc) {
782
- redirectUri = redirectUri.replace(/logout|invalid-session/gmi, '')
783
- // Log off specific session.
784
- if (!clientOidc) {
785
- throw new Error('Unable to get configuration from identity provider', 'ConfigurationError', 404);
786
- }
787
- return clientOidc.endSessionUrl({ post_logout_redirect_uri: redirectUri })
788
- }
789
- oidcMetadataKey() {
790
- return this.authServerConfig.authServer.sessionCookiesDomain || 'oidcMetadata'
791
- }
792
- async configuration (context) {
793
- let metadata = await this.cache.get(this.oidcMetadataKey())
794
- if (typeof context === 'string' && !context.match(/(https?:\/\/.*):?(\d*)\/?(.*)/gi)) {
795
- throw new Exception('Wrong OpenId Provider configuration URI entered', 'AttributeError', 403)
796
- }
797
- if (!metadata || !metadata.issuer) {
798
- if (context.issuer) {
799
- metadata = { ...(metadata || {}), ...context }
800
- } else {
801
- metadata = metadata || {}
802
- metadata.openid_configuration = context
803
- metadata = { ...metadata, ...(await Issuer.discover(context.issuer)) } // Discover an issuer configuration, must be an url
804
- }
805
- await this.cache.set(this.oidcMetadataKey(), metadata, 864e5) // 1 day of cache
806
- }
807
- return new Iss(metadata)
808
- }
809
- async refreshToken (refreshToken) {
810
- // Make a POST request to Keycloak to refresh the token
811
- const response = await axios.post(this.authServerConfig.authServer.tokenEndpoint,
812
- new URLSearchParams({
813
- grant_type: 'refresh_token',
814
- client_id: this.authServerConfig.authServer.clientId,
815
- client_secret: this.authServerConfig.authServer.clientSecret,
816
- refresh_token: refreshToken,
817
- }).toString(),
818
- {
819
- headers: {
820
- 'Content-Type': 'application/x-www-form-urlencoded',
821
- },
822
- }
823
- );
824
-
825
-
826
- if (!(response.status === 200)) {
827
- const errorResponse = await response.json();
828
- console.error('Error refreshing token:', errorResponse);
829
- return errorResponse;
830
- }
831
- // Refresh token response may change from time to time, here are two possible responses
832
- try {
833
- return await response.json(); // all tokens refershed
834
-
835
- } catch (error) {
836
-
837
- }
838
- try {
839
- return response.data;
840
- }
841
- catch {
842
-
843
- }
844
-
845
- }
846
- async decodeJwtToken(token) {
847
- const decodedToken = hapiJwt.token.decode(token);
848
- return decodedToken;
849
- }
850
- async tokenAboutToExpire(token, minutesBeforeExpiration = 0) {
851
- const decodedToken = hapiJwt.token.decode(token);
852
- const expirationTime = decodedToken.decoded.payload.exp * 1000; // Convert to milliseconds
853
- const currentTime = Date.now();
854
- const expirationThreshold = minutesBeforeExpiration * 60 * 1000; // Convert minutes to milliseconds
855
-
856
- // Check if the token is expired or about to expire within the specified minutes
857
- const isAboutToExpire = expirationTime - currentTime <= expirationThreshold;
858
- return isAboutToExpire;
859
- }
860
- async isRefreshTokenExpired (refreshToken) {
861
- try {
862
- // Decode the token without verifying its signature.
863
- const decodedRefreshToken = hapiJwt.token.decode(refreshToken);
864
- // Get the current timestamp (in seconds).
865
- const currentTimestamp = Math.floor(Date.now() / 1000);
866
-
867
- if (decodedRefreshToken && decodedRefreshToken.decoded && decodedRefreshToken.decoded.payload && decodedRefreshToken.decoded.payload.exp) {
868
- return (decodedRefreshToken.decoded.payload.exp < currentTimestamp)
869
- } else
870
- return true;
871
- } catch (error) {
872
- // if there is an error treat as if expired, so a re-login is prompted
873
- console.error('Failed to decode the token: Invalid Refresh token format', error);
874
- return true;
875
- }
876
- }
877
-
878
- async silentAuthenticationAzure ({redirectUri, idToken}) {
879
- const authUrl = this.authServerConfig.authServer.authorizationEndpoint;
880
- const decodedToken = await this.decodeJwtToken(idToken);
881
-
882
- try {
883
- const response = await axios.get(authUrl, {
884
- params: {
885
- client_id: this.authServerConfig.authServer.clientId,
886
- response_type: "id_token",
887
- redirect_uri: redirectUri,
888
- scope: this.authServerConfig.authServer.scope ?? 'openid',
889
- prompt: "none",
890
- response_mode: "fragment",
891
- nonce: "random_nonce", // Should be a securely generated nonce
892
- login_hint: decodedToken.decoded.payload.preferred_username
893
- },
894
- maxRedirects: 0, // Prevent following redirects automatically
895
- validateStatus: (status) => status === 302 // Expecting a redirect response
896
- });
897
-
898
- // Extract the token from the redirect location
899
- const location = response.headers.location;
900
- if (!location) throw new Error("No redirect location found");
901
-
902
- const params = new URLSearchParams(location.split("#")[1]);
903
- if (params.has("id_token")) {
904
- return { idToken: params.get("id_token") };
905
- } else {
906
- throw new Error("No ID token returned");
907
- }
908
- } catch (error) {
909
- console.error("Silent authentication failed:", error.response?.data || error.message);
910
- return null; // Handle failure gracefully
911
- }
912
- }
913
-
914
- async startupJwksClient () {
915
- // Azure rotating certificates, prepare for the hapi jwt module
916
- this.clientJwk = jwksClient({
917
- jwksUri: this.authServerConfig.authServer.jwksUri,
918
- cache: true, // Cache signing keys to avoid frequent network calls
919
- rateLimit: true, // Rate limit the number of requests to the JWKS URI
920
- jwksRequestsPerMinute: 10, // Limit to 10 requests per minute
921
- });
922
- }
923
- async startupPublickKeyFetch () {
924
- // Function to get the signing key
925
- const getKey = async (kid) => {
926
- return new Promise((resolve, reject) => {
927
- this.clientJwk.getSigningKey(kid, (err, key) => {
928
- if (err) {
929
- return reject(err);
930
- }
931
- const signingKey = key.getPublicKey(); // Public key for signature verification
932
- resolve(signingKey);
933
- });
934
- });
935
- };
936
- this.publicKeyFetch = async (artifacts) => {
937
- const kid = artifacts.decoded.header.kid; // Extract 'kid' from JWT header
938
- return getKey(kid); // Fetch the corresponding public key
939
- }
940
- }
941
- }
942
-
943
- class Iss {
944
- /**
945
- * @constructor
946
- * @param {Object} metadata
947
- */
948
- constructor (metadata) {
949
- if (!metadata.id_token_signing_alg_values_supported) {
950
- metadata.id_token_signing_alg_values_supported = ['RS256']
951
- }
952
- if (!metadata.response_types_supported) {
953
- metadata.response_types_supported = ['code', 'none', 'id_token', 'token', 'id_token token', 'code id_token', 'code token', 'code id_token token']
954
- }
955
- if (!metadata.subject_types_supported) {
956
- metadata.subject_types_supported = ['public']
957
- }
958
- const claimsRequired = METADATA.filter(({ type }) => type === 'REQUIRED');
959
- const missingClaims = [];
960
-
961
- for (const claim of claimsRequired) {
962
- const normalizedToCamelClaimName = claim.name.toLowerCase().replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
963
- const attributeCamelCase = metadata[normalizedToCamelClaimName]; // Directly access metadata
964
- const attributeSnakeCase = metadata[claim.name]; // Directly access metadata
965
- if (!attributeSnakeCase && !attributeCamelCase) {
966
- missingClaims.push(claim);
967
- }
968
- }
969
-
970
- if (missingClaims.length > 0) {
971
- console.error(JSON.stringify(missingClaims));
972
- throw new Error(JSON.stringify(missingClaims));
973
- }
974
-
975
- // Issuer needs the metadata in snake_case
976
- const issuer = metadata.Client ? metadata : new Issuer(this.#camelToSnakeCase(metadata))
977
- // Client instance for the authorization server of that issuer.
978
- const clientPayload = {
979
- client_id: metadata.clientId,
980
- response_type: 'code'
981
- }
982
- if (metadata.clientSecret) {
983
- clientPayload.client_secret = metadata.clientSecret
984
- }
985
- this.clientOidc = new issuer.Client(clientPayload);
986
- }
987
- #camelToSnakeCase (obj) {
988
- const toSnakeCase = str => str.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);
989
-
990
- if (typeof obj !== 'object' || obj === null) return obj;
991
-
992
- if (Array.isArray(obj)) {
993
- return obj.map(item => this.#camelToSnakeCase(item));
994
- }
995
-
996
- return Object.entries(obj).reduce((acc, [key, value]) => {
997
- const newKey = toSnakeCase(key);
998
- acc[newKey] = typeof value === 'object' && value !== null
999
- ? this.#camelToSnakeCase(value)
1000
- : value;
1001
- return acc;
1002
- }, {});
1003
- }
1004
- }
1005
-
1006
- module.exports = {
1007
- HapiServer
1008
- }