@authup/server-core 1.0.0-beta.59 → 1.0.0-beta.61

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 (434) hide show
  1. package/dist/adapters/database/domains/client/entity.d.ts.map +1 -1
  2. package/dist/adapters/database/domains/client/entity.mjs +58 -30
  3. package/dist/adapters/database/domains/client/entity.mjs.map +1 -1
  4. package/dist/adapters/database/domains/client-permission/entity.d.ts.map +1 -1
  5. package/dist/adapters/database/domains/client-permission/entity.mjs +48 -24
  6. package/dist/adapters/database/domains/client-permission/entity.mjs.map +1 -1
  7. package/dist/adapters/database/domains/client-role/entity.d.ts.map +1 -1
  8. package/dist/adapters/database/domains/client-role/entity.mjs +37 -17
  9. package/dist/adapters/database/domains/client-role/entity.mjs.map +1 -1
  10. package/dist/adapters/database/domains/client-scope/entity.d.ts.map +1 -1
  11. package/dist/adapters/database/domains/client-scope/entity.mjs +30 -14
  12. package/dist/adapters/database/domains/client-scope/entity.mjs.map +1 -1
  13. package/dist/adapters/database/domains/consent/entity.d.ts.map +1 -1
  14. package/dist/adapters/database/domains/consent/entity.mjs +34 -18
  15. package/dist/adapters/database/domains/consent/entity.mjs.map +1 -1
  16. package/dist/adapters/database/domains/event/entity.d.ts +1 -0
  17. package/dist/adapters/database/domains/event/entity.d.ts.map +1 -1
  18. package/dist/adapters/database/domains/event/entity.mjs +48 -23
  19. package/dist/adapters/database/domains/event/entity.mjs.map +1 -1
  20. package/dist/adapters/database/domains/identity-provider/entity.d.ts.map +1 -1
  21. package/dist/adapters/database/domains/identity-provider/entity.mjs +43 -23
  22. package/dist/adapters/database/domains/identity-provider/entity.mjs.map +1 -1
  23. package/dist/adapters/database/domains/identity-provider-account/entity.d.ts.map +1 -1
  24. package/dist/adapters/database/domains/identity-provider-account/entity.mjs +50 -22
  25. package/dist/adapters/database/domains/identity-provider-account/entity.mjs.map +1 -1
  26. package/dist/adapters/database/domains/identity-provider-attribute/entity.d.ts.map +1 -1
  27. package/dist/adapters/database/domains/identity-provider-attribute/entity.mjs +14 -6
  28. package/dist/adapters/database/domains/identity-provider-attribute/entity.mjs.map +1 -1
  29. package/dist/adapters/database/domains/identity-provider-attribute-mapping/entity.d.ts.map +1 -1
  30. package/dist/adapters/database/domains/identity-provider-attribute-mapping/entity.mjs +5 -1
  31. package/dist/adapters/database/domains/identity-provider-attribute-mapping/entity.mjs.map +1 -1
  32. package/dist/adapters/database/domains/identity-provider-permission-mapping/entity.d.ts.map +1 -1
  33. package/dist/adapters/database/domains/identity-provider-permission-mapping/entity.mjs +18 -6
  34. package/dist/adapters/database/domains/identity-provider-permission-mapping/entity.mjs.map +1 -1
  35. package/dist/adapters/database/domains/identity-provider-role-mapping/entity.d.ts.map +1 -1
  36. package/dist/adapters/database/domains/identity-provider-role-mapping/entity.mjs +34 -14
  37. package/dist/adapters/database/domains/identity-provider-role-mapping/entity.mjs.map +1 -1
  38. package/dist/adapters/database/domains/key/entity.d.ts.map +1 -1
  39. package/dist/adapters/database/domains/key/entity.mjs +35 -19
  40. package/dist/adapters/database/domains/key/entity.mjs.map +1 -1
  41. package/dist/adapters/database/domains/permission/entity.d.ts.map +1 -1
  42. package/dist/adapters/database/domains/permission/entity.mjs +35 -19
  43. package/dist/adapters/database/domains/permission/entity.mjs.map +1 -1
  44. package/dist/adapters/database/domains/permission-policy/entity.d.ts.map +1 -1
  45. package/dist/adapters/database/domains/permission-policy/entity.mjs +37 -17
  46. package/dist/adapters/database/domains/permission-policy/entity.mjs.map +1 -1
  47. package/dist/adapters/database/domains/policy/entity.d.ts.map +1 -1
  48. package/dist/adapters/database/domains/policy/entity.mjs +51 -27
  49. package/dist/adapters/database/domains/policy/entity.mjs.map +1 -1
  50. package/dist/adapters/database/domains/policy-attribute/entity.d.ts.map +1 -1
  51. package/dist/adapters/database/domains/policy-attribute/entity.mjs +14 -6
  52. package/dist/adapters/database/domains/policy-attribute/entity.mjs.map +1 -1
  53. package/dist/adapters/database/domains/realm/entity.d.ts.map +1 -1
  54. package/dist/adapters/database/domains/realm/entity.mjs +36 -20
  55. package/dist/adapters/database/domains/realm/entity.mjs.map +1 -1
  56. package/dist/adapters/database/domains/role/entity.d.ts.map +1 -1
  57. package/dist/adapters/database/domains/role/entity.mjs +44 -24
  58. package/dist/adapters/database/domains/role/entity.mjs.map +1 -1
  59. package/dist/adapters/database/domains/role-attribute/entity.d.ts.map +1 -1
  60. package/dist/adapters/database/domains/role-attribute/entity.mjs +30 -14
  61. package/dist/adapters/database/domains/role-attribute/entity.mjs.map +1 -1
  62. package/dist/adapters/database/domains/role-permission/entity.d.ts.map +1 -1
  63. package/dist/adapters/database/domains/role-permission/entity.mjs +45 -21
  64. package/dist/adapters/database/domains/role-permission/entity.mjs.map +1 -1
  65. package/dist/adapters/database/domains/scope/entity.d.ts.map +1 -1
  66. package/dist/adapters/database/domains/scope/entity.mjs +35 -19
  67. package/dist/adapters/database/domains/scope/entity.mjs.map +1 -1
  68. package/dist/adapters/database/domains/session/entity.d.ts.map +1 -1
  69. package/dist/adapters/database/domains/session/entity.mjs +63 -31
  70. package/dist/adapters/database/domains/session/entity.mjs.map +1 -1
  71. package/dist/adapters/database/domains/session-token/entity.d.ts +4 -1
  72. package/dist/adapters/database/domains/session-token/entity.d.ts.map +1 -1
  73. package/dist/adapters/database/domains/session-token/entity.mjs +40 -11
  74. package/dist/adapters/database/domains/session-token/entity.mjs.map +1 -1
  75. package/dist/adapters/database/domains/trust-anchor/entity.d.ts.map +1 -1
  76. package/dist/adapters/database/domains/trust-anchor/entity.mjs +25 -13
  77. package/dist/adapters/database/domains/trust-anchor/entity.mjs.map +1 -1
  78. package/dist/adapters/database/domains/user/entity.d.ts.map +1 -1
  79. package/dist/adapters/database/domains/user/entity.mjs +58 -34
  80. package/dist/adapters/database/domains/user/entity.mjs.map +1 -1
  81. package/dist/adapters/database/domains/user-attribute/entity.d.ts.map +1 -1
  82. package/dist/adapters/database/domains/user-attribute/entity.mjs +27 -11
  83. package/dist/adapters/database/domains/user-attribute/entity.mjs.map +1 -1
  84. package/dist/adapters/database/domains/user-authenticator/entity.d.ts.map +1 -1
  85. package/dist/adapters/database/domains/user-authenticator/entity.mjs +43 -23
  86. package/dist/adapters/database/domains/user-authenticator/entity.mjs.map +1 -1
  87. package/dist/adapters/database/domains/user-permission/entity.d.ts.map +1 -1
  88. package/dist/adapters/database/domains/user-permission/entity.mjs +45 -21
  89. package/dist/adapters/database/domains/user-permission/entity.mjs.map +1 -1
  90. package/dist/adapters/database/domains/user-role/entity.d.ts.map +1 -1
  91. package/dist/adapters/database/domains/user-role/entity.mjs +37 -17
  92. package/dist/adapters/database/domains/user-role/entity.mjs.map +1 -1
  93. package/dist/adapters/database/errors/driver.d.ts +9 -0
  94. package/dist/adapters/database/errors/driver.d.ts.map +1 -1
  95. package/dist/adapters/database/errors/driver.mjs +20 -1
  96. package/dist/adapters/database/errors/driver.mjs.map +1 -1
  97. package/dist/adapters/database/errors/index.mjs +2 -2
  98. package/dist/adapters/database/helpers/index.mjs +2 -2
  99. package/dist/adapters/database/helpers/is-supported.d.ts +7 -0
  100. package/dist/adapters/database/helpers/is-supported.d.ts.map +1 -1
  101. package/dist/adapters/database/helpers/is-supported.mjs +9 -1
  102. package/dist/adapters/database/helpers/is-supported.mjs.map +1 -1
  103. package/dist/adapters/database/index.mjs +3 -3
  104. package/dist/adapters/database/migrations/mysql/1785871780234-AlignSchemaWithEntityMetadata.d.ts +66 -0
  105. package/dist/adapters/database/migrations/mysql/1785871780234-AlignSchemaWithEntityMetadata.d.ts.map +1 -0
  106. package/dist/adapters/database/migrations/mysql/1785871780234-AlignSchemaWithEntityMetadata.mjs +181 -0
  107. package/dist/adapters/database/migrations/mysql/1785871780234-AlignSchemaWithEntityMetadata.mjs.map +1 -0
  108. package/dist/adapters/database/migrations/mysql/1786436332251-QueryIndexes.d.ts +44 -0
  109. package/dist/adapters/database/migrations/mysql/1786436332251-QueryIndexes.d.ts.map +1 -0
  110. package/dist/adapters/database/migrations/mysql/1786436332251-QueryIndexes.mjs +1294 -0
  111. package/dist/adapters/database/migrations/mysql/1786436332251-QueryIndexes.mjs.map +1 -0
  112. package/dist/adapters/database/migrations/postgres/1785871780234-AlignSchemaWithEntityMetadata.d.ts +43 -0
  113. package/dist/adapters/database/migrations/postgres/1785871780234-AlignSchemaWithEntityMetadata.d.ts.map +1 -0
  114. package/dist/adapters/database/migrations/postgres/1785871780234-AlignSchemaWithEntityMetadata.mjs +120 -0
  115. package/dist/adapters/database/migrations/postgres/1785871780234-AlignSchemaWithEntityMetadata.mjs.map +1 -0
  116. package/dist/adapters/database/migrations/postgres/1786436332251-QueryIndexes.d.ts +44 -0
  117. package/dist/adapters/database/migrations/postgres/1786436332251-QueryIndexes.d.ts.map +1 -0
  118. package/dist/adapters/database/migrations/postgres/1786436332251-QueryIndexes.mjs +987 -0
  119. package/dist/adapters/database/migrations/postgres/1786436332251-QueryIndexes.mjs.map +1 -0
  120. package/dist/adapters/http/controllers/entities/identity-provider/module.d.ts +22 -4
  121. package/dist/adapters/http/controllers/entities/identity-provider/module.d.ts.map +1 -1
  122. package/dist/adapters/http/controllers/entities/identity-provider/module.mjs +190 -47
  123. package/dist/adapters/http/controllers/entities/identity-provider/module.mjs.map +1 -1
  124. package/dist/adapters/http/controllers/entities/identity-provider/types.d.ts +5 -2
  125. package/dist/adapters/http/controllers/entities/identity-provider/types.d.ts.map +1 -1
  126. package/dist/adapters/http/controllers/entities/identity-provider-account/index.d.ts.map +1 -0
  127. package/dist/adapters/http/controllers/entities/identity-provider-account/index.mjs +5 -0
  128. package/dist/adapters/http/controllers/entities/identity-provider-account/module.d.ts +15 -0
  129. package/dist/adapters/http/controllers/entities/identity-provider-account/module.d.ts.map +1 -0
  130. package/dist/adapters/http/controllers/entities/identity-provider-account/module.mjs +94 -0
  131. package/dist/adapters/http/controllers/entities/identity-provider-account/module.mjs.map +1 -0
  132. package/dist/adapters/http/controllers/entities/index.d.ts +2 -0
  133. package/dist/adapters/http/controllers/entities/index.d.ts.map +1 -1
  134. package/dist/adapters/http/controllers/entities/index.mjs +5 -1
  135. package/dist/adapters/http/controllers/entities/session-token/index.d.ts +2 -0
  136. package/dist/adapters/http/controllers/entities/session-token/index.d.ts.map +1 -0
  137. package/dist/adapters/http/controllers/entities/session-token/index.mjs +5 -0
  138. package/dist/adapters/http/controllers/entities/session-token/module.d.ts +23 -0
  139. package/dist/adapters/http/controllers/entities/session-token/module.d.ts.map +1 -0
  140. package/dist/adapters/http/controllers/entities/session-token/module.mjs +112 -0
  141. package/dist/adapters/http/controllers/entities/session-token/module.mjs.map +1 -0
  142. package/dist/adapters/http/controllers/index.mjs +3 -1
  143. package/dist/adapters/http/controllers/workflows/authenticator-challenge/module.d.ts.map +1 -1
  144. package/dist/adapters/http/controllers/workflows/authenticator-challenge/module.mjs +1 -0
  145. package/dist/adapters/http/controllers/workflows/authenticator-challenge/module.mjs.map +1 -1
  146. package/dist/adapters/http/index.mjs +3 -1
  147. package/dist/adapters/http/middleware/built-in/error.d.ts.map +1 -1
  148. package/dist/adapters/http/middleware/built-in/error.mjs +4 -3
  149. package/dist/adapters/http/middleware/built-in/error.mjs.map +1 -1
  150. package/dist/adapters/http/request/event-context.d.ts.map +1 -1
  151. package/dist/adapters/http/request/event-context.mjs +2 -0
  152. package/dist/adapters/http/request/event-context.mjs.map +1 -1
  153. package/dist/app/index.mjs +4 -2
  154. package/dist/app/modules/database/index.mjs +2 -1
  155. package/dist/app/modules/database/repositories/identity-provider-account/index.d.ts +2 -0
  156. package/dist/app/modules/database/repositories/identity-provider-account/index.d.ts.map +1 -0
  157. package/dist/app/modules/database/repositories/identity-provider-account/index.mjs +5 -0
  158. package/dist/app/modules/database/repositories/identity-provider-account/repository.d.ts +18 -0
  159. package/dist/app/modules/database/repositories/identity-provider-account/repository.d.ts.map +1 -0
  160. package/dist/app/modules/database/repositories/identity-provider-account/repository.mjs +69 -0
  161. package/dist/app/modules/database/repositories/identity-provider-account/repository.mjs.map +1 -0
  162. package/dist/app/modules/database/repositories/index.d.ts +1 -0
  163. package/dist/app/modules/database/repositories/index.d.ts.map +1 -1
  164. package/dist/app/modules/database/repositories/index.mjs +3 -1
  165. package/dist/app/modules/database/repositories/key/repository.d.ts +23 -0
  166. package/dist/app/modules/database/repositories/key/repository.d.ts.map +1 -1
  167. package/dist/app/modules/database/repositories/key/repository.mjs +39 -3
  168. package/dist/app/modules/database/repositories/key/repository.mjs.map +1 -1
  169. package/dist/app/modules/database/repositories/schema-validation.d.ts +14 -6
  170. package/dist/app/modules/database/repositories/schema-validation.d.ts.map +1 -1
  171. package/dist/app/modules/database/repositories/schema-validation.mjs +18 -6
  172. package/dist/app/modules/database/repositories/schema-validation.mjs.map +1 -1
  173. package/dist/app/modules/http/modules/controller.d.ts +3 -1
  174. package/dist/app/modules/http/modules/controller.d.ts.map +1 -1
  175. package/dist/app/modules/http/modules/controller.mjs +39 -2
  176. package/dist/app/modules/http/modules/controller.mjs.map +1 -1
  177. package/dist/app/modules/identity/constants.d.ts +2 -1
  178. package/dist/app/modules/identity/constants.d.ts.map +1 -1
  179. package/dist/app/modules/identity/constants.mjs +1 -0
  180. package/dist/app/modules/identity/constants.mjs.map +1 -1
  181. package/dist/app/modules/identity/index.mjs +3 -2
  182. package/dist/app/modules/identity/module.d.ts.map +1 -1
  183. package/dist/app/modules/identity/module.mjs +9 -2
  184. package/dist/app/modules/identity/module.mjs.map +1 -1
  185. package/dist/app/modules/identity/repositories/constants.d.ts +4 -0
  186. package/dist/app/modules/identity/repositories/constants.d.ts.map +1 -0
  187. package/dist/app/modules/identity/repositories/constants.mjs +12 -0
  188. package/dist/app/modules/identity/repositories/constants.mjs.map +1 -0
  189. package/dist/app/modules/identity/repositories/index.d.ts +1 -0
  190. package/dist/app/modules/identity/repositories/index.d.ts.map +1 -1
  191. package/dist/app/modules/identity/repositories/index.mjs +3 -2
  192. package/dist/app/modules/identity/repositories/provider/index.d.ts +1 -1
  193. package/dist/app/modules/identity/repositories/provider/index.d.ts.map +1 -1
  194. package/dist/app/modules/identity/repositories/provider/index.mjs +2 -3
  195. package/dist/app/modules/identity/repositories/provider/link.d.ts +9 -0
  196. package/dist/app/modules/identity/repositories/provider/link.d.ts.map +1 -0
  197. package/dist/app/modules/identity/repositories/provider/link.mjs +34 -0
  198. package/dist/app/modules/identity/repositories/provider/link.mjs.map +1 -0
  199. package/dist/app/modules/index.mjs +4 -2
  200. package/dist/app/modules/logger/module.d.ts.map +1 -1
  201. package/dist/app/modules/logger/module.mjs +1 -0
  202. package/dist/app/modules/logger/module.mjs.map +1 -1
  203. package/dist/app/modules/oauth2/repositories/session-token/repository.d.ts +25 -1
  204. package/dist/app/modules/oauth2/repositories/session-token/repository.d.ts.map +1 -1
  205. package/dist/app/modules/oauth2/repositories/session-token/repository.mjs +70 -1
  206. package/dist/app/modules/oauth2/repositories/session-token/repository.mjs.map +1 -1
  207. package/dist/app/modules/provisioning/module.d.ts.map +1 -1
  208. package/dist/app/modules/provisioning/module.mjs +3 -1
  209. package/dist/app/modules/provisioning/module.mjs.map +1 -1
  210. package/dist/app/modules/provisioning/sources/default/module.d.ts.map +1 -1
  211. package/dist/app/modules/provisioning/sources/default/module.mjs +1 -0
  212. package/dist/app/modules/provisioning/sources/default/module.mjs.map +1 -1
  213. package/dist/core/entities/client/schema.d.ts.map +1 -1
  214. package/dist/core/entities/client/schema.mjs +29 -10
  215. package/dist/core/entities/client/schema.mjs.map +1 -1
  216. package/dist/core/entities/client-permission/schema.d.ts.map +1 -1
  217. package/dist/core/entities/client-permission/schema.mjs +29 -6
  218. package/dist/core/entities/client-permission/schema.mjs.map +1 -1
  219. package/dist/core/entities/client-role/schema.d.ts.map +1 -1
  220. package/dist/core/entities/client-role/schema.mjs +27 -6
  221. package/dist/core/entities/client-role/schema.mjs.map +1 -1
  222. package/dist/core/entities/client-scope/schema.d.ts.map +1 -1
  223. package/dist/core/entities/client-scope/schema.mjs +19 -5
  224. package/dist/core/entities/client-scope/schema.mjs.map +1 -1
  225. package/dist/core/entities/consent/schema.d.ts.map +1 -1
  226. package/dist/core/entities/consent/schema.mjs +28 -6
  227. package/dist/core/entities/consent/schema.mjs.map +1 -1
  228. package/dist/core/entities/event/entity-event-handler.d.ts.map +1 -1
  229. package/dist/core/entities/event/entity-event-handler.mjs +2 -0
  230. package/dist/core/entities/event/entity-event-handler.mjs.map +1 -1
  231. package/dist/core/entities/event/sanitize.d.ts.map +1 -1
  232. package/dist/core/entities/event/sanitize.mjs +7 -4
  233. package/dist/core/entities/event/sanitize.mjs.map +1 -1
  234. package/dist/core/entities/event/schema.d.ts.map +1 -1
  235. package/dist/core/entities/event/schema.mjs +45 -16
  236. package/dist/core/entities/event/schema.mjs.map +1 -1
  237. package/dist/core/entities/event/service.d.ts.map +1 -1
  238. package/dist/core/entities/event/service.mjs +2 -0
  239. package/dist/core/entities/event/service.mjs.map +1 -1
  240. package/dist/core/entities/event/types.d.ts +2 -0
  241. package/dist/core/entities/event/types.d.ts.map +1 -1
  242. package/dist/core/entities/identity-provider/schema.d.ts.map +1 -1
  243. package/dist/core/entities/identity-provider/schema.mjs +29 -11
  244. package/dist/core/entities/identity-provider/schema.mjs.map +1 -1
  245. package/dist/core/entities/identity-provider-account/error.d.ts +7 -0
  246. package/dist/core/entities/identity-provider-account/error.d.ts.map +1 -0
  247. package/dist/core/entities/identity-provider-account/error.mjs +24 -0
  248. package/dist/core/entities/identity-provider-account/error.mjs.map +1 -0
  249. package/dist/core/entities/identity-provider-account/index.d.ts +5 -0
  250. package/dist/core/entities/identity-provider-account/index.d.ts.map +1 -0
  251. package/dist/core/entities/identity-provider-account/index.mjs +8 -0
  252. package/dist/core/entities/identity-provider-account/schema.d.ts +3 -0
  253. package/dist/core/entities/identity-provider-account/schema.d.ts.map +1 -0
  254. package/dist/core/entities/identity-provider-account/schema.mjs +52 -0
  255. package/dist/core/entities/identity-provider-account/schema.mjs.map +1 -0
  256. package/dist/core/entities/identity-provider-account/service.d.ts +24 -0
  257. package/dist/core/entities/identity-provider-account/service.d.ts.map +1 -0
  258. package/dist/core/entities/identity-provider-account/service.mjs +129 -0
  259. package/dist/core/entities/identity-provider-account/service.mjs.map +1 -0
  260. package/dist/core/entities/identity-provider-account/types.d.ts +69 -0
  261. package/dist/core/entities/identity-provider-account/types.d.ts.map +1 -0
  262. package/dist/core/entities/identity-provider-account/types.mjs +17 -0
  263. package/dist/core/entities/identity-provider-account/types.mjs.map +1 -0
  264. package/dist/core/entities/identity-provider-role-mapping/schema.d.ts.map +1 -1
  265. package/dist/core/entities/identity-provider-role-mapping/schema.mjs +27 -6
  266. package/dist/core/entities/identity-provider-role-mapping/schema.mjs.map +1 -1
  267. package/dist/core/entities/index.d.ts +2 -0
  268. package/dist/core/entities/index.d.ts.map +1 -1
  269. package/dist/core/entities/index.mjs +9 -1
  270. package/dist/core/entities/key/schema.d.ts.map +1 -1
  271. package/dist/core/entities/key/schema.mjs +39 -17
  272. package/dist/core/entities/key/schema.mjs.map +1 -1
  273. package/dist/core/entities/key/service.d.ts.map +1 -1
  274. package/dist/core/entities/key/service.mjs +1 -0
  275. package/dist/core/entities/key/service.mjs.map +1 -1
  276. package/dist/core/entities/permission/schema.d.ts.map +1 -1
  277. package/dist/core/entities/permission/schema.mjs +34 -13
  278. package/dist/core/entities/permission/schema.mjs.map +1 -1
  279. package/dist/core/entities/permission-policy/schema.d.ts.map +1 -1
  280. package/dist/core/entities/permission-policy/schema.mjs +27 -6
  281. package/dist/core/entities/permission-policy/schema.mjs.map +1 -1
  282. package/dist/core/entities/policy/schema.d.ts.map +1 -1
  283. package/dist/core/entities/policy/schema.mjs +31 -12
  284. package/dist/core/entities/policy/schema.mjs.map +1 -1
  285. package/dist/core/entities/realm/schema.d.ts.map +1 -1
  286. package/dist/core/entities/realm/schema.mjs +26 -12
  287. package/dist/core/entities/realm/schema.mjs.map +1 -1
  288. package/dist/core/entities/role/schema.d.ts.map +1 -1
  289. package/dist/core/entities/role/schema.mjs +36 -14
  290. package/dist/core/entities/role/schema.mjs.map +1 -1
  291. package/dist/core/entities/role-attribute/schema.d.ts.map +1 -1
  292. package/dist/core/entities/role-attribute/schema.mjs +28 -14
  293. package/dist/core/entities/role-attribute/schema.mjs.map +1 -1
  294. package/dist/core/entities/role-permission/schema.d.ts.map +1 -1
  295. package/dist/core/entities/role-permission/schema.mjs +29 -6
  296. package/dist/core/entities/role-permission/schema.mjs.map +1 -1
  297. package/dist/core/entities/scope/schema.d.ts.map +1 -1
  298. package/dist/core/entities/scope/schema.mjs +28 -12
  299. package/dist/core/entities/scope/schema.mjs.map +1 -1
  300. package/dist/core/entities/session/schema.d.ts.map +1 -1
  301. package/dist/core/entities/session/schema.mjs +41 -9
  302. package/dist/core/entities/session/schema.mjs.map +1 -1
  303. package/dist/core/entities/session-token/index.d.ts +4 -0
  304. package/dist/core/entities/session-token/index.d.ts.map +1 -0
  305. package/dist/core/entities/session-token/index.mjs +6 -0
  306. package/dist/core/entities/session-token/schema.d.ts +12 -0
  307. package/dist/core/entities/session-token/schema.d.ts.map +1 -0
  308. package/dist/core/entities/session-token/schema.mjs +66 -0
  309. package/dist/core/entities/session-token/schema.mjs.map +1 -0
  310. package/dist/core/entities/session-token/service.d.ts +70 -0
  311. package/dist/core/entities/session-token/service.d.ts.map +1 -0
  312. package/dist/core/entities/session-token/service.mjs +216 -0
  313. package/dist/core/entities/session-token/service.mjs.map +1 -0
  314. package/dist/core/entities/session-token/types.d.ts +37 -0
  315. package/dist/core/entities/session-token/types.d.ts.map +1 -0
  316. package/dist/core/entities/session-token/types.mjs +4 -0
  317. package/dist/core/entities/trust-anchor/schema.d.ts.map +1 -1
  318. package/dist/core/entities/trust-anchor/schema.mjs +27 -13
  319. package/dist/core/entities/trust-anchor/schema.mjs.map +1 -1
  320. package/dist/core/entities/trust-anchor/service.d.ts.map +1 -1
  321. package/dist/core/entities/trust-anchor/service.mjs +1 -0
  322. package/dist/core/entities/trust-anchor/service.mjs.map +1 -1
  323. package/dist/core/entities/user/schema.d.ts.map +1 -1
  324. package/dist/core/entities/user/schema.mjs +29 -12
  325. package/dist/core/entities/user/schema.mjs.map +1 -1
  326. package/dist/core/entities/user-attribute/schema.d.ts.map +1 -1
  327. package/dist/core/entities/user-attribute/schema.mjs +28 -14
  328. package/dist/core/entities/user-attribute/schema.mjs.map +1 -1
  329. package/dist/core/entities/user-authenticator/schema.d.ts.map +1 -1
  330. package/dist/core/entities/user-authenticator/schema.mjs +29 -12
  331. package/dist/core/entities/user-authenticator/schema.mjs.map +1 -1
  332. package/dist/core/entities/user-authenticator/service.d.ts +2 -1
  333. package/dist/core/entities/user-authenticator/service.d.ts.map +1 -1
  334. package/dist/core/entities/user-authenticator/service.mjs +5 -0
  335. package/dist/core/entities/user-authenticator/service.mjs.map +1 -1
  336. package/dist/core/entities/user-authenticator/types.d.ts +7 -1
  337. package/dist/core/entities/user-authenticator/types.d.ts.map +1 -1
  338. package/dist/core/entities/user-authenticator/types.mjs.map +1 -1
  339. package/dist/core/entities/user-permission/schema.d.ts.map +1 -1
  340. package/dist/core/entities/user-permission/schema.mjs +29 -6
  341. package/dist/core/entities/user-permission/schema.mjs.map +1 -1
  342. package/dist/core/entities/user-role/schema.d.ts.map +1 -1
  343. package/dist/core/entities/user-role/schema.mjs +27 -6
  344. package/dist/core/entities/user-role/schema.mjs.map +1 -1
  345. package/dist/core/identity/index.mjs +3 -1
  346. package/dist/core/identity/provider/account/constants.d.ts +10 -0
  347. package/dist/core/identity/provider/account/constants.d.ts.map +1 -0
  348. package/dist/core/identity/provider/account/constants.mjs +16 -0
  349. package/dist/core/identity/provider/account/constants.mjs.map +1 -0
  350. package/dist/core/identity/provider/account/error.d.ts +7 -0
  351. package/dist/core/identity/provider/account/error.d.ts.map +1 -0
  352. package/dist/core/identity/provider/account/error.mjs +24 -0
  353. package/dist/core/identity/provider/account/error.mjs.map +1 -0
  354. package/dist/core/identity/provider/account/index.d.ts +2 -0
  355. package/dist/core/identity/provider/account/index.d.ts.map +1 -1
  356. package/dist/core/identity/provider/account/index.mjs +3 -1
  357. package/dist/core/identity/provider/account/module.d.ts +2 -0
  358. package/dist/core/identity/provider/account/module.d.ts.map +1 -1
  359. package/dist/core/identity/provider/account/module.mjs +30 -0
  360. package/dist/core/identity/provider/account/module.mjs.map +1 -1
  361. package/dist/core/identity/provider/account/types.d.ts +44 -7
  362. package/dist/core/identity/provider/account/types.d.ts.map +1 -1
  363. package/dist/core/identity/provider/authentication/protocols/oauth2/module.d.ts +19 -0
  364. package/dist/core/identity/provider/authentication/protocols/oauth2/module.d.ts.map +1 -1
  365. package/dist/core/identity/provider/authentication/protocols/oauth2/module.mjs +60 -3
  366. package/dist/core/identity/provider/authentication/protocols/oauth2/module.mjs.map +1 -1
  367. package/dist/core/identity/provider/authentication/protocols/oauth2/types.d.ts +9 -0
  368. package/dist/core/identity/provider/authentication/protocols/oauth2/types.d.ts.map +1 -1
  369. package/dist/core/identity/provider/authentication/protocols/open-id/module.d.ts +0 -3
  370. package/dist/core/identity/provider/authentication/protocols/open-id/module.d.ts.map +1 -1
  371. package/dist/core/identity/provider/authentication/protocols/open-id/module.mjs +0 -17
  372. package/dist/core/identity/provider/authentication/protocols/open-id/module.mjs.map +1 -1
  373. package/dist/core/identity/provider/index.mjs +3 -1
  374. package/dist/core/index.mjs +11 -2
  375. package/dist/core/oauth2/authorization/code-request/verifier/module.d.ts.map +1 -1
  376. package/dist/core/oauth2/authorization/code-request/verifier/module.mjs +2 -1
  377. package/dist/core/oauth2/authorization/code-request/verifier/module.mjs.map +1 -1
  378. package/dist/core/oauth2/authorization/module.d.ts.map +1 -1
  379. package/dist/core/oauth2/authorization/module.mjs +2 -0
  380. package/dist/core/oauth2/authorization/module.mjs.map +1 -1
  381. package/dist/core/oauth2/authorization/state/types.d.ts +11 -0
  382. package/dist/core/oauth2/authorization/state/types.d.ts.map +1 -1
  383. package/dist/core/oauth2/end-session/service.mjs +2 -2
  384. package/dist/core/oauth2/end-session/service.mjs.map +1 -1
  385. package/dist/core/oauth2/grant-types/authorize.d.ts.map +1 -1
  386. package/dist/core/oauth2/grant-types/authorize.mjs +1 -5
  387. package/dist/core/oauth2/grant-types/authorize.mjs.map +1 -1
  388. package/dist/core/oauth2/grant-types/password.mjs +2 -5
  389. package/dist/core/oauth2/grant-types/password.mjs.map +1 -1
  390. package/dist/core/oauth2/grant-types/refresh-token.d.ts.map +1 -1
  391. package/dist/core/oauth2/grant-types/refresh-token.mjs +37 -24
  392. package/dist/core/oauth2/grant-types/refresh-token.mjs.map +1 -1
  393. package/dist/core/oauth2/index.mjs +3 -1
  394. package/dist/core/oauth2/mfa-login/module.d.ts.map +1 -1
  395. package/dist/core/oauth2/mfa-login/module.mjs +4 -7
  396. package/dist/core/oauth2/mfa-login/module.mjs.map +1 -1
  397. package/dist/core/oauth2/session-token/error.d.ts +36 -0
  398. package/dist/core/oauth2/session-token/error.d.ts.map +1 -0
  399. package/dist/core/oauth2/session-token/error.mjs +49 -0
  400. package/dist/core/oauth2/session-token/error.mjs.map +1 -0
  401. package/dist/core/oauth2/session-token/index.d.ts +1 -0
  402. package/dist/core/oauth2/session-token/index.d.ts.map +1 -1
  403. package/dist/core/oauth2/session-token/index.mjs +2 -1
  404. package/dist/core/oauth2/session-token/types.d.ts +40 -0
  405. package/dist/core/oauth2/session-token/types.d.ts.map +1 -1
  406. package/dist/core/oauth2/token/issuer/access/module.d.ts.map +1 -1
  407. package/dist/core/oauth2/token/issuer/access/module.mjs +1 -0
  408. package/dist/core/oauth2/token/issuer/access/module.mjs.map +1 -1
  409. package/dist/core/oauth2/token/issuer/base.d.ts +1 -1
  410. package/dist/core/oauth2/token/issuer/base.d.ts.map +1 -1
  411. package/dist/core/oauth2/token/issuer/base.mjs.map +1 -1
  412. package/dist/core/oauth2/token/issuer/refresh/module.d.ts.map +1 -1
  413. package/dist/core/oauth2/token/issuer/refresh/module.mjs +1 -0
  414. package/dist/core/oauth2/token/issuer/refresh/module.mjs.map +1 -1
  415. package/dist/core/query/index.mjs +2 -2
  416. package/dist/core/query/module.d.ts +19 -9
  417. package/dist/core/query/module.d.ts.map +1 -1
  418. package/dist/core/query/module.mjs +22 -10
  419. package/dist/core/query/module.mjs.map +1 -1
  420. package/dist/index.mjs +8 -4
  421. package/dist/swagger.json +961 -132
  422. package/dist/utils/error.d.ts +20 -3
  423. package/dist/utils/error.d.ts.map +1 -1
  424. package/dist/utils/error.mjs +102 -5
  425. package/dist/utils/error.mjs.map +1 -1
  426. package/dist/utils/index.mjs +2 -2
  427. package/package.json +23 -21
  428. package/dist/app/modules/identity/repositories/provider/account/index.d.ts.map +0 -1
  429. package/dist/app/modules/identity/repositories/provider/account/index.mjs +0 -5
  430. package/dist/app/modules/identity/repositories/provider/account/module.d.ts +0 -10
  431. package/dist/app/modules/identity/repositories/provider/account/module.d.ts.map +0 -1
  432. package/dist/app/modules/identity/repositories/provider/account/module.mjs +0 -28
  433. package/dist/app/modules/identity/repositories/provider/account/module.mjs.map +0 -1
  434. /package/dist/{app/modules/identity/repositories/provider/account → adapters/http/controllers/entities/identity-provider-account}/index.d.ts +0 -0
@@ -1,9 +1,6 @@
1
- import type { TokenGrantResponse } from '@hapic/oauth2';
2
- import type { IdentityProviderIdentity } from '../../../types.ts';
3
1
  import type { IdentityProviderOAuth2AuthenticatorContext } from '../oauth2/index.ts';
4
2
  import { IdentityProviderOAuth2Authenticator } from '../oauth2/index.ts';
5
3
  export declare class IdentityProviderOpenIDAuthenticator extends IdentityProviderOAuth2Authenticator {
6
4
  constructor(ctx: IdentityProviderOAuth2AuthenticatorContext);
7
- protected buildIdentityWithTokenGrantResponse(input: TokenGrantResponse): Promise<IdentityProviderIdentity>;
8
5
  }
9
6
  //# sourceMappingURL=module.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../../../../../src/core/identity/provider/authentication/protocols/open-id/module.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,KAAK,EAAE,0CAA0C,EAAE,MAAM,oBAAoB,CAAC;AACrF,OAAO,EAAE,mCAAmC,EAAE,MAAM,oBAAoB,CAAC;AAEzE,qBAAa,mCAAoC,SAAQ,mCAAmC;gBAC5E,GAAG,EAAE,0CAA0C;cAU3C,mCAAmC,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,wBAAwB,CAAC;CAmBpH"}
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../../../../../src/core/identity/provider/authentication/protocols/open-id/module.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,0CAA0C,EAAE,MAAM,oBAAoB,CAAC;AACrF,OAAO,EAAE,mCAAmC,EAAE,MAAM,oBAAoB,CAAC;AAEzE,qBAAa,mCAAoC,SAAQ,mCAAmC;gBAC5E,GAAG,EAAE,0CAA0C;CAS9D"}
@@ -3,7 +3,6 @@ import "node:url";
3
3
  import.meta.url;
4
4
  import { IdentityProviderOAuth2Authenticator } from "../oauth2/module.mjs";
5
5
  import "../oauth2/index.mjs";
6
- import { extractTokenPayload } from "@authup/server-kit";
7
6
  import { mergeOAuth2Scopes } from "@authup/specs";
8
7
  //#region src/core/identity/provider/authentication/protocols/open-id/module.ts
9
8
  var IdentityProviderOpenIDAuthenticator = class extends IdentityProviderOAuth2Authenticator {
@@ -11,22 +10,6 @@ var IdentityProviderOpenIDAuthenticator = class extends IdentityProviderOAuth2Au
11
10
  ctx.provider.scope = mergeOAuth2Scopes("openid", ctx.provider.scope || "openid profile email");
12
11
  super(ctx);
13
12
  }
14
- async buildIdentityWithTokenGrantResponse(input) {
15
- const payload = extractTokenPayload(input.access_token);
16
- return {
17
- id: payload.sub,
18
- attributeCandidates: {
19
- name: [
20
- payload.preferred_username,
21
- payload.nickname,
22
- payload.sub
23
- ],
24
- email: [payload.email]
25
- },
26
- data: payload,
27
- provider: this.provider
28
- };
29
- }
30
13
  };
31
14
  //#endregion
32
15
  export { IdentityProviderOpenIDAuthenticator };
@@ -1 +1 @@
1
- {"version":3,"file":"module.mjs","names":["extractTokenPayload","mergeOAuth2Scopes","IdentityProviderOAuth2Authenticator","IdentityProviderOpenIDAuthenticator","ctx","provider","scope","buildIdentityWithTokenGrantResponse","input","payload","access_token","id","sub","attributeCandidates","name","preferred_username","nickname","email","data"],"sources":["../../../../../../../src/core/identity/provider/authentication/protocols/open-id/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2023-2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { extractTokenPayload } from '@authup/server-kit';\nimport { mergeOAuth2Scopes } from '@authup/specs';\nimport type { TokenGrantResponse } from '@hapic/oauth2';\nimport type { IdentityProviderIdentity } from '../../../types.ts';\nimport type { IdentityProviderOAuth2AuthenticatorContext } from '../oauth2/index.ts';\nimport { IdentityProviderOAuth2Authenticator } from '../oauth2/index.ts';\n\nexport class IdentityProviderOpenIDAuthenticator extends IdentityProviderOAuth2Authenticator {\n constructor(ctx: IdentityProviderOAuth2AuthenticatorContext) {\n // OIDC requires the openid scope (Core §3.1.2.1)\n ctx.provider.scope = mergeOAuth2Scopes(\n 'openid',\n ctx.provider.scope || 'openid profile email',\n );\n\n super(ctx);\n }\n\n protected async buildIdentityWithTokenGrantResponse(input: TokenGrantResponse): Promise<IdentityProviderIdentity> {\n const payload = extractTokenPayload(input.access_token);\n\n return {\n id: payload.sub!,\n attributeCandidates: {\n name: [\n payload.preferred_username,\n payload.nickname,\n payload.sub,\n ],\n email: [\n payload.email,\n ],\n },\n data: payload,\n provider: this.provider,\n };\n }\n}\n"],"mappings":";;;;;;;;AAcA,IAAaG,sCAAb,cAAyDD,oCAAAA;CACrD,YAAYE,KAAiD;EAEzDA,IAAIC,SAASC,QAAQL,kBACjB,UACAG,IAAIC,SAASC,SAAS,sBAAA;EAG1B,MAAMF,GAAAA;CACV;CAEA,MAAgBG,oCAAoCC,OAA8D;EAC9G,MAAMC,UAAUT,oBAAoBQ,MAAME,YAAY;EAEtD,OAAO;GACHC,IAAIF,QAAQG;GACZC,qBAAqB;IACjBC,MAAM;KACFL,QAAQM;KACRN,QAAQO;KACRP,QAAQG;IACX;IACDK,OAAO,CACHR,QAAQQ,KACX;GACL;GACAC,MAAMT;GACNJ,UAAU,KAAKA;EACnB;CACJ;AACJ"}
1
+ {"version":3,"file":"module.mjs","names":["mergeOAuth2Scopes","IdentityProviderOAuth2Authenticator","IdentityProviderOpenIDAuthenticator","ctx","provider","scope"],"sources":["../../../../../../../src/core/identity/provider/authentication/protocols/open-id/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2023-2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { mergeOAuth2Scopes } from '@authup/specs';\nimport type { IdentityProviderOAuth2AuthenticatorContext } from '../oauth2/index.ts';\nimport { IdentityProviderOAuth2Authenticator } from '../oauth2/index.ts';\n\nexport class IdentityProviderOpenIDAuthenticator extends IdentityProviderOAuth2Authenticator {\n constructor(ctx: IdentityProviderOAuth2AuthenticatorContext) {\n // OIDC requires the openid scope (Core §3.1.2.1)\n ctx.provider.scope = mergeOAuth2Scopes(\n 'openid',\n ctx.provider.scope || 'openid profile email',\n );\n\n super(ctx);\n }\n}\n"],"mappings":";;;;;;;AAWA,IAAaE,sCAAb,cAAyDD,oCAAAA;CACrD,YAAYE,KAAiD;EAEzDA,IAAIC,SAASC,QAAQL,kBACjB,UACAG,IAAIC,SAASC,SAAS,sBAAA;EAG1B,MAAMF,GAAAA;CACV;AACJ"}
@@ -1,6 +1,8 @@
1
1
  import "node:path";
2
2
  import "node:url";
3
3
  import.meta.url;
4
+ import { IDENTITY_PROVIDER_ACCOUNT_LINK_TTL } from "./account/constants.mjs";
5
+ import { IDENTITY_PROVIDER_ACCOUNT_ALREADY_LINKED_ERROR_INSTANCE, IdentityProviderAccountAlreadyLinkedError, isIdentityProviderAccountAlreadyLinkedError } from "./account/error.mjs";
4
6
  import { IdentityProviderMapperOperation } from "./mapper/constants.mjs";
5
7
  import { IdentityProviderAccountBaseMapper } from "./mapper/base.mjs";
6
8
  import { IdentityProviderAttributeMapper } from "./mapper/attributes/module.mjs";
@@ -21,4 +23,4 @@ import { IdentityProviderPaypalAuthenticator } from "./authentication/presets/pa
21
23
  import { IDENTITY_PROVIDER_LDAP_COLLECTION_AUTHENTICATOR_TOKEN } from "./authentication/constants.mjs";
22
24
  import { createIdentityProviderOAuth2Authenticator } from "./authentication/factory.mjs";
23
25
  import "./authentication/index.mjs";
24
- export { IDENTITY_PROVIDER_LDAP_COLLECTION_AUTHENTICATOR_TOKEN, IdentityProviderAccountBaseMapper, IdentityProviderAccountManager, IdentityProviderAttributeMapper, IdentityProviderFacebookAuthenticator, IdentityProviderGithubAuthenticator, IdentityProviderGoogleAuthenticator, IdentityProviderInstagramAuthenticator, IdentityProviderLdapAuthenticator, IdentityProviderLdapCollectionAuthenticator, IdentityProviderMapperOperation, IdentityProviderOAuth2Authenticator, IdentityProviderOpenIDAuthenticator, IdentityProviderPaypalAuthenticator, IdentityProviderPermissionMapper, IdentityProviderRoleMapper, createIdentityProviderOAuth2Authenticator };
26
+ export { IDENTITY_PROVIDER_ACCOUNT_ALREADY_LINKED_ERROR_INSTANCE, IDENTITY_PROVIDER_ACCOUNT_LINK_TTL, IDENTITY_PROVIDER_LDAP_COLLECTION_AUTHENTICATOR_TOKEN, IdentityProviderAccountAlreadyLinkedError, IdentityProviderAccountBaseMapper, IdentityProviderAccountManager, IdentityProviderAttributeMapper, IdentityProviderFacebookAuthenticator, IdentityProviderGithubAuthenticator, IdentityProviderGoogleAuthenticator, IdentityProviderInstagramAuthenticator, IdentityProviderLdapAuthenticator, IdentityProviderLdapCollectionAuthenticator, IdentityProviderMapperOperation, IdentityProviderOAuth2Authenticator, IdentityProviderOpenIDAuthenticator, IdentityProviderPaypalAuthenticator, IdentityProviderPermissionMapper, IdentityProviderRoleMapper, createIdentityProviderOAuth2Authenticator, isIdentityProviderAccountAlreadyLinkedError };
@@ -25,6 +25,8 @@ import { clientScopeSchema } from "./entities/client-scope/schema.mjs";
25
25
  import { consentSchema } from "./entities/consent/schema.mjs";
26
26
  import { eventSchema } from "./entities/event/schema.mjs";
27
27
  import { identityProviderSchema } from "./entities/identity-provider/schema.mjs";
28
+ import { IDENTITY_PROVIDER_ACCOUNT_FILTER_KEYS } from "./entities/identity-provider-account/types.mjs";
29
+ import { identityProviderAccountSchema } from "./entities/identity-provider-account/schema.mjs";
28
30
  import { identityProviderRoleMappingSchema } from "./entities/identity-provider-role-mapping/schema.mjs";
29
31
  import { keySchema } from "./entities/key/schema.mjs";
30
32
  import { permissionSchema } from "./entities/permission/schema.mjs";
@@ -36,13 +38,14 @@ import { roleAttributeSchema } from "./entities/role-attribute/schema.mjs";
36
38
  import { rolePermissionSchema } from "./entities/role-permission/schema.mjs";
37
39
  import { scopeSchema } from "./entities/scope/schema.mjs";
38
40
  import { sessionSchema } from "./entities/session/schema.mjs";
41
+ import { sessionTokenSchema } from "./entities/session-token/schema.mjs";
39
42
  import { trustAnchorSchema } from "./entities/trust-anchor/schema.mjs";
40
43
  import { userSchema } from "./entities/user/schema.mjs";
41
44
  import { userAttributeSchema } from "./entities/user-attribute/schema.mjs";
42
45
  import { userAuthenticatorSchema } from "./entities/user-authenticator/schema.mjs";
43
46
  import { userPermissionSchema } from "./entities/user-permission/schema.mjs";
44
47
  import { userRoleSchema } from "./entities/user-role/schema.mjs";
45
- import { appendQueryConditions, decodeQuery, queryCodec, schemaRegistry } from "./query/module.mjs";
48
+ import { appendQueryConditions, decodeQuery, queryCodec, schemaRegistry, schemas } from "./query/module.mjs";
46
49
  import "./query/index.mjs";
47
50
  import { ClientService } from "./entities/client/service.mjs";
48
51
  import { SYSTEM_CLIENT_DEFINITIONS, SYSTEM_CLIENT_SCOPE_NAMES, SystemClientProvisioner, buildSystemClientAttributes } from "./entities/client/system-clients.mjs";
@@ -55,6 +58,8 @@ import { EVENT_DIFF_SECRET_KEY_REGEX, EVENT_DIFF_VALUE_MAX_LENGTH, buildEntityDi
55
58
  import { EntityEventHandler } from "./entities/event/entity-event-handler.mjs";
56
59
  import { sanitizeEventData } from "./entities/event/sanitize.mjs";
57
60
  import { EventService } from "./entities/event/service.mjs";
61
+ import { IDENTITY_PROVIDER_ACCOUNT_UNLINK_BLOCKED_ERROR_INSTANCE, IdentityProviderAccountUnlinkBlockedError, isIdentityProviderAccountUnlinkBlockedError } from "./entities/identity-provider-account/error.mjs";
62
+ import { IdentityProviderAccountService } from "./entities/identity-provider-account/service.mjs";
58
63
  import { REALM_CIPHER_BLOB_ERROR_INSTANCE, RealmCipherBlobError } from "./key/error.mjs";
59
64
  import { isRealmCipherBlobError } from "./key/check.mjs";
60
65
  import { KEY_CERTIFICATE_ERROR_INSTANCE, KeyCertificateError } from "./key/certificate-error.mjs";
@@ -74,6 +79,7 @@ import { RoleAttributeService } from "./entities/role-attribute/service.mjs";
74
79
  import { RolePermissionService } from "./entities/role-permission/service.mjs";
75
80
  import { ScopeService } from "./entities/scope/service.mjs";
76
81
  import { SessionService } from "./entities/session/service.mjs";
82
+ import { SESSION_TOKEN_FILTER_KEYS, SessionTokenService } from "./entities/session-token/service.mjs";
77
83
  import { TrustAnchorService } from "./entities/trust-anchor/service.mjs";
78
84
  import { UserService } from "./entities/user/service.mjs";
79
85
  import { UserAttributeService } from "./entities/user-attribute/service.mjs";
@@ -112,6 +118,7 @@ import { OAuth2AuthorizeGrant } from "./oauth2/grant-types/authorize.mjs";
112
118
  import { ClientCredentialsGrant } from "./oauth2/grant-types/client-credentials.mjs";
113
119
  import { IdentityGrantType } from "./oauth2/grant-types/identity.mjs";
114
120
  import { PasswordGrantType } from "./oauth2/grant-types/password.mjs";
121
+ import { SESSION_TOKEN_RELATION_MISSING_ERROR_INSTANCE, SessionTokenRelationMissingError, isSessionTokenRelationMissingError } from "./oauth2/session-token/error.mjs";
115
122
  import { OAuth2RefreshTokenGrant } from "./oauth2/grant-types/refresh-token.mjs";
116
123
  import { OAuth2MfaLoginService } from "./oauth2/mfa-login/module.mjs";
117
124
  import { OAuth2OpenIDClaimsBuilder } from "./oauth2/openid/claims.mjs";
@@ -129,6 +136,8 @@ import { PasswordRecoveryService } from "./identity/password-recovery/service.mj
129
136
  import { PermissionCheckerService } from "./identity/permission/checker/service.mjs";
130
137
  import { IdentityPermissionProvider } from "./identity/permission/module.mjs";
131
138
  import { PolicyCheckerService } from "./identity/policy/checker/service.mjs";
139
+ import { IDENTITY_PROVIDER_ACCOUNT_LINK_TTL } from "./identity/provider/account/constants.mjs";
140
+ import { IDENTITY_PROVIDER_ACCOUNT_ALREADY_LINKED_ERROR_INSTANCE, IdentityProviderAccountAlreadyLinkedError, isIdentityProviderAccountAlreadyLinkedError } from "./identity/provider/account/error.mjs";
132
141
  import { IdentityProviderMapperOperation } from "./identity/provider/mapper/constants.mjs";
133
142
  import { IdentityProviderAccountBaseMapper } from "./identity/provider/mapper/base.mjs";
134
143
  import { IdentityProviderAttributeMapper } from "./identity/provider/mapper/attributes/module.mjs";
@@ -179,4 +188,4 @@ import { UserProvisioningSynchronizer } from "./provisioning/synchronizer/user/m
179
188
  import { WildcardRealmProvisioner, expandWildcardRealmEntry, extractWildcardRealmEntry } from "./provisioning/wildcard/module.mjs";
180
189
  import "./provisioning/index.mjs";
181
190
  import "./security/index.mjs";
182
- export { BaseCredentialsAuthenticator, CLIENT_READ_PERMISSIONS, CONSENT_FILTER_KEYS, CONSENT_SCOPE_MAX_LENGTH, ClientAuthenticator, ClientCertificateValidator, ClientCredentialsGrant, ClientCredentialsService, ClientPermissionService, ClientProvisioningSynchronizer, ClientProvisioningValidator, ClientRoleService, ClientScopeService, ClientService, ConsentService, CredentialsAuthenticator, EVENT_ACTOR_NAME_MAX_LENGTH, EVENT_DIFF_SECRET_KEY_REGEX, EVENT_DIFF_VALUE_MAX_LENGTH, EVENT_LOG_RETENTION_DAYS_DEFAULT, EntityEventHandler, EventService, GraphProvisioningSynchronizer, IDENTITY_PROVIDER_LDAP_COLLECTION_AUTHENTICATOR_TOKEN, IdentityGrantType, IdentityPermissionProvider, IdentityProviderAccountBaseMapper, IdentityProviderAccountManager, IdentityProviderAttributeMapper, IdentityProviderFacebookAuthenticator, IdentityProviderGithubAuthenticator, IdentityProviderGoogleAuthenticator, IdentityProviderInstagramAuthenticator, IdentityProviderLdapAuthenticator, IdentityProviderLdapCollectionAuthenticator, IdentityProviderMapperOperation, IdentityProviderOAuth2Authenticator, IdentityProviderOpenIDAuthenticator, IdentityProviderPaypalAuthenticator, IdentityProviderPermissionMapper, IdentityProviderRoleMapper, IdentityProviderRoleMappingService, IdentityResolver, IdentityRoleProvider, KEY_CERTIFICATE_ERROR_INSTANCE, KeyCertificateError, KeyProvisioner, KeyService, LoginThrottleService, MAIL_TEMPLATE_REGISTRY, MailTemplateName, MailTemplateRenderer, NoopAuthFlowMetrics, OAuth2AccessPolicyEvaluator, OAuth2AccessTokenIssuer, OAuth2Authorization, OAuth2AuthorizationCodeIssuer, OAuth2AuthorizationCodeRequestValidator, OAuth2AuthorizationCodeRequestVerifier, OAuth2AuthorizationCodeVerifier, OAuth2AuthorizationStateManager, OAuth2AuthorizeGrant, OAuth2ClientAuthenticator, OAuth2EndSessionRequestValidator, OAuth2EndSessionService, OAuth2MfaLoginService, OAuth2MfaTokenIssuer, OAuth2OpenIDClaimsBuilder, OAuth2OpenIDTokenIssuer, OAuth2RefreshTokenGrant, OAuth2RefreshTokenIssuer, OAuth2ScopeAttributesResolver, OAuth2TokenRevoker, OAuth2TokenSigner, OAuth2TokenVerifier, PASSWORD_RESET_EXPIRES_IN_MINUTES, PasswordGrantType, PasswordRecoveryService, PermissionBindingPolicyEvaluator, PermissionCheckerService, PermissionPolicyService, PermissionProvisioningRelationsValidator, PermissionProvisioningSynchronizer, PermissionProvisioningValidator, PermissionService, PolicyCheckerService, PolicyEngine, PolicyProvisioningSynchronizer, PolicyProvisioningValidator, PolicyService, ProvisioningEntityResolver, ProvisioningEntityStrategyType, ProvisioningJunctionSynchronizer, ProvisioningStrategyValidator, REALM_CIPHER_BLOB_ERROR_INSTANCE, REALM_CIPHER_BLOB_VERSION, REALM_WILDCARD_NAME, RECORD_QUERY_PARAMETERS, RealmCipher, RealmCipherBlobError, RealmProvisioningSynchronizer, RealmProvisioningValidator, RealmService, RealmWildcardProvisioningValidator, RegistrationService, RoleAttributeService, RolePermissionService, RoleProvisioningSynchronizer, RoleProvisioningValidator, RoleService, RootProvisioningValidator, SESSION_FILTER_KEYS, SYSTEM_CLIENT_DEFINITIONS, SYSTEM_CLIENT_SCOPE_NAMES, ScopeProvisioningSynchronizer, ScopeProvisioningValidator, ScopeService, SessionManager, SessionService, SystemClientProvisioner, TrustAnchorService, USER_AUTHENTICATOR_ATTEMPT_CACHE_PREFIX, USER_AUTHENTICATOR_ATTEMPT_LOCK_FACTOR, USER_AUTHENTICATOR_ATTEMPT_LOCK_MAX, USER_AUTHENTICATOR_ATTEMPT_WINDOW, USER_AUTHENTICATOR_EMAIL_CODE_CACHE_PREFIX, USER_AUTHENTICATOR_EMAIL_CODE_EXPIRES_IN_MINUTES, USER_AUTHENTICATOR_EMAIL_CODE_LENGTH, USER_AUTHENTICATOR_EMAIL_SEND_CACHE_PREFIX, USER_AUTHENTICATOR_EMAIL_SEND_COOLDOWN, USER_AUTHENTICATOR_FILTER_KEYS, USER_AUTHENTICATOR_RECOVERY_CODE_COUNT, USER_AUTHENTICATOR_THROTTLE_CACHE_PREFIX, USER_AUTHENTICATOR_TOTP_ALGORITHM, USER_AUTHENTICATOR_TOTP_DIGITS, USER_AUTHENTICATOR_TOTP_PERIOD, USER_AUTHENTICATOR_VERIFY_LOCK_CACHE_PREFIX, USER_AUTHENTICATOR_VERIFY_LOCK_RENEW_INTERVAL, USER_AUTHENTICATOR_VERIFY_LOCK_TTL, USER_AUTHENTICATOR_WEBAUTHN_AUTH_CACHE_PREFIX, USER_AUTHENTICATOR_WEBAUTHN_CHALLENGE_WINDOW, USER_AUTHENTICATOR_WEBAUTHN_REG_CACHE_PREFIX, UserAttributeService, UserAuthenticator, UserAuthenticatorService, UserCredentialsService, UserPermissionService, UserProvisioningSynchronizer, UserProvisioningValidator, UserRoleService, UserService, WRAPPED_KEY_MATERIAL_PREFIX, WildcardRealmProvisioner, appendQueryConditions, applyJunctionCreateGrant, assertCertificateMatchesKey, assertClientCertificateEvidenceValidForBinding, assertClientGrantAllowed, base64URLEncode, buildCertificateJwkFields, buildClientCertificateThumbprint, buildEntityDiff, buildJunctionUpdateData, buildOAuth2BearerTokenResponse, buildOAuth2CodeChallenge, buildOAuth2TokenHash, buildProvisioningEntityKey, buildSystemClientAttributes, buildWebauthnAuthenticationOptions, buildWebauthnRegistrationOptions, buildX5c, buildX5tS256, clientPermissionSchema, clientRoleSchema, clientSchema, clientScopeSchema, consentSchema, createIdentityProviderOAuth2Authenticator, createProvisioningEntitiesValidator, createRelationsReadGate, decodeQuery, defineMailTemplate, deriveAmrAcr, describeQuerySchema, eventSchema, expandWildcardRealmEntry, extractWildcardRealmEntry, generateNumericCode, generateOAuth2CodeVerifier, generateRecoveryCode, guessUserAuthenticatorKindByResponse, identityProviderRoleMappingSchema, identityProviderSchema, isRealmCipherBlobError, isWrappedKeyMaterial, keySchema, mergeProvisioningEntities, mergeProvisioningEntity, normalizeEntityProvisioningStrategy, parseCertificateChain, parseClientCertificateChain, permissionPolicySchema, permissionSchema, policySchema, queryCodec, realmSchema, roleAttributeSchema, rolePermissionSchema, roleSchema, sanitizeEventData, schemaRegistry, scopeSchema, sessionSchema, toIdentityPolicyData, trustAnchorSchema, unwrapKeyMaterial, userAttributeSchema, userAuthenticatorSchema, userPermissionSchema, userRoleSchema, userSchema, verifyWebauthnAuthentication, verifyWebauthnRegistration, wrapKeyMaterial };
191
+ export { BaseCredentialsAuthenticator, CLIENT_READ_PERMISSIONS, CONSENT_FILTER_KEYS, CONSENT_SCOPE_MAX_LENGTH, ClientAuthenticator, ClientCertificateValidator, ClientCredentialsGrant, ClientCredentialsService, ClientPermissionService, ClientProvisioningSynchronizer, ClientProvisioningValidator, ClientRoleService, ClientScopeService, ClientService, ConsentService, CredentialsAuthenticator, EVENT_ACTOR_NAME_MAX_LENGTH, EVENT_DIFF_SECRET_KEY_REGEX, EVENT_DIFF_VALUE_MAX_LENGTH, EVENT_LOG_RETENTION_DAYS_DEFAULT, EntityEventHandler, EventService, GraphProvisioningSynchronizer, IDENTITY_PROVIDER_ACCOUNT_ALREADY_LINKED_ERROR_INSTANCE, IDENTITY_PROVIDER_ACCOUNT_FILTER_KEYS, IDENTITY_PROVIDER_ACCOUNT_LINK_TTL, IDENTITY_PROVIDER_ACCOUNT_UNLINK_BLOCKED_ERROR_INSTANCE, IDENTITY_PROVIDER_LDAP_COLLECTION_AUTHENTICATOR_TOKEN, IdentityGrantType, IdentityPermissionProvider, IdentityProviderAccountAlreadyLinkedError, IdentityProviderAccountBaseMapper, IdentityProviderAccountManager, IdentityProviderAccountService, IdentityProviderAccountUnlinkBlockedError, IdentityProviderAttributeMapper, IdentityProviderFacebookAuthenticator, IdentityProviderGithubAuthenticator, IdentityProviderGoogleAuthenticator, IdentityProviderInstagramAuthenticator, IdentityProviderLdapAuthenticator, IdentityProviderLdapCollectionAuthenticator, IdentityProviderMapperOperation, IdentityProviderOAuth2Authenticator, IdentityProviderOpenIDAuthenticator, IdentityProviderPaypalAuthenticator, IdentityProviderPermissionMapper, IdentityProviderRoleMapper, IdentityProviderRoleMappingService, IdentityResolver, IdentityRoleProvider, KEY_CERTIFICATE_ERROR_INSTANCE, KeyCertificateError, KeyProvisioner, KeyService, LoginThrottleService, MAIL_TEMPLATE_REGISTRY, MailTemplateName, MailTemplateRenderer, NoopAuthFlowMetrics, OAuth2AccessPolicyEvaluator, OAuth2AccessTokenIssuer, OAuth2Authorization, OAuth2AuthorizationCodeIssuer, OAuth2AuthorizationCodeRequestValidator, OAuth2AuthorizationCodeRequestVerifier, OAuth2AuthorizationCodeVerifier, OAuth2AuthorizationStateManager, OAuth2AuthorizeGrant, OAuth2ClientAuthenticator, OAuth2EndSessionRequestValidator, OAuth2EndSessionService, OAuth2MfaLoginService, OAuth2MfaTokenIssuer, OAuth2OpenIDClaimsBuilder, OAuth2OpenIDTokenIssuer, OAuth2RefreshTokenGrant, OAuth2RefreshTokenIssuer, OAuth2ScopeAttributesResolver, OAuth2TokenRevoker, OAuth2TokenSigner, OAuth2TokenVerifier, PASSWORD_RESET_EXPIRES_IN_MINUTES, PasswordGrantType, PasswordRecoveryService, PermissionBindingPolicyEvaluator, PermissionCheckerService, PermissionPolicyService, PermissionProvisioningRelationsValidator, PermissionProvisioningSynchronizer, PermissionProvisioningValidator, PermissionService, PolicyCheckerService, PolicyEngine, PolicyProvisioningSynchronizer, PolicyProvisioningValidator, PolicyService, ProvisioningEntityResolver, ProvisioningEntityStrategyType, ProvisioningJunctionSynchronizer, ProvisioningStrategyValidator, REALM_CIPHER_BLOB_ERROR_INSTANCE, REALM_CIPHER_BLOB_VERSION, REALM_WILDCARD_NAME, RECORD_QUERY_PARAMETERS, RealmCipher, RealmCipherBlobError, RealmProvisioningSynchronizer, RealmProvisioningValidator, RealmService, RealmWildcardProvisioningValidator, RegistrationService, RoleAttributeService, RolePermissionService, RoleProvisioningSynchronizer, RoleProvisioningValidator, RoleService, RootProvisioningValidator, SESSION_FILTER_KEYS, SESSION_TOKEN_FILTER_KEYS, SESSION_TOKEN_RELATION_MISSING_ERROR_INSTANCE, SYSTEM_CLIENT_DEFINITIONS, SYSTEM_CLIENT_SCOPE_NAMES, ScopeProvisioningSynchronizer, ScopeProvisioningValidator, ScopeService, SessionManager, SessionService, SessionTokenRelationMissingError, SessionTokenService, SystemClientProvisioner, TrustAnchorService, USER_AUTHENTICATOR_ATTEMPT_CACHE_PREFIX, USER_AUTHENTICATOR_ATTEMPT_LOCK_FACTOR, USER_AUTHENTICATOR_ATTEMPT_LOCK_MAX, USER_AUTHENTICATOR_ATTEMPT_WINDOW, USER_AUTHENTICATOR_EMAIL_CODE_CACHE_PREFIX, USER_AUTHENTICATOR_EMAIL_CODE_EXPIRES_IN_MINUTES, USER_AUTHENTICATOR_EMAIL_CODE_LENGTH, USER_AUTHENTICATOR_EMAIL_SEND_CACHE_PREFIX, USER_AUTHENTICATOR_EMAIL_SEND_COOLDOWN, USER_AUTHENTICATOR_FILTER_KEYS, USER_AUTHENTICATOR_RECOVERY_CODE_COUNT, USER_AUTHENTICATOR_THROTTLE_CACHE_PREFIX, USER_AUTHENTICATOR_TOTP_ALGORITHM, USER_AUTHENTICATOR_TOTP_DIGITS, USER_AUTHENTICATOR_TOTP_PERIOD, USER_AUTHENTICATOR_VERIFY_LOCK_CACHE_PREFIX, USER_AUTHENTICATOR_VERIFY_LOCK_RENEW_INTERVAL, USER_AUTHENTICATOR_VERIFY_LOCK_TTL, USER_AUTHENTICATOR_WEBAUTHN_AUTH_CACHE_PREFIX, USER_AUTHENTICATOR_WEBAUTHN_CHALLENGE_WINDOW, USER_AUTHENTICATOR_WEBAUTHN_REG_CACHE_PREFIX, UserAttributeService, UserAuthenticator, UserAuthenticatorService, UserCredentialsService, UserPermissionService, UserProvisioningSynchronizer, UserProvisioningValidator, UserRoleService, UserService, WRAPPED_KEY_MATERIAL_PREFIX, WildcardRealmProvisioner, appendQueryConditions, applyJunctionCreateGrant, assertCertificateMatchesKey, assertClientCertificateEvidenceValidForBinding, assertClientGrantAllowed, base64URLEncode, buildCertificateJwkFields, buildClientCertificateThumbprint, buildEntityDiff, buildJunctionUpdateData, buildOAuth2BearerTokenResponse, buildOAuth2CodeChallenge, buildOAuth2TokenHash, buildProvisioningEntityKey, buildSystemClientAttributes, buildWebauthnAuthenticationOptions, buildWebauthnRegistrationOptions, buildX5c, buildX5tS256, clientPermissionSchema, clientRoleSchema, clientSchema, clientScopeSchema, consentSchema, createIdentityProviderOAuth2Authenticator, createProvisioningEntitiesValidator, createRelationsReadGate, decodeQuery, defineMailTemplate, deriveAmrAcr, describeQuerySchema, eventSchema, expandWildcardRealmEntry, extractWildcardRealmEntry, generateNumericCode, generateOAuth2CodeVerifier, generateRecoveryCode, guessUserAuthenticatorKindByResponse, identityProviderAccountSchema, identityProviderRoleMappingSchema, identityProviderSchema, isIdentityProviderAccountAlreadyLinkedError, isIdentityProviderAccountUnlinkBlockedError, isRealmCipherBlobError, isSessionTokenRelationMissingError, isWrappedKeyMaterial, keySchema, mergeProvisioningEntities, mergeProvisioningEntity, normalizeEntityProvisioningStrategy, parseCertificateChain, parseClientCertificateChain, permissionPolicySchema, permissionSchema, policySchema, queryCodec, realmSchema, roleAttributeSchema, rolePermissionSchema, roleSchema, sanitizeEventData, schemaRegistry, schemas, scopeSchema, sessionSchema, sessionTokenSchema, toIdentityPolicyData, trustAnchorSchema, unwrapKeyMaterial, userAttributeSchema, userAuthenticatorSchema, userPermissionSchema, userRoleSchema, userSchema, verifyWebauthnAuthentication, verifyWebauthnRegistration, wrapKeyMaterial };
@@ -1 +1 @@
1
- {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../../../../src/core/oauth2/authorization/code-request/verifier/module.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAC;AAWvE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAExE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,KAAK,EACR,uCAAuC,EACvC,gDAAgD,EAChD,6CAA6C,EAChD,MAAM,YAAY,CAAC;AAEpB,qBAAa,sCAAuC,YAAW,uCAAuC;IAClG,SAAS,CAAC,gBAAgB,EAAE,uBAAuB,CAAC;IAEpD,SAAS,CAAC,eAAe,EAAE,sBAAsB,CAAC;gBAEtC,GAAG,EAAE,6CAA6C;IAK9D;;;OAGG;IACG,MAAM,CACR,IAAI,EAAE,8BAA8B,GACpC,OAAO,CAAC,gDAAgD,CAAC;CA6FhE"}
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../../../../src/core/oauth2/authorization/code-request/verifier/module.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAC;AAWvE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAExE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,KAAK,EACR,uCAAuC,EACvC,gDAAgD,EAChD,6CAA6C,EAChD,MAAM,YAAY,CAAC;AAEpB,qBAAa,sCAAuC,YAAW,uCAAuC;IAClG,SAAS,CAAC,gBAAgB,EAAE,uBAAuB,CAAC;IAEpD,SAAS,CAAC,eAAe,EAAE,sBAAsB,CAAC;gBAEtC,GAAG,EAAE,6CAA6C;IAK9D;;;OAGG;IACG,MAAM,CACR,IAAI,EAAE,8BAA8B,GACpC,OAAO,CAAC,gDAAgD,CAAC;CAmGhE"}
@@ -34,10 +34,11 @@ var OAuth2AuthorizationCodeRequestVerifier = class {
34
34
  if (data.scope) {
35
35
  if (!hasOAuth2Scopes(scopeNames, data.scope) && !hasOAuth2Scopes(data.scope, ScopeName.GLOBAL)) throw OAuth2ScopeError.insufficient();
36
36
  } else data.scope = scopeNames.join(" ");
37
- const redirectUriVerified = !!data.redirect_uri;
37
+ let redirectUriVerified = false;
38
38
  if (data.redirect_uri) {
39
39
  const redirectUris = client.redirectUri.split(",");
40
40
  if (!isSimpleURLMatch(data.redirect_uri, redirectUris)) throw OAuth2GrantError.redirectUriMismatch();
41
+ redirectUriVerified = true;
41
42
  }
42
43
  return {
43
44
  data,
@@ -1 +1 @@
1
- {"version":3,"file":"module.mjs","names":["ScopeName","isClientPublic","isSimpleURLMatch","isUUID","OAuth2ClientError","OAuth2GrantError","OAuth2RequestError","OAuth2ScopeError","OAuth2TokenGrant","hasOAuth2Scopes","assertClientGrantAllowed","OAuth2AuthorizationCodeRequestVerifier","clientRepository","scopeRepository","ctx","verify","data","client_id","invalid","realm_id","malformed","client","findOneByIdOrName","active","inactive","AUTHORIZATION_CODE","redirectUri","redirectUriMismatch","code_challenge","state","id","realmId","scopes","findByClientId","scopeNames","map","scope","name","GLOBAL","insufficient","join","redirectUriVerified","redirect_uri","redirectUris","split"],"sources":["../../../../../../src/core/oauth2/authorization/code-request/verifier/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { OAuth2AuthorizationCodeRequest } from '@authup/core-kit';\nimport { ScopeName, isClientPublic } from '@authup/core-kit';\nimport { isSimpleURLMatch, isUUID } from '@authup/kit';\nimport {\n OAuth2ClientError,\n OAuth2GrantError,\n OAuth2RequestError,\n OAuth2ScopeError,\n OAuth2TokenGrant,\n hasOAuth2Scopes,\n} from '@authup/specs';\nimport type { IOAuth2ClientRepository } from '../../../client/index.ts';\nimport { assertClientGrantAllowed } from '../../../client/index.ts';\nimport type { IOAuth2ScopeRepository } from '../../../scope/index.ts';\nimport type {\n IOAuth2AuthorizationCodeRequestVerifier,\n OAuth2AuthorizationCodeRequestVerificationResult,\n OAuth2AuthorizationCodeRequestVerifierContext,\n} from './types.ts';\n\nexport class OAuth2AuthorizationCodeRequestVerifier implements IOAuth2AuthorizationCodeRequestVerifier {\n protected clientRepository: IOAuth2ClientRepository;\n\n protected scopeRepository: IOAuth2ScopeRepository;\n\n constructor(ctx: OAuth2AuthorizationCodeRequestVerifierContext) {\n this.clientRepository = ctx.clientRepository;\n this.scopeRepository = ctx.scopeRepository;\n }\n\n /**\n * Verify validated authorization code request.\n * @param data\n */\n async verify(\n data: OAuth2AuthorizationCodeRequest,\n ) : Promise<OAuth2AuthorizationCodeRequestVerificationResult> {\n if (!data.client_id) {\n throw OAuth2ClientError.invalid();\n }\n\n // A name-identified client needs a realm hint to resolve deterministically\n // — client names are only unique per realm (every realm carries the\n // same-named system clients, and a wildcard-provisioned client exists in\n // every realm), so a bare name would bind to an arbitrary realm's client\n // (and, post realm-gate, produce a confusing mismatch against a random\n // realm). Require the hint.\n if (!isUUID(data.client_id) && !data.realm_id) {\n throw OAuth2RequestError.malformed('A realm is required to resolve a client by name.');\n }\n\n const client = await this.clientRepository.findOneByIdOrName(data.client_id, data.realm_id);\n if (!client) {\n throw OAuth2ClientError.invalid();\n }\n\n if (!client.active) {\n throw OAuth2ClientError.inactive();\n }\n\n // A non-null grant_types allowlist must cover the code flow — an RP\n // misconfiguration fails at the front door, not at code redemption.\n assertClientGrantAllowed(client, OAuth2TokenGrant.AUTHORIZATION_CODE);\n\n // OAuth 2.1 posture: a client with no registered redirect_uri pattern\n // can never be matched — reject outright instead of trusting whatever\n // redirect_uri the request carries (the server would otherwise issue a\n // code to an attacker-supplied URI).\n if (!client.redirectUri) {\n throw OAuth2GrantError.redirectUriMismatch();\n }\n\n // Public clients MUST use PKCE (RFC 7636 §4.4.1, OAuth 2.1). Without\n // PKCE a public client's code flow has no second factor — anyone who\n // intercepts the redirect can redeem the code at /token. The code flow\n // is the only supported response type, so this holds unconditionally.\n if (isClientPublic(client) && !data.code_challenge) {\n throw OAuth2RequestError.malformed('PKCE code_challenge is required for public clients.');\n }\n\n // Public clients SHOULD include state to bind the redirect to the\n // initiating session and prevent CSRF (RFC 6749 §10.12). Confidential\n // clients are exempt because the /token exchange already authenticates\n // them via client_secret.\n if (isClientPublic(client) && !data.state) {\n throw OAuth2RequestError.malformed('state is required for public clients in the code flow.');\n }\n\n data.client_id = client.id;\n data.realm_id = client.realmId;\n\n const scopes = await this.scopeRepository.findByClientId(client.id);\n const scopeNames = scopes.map((scope) => scope.name);\n if (data.scope) {\n if (\n !hasOAuth2Scopes(scopeNames, data.scope) &&\n !hasOAuth2Scopes(data.scope, ScopeName.GLOBAL)\n ) {\n throw OAuth2ScopeError.insufficient();\n }\n } else {\n data.scope = scopeNames.join(' ');\n }\n\n // Verified only when the request's redirect_uri matched a registered\n // pattern (pattern-less clients were rejected above). A request without\n // a redirect_uri (e.g. the GET page render) stays unverified so\n // consumers never auto-redirect without a match.\n const redirectUriVerified = !!data.redirect_uri;\n if (data.redirect_uri) {\n const redirectUris = client.redirectUri.split(',');\n\n // isSimpleURLMatch, never isSimpleMatch: the raw matcher treats `/`\n // as its only boundary, so a `*` in a registered pattern's host\n // absorbs a `?`, `#` or `\\` and the pattern's remaining host\n // literal lands in the query of a foreign origin. The code would\n // then be issued to that origin.\n if (!isSimpleURLMatch(data.redirect_uri, redirectUris)) {\n throw OAuth2GrantError.redirectUriMismatch();\n }\n }\n\n return {\n data,\n client,\n scopes,\n redirectUriVerified,\n };\n }\n}\n"],"mappings":";;;;;;;;;AA2BA,IAAaW,yCAAb,MAAaA;CACCC;CAEAC;CAEV,YAAYC,KAAoD;EAC5D,KAAKF,mBAAmBE,IAAIF;EAC5B,KAAKC,kBAAkBC,IAAID;CAC/B;;;;IAMA,MAAME,OACFC,MAC0D;EAC1D,IAAI,CAACA,KAAKC,WACN,MAAMb,kBAAkBc,QAAO;EASnC,IAAI,CAACf,OAAOa,KAAKC,SAAS,KAAK,CAACD,KAAKG,UACjC,MAAMb,mBAAmBc,UAAU,kDAAA;EAGvC,MAAMC,SAAS,MAAM,KAAKT,iBAAiBU,kBAAkBN,KAAKC,WAAWD,KAAKG,QAAQ;EAC1F,IAAI,CAACE,QACD,MAAMjB,kBAAkBc,QAAO;EAGnC,IAAI,CAACG,OAAOE,QACR,MAAMnB,kBAAkBoB,SAAQ;EAKpCd,yBAAyBW,QAAQb,iBAAiBiB,kBAAkB;EAMpE,IAAI,CAACJ,OAAOK,aACR,MAAMrB,iBAAiBsB,oBAAmB;EAO9C,IAAI1B,eAAeoB,MAAAA,KAAW,CAACL,KAAKY,gBAChC,MAAMtB,mBAAmBc,UAAU,qDAAA;EAOvC,IAAInB,eAAeoB,MAAAA,KAAW,CAACL,KAAKa,OAChC,MAAMvB,mBAAmBc,UAAU,wDAAA;EAGvCJ,KAAKC,YAAYI,OAAOS;EACxBd,KAAKG,WAAWE,OAAOU;EAEvB,MAAMC,SAAS,MAAM,KAAKnB,gBAAgBoB,eAAeZ,OAAOS,EAAE;EAClE,MAAMI,aAAaF,OAAOG,KAAKC,UAAUA,MAAMC,IAAI;EACnD,IAAIrB,KAAKoB,OAED;OAAA,CAAC3B,gBAAgByB,YAAYlB,KAAKoB,KAAK,KACvC,CAAC3B,gBAAgBO,KAAKoB,OAAOpC,UAAUsC,MAAM,GAE7C,MAAM/B,iBAAiBgC,aAAY;EAAA,OAGvCvB,KAAKoB,QAAQF,WAAWM,KAAK,GAAA;EAOjC,MAAMC,sBAAsB,CAAC,CAACzB,KAAK0B;EACnC,IAAI1B,KAAK0B,cAAc;GACnB,MAAMC,eAAetB,OAAOK,YAAYkB,MAAM,GAAA;GAO9C,IAAI,CAAC1C,iBAAiBc,KAAK0B,cAAcC,YAAAA,GACrC,MAAMtC,iBAAiBsB,oBAAmB;EAElD;EAEA,OAAO;GACHX;GACAK;GACAW;GACAS;EACJ;CACJ;AACJ"}
1
+ {"version":3,"file":"module.mjs","names":["ScopeName","isClientPublic","isSimpleURLMatch","isUUID","OAuth2ClientError","OAuth2GrantError","OAuth2RequestError","OAuth2ScopeError","OAuth2TokenGrant","hasOAuth2Scopes","assertClientGrantAllowed","OAuth2AuthorizationCodeRequestVerifier","clientRepository","scopeRepository","ctx","verify","data","client_id","invalid","realm_id","malformed","client","findOneByIdOrName","active","inactive","AUTHORIZATION_CODE","redirectUri","redirectUriMismatch","code_challenge","state","id","realmId","scopes","findByClientId","scopeNames","map","scope","name","GLOBAL","insufficient","join","redirectUriVerified","redirect_uri","redirectUris","split"],"sources":["../../../../../../src/core/oauth2/authorization/code-request/verifier/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { OAuth2AuthorizationCodeRequest } from '@authup/core-kit';\nimport { ScopeName, isClientPublic } from '@authup/core-kit';\nimport { isSimpleURLMatch, isUUID } from '@authup/kit';\nimport {\n OAuth2ClientError,\n OAuth2GrantError,\n OAuth2RequestError,\n OAuth2ScopeError,\n OAuth2TokenGrant,\n hasOAuth2Scopes,\n} from '@authup/specs';\nimport type { IOAuth2ClientRepository } from '../../../client/index.ts';\nimport { assertClientGrantAllowed } from '../../../client/index.ts';\nimport type { IOAuth2ScopeRepository } from '../../../scope/index.ts';\nimport type {\n IOAuth2AuthorizationCodeRequestVerifier,\n OAuth2AuthorizationCodeRequestVerificationResult,\n OAuth2AuthorizationCodeRequestVerifierContext,\n} from './types.ts';\n\nexport class OAuth2AuthorizationCodeRequestVerifier implements IOAuth2AuthorizationCodeRequestVerifier {\n protected clientRepository: IOAuth2ClientRepository;\n\n protected scopeRepository: IOAuth2ScopeRepository;\n\n constructor(ctx: OAuth2AuthorizationCodeRequestVerifierContext) {\n this.clientRepository = ctx.clientRepository;\n this.scopeRepository = ctx.scopeRepository;\n }\n\n /**\n * Verify validated authorization code request.\n * @param data\n */\n async verify(\n data: OAuth2AuthorizationCodeRequest,\n ) : Promise<OAuth2AuthorizationCodeRequestVerificationResult> {\n if (!data.client_id) {\n throw OAuth2ClientError.invalid();\n }\n\n // A name-identified client needs a realm hint to resolve deterministically\n // — client names are only unique per realm (every realm carries the\n // same-named system clients, and a wildcard-provisioned client exists in\n // every realm), so a bare name would bind to an arbitrary realm's client\n // (and, post realm-gate, produce a confusing mismatch against a random\n // realm). Require the hint.\n if (!isUUID(data.client_id) && !data.realm_id) {\n throw OAuth2RequestError.malformed('A realm is required to resolve a client by name.');\n }\n\n const client = await this.clientRepository.findOneByIdOrName(data.client_id, data.realm_id);\n if (!client) {\n throw OAuth2ClientError.invalid();\n }\n\n if (!client.active) {\n throw OAuth2ClientError.inactive();\n }\n\n // A non-null grant_types allowlist must cover the code flow — an RP\n // misconfiguration fails at the front door, not at code redemption.\n assertClientGrantAllowed(client, OAuth2TokenGrant.AUTHORIZATION_CODE);\n\n // OAuth 2.1 posture: a client with no registered redirect_uri pattern\n // can never be matched — reject outright instead of trusting whatever\n // redirect_uri the request carries (the server would otherwise issue a\n // code to an attacker-supplied URI).\n if (!client.redirectUri) {\n throw OAuth2GrantError.redirectUriMismatch();\n }\n\n // Public clients MUST use PKCE (RFC 7636 §4.4.1, OAuth 2.1). Without\n // PKCE a public client's code flow has no second factor — anyone who\n // intercepts the redirect can redeem the code at /token. The code flow\n // is the only supported response type, so this holds unconditionally.\n if (isClientPublic(client) && !data.code_challenge) {\n throw OAuth2RequestError.malformed('PKCE code_challenge is required for public clients.');\n }\n\n // Public clients SHOULD include state to bind the redirect to the\n // initiating session and prevent CSRF (RFC 6749 §10.12). Confidential\n // clients are exempt because the /token exchange already authenticates\n // them via client_secret.\n if (isClientPublic(client) && !data.state) {\n throw OAuth2RequestError.malformed('state is required for public clients in the code flow.');\n }\n\n data.client_id = client.id;\n data.realm_id = client.realmId;\n\n const scopes = await this.scopeRepository.findByClientId(client.id);\n const scopeNames = scopes.map((scope) => scope.name);\n if (data.scope) {\n if (\n !hasOAuth2Scopes(scopeNames, data.scope) &&\n !hasOAuth2Scopes(data.scope, ScopeName.GLOBAL)\n ) {\n throw OAuth2ScopeError.insufficient();\n }\n } else {\n data.scope = scopeNames.join(' ');\n }\n\n // Verified only when the request's redirect_uri matched a registered\n // pattern (pattern-less clients were rejected above). A request without\n // a redirect_uri (e.g. the GET page render) stays unverified so\n // consumers never auto-redirect without a match.\n //\n // Set from the match itself, never from mere presence: consumers make\n // redirect decisions on this flag, so it must not survive a refactor\n // that turns the throw below into a soft branch.\n let redirectUriVerified = false;\n if (data.redirect_uri) {\n const redirectUris = client.redirectUri.split(',');\n\n // isSimpleURLMatch, never isSimpleMatch: the raw matcher treats `/`\n // as its only boundary, so a `*` in a registered pattern's host\n // absorbs a `?`, `#` or `\\` and the pattern's remaining host\n // literal lands in the query of a foreign origin. The code would\n // then be issued to that origin.\n if (!isSimpleURLMatch(data.redirect_uri, redirectUris)) {\n throw OAuth2GrantError.redirectUriMismatch();\n }\n\n redirect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CAAmC,CAAC;IAEtE,SAAS,CAAC,qBAAqB,CAAC,EAAG,4BAA4B,CAAC;gBAEpD,GAAG,EAAE,iCAAiC;IAWlD;;;;;;OAMG;IACG,SAAS,CACX,IAAI,EAAE,8BAA8B,EACpC,QAAQ,EAAE,QAAQ,EAClB,OAAO,GAAE,0BAA+B,GACxC,OAAO,CAAC,yBAAyB,CAAC;cAmDtB,cAAc,CAC1B,IAAI,EAAE,8BAA8B,EACpC,QAAQ,EAAE,QAAQ,EAClB,OAAO,GAAE,0BAA+B,GACxC,OAAO,CAAC,yBAAyB,CAAC;CA4KzC"}
@@ -42,6 +42,7 @@ var OAuth2Authorization = class {
42
42
  refType: EventRefType.CLIENT,
43
43
  refId: options.client?.id ?? data.client_id ?? null,
44
44
  clientId: options.client?.id ?? data.client_id ?? null,
45
+ sessionId: options.sessionId ?? null,
45
46
  actorType: identity.type,
46
47
  actorId: identity.data.id,
47
48
  actorName: identity.data.name,
@@ -61,6 +62,7 @@ var OAuth2Authorization = class {
61
62
  refType: EventRefType.CLIENT,
62
63
  refId: options.client?.id ?? data.client_id ?? null,
63
64
  clientId: options.client?.id ?? data.client_id ?? null,
65
+ sessionId: options.sessionId ?? null,
64
66
  actorType: identity.type,
65
67
  actorId: identity.data.id,
66
68
  actorName: identity.data.name,
@@ -1 +1 @@
1
- {"version":3,"file":"module.mjs","names":["EventName","EventRefType","EventScope","IdentityType","hasInstanceof","OAUTH2_ACCESS_DENIED_ERROR_INSTANCE","OAUTH2_LOGIN_REQUIRED_ERROR_INSTANCE","OAUTH2_MFA_REQUIRED_ERROR_INSTANCE","OAuth2AccessDeniedError","OAuth2AuthenticationContextClass","OAuth2AuthorizationPrompt","OAuth2AuthorizationResponseType","OAuth2GrantError","OAuth2LoginRequiredError","OAuth2MfaRequiredError","OAuth2RequestError","OAuth2ResponseTypeError","toIdentityPolicyData","DEFAULT_PROMPT_LOGIN_MAX_AGE","DEFAULT_MFA_FRESHNESS_MAX_AGE","OAuth2Authorization","codeIssuer","sessionManager","eventService","metrics","promptLoginMaxAge","mfaFreshnessMaxAge","mfaChallengeProvider","accessPolicyEvaluator","ctx","authorize","data","identity","options","result","authorizeInner","record","scope","OAUTH2","name","AUTHORIZE","refType","CLIENT","refId","client","id","client_id","clientId","actorType","type","actorId","actorName","realmId","realm_id","reason","builtIn","recordAuthorize","e","AUTHORIZE_FAILED","responseTypes","response_type","Array","isArray","split","responseType","CODE","unsupported","includes","redirect_uri","redirectUriMismatch","output","redirectUri","state","identityInvalid","realmMismatch","nowSeconds","Math","floor","Date","now","authTime","session","sessionId","findOneById","createdAt","getTime","USER","challenge","issueMaterial","required","mfaAt","challengeRequired","enrollmentRequired","acr_values","acrValues","MFA","mfaAtSeconds","stepUpRequired","prompts","prompt","LOGIN","reauthenticationRequired","max_age","maxAge","Number","isFinite","accessPolicyId","allowed","subject","evaluate","forClient","redirectUriVerified","undefined","codeEntity","issue","authMethod","authorizationCode"],"sources":["../../../../src/core/oauth2/authorization/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type {\n Identity, \n OAuth2AuthorizationCode, \n OAuth2AuthorizationCodeRequest, \n Session,\n} from '@authup/core-kit';\nimport {\n EventName, \n EventRefType, \n EventScope, \n IdentityType,\n} from '@authup/core-kit';\nimport { hasInstanceof } from '@authup/errors';\nimport {\n OAUTH2_ACCESS_DENIED_ERROR_INSTANCE,\n OAUTH2_LOGIN_REQUIRED_ERROR_INSTANCE,\n OAUTH2_MFA_REQUIRED_ERROR_INSTANCE,\n OAuth2AccessDeniedError,\n OAuth2AuthenticationContextClass,\n OAuth2AuthorizationPrompt,\n OAuth2AuthorizationResponseType,\n OAuth2GrantError,\n OAuth2LoginRequiredError,\n OAuth2MfaRequiredError,\n OAuth2RequestError,\n OAuth2ResponseTypeError,\n} from '@authup/specs';\nimport type { IOAuth2AuthorizationCodeIssuer } from './code/index.ts';\nimport type { IOAuth2AccessPolicyEvaluator } from '../access-policy/index.ts';\nimport { toIdentityPolicyData } from '../../identity/permission/identity-policy-data.ts';\nimport type {\n OAuth2AuthorizationManagerContext,\n OAuth2AuthorizationOptions,\n OAuth2AuthorizationResult,\n} from './types.ts';\nimport type { ISessionManager } from '../../authentication/index.ts';\nimport type { IEventService, IUserAuthenticatorChallengeProvider } from '../../entities/index.ts';\nimport type { IAuthFlowMetrics } from '../../metrics/index.ts';\n\nconst DEFAULT_PROMPT_LOGIN_MAX_AGE = 60;\n\n// Deliberately 60 (not 0, deviating from the plan-050 sketch): the hosted\n// challenge round-trip (stamp mfa_at → retry POST /authorize) takes seconds,\n// so a 0-window step-up could never be satisfied and would loop the ladder.\nconst DEFAULT_MFA_FRESHNESS_MAX_AGE = 60;\n\nexport class OAuth2Authorization {\n protected codeIssuer : IOAuth2AuthorizationCodeIssuer;\n\n protected sessionManager : ISessionManager;\n\n protected eventService? : IEventService;\n\n protected metrics? : IAuthFlowMetrics;\n\n protected promptLoginMaxAge : number;\n\n protected mfaFreshnessMaxAge : number;\n\n protected mfaChallengeProvider? : IUserAuthenticatorChallengeProvider;\n\n protected accessPolicyEvaluator? : IOAuth2AccessPolicyEvaluator;\n\n constructor(ctx: OAuth2AuthorizationManagerContext) {\n this.codeIssuer = ctx.codeIssuer;\n this.sessionManager = ctx.sessionManager;\n this.eventService = ctx.eventService;\n this.metrics = ctx.metrics;\n this.accessPolicyEvaluator = ctx.accessPolicyEvaluator;\n this.promptLoginMaxAge = ctx.promptLoginMaxAge ?? DEFAULT_PROMPT_LOGIN_MAX_AGE;\n this.mfaFreshnessMaxAge = ctx.mfaFreshnessMaxAge ?? DEFAULT_MFA_FRESHNESS_MAX_AGE;\n this.mfaChallengeProvider = ctx.mfaChallengeProvider;\n }\n\n /**\n * Authorize with validated codeRequest.\n *\n * @param data\n * @param identity\n * @param options\n */\n async authorize(\n data: OAuth2AuthorizationCodeRequest,\n identity: Identity,\n options: OAuth2AuthorizationOptions = {},\n ) : Promise<OAuth2AuthorizationResult> {\n try {\n const result = await this.authorizeInner(data, identity, options);\n\n await this.eventService?.record({\n scope: EventScope.OAUTH2,\n name: EventName.AUTHORIZE,\n refType: EventRefType.CLIENT,\n refId: options.client?.id ?? data.client_id ?? null,\n clientId: options.client?.id ?? data.client_id ?? null,\n actorType: identity.type,\n actorId: identity.data.id,\n actorName: identity.data.name,\n realmId: data.realm_id ?? null,\n data: {\n reason: options.client?.builtIn ? 'autoConsent' : 'consent',\n ...(data.scope ? { scope: data.scope } : {}),\n },\n });\n this.metrics?.recordAuthorize('issued');\n\n return result;\n } catch (e) {\n if (hasInstanceof(e, OAUTH2_ACCESS_DENIED_ERROR_INSTANCE)) {\n await this.eventService?.record({\n scope: EventScope.OAUTH2,\n name: EventName.AUTHORIZE_FAILED,\n refType: EventRefType.CLIENT,\n refId: options.client?.id ?? data.client_id ?? null,\n clientId: options.client?.id ?? data.client_id ?? null,\n actorType: identity.type,\n actorId: identity.data.id,\n actorName: identity.data.name,\n realmId: data.realm_id ?? null,\n data: { reason: 'accessPolicy' },\n });\n this.metrics?.recordAuthorize('denied');\n } else if (hasInstanceof(e, OAUTH2_LOGIN_REQUIRED_ERROR_INSTANCE)) {\n this.metrics?.recordAuthorize('login_required');\n } else if (hasInstanceof(e, OAUTH2_MFA_REQUIRED_ERROR_INSTANCE)) {\n this.metrics?.recordAuthorize('mfa_required');\n } else {\n this.metrics?.recordAuthorize('error');\n }\n\n throw e;\n }\n }\n\n protected async authorizeInner(\n data: OAuth2AuthorizationCodeRequest,\n identity: Identity,\n options: OAuth2AuthorizationOptions = {},\n ) : Promise<OAuth2AuthorizationResult> {\n // OAuth 2.1 posture: only the authorization-code response type is\n // supported — implicit/hybrid (token, id_token, none) were dropped\n // (plan 042 item 3). Defense in depth behind the request validator.\n let responseTypes : string[] = [];\n if (data.response_type) {\n responseTypes = Array.isArray(data.response_type) ?\n data.response_type :\n data.response_type.split(' ');\n }\n\n for (const responseType of responseTypes) {\n if (responseType !== OAuth2AuthorizationResponseType.CODE) {\n throw OAuth2ResponseTypeError.unsupported();\n }\n }\n\n if (!responseTypes.includes(OAuth2AuthorizationResponseType.CODE)) {\n throw OAuth2ResponseTypeError.unsupported();\n }\n\n if (!data.redirect_uri) {\n throw OAuth2GrantError.redirectUriMismatch();\n }\n\n const output : OAuth2AuthorizationResult = {\n redirectUri: data.redirect_uri,\n ...(data.state ? { state: data.state } : {}),\n };\n\n if (!identity) {\n throw OAuth2RequestError.identityInvalid();\n }\n\n // Realm binding: the code-request verifier stamped data.realm_id with the\n // resolved client's realm. The authenticated identity must belong to that\n // same realm — otherwise a lingering session for realm A could silently\n // mint a code/token for realm B's client (confused deputy). The error body\n // deliberately carries no identity data (no realm-enumeration oracle).\n // The comparison reads the scalar realmId column, NOT the realm\n // relation — the relation may simply not be loaded on the resolved\n // identity. An identity without a realmId fails closed the same way —\n // clean login_required, never a TypeError.\n if (\n data.realm_id &&\n identity.data.realmId !== data.realm_id\n ) {\n throw OAuth2LoginRequiredError.realmMismatch();\n }\n\n // Authentication time = the backing session's creation instant (NOT\n // refreshed_at — a token refresh must not reset it). Session-less flows\n // (e.g. HTTP Basic authorize) present live credentials on this request,\n // so the authentication time is \"now\".\n const nowSeconds = Math.floor(Date.now() / 1000);\n let authTime = nowSeconds;\n let session : Session | null = null;\n if (options.sessionId) {\n session = await this.sessionManager.findOneById(options.sessionId);\n if (session && session.createdAt) {\n authTime = Math.floor(new Date(session.createdAt).getTime() / 1000);\n }\n }\n\n // MFA backstop (plan 049) — the authoritative server-side gate; the\n // hosted UI's challenge step is convenience. The proof is session-bound\n // (mfa_at — stamped by the challenge endpoint or the password grant's\n // otp param), so a session-less flow (HTTP Basic) cannot carry one and\n // fails closed while the user holds a confirmed device. A user without\n // a device under mfaRequired is routed to inline enrollment.\n if (this.mfaChallengeProvider && identity.type === IdentityType.USER) {\n // requirement flags only — the interactive challenge material (the\n // webauthn nonce) is issued by the status endpoint, not this backstop.\n const challenge = await this.mfaChallengeProvider.challenge(\n identity.data.id,\n { issueMaterial: false },\n );\n if (challenge.required && !session?.mfaAt) {\n throw OAuth2MfaRequiredError.challengeRequired();\n }\n\n if (challenge.enrollmentRequired) {\n throw OAuth2MfaRequiredError.enrollmentRequired();\n }\n\n // Step-up (plan 050 stage 3): a requested `acr_values` containing\n // urn:authup:mfa is a TRIGGER (Auth0/Keycloak stance) — the proof\n // must additionally be FRESH (mfaFreshnessMaxAge window, mirroring\n // promptLoginMaxAge's absorb-the-round-trip semantics). Enforced\n // only while the user actually holds a factor — per OIDC Core\n // §5.5.1.1 acr is voluntary, so an unsatisfiable request degrades\n // to the achieved acr instead of bricking the RP.\n if (challenge.required && data.acr_values) {\n const acrValues = data.acr_values.split(' ');\n if (acrValues.includes(OAuth2AuthenticationContextClass.MFA)) {\n const mfaAtSeconds = session?.mfaAt ?\n Math.floor(new Date(session.mfaAt).getTime() / 1000) :\n null;\n if (mfaAtSeconds === null || nowSeconds - mfaAtSeconds > this.mfaFreshnessMaxAge) {\n throw OAuth2MfaRequiredError.stepUpRequired();\n }\n }\n }\n }\n\n // OIDC §3.1.2.1 prompt=login / max_age freshness (enforced only when\n // requested — a plain authorize never throws here). The hosted page\n // renders the login form for prompt=login; this is the server backstop.\n const prompts = data.prompt ? data.prompt.split(' ') : [];\n if (\n prompts.includes(OAuth2AuthorizationPrompt.LOGIN) &&\n nowSeconds - authTime > this.promptLoginMaxAge\n ) {\n throw OAuth2LoginRequiredError.reauthenticationRequired();\n }\n\n if (\n typeof data.max_age !== 'undefined' &&\n data.max_age !== null\n ) {\n const maxAge = Number(data.max_age);\n if (\n Number.isFinite(maxAge) &&\n nowSeconds - authTime > maxAge\n ) {\n throw OAuth2LoginRequiredError.reauthenticationRequired();\n }\n }\n\n // Application access policy (plan 052) — the last gate before\n // issuance: a denial is only revealed to a fully-authenticated\n // (incl. second-factor) identity. A client carrying a policy id with\n // no wired evaluator denies too (never silently allow a configured\n // gate). The redirect target rides the error only when the\n // redirect_uri was pattern-verified (RFC 6749 §4.1.2.1).\n if (options.client?.accessPolicyId) {\n let allowed = false;\n\n const subject = toIdentityPolicyData(identity);\n if (this.accessPolicyEvaluator && subject) {\n allowed = await this.accessPolicyEvaluator.evaluate(\n options.client.accessPolicyId,\n subject,\n );\n }\n\n if (!allowed) {\n throw OAuth2AccessDeniedError.forClient(\n options.redirectUriVerified && data.redirect_uri ?\n { redirectUri: data.redirect_uri, state: data.state ?? null } :\n undefined,\n );\n }\n }\n\n // The id_token is NOT minted here — the /token exchange mints it after\n // resolving the real backing session, so its `sid` is authoritative\n // (plan 042 item 6). The code carries the authentication instant.\n const codeEntity : OAuth2AuthorizationCode = await this.codeIssuer.issue(\n data,\n identity,\n {\n sessionId: options.sessionId,\n authTime,\n authMethod: session?.authMethod ?? null,\n },\n );\n\n output.authorizationCode = codeEntity.id;\n\n return output;\n }\n}\n"],"mappings":";;;;;;;;AA8CA,MAAMkB,+BAA+B;AAKrC,MAAMC,gCAAgC;AAEtC,IAAaC,sBAAb,MAAaA;CACCC;CAEAC;CAEAC;CAEAC;CAEAC;CAEAC;CAEAC;CAEAC;CAEV,YAAYC,KAAwC;EAChD,KAAKR,aAAaQ,IAAIR;EACtB,KAAKC,iBAAiBO,IAAIP;EAC1B,KAAKC,eAAeM,IAAIN;EACxB,KAAKC,UAAUK,IAAIL;EACnB,KAAKI,wBAAwBC,IAAID;EACjC,KAAKH,oBAAoBI,IAAIJ,qBAAqBP;EAClD,KAAKQ,qBAAqBG,IAAIH,sBAAsBP;EACpD,KAAKQ,uBAAuBE,IAAIF;CACpC;;;;;;;IASA,MAAMG,UACFC,MACAC,UACAC,UAAsC,CAAC,GACJ;EACnC,IAAI;GACA,MAAMC,SAAS,MAAM,KAAKC,eAAeJ,MAAMC,UAAUC,OAAAA;GAEzD,MAAM,KAAKV,cAAca,OAAO;IAC5BC,OAAOnC,WAAWoC;IAClBC,MAAMvC,UAAUwC;IAChBC,SAASxC,aAAayC;IACtBC,OAAOV,QAAQW,Q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"file":"module.mjs","names":["EventName","EventRefType","EventScope","IdentityType","hasInstanceof","OAUTH2_ACCESS_DENIED_ERROR_INSTANCE","OAUTH2_LOGIN_REQUIRED_ERROR_INSTANCE","OAUTH2_MFA_REQUIRED_ERROR_INSTANCE","OAuth2AccessDeniedError","OAuth2AuthenticationContextClass","OAuth2AuthorizationPrompt","OAuth2AuthorizationResponseType","OAuth2GrantError","OAuth2LoginRequiredError","OAuth2MfaRequiredError","OAuth2RequestError","OAuth2ResponseTypeError","toIdentityPolicyData","DEFAULT_PROMPT_LOGIN_MAX_AGE","DEFAULT_MFA_FRESHNESS_MAX_AGE","OAuth2Authorization","codeIssuer","sessionManager","eventService","metrics","promptLoginMaxAge","mfaFreshnessMaxAge","mfaChallengeProvider","accessPolicyEvaluator","ctx","authorize","data","identity","options","result","authorizeInner","record","scope","OAUTH2","name","AUTHORIZE","refType","CLIENT","refId","client","id","client_id","clientId","sessionId","actorType","type","actorId","actorName","realmId","realm_id","reason","builtIn","recordAuthorize","e","AUTHORIZE_FAILED","responseTypes","response_type","Array","isArray","split","responseType","CODE","unsupported","includes","redirect_uri","redirectUriMismatch","output","redirectUri","state","identityInvalid","realmMismatch","nowSeconds","Math","floor","Date","now","authTime","session","findOneById","createdAt","getTime","USER","challenge","issueMaterial","required","mfaAt","challengeRequired","enrollmentRequired","acr_values","acrValues","MFA","mfaAtSeconds","stepUpRequired","prompts","prompt","LOGIN","reauthenticationRequired","max_age","maxAge","Number","isFinite","accessPolicyId","allowed","subject","evaluate","forClient","redirectUriVerified","undefined","codeEntity","issue","authMethod","authorizationCode"],"sources":["../../../../src/core/oauth2/authorization/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type {\n Identity, \n OAuth2AuthorizationCode, \n OAuth2AuthorizationCodeRequest, \n Session,\n} from '@authup/core-kit';\nimport {\n EventName, \n EventRefType, \n EventScope, \n IdentityType,\n} from '@authup/core-kit';\nimport { hasInstanceof } from '@authup/errors';\nimport {\n OAUTH2_ACCESS_DENIED_ERROR_INSTANCE,\n OAUTH2_LOGIN_REQUIRED_ERROR_INSTANCE,\n OAUTH2_MFA_REQUIRED_ERROR_INSTANCE,\n OAuth2AccessDeniedError,\n OAuth2AuthenticationContextClass,\n OAuth2AuthorizationPrompt,\n OAuth2AuthorizationResponseType,\n OAuth2GrantError,\n OAuth2LoginRequiredError,\n OAuth2MfaRequiredError,\n OAuth2RequestError,\n OAuth2ResponseTypeError,\n} from '@authup/specs';\nimport type { IOAuth2AuthorizationCodeIssuer } from './code/index.ts';\nimport type { IOAuth2AccessPolicyEvaluator } from '../access-policy/index.ts';\nimport { toIdentityPolicyData } from '../../identity/permission/identity-policy-data.ts';\nimport type {\n OAuth2AuthorizationManagerContext,\n OAuth2AuthorizationOptions,\n OAuth2AuthorizationResult,\n} from './types.ts';\nimport type { ISessionManager } from '../../authentication/index.ts';\nimport type { IEventService, IUserAuthenticatorChallengeProvider } from '../../entities/index.ts';\nimport type { IAuthFlowMetrics } from '../../metrics/index.ts';\n\nconst DEFAULT_PROMPT_LOGIN_MAX_AGE = 60;\n\n// Deliberately 60 (not 0, deviating from the plan-050 sketch): the hosted\n// challenge round-trip (stamp mfa_at → retry POST /authorize) takes seconds,\n// so a 0-window step-up could never be satisfied and would loop the ladder.\nconst DEFAULT_MFA_FRESHNESS_MAX_AGE = 60;\n\nexport class OAuth2Authorization {\n protected codeIssuer : IOAuth2AuthorizationCodeIssuer;\n\n protected sessionManager : ISessionManager;\n\n protected eventService? : IEventService;\n\n protected metrics? : IAuthFlowMetrics;\n\n protected promptLoginMaxAge : number;\n\n protected mfaFreshnessMaxAge : number;\n\n protected mfaChallengeProvider? : IUserAuthenticatorChallengeProvider;\n\n protected accessPolicyEvaluator? : IOAuth2AccessPolicyEvaluator;\n\n constructor(ctx: OAuth2AuthorizationManagerContext) {\n this.codeIssuer = ctx.codeIssuer;\n this.sessionManager = ctx.sessionManager;\n this.eventService = ctx.eventService;\n this.metrics = ctx.metrics;\n this.accessPolicyEvaluator = ctx.accessPolicyEvaluator;\n this.promptLoginMaxAge = ctx.promptLoginMaxAge ?? DEFAULT_PROMPT_LOGIN_MAX_AGE;\n this.mfaFreshnessMaxAge = ctx.mfaFreshnessMaxAge ?? DEFAULT_MFA_FRESHNESS_MAX_AGE;\n this.mfaChallengeProvider = ctx.mfaChallengeProvider;\n }\n\n /**\n * Authorize with validated codeRequest.\n *\n * @param data\n * @param identity\n * @param options\n */\n async authorize(\n data: OAuth2AuthorizationCodeRequest,\n identity: Identity,\n options: OAuth2AuthorizationOptions = {},\n ) : Promise<OAuth2AuthorizationResult> {\n try {\n const result = await this.authorizeInner(data, identity, options);\n\n await this.eventService?.record({\n scope: EventScope.OAUTH2,\n name: EventName.AUTHORIZE,\n refType: EventRefType.CLIENT,\n refId: options.client?.id ?? data.client_id ?? null,\n clientId: options.client?.id ?? data.client_id ?? null,\n sessionId: options.sessionId ?? null,\n actorType: identity.type,\n actorId: identity.data.id,\n actorName: identity.data.name,\n realmId: data.realm_id ?? null,\n data: {\n reason: options.client?.builtIn ? 'autoConsent' : 'consent',\n ...(data.scope ? { scope: data.scope } : {}),\n },\n });\n this.metrics?.recordAuthorize('issued');\n\n return result;\n } catch (e) {\n if (hasInstanceof(e, OAUTH2_ACCESS_DENIED_ERROR_INSTANCE)) {\n await this.eventService?.record({\n scope: EventScope.OAUTH2,\n name: EventName.AUTHORIZE_FAILED,\n refType: EventRefType.CLIENT,\n refId: options.client?.id ?? data.client_id ?? null,\n clientId: options.client?.id ?? data.client_id ?? null,\n sessionId: options.sessionId ?? null,\n actorType: identity.type,\n actorId: identity.data.id,\n actorName: identity.data.name,\n realmId: data.realm_id ?? null,\n data: { reason: 'accessPolicy' },\n });\n this.metrics?.recordAuthorize('denied');\n } else if (hasInstanceof(e, OAUTH2_LOGIN_REQUIRED_ERROR_INSTANCE)) {\n this.metrics?.recordAuthorize('login_required');\n } else if (hasInstanceof(e, OAUTH2_MFA_REQUIRED_ERROR_INSTANCE)) {\n this.metrics?.recordAuthorize('mfa_required');\n } else {\n this.metrics?.recordAuthorize('error');\n }\n\n throw e;\n }\n }\n\n protected async authorizeInner(\n data: OAuth2AuthorizationCodeRequest,\n identity: Identity,\n options: OAuth2AuthorizationOptions = {},\n ) : Promise<OAuth2AuthorizationResult> {\n // OAuth 2.1 posture: only the authorization-code response type is\n // supported — implicit/hybrid (token, id_token, none) were dropped\n // (plan 042 item 3). Defense in depth behind the request validator.\n let responseTypes : string[] = [];\n if (data.response_type) {\n responseTypes = Array.isArray(data.response_type) ?\n data.response_type :\n data.response_type.split(' ');\n }\n\n for (const responseType of responseTypes) {\n if (responseType !== OAuth2AuthorizationResponseType.CODE) {\n throw OAuth2ResponseTypeError.unsupported();\n }\n }\n\n if (!responseTypes.includes(OAuth2AuthorizationResponseType.CODE)) {\n throw OAuth2ResponseTypeError.unsupported();\n }\n\n if (!data.redirect_uri) {\n throw OAuth2GrantError.redirectUriMismatch();\n }\n\n const output : OAuth2AuthorizationResult = {\n redirectUri: data.redirect_uri,\n ...(data.state ? { state: data.state } : {}),\n };\n\n if (!identity) {\n throw OAuth2RequestError.identityInvalid();\n }\n\n // Realm binding: the code-request verifier stamped data.realm_id with the\n // resolved client's realm. The authenticated identity must belong to that\n // same realm — otherwise a lingering session for realm A could silently\n // mint a code/token for realm B's client (confused deputy). The error body\n // deliberately carries no identity data (no realm-enumeration oracle).\n // The comparison reads the scalar realmId column, NOT the realm\n // relation — the relation may simply not be loaded on the resolved\n // identity. An identity without a realmId fails closed the same way —\n // clean login_required, never a TypeError.\n if (\n data.realm_id &&\n identity.data.realmId !== data.realm_id\n ) {\n throw OAuth2LoginRequiredError.realmMismatch();\n }\n\n // Authentication time = the backing session's creation instant (NOT\n // refreshed_at — a token refresh must not reset it). Session-less flows\n // (e.g. HTTP Basic authorize) present live credentials on this request,\n // so the authentication time is \"now\".\n const nowSeconds = Math.floor(Date.now() / 1000);\n let authTime = nowSeconds;\n let session : Session | null = null;\n if (options.sessionId) {\n session = await this.sessionManager.findOneById(options.sessionId);\n if (session && session.createdAt) {\n authTime = Math.floor(new Date(session.createdAt).getTime() / 1000);\n }\n }\n\n // MFA backstop (plan 049) — the authoritative server-side gate; the\n // hosted UI's challenge step is convenience. The proof is session-bound\n // (mfa_at — stamped by the challenge endpoint or the password grant's\n // otp param), so a session-less flow (HTTP Basic) cannot carry one and\n // fails closed while the user holds a confirmed device. A user without\n // a device under mfaRequired is routed to inline enrollment.\n if (this.mfaChallengeProvider && identity.type === IdentityType.USER) {\n // requirement flags only — the interactive challenge material (the\n // webauthn nonce) is issued by the status endpoint, not this backstop.\n const challenge = await this.mfaChallengeProvider.challenge(\n identity.data.id,\n { issueMaterial: false },\n );\n if (challenge.required && !session?.mfaAt) {\n throw OAuth2MfaRequiredError.challengeRequired();\n }\n\n if (challenge.enrollmentRequired) {\n throw OAuth2MfaRequiredError.enrollmentRequired();\n }\n\n // Step-up (plan 050 stage 3): a requested `acr_values` containing\n // urn:authup:mfa is a TRIGGER (Auth0/Keycloak stance) — the proof\n // must additionally be FRESH (mfaFreshnessMaxAge window, mirroring\n // promptLoginMaxAge's absorb-the-round-trip semantics). Enforced\n // only while the user actually holds a factor — per OIDC Core\n // §5.5.1.1 acr is voluntary, so an unsatisfiable request degrades\n // to the achieved acr instead of bricking the RP.\n if (challenge.required && data.acr_values) {\n const acrValues = data.acr_values.split(' ');\n if (acrValues.includes(OAuth2AuthenticationContextClass.MFA)) {\n const mfaAtSeconds = session?.mfaAt ?\n Math.floor(new Date(session.mfaAt).getTime() / 1000) :\n null;\n if (mfaAtSeconds === null || nowSeconds - mfaAtSeconds > this.mfaFreshnessMaxAge) {\n throw OAuth2MfaRequiredError.stepUpRequired();\n }\n }\n }\n }\n\n // OIDC §3.1.2.1 prompt=login / max_age freshness (enforced only when\n // requested — a plain authorize never throws here). The hosted page\n // renders the login form for prompt=login; this is the server backstop.\n const prompts = data.prompt ? data.prompt.split(' ') : [];\n if (\n prompts.includes(OAuth2AuthorizationPrompt.LOGIN) &&\n nowSeconds - authTime > this.promptLoginMaxAge\n ) {\n throw OAuth2LoginRequiredError.reauthenticationRequired();\n }\n\n if (\n typeof data.max_age !== 'undefined' &&\n data.max_age !== null\n ) {\n const maxAge = Number(data.max_age);\n if (\n Number.isFinite(maxAge) &&\n nowSeconds - authTime > maxAge\n ) {\n throw OAuth2LoginRequiredError.reauthenticationRequired();\n }\n }\n\n // Application access policy (plan 052) — the last gate before\n // issuance: a denial is only revealed to a fully-authenticated\n // (incl. second-factor) identity. A client carrying a policy id with\n // no wired evaluator denies too (never silently allow a configured\n // gate). The redirect target rides the error only when the\n // redirect_uri was pattern-verified (RFC 6749 §4.1.2.1).\n if (options.client?.accessPolicyId) {\n let allowed = false;\n\n const subject = toIdentityPolicyData(identity);\n if (this.accessPolicyEvaluator && subject) {\n allowed = await this.accessPolicyEvaluator.evaluate(\n options.client.accessPolicyId,\n subject,\n );\n }\n\n if (!allowed) {\n throw OAuth2AccessDeniedError.forClient(\n options.redirectUriVerified && data.redirect_uri ?\n { redirectUri: data.redirect_uri, state: data.state ?? null } :\n undefined,\n );\n }\n }\n\n // The id_token is NOT minted here — the /token exchange mints it after\n // resolving the real backing session, so its `sid` is authoritative\n // (plan 042 item 6). The code carries the authentication instant.\n const codeEntity : OAuth2AuthorizationCode = await this.codeIssuer.issue(\n data,\n identity,\n {\n sessionId: options.sessionId,\n authTime,\n authMethod: session?.authMethod ?? null,\n },\n );\n\n output.authorizationCode = codeEntity.id;\n\n return output;\n }\n}\n"],"mappings":";;;;;;;;AA8CA,MAAMkB,+BAA+B;AAKrC,MAAMC,gCAAgC;AAEtC,IAAaC,sBAAb,MAAaA;CACCC;CAEAC;CAEAC;CAEAC;CAEAC;CAEAC;CAEAC;CAEAC;CAEV,YAAYC,KAAwC;EAChD,KAAKR,aAAaQ,IAAIR;EACtB,KAAKC,iBAAiBO,IAAIP;EAC1B,KAAKC,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BAAqBe,QAAAA;GACrC,IAAI,KAAKJ,yBAAyBgF,SAC9BD,UAAU,MAAM,KAAK/E,sBAAsBiF,SACvC5E,QAAQW,OAAO8D,gBACfE,OAAAA;GAIR,IAAI,CAACD,SACD,MAAMnG,wBAAwBsG,UAC1B7E,QAAQ8E,uBAAuBhF,KAAKsC,eAChC;IAAEG,aAAazC,KAAKsC;IAAcI,OAAO1C,KAAK0C,SAAS;GAAK,IAC5DuC,KAAAA,CAAAA;EAGhB;EAeAzC,OAAO6C,qBAAoBH,MAVwB,KAAK5F,WAAW6F,MAC/DnF,MACAC,UACA;GACIgB,WAAWf,QAAQe;GACnBiC;GACAkC,YAAYjC,SAASiC,cAAc;EACvC,CAAA,EAAA,CAGkCtE;EAEtC,OAAO0B;CACX;AACJ"}
@@ -1,6 +1,17 @@
1
1
  import type { OAuth2AuthorizationCodeRequest } from '@authup/core-kit';
2
+ export type OAuth2AuthorizationStateLink = {
3
+ userId: string;
4
+ providerId: string;
5
+ };
2
6
  export type OAuth2AuthorizationState = {
3
7
  codeRequest?: OAuth2AuthorizationCodeRequest;
8
+ /**
9
+ * Present on an account-linking round-trip (plan 091): the callback
10
+ * links the external identity to this user instead of running the
11
+ * login path. Minted only by the bearer-authenticated link-request
12
+ * endpoint, never from client input.
13
+ */
14
+ link?: OAuth2AuthorizationStateLink;
4
15
  ip: string;
5
16
  userAgent?: string | null;
6
17
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/core/oauth2/authorization/state/types.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAC;AAEvE,MAAM,MAAM,wBAAwB,GAAG;IACnC,WAAW,CAAC,EAAE,8BAA8B,CAAC;IAC7C,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC5B,CAAC;AAEF,MAAM,WAAW,+BAA+B;IAC5C,WAAW,C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,CAAC,IAAI,EAAE,wBAAwB,GAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAEvD,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,wBAAwB,CAAC,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;CACtG"}
@@ -91,10 +91,10 @@ var OAuth2EndSessionService = class {
91
91
  name: EventName.LOGOUT,
92
92
  refType: EventRefType.SESSION,
93
93
  refId: sessionId,
94
+ sessionId,
94
95
  actorType: session.subKind,
95
96
  actorId: session.sub,
96
- realmId: session.realmId,
97
- data: { revokedSessionId: sessionId }
97
+ realmId: session.realmId
98
98
  });
99
99
  return true;
100
100
  }
@@ -1 +1 @@
1
- {"version":3,"file":"service.mjs","names":["isSimpleURLMatch","isUUID","EventName","EventRefType","EventScope","OAuth2TokenKind","OAuth2EndSessionService","tokenVerifier","sessionManager","clientRepository","realmRepository","eventService","hintGracePeriod","ctx","verify","data","hintVerified","sub","subKind","sessionId","hintRealmId","audiences","id_token_hint","payload","ignoreExpiry","skipActiveCheck","kind","ID_TOKEN","isWithinHintGraceWindow","sub_kind","sid","session_id","undefined","realm_id","aud","Array","isArray","filter","entry","clientId","client_id","length","client","realmKey","realm_name","realm","resolve","findOneByIdOrName","id","expected","includes","clientName","redirectUri","name","post_logout_redirect_uri","isValidPostLogoutRedirect","postLogoutRedirectUri","state","revoke","session","findOneById","record","scope","OAUTH2","LOGOUT","refType","SESSION","refId","actorType","actorId","realmId","revokedSessionId","exp","nowSeconds","Math","floor","Date","now","registered","candidate","parsed","URL","protocol","split"],"sources":["../../../../src/core/oauth2/end-session/service.ts"],"sourcesContent":["/*\n * Copyright (c) 2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { isSimpleURLMatch, isUUID } from '@authup/kit';\nimport type { Client, IdentityType } from '@authup/core-kit';\nimport { EventName, EventRefType, EventScope } from '@authup/core-kit';\nimport type { OAuth2TokenPayload } from '@authup/specs';\nimport { OAuth2TokenKind } from '@authup/specs';\nimport type { IEventService, IRealmRepository } from '../../entities/index.ts';\nimport type { ISessionManager } from '../../authentication/index.ts';\nimport type { IOAuth2ClientRepository } from '../client/index.ts';\nimport type { IOAuth2TokenVerifier } from '../token/index.ts';\nimport type {\n IOAuth2EndSessionService,\n OAuth2EndSessionRequest,\n OAuth2EndSessionResult,\n OAuth2EndSessionServiceContext,\n} from './types.ts';\n\nexport class OAuth2EndSessionService implements IOAuth2EndSessionService {\n protected tokenVerifier: IOAuth2TokenVerifier;\n\n protected sessionManager: ISessionManager;\n\n protected clientRepository: IOAuth2ClientRepository;\n\n protected realmRepository: IRealmRepository;\n\n protected eventService?: IEventService;\n\n protected hintGracePeriod: number;\n\n constructor(ctx: OAuth2EndSessionServiceContext) {\n this.tokenVerifier = ctx.tokenVerifier;\n this.sessionManager = ctx.sessionManager;\n this.clientRepository = ctx.clientRepository;\n this.realmRepository = ctx.realmRepository;\n this.eventService = ctx.eventService;\n this.hintGracePeriod = ctx.hintGracePeriod ?? 0;\n }\n\n async verify(data: OAuth2EndSessionRequest): Promise<OAuth2EndSessionResult> {\n let hintVerified = false;\n let sub: string | undefined;\n let subKind: string | undefined;\n let sessionId: string | undefined;\n let hintRealmId: string | undefined;\n let audiences: string[] = [];\n\n if (data.id_token_hint) {\n try {\n // Signature + kind are the anchors; exp is skipped (a logout hint\n // is routinely expired) and the cache blocklist is irrelevant.\n const payload = await this.tokenVerifier.verify(data.id_token_hint, {\n ignoreExpiry: true,\n skipActiveCheck: true,\n });\n\n // MUST be an id_token — access/refresh tokens also carry\n // session_id, so accepting them would let a leaked access token\n // act as a logout weapon.\n if (payload.kind === OAuth2TokenKind.ID_TOKEN && this.isWithinHintGraceWindow(payload)) {\n hintVerified = true;\n sub = payload.sub;\n subKind = payload.sub_kind;\n sessionId = payload.sid ?? payload.session_id ?? undefined;\n hintRealmId = payload.realm_id ?? undefined;\n // aud may be a single string or an array (JWT spec).\n const { aud } = payload;\n if (Array.isArray(aud)) {\n audiences = aud.filter((entry): entry is string => typeof entry === 'string');\n } else if (typeof aud === 'string') {\n audiences = [aud];\n }\n }\n } catch {\n // forged / unverifiable hint → stays unverified (no revoke)\n }\n }\n\n // Resolve a single client for the aud cross-check and redirect\n // validation: the request's client_id, else the hint's sole audience\n // (ambiguous for a multi-aud hint).\n const clientId = data.client_id ?? (audiences.length === 1 ? audiences[0] : undefined);\n\n let client: Client | null = null;\n if (clientId) {\n // Scope a name-identified client to the request's realm hint; a\n // VERIFIED hint's own realm claim serves as fallback (claims from an\n // unverified hint are never trusted). No master fallback here\n // (unlike /token): a bogus hint must NOT silently resolve a\n // same-named client in master → null realm.\n const realmKey = data.realm_id ?? data.realm_name ?? (hintVerified ? hintRealmId : undefined);\n const realm = await this.realmRepository.resolve(realmKey, false);\n\n // Fail closed instead of dropping the realm predicate: a supplied\n // realm key that does not resolve never degrades to an unscoped\n // lookup, and a NAME-form client_id without any realm key is\n // ambiguous (client names are only unique per realm, and every\n // realm carries the same-named system clients — same rule as the\n // /authorize verifier). A UUID is globally unique and needs no\n // scope; the sole-aud-derived clientId is always a UUID.\n if (realm) {\n client = await this.clientRepository.findOneByIdOrName(clientId, realm.id);\n } else if (!realmKey && isUUID(clientId)) {\n client = await this.clientRepository.findOneByIdOrName(clientId);\n }\n }\n\n // aud/client_id cross-check: when the request supplies a client_id on a\n // verified hint, it MUST denote one of the hint's audiences. The aud is\n // the client UUID, so a name-form client_id is compared via its resolved\n // client's id. Fail closed: an aud-less hint, or a name that did not\n // resolve, counts as unverified.\n if (hintVerified && data.client_id) {\n const expected = isUUID(data.client_id) ? data.client_id : client?.id;\n if (audiences.length === 0 || !expected || !audiences.includes(expected)) {\n hintVerified = false;\n sub = undefined;\n subKind = undefined;\n sessionId = undefined;\n }\n }\n\n let clientName: string | undefined;\n let redirectUri: string | undefined;\n\n // Redirect validation is independent of hint verification — the\n // click-gated confirm page (unverified hint / hint-less request) still\n // honors a registered post-logout redirect.\n if (client) {\n clientName = client.name;\n if (\n data.post_logout_redirect_uri &&\n this.isValidPostLogoutRedirect(client.postLogoutRedirectUri, data.post_logout_redirect_uri)\n ) {\n redirectUri = data.post_logout_redirect_uri;\n }\n }\n\n return {\n hintVerified,\n ...(hintVerified ? {\n sub,\n subKind,\n sessionId,\n } : {}),\n ...(clientId ? { clientId } : {}),\n ...(clientName ? { clientName } : {}),\n ...(redirectUri ? { redirectUri, ...(data.state ? { state: data.state } : {}) } : {}),\n };\n }\n\n async revoke(sessionId: string, sub: string, subKind: string): Promise<boolean> {\n const session = await this.sessionManager.findOneById(sessionId);\n if (!session) {\n return false;\n }\n\n // Never revoke a session that does not belong to the hint's subject.\n if (session.sub !== sub || session.subKind !== subKind) {\n return false;\n }\n\n await this.sessionManager.revoke(sessionId);\n\n await this.eventService?.record({\n scope: EventScope.OAUTH2,\n name: EventName.LOGOUT,\n refType: EventRefType.SESSION,\n refId: sessionId,\n actorType: session.subKind as `${IdentityType}`,\n actorId: session.sub,\n realmId: session.realmId,\n data: { revokedSessionId: sessionId },\n });\n\n return true;\n }\n\n /**\n * With a positive `hintGracePeriod`, an expired hint is honored only within\n * the window past `exp` — beyond it a leaked id_token stops being a\n * replayable remote logout (the hint counts as unverified; the click-gated\n * confirm page still works). 0 keeps spec/Keycloak parity: any expired hint.\n */\n protected isWithinHintGraceWindow(payload: OAuth2TokenPayload): boolean {\n if (this.hintGracePeriod <= 0) {\n return true;\n }\n\n // a bounded window without an exp claim to judge against fails closed\n if (typeof payload.exp !== 'number') {\n return false;\n }\n\n const nowSeconds = Math.floor(Date.now() / 1000);\n return nowSeconds - payload.exp <= this.hintGracePeriod;\n }\n\n /**\n * A post-logout redirect is honored only when it is an absolute http(s) URL\n * that matches a registered client redirect pattern (defense against open\n * redirects to attacker-controlled URLs).\n */\n protected isValidPostLogoutRedirect(\n registered: string | null | undefined,\n candidate: string,\n ): boolean {\n let parsed: URL;\n try {\n parsed = new URL(candidate);\n } catch {\n return false;\n }\n\n if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {\n return false;\n }\n\n if (!registered) {\n return false;\n }\n\n // isSimpleURLMatch, never isSimpleMatch: matched against the raw\n // string, a `*` in a registered pattern's host absorbs a `?`, `#` or\n // `\\`, which would turn this endpoint into a server-issued open\n // redirect carrying `state`.\n return isSimpleURLMatch(candidate, registered.split(','));\n }\n}\n"],"mappings":";;;;;;;AAuBA,IAAaM,0BAAb,MAAaA;CACCC;CAEAC;CAEAC;CAEAC;CAEAC;CAEAC;CAEV,YAAYC,KAAqC;EAC7C,KAAKN,gBAAgBM,IAAIN;EACzB,KAAKC,iBAAiBK,IAAIL;EAC1B,KAAKC,mBAAmBI,IAAIJ;EAC5B,KAAKC,kBAAkBG,IAAIH;EAC3B,KAAKC,eAAeE,IAAIF;EACxB,KAAKC,kBAAkBC,IAAID,mBAAmB;CAClD;CAEA,MAAME,OAAOC,MAAgE;EACzE,IAAIC,eAAe;EACnB,IAAIC;EACJ,IAAIC;EACJ,IAAIC;EACJ,IAAIC;EACJ,IAAIC,YAAsB,CAAA;EAE1B,IAAIN,KAAKO,eACL,IAAI;GAGA,MAAMC,UAAU,MAAM,KAAKhB,cAAcO,OAAOC,KAAKO,eAAe;IAChEE,cAAc;IACdC,iBAAiB;GACrB,CAAA;GAKA,IAAIF,QAAQG,SAASrB,gBAAgBsB,YAAY,KAAKC,wBAAwBL,OAAAA,GAAU;IACpFP,eAAe;IACfC,MAAMM,QAAQN;IACdC,UAAUK,QAAQM;IAClBV,YAAYI,QAAQO,OAAOP,QAAQQ,cAAcC,KAAAA;IACjDZ,cAAcG,QAAQU,YAAYD,KAAAA;IAElC,MAAM,EAAEE,QAAQX;IAChB,IAAIY,MAAMC,QAAQF,GAAAA,GACdb,YAAYa,IAAIG,QAAQC,UAA2B,OAAOA,UAAU,QAAA;SACjE,IAAI,OAAOJ,QAAQ,UACtBb,YAAY,CAACa,GAAI;GAEzB;EACJ,QAAQ,CAER;EAMJ,MAAMK,WAAW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AAmC;EAC5E,MAAMyC,UAAU,MAAM,KAAKnD,eAAeoD,YAAYzC,SAAAA;EACtD,IAAI,CAACwC,SACD,OAAO;EAIX,IAAIA,QAAQ1C,QAAQA,OAAO0C,QAAQzC,YAAYA,SAC3C,OAAO;EAGX,MAAM,KAAKV,eAAekD,OAAOvC,SAAAA;EAEjC,MAAM,KAAKR,cAAckD,OAAO;GAC5BC,OAAO1D,WAAW2D;GAClBV,MAAMnD,UAAU8D;GAChBC,SAAS9D,aAAa+D;GACtBC,OAAOhD;GACPiD,WAAWT,QAAQzC;GACnBmD,SAASV,QAAQ1C;GACjBqD,SAASX,QAAQW;GACjBvD,MAAM,EAAEwD,kBAAkBpD,UAAU;EACxC,CAAA;EAEA,OAAO;CACX;;;;;;IAQA,wBAAkCI,SAAsC;EACpE,IAAI,KAAKX,mBAAmB,GACxB,OAAO;EAIX,IAAI,OAAOW,QAAQiD,QAAQ,UACvB,OAAO;EAIX,OADmBE,KAAKC,MAAMC,KAAKC,IAAG,IAAK,GACpCJ,IAAalD,QAAQiD,OAAO,KAAK5D;CAC5C;;;;;IAOA,0BACIkE,YACAC,WACO;EACP,IAAIC;EACJ,IAAI;GACAA,SAAS,IAAIC,IAAIF,SAAAA;EACrB,QAAQ;GACJ,OAAO;EACX;EAEA,IAAIC,OAAOE,aAAa,WAAWF,OAAOE,aAAa,UACnD,OAAO;EAGX,IAAI,CAACJ,YACD,OAAO;EAOX,OAAO9E,iBAAiB+E,WAAWD,WAAWK,MAAM,GAAA,CAAA;CACxD;AACJ"}
1
+ {"version":3,"file":"service.mjs","names":["isSimpleURLMatch","isUUID","EventName","EventRefType","EventScope","OAuth2TokenKind","OAuth2EndSessionService","tokenVerifier","sessionManager","clientRepository","realmRepository","eventService","hintGracePeriod","ctx","verify","data","hintVerified","sub","subKind","sessionId","hintRealmId","audiences","id_token_hint","payload","ignoreExpiry","skipActiveCheck","kind","ID_TOKEN","isWithinHintGraceWindow","sub_kind","sid","session_id","undefined","realm_id","aud","Array","isArray","filter","entry","clientId","client_id","length","client","realmKey","realm_name","realm","resolve","findOneByIdOrName","id","expected","includes","clientName","redirectUri","name","post_logout_redirect_uri","isValidPostLogoutRedirect","postLogoutRedirectUri","state","revoke","session","findOneById","record","scope","OAUTH2","LOGOUT","refType","SESSION","refId","actorType","actorId","realmId","exp","nowSeconds","Math","floor","Date","now","registered","candidate","parsed","URL","protocol","split"],"sources":["../../../../src/core/oauth2/end-session/service.ts"],"sourcesContent":["/*\n * Copyright (c) 2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { isSimpleURLMatch, isUUID } from '@authup/kit';\nimport type { Client, IdentityType } from '@authup/core-kit';\nimport { EventName, EventRefType, EventScope } from '@authup/core-kit';\nimport type { OAuth2TokenPayload } from '@authup/specs';\nimport { OAuth2TokenKind } from '@authup/specs';\nimport type { IEventService, IRealmRepository } from '../../entities/index.ts';\nimport type { ISessionManager } from '../../authentication/index.ts';\nimport type { IOAuth2ClientRepository } from '../client/index.ts';\nimport type { IOAuth2TokenVerifier } from '../token/index.ts';\nimport type {\n IOAuth2EndSessionService,\n OAuth2EndSessionRequest,\n OAuth2EndSessionResult,\n OAuth2EndSessionServiceContext,\n} from './types.ts';\n\nexport class OAuth2EndSessionService implements IOAuth2EndSessionService {\n protected tokenVerifier: IOAuth2TokenVerifier;\n\n protected sessionManager: ISessionManager;\n\n protected clientRepository: IOAuth2ClientRepository;\n\n protected realmRepository: IRealmRepository;\n\n protected eventService?: IEventService;\n\n protected hintGracePeriod: number;\n\n constructor(ctx: OAuth2EndSessionServiceContext) {\n this.tokenVerifier = ctx.tokenVerifier;\n this.sessionManager = ctx.sessionManager;\n this.clientRepository = ctx.clientRepository;\n this.realmRepository = ctx.realmRepository;\n this.eventService = ctx.eventService;\n this.hintGracePeriod = ctx.hintGracePeriod ?? 0;\n }\n\n async verify(data: OAuth2EndSessionRequest): Promise<OAuth2EndSessionResult> {\n let hintVerified = false;\n let sub: string | undefined;\n let subKind: string | undefined;\n let sessionId: string | undefined;\n let hintRealmId: string | undefined;\n let audiences: string[] = [];\n\n if (data.id_token_hint) {\n try {\n // Signature + kind are the anchors; exp is skipped (a logout hint\n // is routinely expired) and the cache blocklist is irrelevant.\n const payload = await this.tokenVerifier.verify(data.id_token_hint, {\n ignoreExpiry: true,\n skipActiveCheck: true,\n });\n\n // MUST be an id_token — access/refresh tokens also carry\n // session_id, so accepting them would let a leaked access token\n // act as a logout weapon.\n if (payload.kind === OAuth2TokenKind.ID_TOKEN && this.isWithinHintGraceWindow(payload)) {\n hintVerified = true;\n sub = payload.sub;\n subKind = payload.sub_kind;\n sessionId = payload.sid ?? payload.session_id ?? undefined;\n hintRealmId = payload.realm_id ?? undefined;\n // aud may be a single string or an array (JWT spec).\n const { aud } = payload;\n if (Array.isArray(aud)) {\n audiences = aud.filter((entry): entry is string => typeof entry === 'string');\n } else if (typeof aud === 'string') {\n audiences = [aud];\n }\n }\n } catch {\n // forged / unverifiable hint → stays unverified (no revoke)\n }\n }\n\n // Resolve a single client for the aud cross-check and redirect\n // validation: the request's client_id, else the hint's sole audience\n // (ambiguous for a multi-aud hint).\n const clientId = data.client_id ?? (audiences.length === 1 ? audiences[0] : undefined);\n\n let client: Client | null = null;\n if (clientId) {\n // Scope a name-identified client to the request's realm hint; a\n // VERIFIED hint's own realm claim serves as fallback (claims from an\n // unverified hint are never trusted). No master fallback here\n // (unlike /token): a bogus hint must NOT silently resolve a\n // same-named client in master → null realm.\n const realmKey = data.realm_id ?? data.realm_name ?? (hintVerified ? hintRealmId : undefined);\n const realm = await this.realmRepository.resolve(realmKey, false);\n\n // Fail closed instead of dropping the realm predicate: a supplied\n // realm key that does not resolve never degrades to an unscoped\n // lookup, and a NAME-form client_id without any realm key is\n // ambiguous (client names are only unique per realm, and every\n // realm carries the same-named system clients — same rule as the\n // /authorize verifier). A UUID is globally unique and needs no\n // scope; the sole-aud-derived clientId is always a UUID.\n if (realm) {\n client = await this.clientRepository.findOneByIdOrName(clientId, realm.id);\n } else if (!realmKey && isUUID(clientId)) {\n client = await this.clientRepository.findOneByIdOrName(clientId);\n }\n }\n\n // aud/client_id cross-check: when the request supplies a client_id on a\n // verified hint, it MUST denote one of the hint's audiences. The aud is\n // the client UUID, so a name-form client_id is compared via its resolved\n // client's id. Fail closed: an aud-less hint, or a name that did not\n // resolve, counts as unverified.\n if (hintVerified && data.client_id) {\n const expected = isUUID(data.client_id) ? data.client_id : client?.id;\n if (audiences.length === 0 || !expected || !audiences.includes(expected)) {\n hintVerified = false;\n sub = undefined;\n subKind = undefined;\n sessionId = undefined;\n }\n }\n\n let clientName: string | undefined;\n let redirectUri: string | undefined;\n\n // Redirect validation is independent of hint verification — the\n // click-gated confirm page (unverified hint / hint-less request) still\n // honors a registered post-logout redirect.\n if (client) {\n clientName = client.name;\n if (\n data.post_logout_redirect_uri &&\n this.isValidPostLogoutRedirect(client.postLogoutRedirectUri, data.post_logout_redirect_uri)\n ) {\n redirectUri = data.post_logout_redirect_uri;\n }\n }\n\n return {\n hintVerified,\n ...(hintVerified ? {\n sub,\n subKind,\n sessionId,\n } : {}),\n ...(clientId ? { clientId } : {}),\n ...(clientName ? { clientName } : {}),\n ...(redirectUri ? { redirectUri, ...(data.state ? { state: data.state } : {}) } : {}),\n };\n }\n\n async revoke(sessionId: string, sub: string, subKind: string): Promise<boolean> {\n const session = await this.sessionManager.findOneById(sessionId);\n if (!session) {\n return false;\n }\n\n // Never revoke a session that does not belong to the hint's subject.\n if (session.sub !== sub || session.subKind !== subKind) {\n return false;\n }\n\n await this.sessionManager.revoke(sessionId);\n\n await this.eventService?.record({\n scope: EventScope.OAUTH2,\n name: EventName.LOGOUT,\n refType: EventRefType.SESSION,\n refId: sessionId,\n sessionId,\n actorType: session.subKind as `${IdentityType}`,\n actorId: session.sub,\n realmId: session.realmId,\n });\n\n return true;\n }\n\n /**\n * With a positive `hintGracePeriod`, an expired hint is honored only within\n * the window past `exp` — beyond it a leaked id_token stops being a\n * replayable remote logout (the hint counts as unverified; the click-gated\n * confirm page still works). 0 keeps spec/Keycloak parity: any expired hint.\n */\n protected isWithinHintGraceWindow(payload: OAuth2TokenPayload): boolean {\n if (this.hintGracePeriod <= 0) {\n return true;\n }\n\n // a bounded window without an exp claim to judge against fails closed\n if (typeof payload.exp !== 'number') {\n return false;\n }\n\n const nowSeconds = Math.floor(Date.now() / 1000);\n return nowSeconds - payload.exp <= this.hintGracePeriod;\n }\n\n /**\n * A post-logout redirect is honored only when it is an absolute http(s) URL\n * that matches a registered client redirect pattern (defense against open\n * redirects to attacker-controlled URLs).\n */\n protected isValidPostLogoutRedirect(\n registered: string | null | undefined,\n candidate: string,\n ): boolean {\n let parsed: URL;\n try {\n parsed = new URL(candidate);\n } catch {\n return false;\n }\n\n if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {\n return false;\n }\n\n if (!registered) {\n return false;\n }\n\n // isSimpleURLMatch, never isSimpleMatch: matched against the raw\n // string, a `*` in a registered pattern's host absorbs a `?`, `#` or\n // `\\`, which would turn this endpoint into a server-issued open\n // redirect carrying `state`.\n return isSimpleURLMatch(candidate, registered.split(','));\n }\n}\n"],"mappings":";;;;;;;AAuBA,IAAaM,0BAAb,MAAaA;CACCC;CAEAC;CAEAC;CAEAC;CAEAC;CAEAC;CAEV,YAAYC,KAAqC;EAC7C,KAAKN,gBAAgBM,IAAIN;EACzB,KAAKC,iBAAiBK,IAAIL;EAC1B,KAAKC,mBAAmBI,IAAIJ;EAC5B,KAAKC,kBAAkBG,IAAIH;EAC3B,KAAKC,eAAeE,IAAIF;EACxB,KAAKC,kBAAkBC,IAAID,mBAAmB;CAClD;CAEA,MAAME,OAAOC,MAAgE;EACzE,IAAIC,eAAe;EACnB,IAAIC;EACJ,IAAIC;EACJ,IAAIC;EACJ,IAAIC;EACJ,IAAIC,YAAsB,CAAA;EAE1B,IAAIN,KAAKO,eACL,IAAI;GAGA,MAAMC,UAAU,MAAM,KAAKhB,cAAcO,OAA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J,OAAO;EACX;EAEA,IAAIC,OAAOE,aAAa,WAAWF,OAAOE,aAAa,UACnD,OAAO;EAGX,IAAI,CAACJ,YACD,OAAO;EAOX,OAAO7E,iBAAiB8E,WAAWD,WAAWK,MAAM,GAAA,CAAA;CACxD;AACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"authorize.d.ts","sourceRoot":"","sources":["../../../../src/core/oauth2/grant-types/authorize.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,wBAAwB,EAAsB,MAAM,eAAe,CAAC;AAElF,OAAO,KAAK,EAAE,uBAAuB,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAGzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,2BAA2B,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAIvG,qBAAa,oBAAqB,SAAQ,eAAe,CAAC,uBAAuB,CAAE,YAAW,YAAY;IACtG,SAAS,CAAC,kBAAkB,EAAG,kBAAkB,CAAC;IAElD,SAAS,CAAC,iBAAiB,EAAG,wBAAwB,CAAC;IAEvD,SAAS,CAAC,QAAQ,EAAG,SAAS,CAAC;gBAEnB,GAAG,EAAE,2BAA2B;IAWtC,OAAO,CACT,iBAAiB,EAAE,uBAAuB,EAC1C,OAAO,GAAE,yBAA8B,GACvC,OAAO,CAAC,wBAAwB,CAAC;IAmErC;;;;;;;;;;;;OAYG;cACa,cAAc,CAC1B,iBAAiB,EAAE,uBAAuB,EAC1C,OAAO,EAAE,yBAAyB,GAClC,OAAO,CAAC,OAAO,CAAC;CAyBvB"}
1
+ {"version":3,"file":"authorize.d.ts","sourceRoot":"","sources":["../../../../src/core/oauth2/grant-types/authorize.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,wBAAwB,EAAsB,MAAM,eAAe,CAAC;AAElF,OAAO,KAAK,EAAE,uBAAuB,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAGzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,2BAA2B,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAIvG,qBAAa,oBAAqB,SAAQ,eAAe,CAAC,uBAAuB,CAAE,YAAW,YAAY;IACtG,SAAS,CAAC,kBAAkB,EAAG,kBAAkB,CAAC;IAElD,SAAS,CAAC,iBAAiB,EAAG,wBAAwB,CAAC;IAEvD,SAAS,CAAC,QAAQ,EAAG,SAAS,CAAC;gBAEnB,GAAG,EAAE,2BAA2B;IAWtC,OAAO,CACT,iBAAiB,EAAE,uBAAuB,EAC1C,OAAO,GAAE,yBAA8B,GACvC,OAAO,CAAC,wBAAwB,CAAC;IAmErC;;;;;;;;;;;;OAYG;cACa,cAAc,CAC1B,iBAAiB,EAAE,uBAAuB,EAC1C,OAAO,EAAE,yBAAyB,GAClC,OAAO,CAAC,OAAO,CAAC;CAmCvB"}
@@ -78,16 +78,12 @@ var OAuth2AuthorizeGrant = class extends OAuth2BaseGrant {
78
78
  */ async resolveSession(authorizationCode, options) {
79
79
  if (authorizationCode.session_id) {
80
80
  const existing = await this.sessionManager.findOneById(authorizationCode.session_id);
81
- if (existing && existing.sub === authorizationCode.sub && existing.subKind === authorizationCode.sub_kind && existing.realmId === authorizationCode.realm_id) {
82
- existing.clientId = authorizationCode.client_id || null;
83
- return this.sessionManager.refresh(existing);
84
- }
81
+ if (existing && existing.sub === authorizationCode.sub && existing.subKind === authorizationCode.sub_kind && existing.realmId === authorizationCode.realm_id) return this.sessionManager.refresh(existing);
85
82
  }
86
83
  return this.sessionManager.create({
87
84
  userAgent: options.userAgent,
88
85
  ipAddress: options.ipAddress,
89
86
  realmId: authorizationCode.realm_id,
90
- clientId: authorizationCode.client_id,
91
87
  subKind: authorizationCode.sub_kind,
92
88
  sub: authorizationCode.sub,
93
89
  authMethod: authorizationCode.auth_method ?? null
@@ -1 +1 @@
1
- {"version":3,"file":"authorize.mjs","names":["JWKUse","hasOAuth2Scopes","ScopeName","buildOAuth2TokenHash","deriveAmrAcr","OAuth2BaseGrant","buildOAuth2BearerTokenResponse","OAuth2AuthorizeGrant","refreshTokenIssuer","openIdTokenIssuer","keyStore","ctx","accessTokenIssuer","sessionManager","runWith","authorizationCode","options","session","resolveSession","amrAcr","issuePayload","user_agent","userAgent","remote_address","ipAddress","session_id","id","sub","undefined","sub_kind","realm_id","realm_name","scope","client_id","confirmation","cnf","accessToken","accessTokenPayload","issue","refreshToken","refreshTokenPayload","buildContext","OPEN_ID","key","resolveOrCreate","SIGNATURE","idToken","nonce","auth_time","sid","at_hash","signatureAlgorithm","existing","findOneById","subKind","realmId","clientId","refresh","create","authMethod","auth_method"],"sources":["../../../../src/core/oauth2/grant-types/authorize.ts"],"sourcesContent":["/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { OAuth2TokenGrantResponse, OAuth2TokenPayload } from '@authup/specs';\nimport { JWKUse, hasOAuth2Scopes } from '@authup/specs';\nimport type { OAuth2AuthorizationCode, Session } from '@authup/core-kit';\nimport { ScopeName } from '@authup/core-kit';\nimport { buildOAuth2TokenHash, deriveAmrAcr } from '../authorization/helpers.ts';\nimport type { IKeyStore } from '../../key/index.ts';\nimport type { IOAuth2OpenIDTokenIssuer, IOAuth2TokenIssuer } from '../token/index.ts';\nimport { OAuth2BaseGrant } from './base.ts';\nimport type { IOAuth2Grant, OAuth2AuthorizeGrantContext, OAuth2GrantRunWIthOptions } from './types.ts';\nimport type { OAuth2BearerResponseBuildContext } from '../response/index.ts';\nimport { buildOAuth2BearerTokenResponse } from '../response/index.ts';\n\nexport class OAuth2AuthorizeGrant extends OAuth2BaseGrant<OAuth2AuthorizationCode> implements IOAuth2Grant {\n protected refreshTokenIssuer : IOAuth2TokenIssuer;\n\n protected openIdTokenIssuer : IOAuth2OpenIDTokenIssuer;\n\n protected keyStore : IKeyStore;\n\n constructor(ctx: OAuth2AuthorizeGrantContext) {\n super({\n accessTokenIssuer: ctx.accessTokenIssuer,\n sessionManager: ctx.sessionManager,\n });\n\n this.refreshTokenIssuer = ctx.refreshTokenIssuer;\n this.openIdTokenIssuer = ctx.openIdTokenIssuer;\n this.keyStore = ctx.keyStore;\n }\n\n async runWith(\n authorizationCode: OAuth2AuthorizationCode,\n options: OAuth2GrantRunWIthOptions = {},\n ) : Promise<OAuth2TokenGrantResponse> {\n const session = await this.resolveSession(authorizationCode, options);\n\n // amr/acr derive from the RESOLVED session (authMethod + mfaAt) —\n // deliberately on every token kind, not only the id_token, so\n // resource servers can read the method without parsing an id_token.\n const amrAcr = deriveAmrAcr(session);\n\n const issuePayload : Partial<OAuth2TokenPayload> = {\n user_agent: options.userAgent,\n remote_address: options.ipAddress,\n session_id: session.id,\n sub: authorizationCode.sub || undefined,\n sub_kind: authorizationCode.sub_kind,\n realm_id: authorizationCode.realm_id,\n realm_name: authorizationCode.realm_name,\n scope: authorizationCode.scope || undefined,\n client_id: authorizationCode.client_id || undefined,\n ...(options.confirmation ? { cnf: options.confirmation } : {}),\n ...amrAcr,\n };\n\n const [accessToken, accessTokenPayload] = await this.accessTokenIssuer.issue(issuePayload);\n const [refreshToken, refreshTokenPayload] = await this.refreshTokenIssuer.issue(issuePayload);\n\n const buildContext : OAuth2BearerResponseBuildContext = {\n accessToken,\n accessTokenPayload,\n refreshToken,\n refreshTokenPayload,\n };\n\n // The id_token is minted HERE — after resolveSession — so its `sid`\n // references the real backing session for the reuse branch, the\n // fallback branch, and session-less (federated IdP) codes alike.\n // `auth_time` is the authentication instant captured on the code.\n if (\n authorizationCode.scope &&\n hasOAuth2Scopes(authorizationCode.scope, ScopeName.OPEN_ID)\n ) {\n // The at_hash digest follows the id_token's JWS alg (OIDC Core\n // §3.1.3.6) — the alg of the realm key the openid issuer signs\n // with. The access token above was signed with the same key, so a\n // missing key would already have thrown; this resolves the same\n // active key.\n const key = await this.keyStore.resolveOrCreate(authorizationCode.realm_id, JWKUse.SIGNATURE);\n\n const [idToken] = await this.openIdTokenIssuer.issue({\n sub: authorizationCode.sub || undefined,\n sub_kind: authorizationCode.sub_kind,\n realm_id: authorizationCode.realm_id,\n realm_name: authorizationCode.realm_name,\n scope: authorizationCode.scope || undefined,\n client_id: authorizationCode.client_id || undefined,\n ...(authorizationCode.nonce ? { nonce: authorizationCode.nonce } : {}),\n ...(typeof authorizationCode.auth_time === 'number' ? { auth_time: authorizationCode.auth_time } : {}),\n ...amrAcr,\n sid: session.id,\n at_hash: await buildOAuth2TokenHash(accessToken, key.signatureAlgorithm),\n });\n\n buildContext.idToken = idToken;\n }\n\n return buildOAuth2BearerTokenResponse(buildContext);\n }\n\n /**\n * Reuse the bearer's session when the authorization code was issued from an\n * (interactive) `/authorize` request that carried one — otherwise the\n * interactive login would create a second session (the abandoned bearer\n * session that authenticated `POST /authorize`, plus this one).\n *\n * The reuse is gated on the session still existing and belonging to the\n * same subject/realm as the code (defense in depth — the id is\n * server-derived from the authenticated bearer, never client input). Any\n * mismatch, or a session-less authorize flow (external IdP, non-interactive\n * clients), falls back to creating a fresh session — preserving prior\n * behavior.\n */\n protected async resolveSession(\n authorizationCode: OAuth2AuthorizationCode,\n options: OAuth2GrantRunWIthOptions,\n ) : Promise<Session> {\n if (authorizationCode.session_id) {\n const existing = await this.sessionManager.findOneById(authorizationCode.session_id);\n if (\n existing &&\n existing.sub === authorizationCode.sub &&\n existing.subKind === authorizationCode.sub_kind &&\n existing.realmId === authorizationCode.realm_id\n ) {\n existing.clientId = authorizationCode.client_id || null;\n\n return this.sessionManager.refresh(existing);\n }\n }\n\n return this.sessionManager.create({\n userAgent: options.userAgent,\n ipAddress: options.ipAddress,\n realmId: authorizationCode.realm_id,\n clientId: authorizationCode.client_id,\n subKind: authorizationCode.sub_kind,\n sub: authorizationCode.sub,\n authMethod: authorizationCode.auth_method ?? null,\n });\n }\n}\n"],"mappings":";;;;;;;;;AAmBA,IAAaO,uBAAb,cAA0CF,gBAAAA;CAC5BG;CAEAC;CAEAC;CAEV,YAAYC,KAAkC;EAC1C,MAAM;GACFC,mBAAmBD,IAAIC;GACvBC,gBAAgBF,IAAIE;EACxB,CAAA;EAEA,KAAKL,qBAAqBG,IAAIH;EAC9B,KAAKC,oBAAoBE,IAAIF;EAC7B,KAAKC,WAAWC,IAAID;CACxB;CAEA,MAAMI,QACFC,mBACAC,UAAqC,CAAC,GACJ;EAClC,MAAMC,UAAU,MAAM,KAAKC,eAAeH,mBAAmBC,OAAAA;EAK7D,MAAMG,SAASf,aAAaa,OAAAA;EAE5B,MAAMG,eAA6C;GAC/CC,YAAYL,QAAQM;GACpBC,gBAAgBP,QAAQQ;GACxBC,YAAYR,QAAQS;GACpBC,KAAKZ,kBAAkBY,OAAOC,KAAAA;GAC9BC,UAAUd,kBAAkBc;GAC5BC,UAAUf,kBAAkBe;GAC5BC,YAAYhB,kBAAkBgB;GAC9BC,OAAOjB,kBAAkBiB,SAASJ,KAAAA;GAClCK,WAAWlB,kBAAkBkB,aAAaL,KAAAA;GAC1C,GAAIZ,QAAQkB,eAAe,EAAEC,KAAKnB,QAAQkB,aAAa,IAAI,CAAC;GAC5D,GAAGf;EACP;EAEA,MAAM,CAACiB,aAAaC,sBAAsB,MAAM,KAAKzB,kBAAkB0B,MAAMlB,YAAAA;EAC7E,MAAM,CAACmB,cAAcC,uBAAuB,MAAM,KAAKhC,mBAAmB8B,MAAMlB,YAAAA;EAEhF,MAAMqB,eAAkD;GACpDL;GACAC;GACAE;GACAC;EACJ;EAMA,IACIzB,kBAA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BkB;GAC5BqB,SAASvC,kBAAkBc;GAC3BF,KAAKZ,kBAAkBY;GACvBgC,YAAY5C,kBAAkB6C,eAAe;EACjD,CAAA;CACJ;AACJ"}
1
+ {"version":3,"file":"authorize.mjs","names":["JWKUse","hasOAuth2Scopes","ScopeName","buildOAuth2TokenHash","deriveAmrAcr","OAuth2BaseGrant","buildOAuth2BearerTokenResponse","OAuth2AuthorizeGrant","refreshTokenIssuer","openIdTokenIssuer","keyStore","ctx","accessTokenIssuer","sessionManager","runWith","authorizationCode","options","session","resolveSession","amrAcr","issuePayload","user_agent","userAgent","remote_address","ipAddress","session_id","id","sub","undefined","sub_kind","realm_id","realm_name","scope","client_id","confirmation","cnf","accessToken","accessTokenPayload","issue","refreshToken","refreshTokenPayload","buildContext","OPEN_ID","key","resolveOrCreate","SIGNATURE","idToken","nonce","auth_time","sid","at_hash","signatureAlgorithm","existing","findOneById","subKind","realmId","refresh","create","authMethod","auth_method"],"sources":["../../../../src/core/oauth2/grant-types/authorize.ts"],"sourcesContent":["/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { OAuth2TokenGrantResponse, OAuth2TokenPayload } from '@authup/specs';\nimport { JWKUse, hasOAuth2Scopes } from '@authup/specs';\nimport type { OAuth2AuthorizationCode, Session } from '@authup/core-kit';\nimport { ScopeName } from '@authup/core-kit';\nimport { buildOAuth2TokenHash, deriveAmrAcr } from '../authorization/helpers.ts';\nimport type { IKeyStore } from '../../key/index.ts';\nimport type { IOAuth2OpenIDTokenIssuer, IOAuth2TokenIssuer } from '../token/index.ts';\nimport { OAuth2BaseGrant } from './base.ts';\nimport type { IOAuth2Grant, OAuth2AuthorizeGrantContext, OAuth2GrantRunWIthOptions } from './types.ts';\nimport type { OAuth2BearerResponseBuildContext } from '../response/index.ts';\nimport { buildOAuth2BearerTokenResponse } from '../response/index.ts';\n\nexport class OAuth2AuthorizeGrant extends OAuth2BaseGrant<OAuth2AuthorizationCode> implements IOAuth2Grant {\n protected refreshTokenIssuer : IOAuth2TokenIssuer;\n\n protected openIdTokenIssuer : IOAuth2OpenIDTokenIssuer;\n\n protected keyStore : IKeyStore;\n\n constructor(ctx: OAuth2AuthorizeGrantContext) {\n super({\n accessTokenIssuer: ctx.accessTokenIssuer,\n sessionManager: ctx.sessionManager,\n });\n\n this.refreshTokenIssuer = ctx.refreshTokenIssuer;\n this.openIdTokenIssuer = ctx.openIdTokenIssuer;\n this.keyStore = ctx.keyStore;\n }\n\n async runWith(\n authorizationCode: OAuth2AuthorizationCode,\n options: OAuth2GrantRunWIthOptions = {},\n ) : Promise<OAuth2TokenGrantResponse> {\n const session = await this.resolveSession(authorizationCode, options);\n\n // amr/acr derive from the RESOLVED session (authMethod + mfaAt) —\n // deliberately on every token kind, not only the id_token, so\n // resource servers can read the method without parsing an id_token.\n const amrAcr = deriveAmrAcr(session);\n\n const issuePayload : Partial<OAuth2TokenPayload> = {\n user_agent: options.userAgent,\n remote_address: options.ipAddress,\n session_id: session.id,\n sub: authorizationCode.sub || undefined,\n sub_kind: authorizationCode.sub_kind,\n realm_id: authorizationCode.realm_id,\n realm_name: authorizationCode.realm_name,\n scope: authorizationCode.scope || undefined,\n client_id: authorizationCode.client_id || undefined,\n ...(options.confirmation ? { cnf: options.confirmation } : {}),\n ...amrAcr,\n };\n\n const [accessToken, accessTokenPayload] = await this.accessTokenIssuer.issue(issuePayload);\n const [refreshToken, refreshTokenPayload] = await this.refreshTokenIssuer.issue(issuePayload);\n\n const buildContext : OAuth2BearerResponseBuildContext = {\n accessToken,\n accessTokenPayload,\n refreshToken,\n refreshTokenPayload,\n };\n\n // The id_token is minted HERE — after resolveSession — so its `sid`\n // references the real backing session for the reuse branch, the\n // fallback branch, and session-less (federated IdP) codes alike.\n // `auth_time` is the authentication instant captured on the code.\n if (\n authorizationCode.scope &&\n hasOAuth2Scopes(authorizationCode.scope, ScopeName.OPEN_ID)\n ) {\n // The at_hash digest follows the id_token's JWS alg (OIDC Core\n // §3.1.3.6) — the alg of the realm key the openid issuer signs\n // with. The access token above was signed with the same key, so a\n // missing key would already have thrown; this resolves the same\n // active key.\n const key = await this.keyStore.resolveOrCreate(authorizationCode.realm_id, JWKUse.SIGNATURE);\n\n const [idToken] = await this.openIdTokenIssuer.issue({\n sub: authorizationCode.sub || undefined,\n sub_kind: authorizationCode.sub_kind,\n realm_id: authorizationCode.realm_id,\n realm_name: authorizationCode.realm_name,\n scope: authorizationCode.scope || undefined,\n client_id: authorizationCode.client_id || undefined,\n ...(authorizationCode.nonce ? { nonce: authorizationCode.nonce } : {}),\n ...(typeof authorizationCode.auth_time === 'number' ? { auth_time: authorizationCode.auth_time } : {}),\n ...amrAcr,\n sid: session.id,\n at_hash: await buildOAuth2TokenHash(accessToken, key.signatureAlgorithm),\n });\n\n buildContext.idToken = idToken;\n }\n\n return buildOAuth2BearerTokenResponse(buildContext);\n }\n\n /**\n * Reuse the bearer's session when the authorization code was issued from an\n * (interactive) `/authorize` request that carried one — otherwise the\n * interactive login would create a second session (the abandoned bearer\n * session that authenticated `POST /authorize`, plus this one).\n *\n * The reuse is gated on the session still existing and belonging to the\n * same subject/realm as the code (defense in depth — the id is\n * server-derived from the authenticated bearer, never client input). Any\n * mismatch, or a session-less authorize flow (external IdP, non-interactive\n * clients), falls back to creating a fresh session — preserving prior\n * behavior.\n */\n protected async resolveSession(\n authorizationCode: OAuth2AuthorizationCode,\n options: OAuth2GrantRunWIthOptions,\n ) : Promise<Session> {\n if (authorizationCode.session_id) {\n const existing = await this.sessionManager.findOneById(authorizationCode.session_id);\n if (\n existing &&\n existing.sub === authorizationCode.sub &&\n existing.subKind === authorizationCode.sub_kind &&\n existing.realmId === authorizationCode.realm_id\n ) {\n // `auth_sessions.client_id` is deliberately NOT touched. It\n // is the client-SUBJECT foreign key, the counterpart of\n // `user_id` that `SessionManager.create` populates from `sub`\n // when `subKind` is client, and its ON DELETE CASCADE means\n // \"this client owns this row\". Writing the authorizing\n // application into it put an unrelated id behind that cascade,\n // so deleting that application deleted a USER's session and,\n // through `auth_session_tokens.session_id`, every other\n // application's tokens on it.\n //\n // Which application authorized is recorded per token, on\n // `auth_session_tokens.client_id`, where a session serving\n // several applications can say so.\n return this.sessionManager.refresh(existing);\n }\n }\n\n return this.sessionManager.create({\n userAgent: options.userAgent,\n ipAddress: options.ipAddress,\n realmId: authorizationCode.realm_id,\n subKind: authorizationCode.sub_kind,\n sub: authorizationCode.sub,\n authMethod: authorizationCode.auth_method ?? null,\n });\n }\n}\n"],"mappings":";;;;;;;;;AAmBA,IAAaO,uBAAb,cAA0CF,gBAAAA;CAC5BG;CAEAC;CAEAC;CAEV,YAAYC,KAAkC;EAC1C,MAAM;GACFC,mBAAmBD,IAAIC;GACvBC,gBAAgBF,IAAIE;EACxB,CAAA;EAEA,KAAKL,qBAAqBG,IAAIH;EAC9B,KAAKC,oBAAoBE,IAAIF;EAC7B,KAAKC,WAAWC,IAAID;CACxB;CAEA,MAAMI,QACFC,mBACAC,UAAqC,CAAC,GACJ;EAClC,MAAMC,UAAU,MAAM,KAAKC,eAAeH,mBAAmBC,OAAAA;EAK7D,MAAMG,SAASf,aAAaa,OAAAA;EAE5B,MAAMG,eAA6C;GAC/CC,YAAYL,QAAQM;GACpBC,gBAAgBP,QAAQQ;GACxBC,YAAYR,QAAQS;GACpBC,KAAKZ,kBAAkBY,OAAOC,KAAAA;GAC9BC,UAAUd,kBAAkBc;GAC5BC,UAAUf,kBAAkBe;GAC5BC,YAAYhB,kBAAkBgB;GAC9BC,OAAOjB,kBAAkBiB,SAASJ,KAAAA;GAClCK,WAAWlB,kBAAkBkB,aAAaL,KAAAA;GAC1C,GAAIZ,QAAQkB,eAAe,EAAEC,KAAKnB,QAAQkB,aAAa,IAAI,CAAC;GAC5D,GAAGf;EACP;EAEA,MAAM,CAACiB,aAAaC,sBAAsB,MAAM,KAAKzB,kBAAkB0B,MAAMlB,YAAAA;EAC7E,MAAM,CAACmB,cAAcC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;GACnBE,WAAWR,QAAQQ;GACnB+B,SAASxC,kBAAkBe;GAC3BwB,SAASvC,kBAAkBc;GAC3BF,KAAKZ,kBAAkBY;GACvB+B,YAAY3C,kBAAkB4C,eAAe;EACjD,CAAA;CACJ;AACJ"}
@@ -27,7 +27,6 @@ var PasswordGrantType = class extends OAuth2BaseGrant {
27
27
  userAgent: options.userAgent,
28
28
  ipAddress: options.ipAddress,
29
29
  realmId: user.realmId,
30
- clientId,
31
30
  sub: user.id,
32
31
  subKind: IdentityType.USER,
33
32
  mfaAt: input.mfaVerifiedAt ?? null,
@@ -55,16 +54,14 @@ var PasswordGrantType = class extends OAuth2BaseGrant {
55
54
  refType: EventRefType.SESSION,
56
55
  refId: session.id,
57
56
  clientId: clientId ?? null,
57
+ sessionId: session.id,
58
58
  actorType: IdentityType.USER,
59
59
  actorId: user.id,
60
60
  actorName: user.name,
61
61
  realmId: user.realmId,
62
62
  requestIpAddress: options.ipAddress ?? null,
63
63
  requestUserAgent: options.userAgent ?? null,
64
- data: {
65
- grantType: OAuth2TokenGrant.PASSWORD,
66
- sessionId: session.id
67
- }
64
+ data: { grantType: OAuth2TokenGrant.PASSWORD }
68
65
  });
69
66
  this.metrics?.recordLogin("success");
70
67
  return buildOAuth2BearerTokenResponse({