@udibo/oauth2 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (375) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +174 -0
  3. package/SECURITY.md +77 -0
  4. package/esm/_dnt.polyfills.d.ts +17 -0
  5. package/esm/_dnt.polyfills.js +15 -0
  6. package/esm/adapters/hono/_common.d.ts +66 -0
  7. package/esm/adapters/hono/_common.js +108 -0
  8. package/esm/adapters/hono/authorization-server.d.ts +211 -0
  9. package/esm/adapters/hono/authorization-server.js +214 -0
  10. package/esm/adapters/hono/bff/auth-request-store.d.ts +164 -0
  11. package/esm/adapters/hono/bff/auth-request-store.js +154 -0
  12. package/esm/adapters/hono/bff/bff.d.ts +852 -0
  13. package/esm/adapters/hono/bff/bff.js +1194 -0
  14. package/esm/adapters/hono/bff/cookie-prefix.d.ts +72 -0
  15. package/esm/adapters/hono/bff/cookie-prefix.js +85 -0
  16. package/esm/adapters/hono/bff/mod.d.ts +19 -0
  17. package/esm/adapters/hono/bff/mod.js +19 -0
  18. package/esm/adapters/hono/bff/proxy.d.ts +108 -0
  19. package/esm/adapters/hono/bff/proxy.js +314 -0
  20. package/esm/adapters/hono/bff/session-store.d.ts +250 -0
  21. package/esm/adapters/hono/bff/session-store.js +216 -0
  22. package/esm/adapters/hono/bff/testing.d.ts +165 -0
  23. package/esm/adapters/hono/bff/testing.js +254 -0
  24. package/esm/adapters/hono/identity.d.ts +117 -0
  25. package/esm/adapters/hono/identity.js +215 -0
  26. package/esm/adapters/hono/log.d.ts +49 -0
  27. package/esm/adapters/hono/log.js +66 -0
  28. package/esm/adapters/hono/resource-server.d.ts +101 -0
  29. package/esm/adapters/hono/resource-server.js +108 -0
  30. package/esm/client/_http.d.ts +91 -0
  31. package/esm/client/_http.js +303 -0
  32. package/esm/client/base.d.ts +184 -0
  33. package/esm/client/base.js +93 -0
  34. package/esm/client/bff-client.d.ts +235 -0
  35. package/esm/client/bff-client.js +280 -0
  36. package/esm/client/browser-storage.d.ts +152 -0
  37. package/esm/client/browser-storage.js +246 -0
  38. package/esm/client/check.d.ts +114 -0
  39. package/esm/client/check.js +97 -0
  40. package/esm/client/direct-client.d.ts +707 -0
  41. package/esm/client/direct-client.js +1237 -0
  42. package/esm/client/discovery-cache.d.ts +138 -0
  43. package/esm/client/discovery-cache.js +124 -0
  44. package/esm/client/events.d.ts +54 -0
  45. package/esm/client/events.js +37 -0
  46. package/esm/client/mod.d.ts +35 -0
  47. package/esm/client/mod.js +33 -0
  48. package/esm/client/storage.d.ts +127 -0
  49. package/esm/client/storage.js +81 -0
  50. package/esm/deps/jsr.io/@std/assert/1.0.19/almost_equals.d.ts +29 -0
  51. package/esm/deps/jsr.io/@std/assert/1.0.19/almost_equals.js +47 -0
  52. package/esm/deps/jsr.io/@std/assert/1.0.19/array_includes.d.ts +28 -0
  53. package/esm/deps/jsr.io/@std/assert/1.0.19/array_includes.js +65 -0
  54. package/esm/deps/jsr.io/@std/assert/1.0.19/assert.d.ts +16 -0
  55. package/esm/deps/jsr.io/@std/assert/1.0.19/assert.js +23 -0
  56. package/esm/deps/jsr.io/@std/assert/1.0.19/assertion_error.d.ts +25 -0
  57. package/esm/deps/jsr.io/@std/assert/1.0.19/assertion_error.js +30 -0
  58. package/esm/deps/jsr.io/@std/assert/1.0.19/equal.d.ts +24 -0
  59. package/esm/deps/jsr.io/@std/assert/1.0.19/equal.js +193 -0
  60. package/esm/deps/jsr.io/@std/assert/1.0.19/equals.d.ts +36 -0
  61. package/esm/deps/jsr.io/@std/assert/1.0.19/equals.js +61 -0
  62. package/esm/deps/jsr.io/@std/assert/1.0.19/exists.d.ts +17 -0
  63. package/esm/deps/jsr.io/@std/assert/1.0.19/exists.js +27 -0
  64. package/esm/deps/jsr.io/@std/assert/1.0.19/fail.d.ts +14 -0
  65. package/esm/deps/jsr.io/@std/assert/1.0.19/fail.js +20 -0
  66. package/esm/deps/jsr.io/@std/assert/1.0.19/false.d.ts +18 -0
  67. package/esm/deps/jsr.io/@std/assert/1.0.19/false.js +23 -0
  68. package/esm/deps/jsr.io/@std/assert/1.0.19/greater.d.ts +19 -0
  69. package/esm/deps/jsr.io/@std/assert/1.0.19/greater.js +29 -0
  70. package/esm/deps/jsr.io/@std/assert/1.0.19/greater_or_equal.d.ts +19 -0
  71. package/esm/deps/jsr.io/@std/assert/1.0.19/greater_or_equal.js +29 -0
  72. package/esm/deps/jsr.io/@std/assert/1.0.19/instance_of.d.ts +22 -0
  73. package/esm/deps/jsr.io/@std/assert/1.0.19/instance_of.js +52 -0
  74. package/esm/deps/jsr.io/@std/assert/1.0.19/is_error.d.ts +24 -0
  75. package/esm/deps/jsr.io/@std/assert/1.0.19/is_error.js +53 -0
  76. package/esm/deps/jsr.io/@std/assert/1.0.19/less.d.ts +18 -0
  77. package/esm/deps/jsr.io/@std/assert/1.0.19/less.js +28 -0
  78. package/esm/deps/jsr.io/@std/assert/1.0.19/less_or_equal.d.ts +19 -0
  79. package/esm/deps/jsr.io/@std/assert/1.0.19/less_or_equal.js +29 -0
  80. package/esm/deps/jsr.io/@std/assert/1.0.19/match.d.ts +17 -0
  81. package/esm/deps/jsr.io/@std/assert/1.0.19/match.js +26 -0
  82. package/esm/deps/jsr.io/@std/assert/1.0.19/mod.d.ts +43 -0
  83. package/esm/deps/jsr.io/@std/assert/1.0.19/mod.js +45 -0
  84. package/esm/deps/jsr.io/@std/assert/1.0.19/not_equals.d.ts +26 -0
  85. package/esm/deps/jsr.io/@std/assert/1.0.19/not_equals.js +39 -0
  86. package/esm/deps/jsr.io/@std/assert/1.0.19/not_instance_of.d.ts +19 -0
  87. package/esm/deps/jsr.io/@std/assert/1.0.19/not_instance_of.js +29 -0
  88. package/esm/deps/jsr.io/@std/assert/1.0.19/not_match.d.ts +17 -0
  89. package/esm/deps/jsr.io/@std/assert/1.0.19/not_match.js +26 -0
  90. package/esm/deps/jsr.io/@std/assert/1.0.19/not_strict_equals.d.ts +22 -0
  91. package/esm/deps/jsr.io/@std/assert/1.0.19/not_strict_equals.js +32 -0
  92. package/esm/deps/jsr.io/@std/assert/1.0.19/object_match.d.ts +28 -0
  93. package/esm/deps/jsr.io/@std/assert/1.0.19/object_match.js +177 -0
  94. package/esm/deps/jsr.io/@std/assert/1.0.19/rejects.d.ts +41 -0
  95. package/esm/deps/jsr.io/@std/assert/1.0.19/rejects.js +53 -0
  96. package/esm/deps/jsr.io/@std/assert/1.0.19/strict_equals.d.ts +23 -0
  97. package/esm/deps/jsr.io/@std/assert/1.0.19/strict_equals.js +58 -0
  98. package/esm/deps/jsr.io/@std/assert/1.0.19/string_includes.d.ts +17 -0
  99. package/esm/deps/jsr.io/@std/assert/1.0.19/string_includes.js +26 -0
  100. package/esm/deps/jsr.io/@std/assert/1.0.19/throws.d.ts +44 -0
  101. package/esm/deps/jsr.io/@std/assert/1.0.19/throws.js +44 -0
  102. package/esm/deps/jsr.io/@std/assert/1.0.19/unimplemented.d.ts +14 -0
  103. package/esm/deps/jsr.io/@std/assert/1.0.19/unimplemented.js +20 -0
  104. package/esm/deps/jsr.io/@std/assert/1.0.19/unreachable.d.ts +14 -0
  105. package/esm/deps/jsr.io/@std/assert/1.0.19/unreachable.js +20 -0
  106. package/esm/deps/jsr.io/@std/async/1.5.0/delay.d.ts +44 -0
  107. package/esm/deps/jsr.io/@std/async/1.5.0/delay.js +84 -0
  108. package/esm/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.d.ts +39 -0
  109. package/esm/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.js +61 -0
  110. package/esm/deps/jsr.io/@std/encoding/1.0.11/_common16.d.ts +22 -0
  111. package/esm/deps/jsr.io/@std/encoding/1.0.11/_common16.js +51 -0
  112. package/esm/deps/jsr.io/@std/encoding/1.0.11/_common32.d.ts +34 -0
  113. package/esm/deps/jsr.io/@std/encoding/1.0.11/_common32.js +192 -0
  114. package/esm/deps/jsr.io/@std/encoding/1.0.11/_common64.d.ts +34 -0
  115. package/esm/deps/jsr.io/@std/encoding/1.0.11/_common64.js +113 -0
  116. package/esm/deps/jsr.io/@std/encoding/1.0.11/_common_detach.d.ts +3 -0
  117. package/esm/deps/jsr.io/@std/encoding/1.0.11/_common_detach.js +13 -0
  118. package/esm/deps/jsr.io/@std/encoding/1.0.11/_types.d.ts +8 -0
  119. package/esm/deps/jsr.io/@std/encoding/1.0.11/_types.js +2 -0
  120. package/esm/deps/jsr.io/@std/encoding/1.0.11/_validate_binary_like.d.ts +1 -0
  121. package/esm/deps/jsr.io/@std/encoding/1.0.11/_validate_binary_like.js +26 -0
  122. package/esm/deps/jsr.io/@std/encoding/1.0.11/ascii85.d.ts +60 -0
  123. package/esm/deps/jsr.io/@std/encoding/1.0.11/ascii85.js +152 -0
  124. package/esm/deps/jsr.io/@std/encoding/1.0.11/base32.d.ts +39 -0
  125. package/esm/deps/jsr.io/@std/encoding/1.0.11/base32.js +87 -0
  126. package/esm/deps/jsr.io/@std/encoding/1.0.11/base58.d.ts +39 -0
  127. package/esm/deps/jsr.io/@std/encoding/1.0.11/base58.js +131 -0
  128. package/esm/deps/jsr.io/@std/encoding/1.0.11/base64.d.ts +39 -0
  129. package/esm/deps/jsr.io/@std/encoding/1.0.11/base64.js +82 -0
  130. package/esm/deps/jsr.io/@std/encoding/1.0.11/base64url.d.ts +39 -0
  131. package/esm/deps/jsr.io/@std/encoding/1.0.11/base64url.js +72 -0
  132. package/esm/deps/jsr.io/@std/encoding/1.0.11/hex.d.ts +38 -0
  133. package/esm/deps/jsr.io/@std/encoding/1.0.11/hex.js +87 -0
  134. package/esm/deps/jsr.io/@std/encoding/1.0.11/mod.d.ts +97 -0
  135. package/esm/deps/jsr.io/@std/encoding/1.0.11/mod.js +99 -0
  136. package/esm/deps/jsr.io/@std/encoding/1.0.11/varint.d.ts +119 -0
  137. package/esm/deps/jsr.io/@std/encoding/1.0.11/varint.js +209 -0
  138. package/esm/deps/jsr.io/@std/http/1.1.3/status.d.ts +343 -0
  139. package/esm/deps/jsr.io/@std/http/1.1.3/status.js +343 -0
  140. package/esm/deps/jsr.io/@std/internal/1.0.14/assertion_state.d.ts +159 -0
  141. package/esm/deps/jsr.io/@std/internal/1.0.14/assertion_state.js +223 -0
  142. package/esm/deps/jsr.io/@std/internal/1.0.14/build_message.d.ts +79 -0
  143. package/esm/deps/jsr.io/@std/internal/1.0.14/build_message.js +116 -0
  144. package/esm/deps/jsr.io/@std/internal/1.0.14/diff.d.ts +139 -0
  145. package/esm/deps/jsr.io/@std/internal/1.0.14/diff.js +277 -0
  146. package/esm/deps/jsr.io/@std/internal/1.0.14/diff_str.d.ts +98 -0
  147. package/esm/deps/jsr.io/@std/internal/1.0.14/diff_str.js +181 -0
  148. package/esm/deps/jsr.io/@std/internal/1.0.14/format.d.ts +29 -0
  149. package/esm/deps/jsr.io/@std/internal/1.0.14/format.js +68 -0
  150. package/esm/deps/jsr.io/@std/internal/1.0.14/styles.d.ts +158 -0
  151. package/esm/deps/jsr.io/@std/internal/1.0.14/styles.js +206 -0
  152. package/esm/deps/jsr.io/@std/internal/1.0.14/types.d.ts +24 -0
  153. package/esm/deps/jsr.io/@std/internal/1.0.14/types.js +3 -0
  154. package/esm/deps/jsr.io/@std/testing/1.0.20/_test_suite.d.ts +91 -0
  155. package/esm/deps/jsr.io/@std/testing/1.0.20/_test_suite.js +347 -0
  156. package/esm/deps/jsr.io/@std/testing/1.0.20/bdd.d.ts +382 -0
  157. package/esm/deps/jsr.io/@std/testing/1.0.20/bdd.js +1110 -0
  158. package/esm/deps/jsr.io/@udibo/http-error/0.11.1/mod.d.ts +363 -0
  159. package/esm/deps/jsr.io/@udibo/http-error/0.11.1/mod.js +616 -0
  160. package/esm/errors.d.ts +203 -0
  161. package/esm/errors.js +287 -0
  162. package/esm/identity/captcha.d.ts +147 -0
  163. package/esm/identity/captcha.js +64 -0
  164. package/esm/identity/delivery.d.ts +96 -0
  165. package/esm/identity/delivery.js +41 -0
  166. package/esm/identity/errors.d.ts +39 -0
  167. package/esm/identity/errors.js +46 -0
  168. package/esm/identity/events.d.ts +242 -0
  169. package/esm/identity/events.js +39 -0
  170. package/esm/identity/external/_shared.d.ts +86 -0
  171. package/esm/identity/external/_shared.js +107 -0
  172. package/esm/identity/external/_token-exchange.d.ts +61 -0
  173. package/esm/identity/external/_token-exchange.js +179 -0
  174. package/esm/identity/external/apple-client-secret.d.ts +82 -0
  175. package/esm/identity/external/apple-client-secret.js +133 -0
  176. package/esm/identity/external/apple.d.ts +64 -0
  177. package/esm/identity/external/apple.js +248 -0
  178. package/esm/identity/external/discord.d.ts +38 -0
  179. package/esm/identity/external/discord.js +62 -0
  180. package/esm/identity/external/errors.d.ts +48 -0
  181. package/esm/identity/external/errors.js +36 -0
  182. package/esm/identity/external/flow.d.ts +107 -0
  183. package/esm/identity/external/flow.js +158 -0
  184. package/esm/identity/external/github.d.ts +42 -0
  185. package/esm/identity/external/github.js +164 -0
  186. package/esm/identity/external/google.d.ts +52 -0
  187. package/esm/identity/external/google.js +38 -0
  188. package/esm/identity/external/mod.d.ts +63 -0
  189. package/esm/identity/external/mod.js +61 -0
  190. package/esm/identity/external/oauth2.d.ts +110 -0
  191. package/esm/identity/external/oauth2.js +158 -0
  192. package/esm/identity/external/oidc.d.ts +81 -0
  193. package/esm/identity/external/oidc.js +250 -0
  194. package/esm/identity/external/provider.d.ts +132 -0
  195. package/esm/identity/external/provider.js +12 -0
  196. package/esm/identity/hibp.d.ts +67 -0
  197. package/esm/identity/hibp.js +87 -0
  198. package/esm/identity/identifier.d.ts +44 -0
  199. package/esm/identity/identifier.js +47 -0
  200. package/esm/identity/lockout.d.ts +155 -0
  201. package/esm/identity/lockout.js +117 -0
  202. package/esm/identity/mfa/mod.d.ts +42 -0
  203. package/esm/identity/mfa/mod.js +42 -0
  204. package/esm/identity/mfa/recovery-codes.d.ts +96 -0
  205. package/esm/identity/mfa/recovery-codes.js +80 -0
  206. package/esm/identity/mfa/service.d.ts +338 -0
  207. package/esm/identity/mfa/service.js +351 -0
  208. package/esm/identity/mfa/totp.d.ts +186 -0
  209. package/esm/identity/mfa/totp.js +194 -0
  210. package/esm/identity/migration.d.ts +155 -0
  211. package/esm/identity/migration.js +243 -0
  212. package/esm/identity/mod.d.ts +65 -0
  213. package/esm/identity/mod.js +64 -0
  214. package/esm/identity/otp.d.ts +255 -0
  215. package/esm/identity/otp.js +245 -0
  216. package/esm/identity/password-policy.d.ts +45 -0
  217. package/esm/identity/password-policy.js +60 -0
  218. package/esm/identity/password.d.ts +171 -0
  219. package/esm/identity/password.js +160 -0
  220. package/esm/identity/rate-limit.d.ts +192 -0
  221. package/esm/identity/rate-limit.js +168 -0
  222. package/esm/identity/service.d.ts +579 -0
  223. package/esm/identity/service.js +835 -0
  224. package/esm/identity/session.d.ts +122 -0
  225. package/esm/identity/session.js +48 -0
  226. package/esm/identity/token-flow.d.ts +214 -0
  227. package/esm/identity/token-flow.js +173 -0
  228. package/esm/models/authentication.d.ts +24 -0
  229. package/esm/models/authentication.js +1 -0
  230. package/esm/models/authorization-code.d.ts +63 -0
  231. package/esm/models/authorization-code.js +1 -0
  232. package/esm/models/authorization.d.ts +165 -0
  233. package/esm/models/authorization.js +160 -0
  234. package/esm/models/client.d.ts +78 -0
  235. package/esm/models/client.js +1 -0
  236. package/esm/models/device-authorization.d.ts +30 -0
  237. package/esm/models/device-authorization.js +1 -0
  238. package/esm/models/responses.d.ts +93 -0
  239. package/esm/models/responses.js +1 -0
  240. package/esm/models/scope.d.ts +81 -0
  241. package/esm/models/scope.js +125 -0
  242. package/esm/models/token.d.ts +135 -0
  243. package/esm/models/token.js +1 -0
  244. package/esm/package.json +3 -0
  245. package/esm/react/callback.d.ts +52 -0
  246. package/esm/react/callback.js +71 -0
  247. package/esm/react/components/class-names.d.ts +91 -0
  248. package/esm/react/components/class-names.js +118 -0
  249. package/esm/react/components/internal.d.ts +62 -0
  250. package/esm/react/components/internal.js +102 -0
  251. package/esm/react/components/mfa-challenge-form.d.ts +66 -0
  252. package/esm/react/components/mfa-challenge-form.js +46 -0
  253. package/esm/react/components/mfa-enrollment-form.d.ts +83 -0
  254. package/esm/react/components/mfa-enrollment-form.js +41 -0
  255. package/esm/react/components/mod.d.ts +103 -0
  256. package/esm/react/components/mod.js +93 -0
  257. package/esm/react/components/request-password-reset-form.d.ts +61 -0
  258. package/esm/react/components/request-password-reset-form.js +41 -0
  259. package/esm/react/components/reset-password-form.d.ts +66 -0
  260. package/esm/react/components/reset-password-form.js +56 -0
  261. package/esm/react/components/sign-in-form.d.ts +74 -0
  262. package/esm/react/components/sign-in-form.js +43 -0
  263. package/esm/react/components/sign-up-form.d.ts +85 -0
  264. package/esm/react/components/sign-up-form.js +57 -0
  265. package/esm/react/components/types.d.ts +208 -0
  266. package/esm/react/components/types.js +14 -0
  267. package/esm/react/components/use-auth-form.d.ts +118 -0
  268. package/esm/react/components/use-auth-form.js +172 -0
  269. package/esm/react/components/user-menu.d.ts +79 -0
  270. package/esm/react/components/user-menu.js +73 -0
  271. package/esm/react/context.d.ts +51 -0
  272. package/esm/react/context.js +16 -0
  273. package/esm/react/mod.d.ts +26 -0
  274. package/esm/react/mod.js +26 -0
  275. package/esm/react/provider.d.ts +40 -0
  276. package/esm/react/provider.js +189 -0
  277. package/esm/react/require-auth.d.ts +31 -0
  278. package/esm/react/require-auth.js +37 -0
  279. package/esm/react/testing.d.ts +322 -0
  280. package/esm/react/testing.js +461 -0
  281. package/esm/react/use-authorization.d.ts +31 -0
  282. package/esm/react/use-authorization.js +36 -0
  283. package/esm/react/use-oauth2.d.ts +112 -0
  284. package/esm/react/use-oauth2.js +127 -0
  285. package/esm/server/authorization-server.d.ts +736 -0
  286. package/esm/server/authorization-server.js +1304 -0
  287. package/esm/server/client-authentication.d.ts +28 -0
  288. package/esm/server/client-authentication.js +51 -0
  289. package/esm/server/grants/authorization-code.d.ts +179 -0
  290. package/esm/server/grants/authorization-code.js +232 -0
  291. package/esm/server/grants/client-credentials.d.ts +52 -0
  292. package/esm/server/grants/client-credentials.js +53 -0
  293. package/esm/server/grants/device-authorization.d.ts +103 -0
  294. package/esm/server/grants/device-authorization.js +156 -0
  295. package/esm/server/grants/grant.d.ts +165 -0
  296. package/esm/server/grants/grant.js +173 -0
  297. package/esm/server/grants/password.d.ts +80 -0
  298. package/esm/server/grants/password.js +92 -0
  299. package/esm/server/grants/refresh-token.d.ts +80 -0
  300. package/esm/server/grants/refresh-token.js +136 -0
  301. package/esm/server/introspection-token-reader.d.ts +153 -0
  302. package/esm/server/introspection-token-reader.js +164 -0
  303. package/esm/server/jwks-token-reader.d.ts +263 -0
  304. package/esm/server/jwks-token-reader.js +508 -0
  305. package/esm/server/mod.d.ts +23 -0
  306. package/esm/server/mod.js +15 -0
  307. package/esm/server/public-suffix/mod.d.ts +62 -0
  308. package/esm/server/public-suffix/mod.js +103 -0
  309. package/esm/server/public-suffix/rules.d.ts +23 -0
  310. package/esm/server/public-suffix/rules.js +23 -0
  311. package/esm/server/redirect-uri.d.ts +187 -0
  312. package/esm/server/redirect-uri.js +331 -0
  313. package/esm/server/resource-server.d.ts +286 -0
  314. package/esm/server/resource-server.js +365 -0
  315. package/esm/server/services/authorization-code.d.ts +84 -0
  316. package/esm/server/services/authorization-code.js +35 -0
  317. package/esm/server/services/client.d.ts +35 -0
  318. package/esm/server/services/client.js +1 -0
  319. package/esm/server/services/device-authorization.d.ts +134 -0
  320. package/esm/server/services/device-authorization.js +7 -0
  321. package/esm/server/services/token.d.ts +242 -0
  322. package/esm/server/services/token.js +78 -0
  323. package/esm/server/services/user.d.ts +29 -0
  324. package/esm/server/services/user.js +7 -0
  325. package/esm/server/signing-keys.d.ts +201 -0
  326. package/esm/server/signing-keys.js +225 -0
  327. package/esm/server/utils/hash.d.ts +6 -0
  328. package/esm/server/utils/hash.js +11 -0
  329. package/esm/testing/contract/authorization-code.d.ts +37 -0
  330. package/esm/testing/contract/authorization-code.js +93 -0
  331. package/esm/testing/contract/client.d.ts +85 -0
  332. package/esm/testing/contract/client.js +126 -0
  333. package/esm/testing/contract/device-authorization.d.ts +37 -0
  334. package/esm/testing/contract/device-authorization.js +193 -0
  335. package/esm/testing/contract/lockout-store.d.ts +47 -0
  336. package/esm/testing/contract/lockout-store.js +122 -0
  337. package/esm/testing/contract/mfa-store.d.ts +50 -0
  338. package/esm/testing/contract/mfa-store.js +226 -0
  339. package/esm/testing/contract/mod.d.ts +39 -0
  340. package/esm/testing/contract/mod.js +39 -0
  341. package/esm/testing/contract/otp-store.d.ts +48 -0
  342. package/esm/testing/contract/otp-store.js +197 -0
  343. package/esm/testing/contract/rate-limit-store.d.ts +52 -0
  344. package/esm/testing/contract/rate-limit-store.js +105 -0
  345. package/esm/testing/contract/token-flow-store.d.ts +54 -0
  346. package/esm/testing/contract/token-flow-store.js +179 -0
  347. package/esm/testing/contract/token-reader.d.ts +77 -0
  348. package/esm/testing/contract/token-reader.js +78 -0
  349. package/esm/testing/contract/token.d.ts +61 -0
  350. package/esm/testing/contract/token.js +287 -0
  351. package/esm/testing/contract/user.d.ts +63 -0
  352. package/esm/testing/contract/user.js +75 -0
  353. package/esm/testing/mod.d.ts +34 -0
  354. package/esm/testing/mod.js +34 -0
  355. package/esm/testing/server.d.ts +197 -0
  356. package/esm/testing/server.js +193 -0
  357. package/esm/testing/services.d.ts +373 -0
  358. package/esm/testing/services.js +703 -0
  359. package/esm/utils/_buffer.d.ts +10 -0
  360. package/esm/utils/_buffer.js +12 -0
  361. package/esm/utils/_timing-safe.d.ts +13 -0
  362. package/esm/utils/_timing-safe.js +22 -0
  363. package/esm/utils/authentication-context.d.ts +3 -0
  364. package/esm/utils/authentication-context.js +14 -0
  365. package/esm/utils/basic-auth.d.ts +50 -0
  366. package/esm/utils/basic-auth.js +106 -0
  367. package/esm/utils/crypto.d.ts +97 -0
  368. package/esm/utils/crypto.js +162 -0
  369. package/esm/utils/pkce.d.ts +151 -0
  370. package/esm/utils/pkce.js +179 -0
  371. package/esm/utils/text.d.ts +24 -0
  372. package/esm/utils/text.js +28 -0
  373. package/esm/utils/url.d.ts +66 -0
  374. package/esm/utils/url.js +90 -0
  375. package/package.json +92 -0
@@ -0,0 +1,736 @@
1
+ /**
2
+ * Authorization Server implementation for issuing OAuth2 tokens.
3
+ *
4
+ * Implements the OAuth 2.0 Authorization Framework (RFC 6749) with support for:
5
+ * - Token endpoint (RFC 6749 Section 3.2)
6
+ * - Authorization endpoint (RFC 6749 Section 3.1)
7
+ * - Token revocation (RFC 7009)
8
+ * - Token introspection (RFC 7662)
9
+ * - Server metadata (RFC 8414)
10
+ * - Device authorization (RFC 8628)
11
+ *
12
+ * **Configuration.** A single instance serves every tenant/origin. The only
13
+ * configuration seam is `resolve(request)`, which returns the services the
14
+ * server's own endpoints need (`{ clientService, tokenService }`) plus the
15
+ * issuer/endpoints. Each grant resolves its own services independently. For a
16
+ * single-tenant server, `resolve` is a constant function (create the services
17
+ * once, outside it, and return them every time).
18
+ *
19
+ * @see https://datatracker.ietf.org/doc/html/rfc6749
20
+ * @module
21
+ */
22
+ import "../_dnt.polyfills.js";
23
+ import type { AuthorizeParameters } from "../models/authorization-code.js";
24
+ import type { AuthenticationContext } from "../models/authentication.js";
25
+ import type { ClientInterface } from "../models/client.js";
26
+ import type { Token, TokenResponse } from "../models/token.js";
27
+ import type { AuthorizationServerMetadata } from "../models/responses.js";
28
+ import type { AbstractScope, BasicScope } from "../models/scope.js";
29
+ import type { IsPublicSuffix } from "./redirect-uri.js";
30
+ import type { DispatchableGrant } from "./grants/grant.js";
31
+ import type { ClientServiceInterface } from "./services/client.js";
32
+ import type { TokenServiceInterface } from "./services/token.js";
33
+ import { ResourceServer, type ResourceServerOptions, type ResourceServerServices } from "./resource-server.js";
34
+ import { type SigningKeyProvider } from "./signing-keys.js";
35
+ /** What {@link AuthorizationServer.handleEndSessionRequest} tells the app. */
36
+ export interface EndSessionContext<Client extends ClientInterface> {
37
+ /** The logout request itself. */
38
+ request: Request;
39
+ /**
40
+ * The relying party the logout names — from a signature-valid
41
+ * `id_token_hint`'s audience, or from `client_id`. Null when the request
42
+ * named none, or named one this server does not know.
43
+ */
44
+ client: Client | null;
45
+ /**
46
+ * The `sub` of a signature-valid `id_token_hint`. Null when the request sent
47
+ * no hint, or one that did not verify — so a session lookup keyed on it must
48
+ * handle "no subject", which is the ordinary case for a client that never
49
+ * requested `openid`.
50
+ */
51
+ subject: string | null;
52
+ /**
53
+ * The RP's `logout_hint`, verbatim. **Unvalidated and unauthenticated** —
54
+ * OIDC defines it as a hint about which user to log out and nothing checks
55
+ * it, so treat it as a suggestion for a chooser UI, never as an identifier
56
+ * to end a session by.
57
+ */
58
+ logoutHint: string | null;
59
+ }
60
+ /** What an app's {@link EndSessionFn} may ask the server to do afterwards. */
61
+ export interface EndSessionResult {
62
+ /**
63
+ * Headers to merge into the response — the session-clearing `Set-Cookie`,
64
+ * typically. The server owns `Location`; anything else is yours.
65
+ */
66
+ headers?: HeadersInit;
67
+ /**
68
+ * Where to send the browser when the request named no **authorized**
69
+ * `post_logout_redirect_uri` — your own "you are signed out" page. Not
70
+ * validated: it comes from your code, not from the request. Omit it and such
71
+ * a logout answers 204.
72
+ */
73
+ fallback?: string;
74
+ }
75
+ /**
76
+ * Ends the app's session for an RP-initiated logout. Called for every logout
77
+ * request that reaches the endpoint, including ones whose parameters do not
78
+ * check out — refusing to end a session because a *redirect* was unauthorized
79
+ * would leave the person signed in, which is the opposite of what they asked
80
+ * for.
81
+ */
82
+ export type EndSessionFn<Client extends ClientInterface> = (context: EndSessionContext<Client>) => EndSessionResult | void | Promise<EndSessionResult | void>;
83
+ /** Grants configuration for the authorization server. */
84
+ export interface AuthorizationServerGrants<Client extends ClientInterface, User, S extends AbstractScope> {
85
+ /** Maps an OAuth2 `grant_type` value to the grant that handles it. */
86
+ [grantType: string]: DispatchableGrant<Client, User, S>;
87
+ }
88
+ /**
89
+ * Services the authorization server's OWN endpoints need: client lookup/auth
90
+ * (token, revocation, introspection, device-authorization) and token storage
91
+ * (plus the inherited bearer-token validation). Grant-specific services
92
+ * (authorization-code, user, device) live on the grants, not here.
93
+ */
94
+ export interface AuthorizationServerServices<Client extends ClientInterface, User, S extends AbstractScope> extends ResourceServerServices<Client, User, S> {
95
+ /** Looks up and authenticates clients for the AS endpoints. */
96
+ clientService: ClientServiceInterface<Client, User>;
97
+ /** The full token service (read + write) the AS endpoints need. */
98
+ tokenService: TokenServiceInterface<Client, User, S>;
99
+ }
100
+ /**
101
+ * Per-request context resolved by an {@link AuthorizationServer}.
102
+ *
103
+ * `services` is the server's own services for this request. The issuer and
104
+ * endpoint fields drive the RFC 8414 metadata and the in-process
105
+ * {@link localAuthServerFetch} routing; any endpoint omitted defaults to
106
+ * `${issuer}${path}` (e.g. `${issuer}/token`), so a server whose endpoints sit
107
+ * at the issuer root needs only `issuer`.
108
+ */
109
+ export interface AuthorizationServerContext<Client extends ClientInterface, User, S extends AbstractScope> {
110
+ /** The server's own services for this request. */
111
+ services: AuthorizationServerServices<Client, User, S>;
112
+ /** The issuer identifier URL for this request. */
113
+ issuer?: string;
114
+ /** URL of the authorization endpoint. Defaults to `${issuer}/authorize`. */
115
+ authorizationEndpoint?: string;
116
+ /** URL of the token endpoint. Defaults to `${issuer}/token`. */
117
+ tokenEndpoint?: string;
118
+ /** URL of the token revocation endpoint (RFC 7009). Defaults to `${issuer}/revoke`. */
119
+ revocationEndpoint?: string;
120
+ /** URL of the token introspection endpoint (RFC 7662). Defaults to `${issuer}/introspect`. */
121
+ introspectionEndpoint?: string;
122
+ /** URL of the device authorization endpoint (RFC 8628). Defaults to `${issuer}/device_authorization`. */
123
+ deviceAuthorizationEndpoint?: string;
124
+ /**
125
+ * URL where users verify device codes (RFC 8628 Section 3.2). Unlike the
126
+ * `*Endpoint` fields it has no issuer-derived default: the device
127
+ * authorization endpoint answers 500 `server_error` until it is set.
128
+ */
129
+ verificationUri?: string;
130
+ /** URL of the JWKS endpoint. Defaults to `${issuer}/jwks`. */
131
+ jwksEndpoint?: string;
132
+ /** URL of the OIDC UserInfo endpoint. Defaults to `${issuer}/userinfo`. */
133
+ userinfoEndpoint?: string;
134
+ /**
135
+ * URL of the OIDC RP-Initiated Logout end-session endpoint. Defaults to
136
+ * `${issuer}/end_session`.
137
+ */
138
+ endSessionEndpoint?: string;
139
+ }
140
+ /**
141
+ * Options for configuring the authorization server.
142
+ */
143
+ export interface AuthorizationServerOptions<Client extends ClientInterface, User, S extends AbstractScope> extends Omit<ResourceServerOptions<Client, User, S>, "resolve"> {
144
+ /**
145
+ * Resolves the per-request context — the server's own services plus the
146
+ * issuer/endpoints. This is the only services seam: for a single-tenant
147
+ * server it is a constant function returning the same context every time.
148
+ */
149
+ resolve: (request: Request) => AuthorizationServerContext<Client, User, S> | Promise<AuthorizationServerContext<Client, User, S>>;
150
+ /** Grants the server supports, keyed by `grant_type` (each key must equal `grant.grantType`). */
151
+ grants: AuthorizationServerGrants<Client, User, S>;
152
+ /** Scopes supported by this server (advertised in RFC 8414 metadata). */
153
+ scopesSupported?: string[];
154
+ /**
155
+ * OIDC issuance keys. Configuring this turns the OIDC provider surface on:
156
+ * the token endpoint mints an `id_token` for user-bound grants with the
157
+ * `openid` scope, and the JWKS/UserInfo endpoints and
158
+ * `openid-configuration` metadata go live. In multi-instance deploys load
159
+ * one persisted key on every instance (see `signing-keys.ts`).
160
+ */
161
+ signingKeys?: SigningKeyProvider;
162
+ /**
163
+ * Refuses to construct a server that would run with OIDC issuance off. Set
164
+ * it on any deployment that issues `id_token`s: without `signingKeys` an
165
+ * instance still boots and serves plain OAuth2 while answering 404 from the
166
+ * OIDC surface, so a rollout that dropped the key presents as "some relying
167
+ * parties broke" instead of a failed deploy.
168
+ *
169
+ * It asserts that a {@linkcode SigningKeyProvider} is wired, not that the
170
+ * provider can produce a key. For a true fail-to-start, load the key before
171
+ * constructing the server (`await importSigningKeyJwk(...)` into a
172
+ * `StaticSigningKeyProvider`) so an unreadable key throws on the same boot
173
+ * path.
174
+ *
175
+ * @default false
176
+ */
177
+ requireOidc?: boolean;
178
+ /**
179
+ * Ends the app's session for an OIDC RP-Initiated Logout. Configuring it is
180
+ * what turns the end-session endpoint on: without it the endpoint answers
181
+ * 404 **and** `end_session_endpoint` stays out of the discovery document, so
182
+ * metadata never advertises a logout the server cannot perform.
183
+ */
184
+ endSession?: EndSessionFn<Client>;
185
+ /**
186
+ * Maps a user to the id_token/UserInfo `sub` claim. Defaults to the user's
187
+ * `id` property; override when your subject identifier differs.
188
+ */
189
+ subjectOf?: (user: User) => string;
190
+ /**
191
+ * Extra OIDC claims for the id_token and UserInfo response (e.g. `name`,
192
+ * `email` when the scope allows). Merged under the protocol claims — `sub`
193
+ * (from `subjectOf`) and the id_token's `iss`/`aud`/`iat`/`exp`/`nonce`
194
+ * always win.
195
+ * The third argument is this credential's recorded authentication event,
196
+ * including on refresh and UserInfo. Return its fields to emit them; never
197
+ * substitute a user's newer session event. It is absent for legacy records.
198
+ */
199
+ userClaims?: (user: User, scope?: S | null, authenticationContext?: AuthenticationContext) => Promise<Record<string, unknown>> | Record<string, unknown>;
200
+ /**
201
+ * Extension fields for an **active** introspection response (RFC 7662
202
+ * permits them), so a resource server validating by introspection sees the
203
+ * same authorization claims a JWT access token carries — feed it the same
204
+ * computation `userClaims` uses and the two validation strategies stay in
205
+ * field-level parity. Called with the introspected token; the RFC 7662
206
+ * protocol fields (`active`, `scope`, `client_id`, `token_type`, `exp`,
207
+ * `iss`, `sub`, `username`) always win over anything it returns.
208
+ */
209
+ introspectionClaims?: (token: Token<Client, User, S>) => Promise<Record<string, unknown>> | Record<string, unknown>;
210
+ /**
211
+ * Authorizes a client to introspect a resolved, unexpired token. A false
212
+ * result returns only `{ active: false }`, without invoking
213
+ * {@linkcode introspectionClaims}. An error fails the request closed.
214
+ * `tokenType` is the resolved kind, regardless of the request's hint.
215
+ *
216
+ * Omitted by default for compatibility with separately authorized resource
217
+ * servers: every client admitted to the endpoint may introspect any token.
218
+ * Configure this policy when ordinary client credentials can reach the
219
+ * endpoint. A public client ID alone does not authenticate its holder.
220
+ *
221
+ * @example
222
+ * ```ts
223
+ * const canIntrospectToken = (client: { id: string; confidential?: boolean },
224
+ * token: { client: { id: string } }): boolean =>
225
+ * client.confidential === true && client.id === token.client.id;
226
+ * ```
227
+ */
228
+ canIntrospectToken?: (client: Client, token: Token<Client, User, S>, tokenType: "access_token" | "refresh_token") => boolean | Promise<boolean>;
229
+ /**
230
+ * Decides whether the domain under a wildcard redirect URI is a public
231
+ * suffix, which is what bounds a wildcard registration to one registrant's
232
+ * namespace. Import `isPublicSuffix` from
233
+ * `@udibo/oauth2/server/public-suffix` to use the bundled list.
234
+ *
235
+ * Leaving it unset makes every wildcard registration inert — the authorize
236
+ * endpoint will not match one — which is the right setting for a server that
237
+ * only ever registers literal redirect URIs, and keeps the list out of the
238
+ * bundle.
239
+ */
240
+ isPublicSuffix?: IsPublicSuffix;
241
+ }
242
+ /**
243
+ * Function to authenticate the user during authorization.
244
+ *
245
+ * Return one of:
246
+ *
247
+ * - `{ user, authorizedScope?, authenticationContext? }` — user is authenticated; the authorize flow
248
+ * continues. `authorizedScope` declares scopes the user has already
249
+ * pre-authorized for this client; anything in the requested scope not
250
+ * covered by it triggers consent. **Omitting `authorizedScope` means
251
+ * "nothing pre-authorized"** — so any requested scope needs consent: the
252
+ * framework calls `handleConsent` when one is configured, and otherwise
253
+ * treats the request as consented and grants the accepted scope. To
254
+ * pre-authorize everything, return the requested scope as `authorizedScope`.
255
+ * Supply only verified event claims in `authenticationContext`; the code,
256
+ * token and refresh descendants retain a snapshot. Omit unknown claims.
257
+ * - `null` — explicit denial. The framework redirects the browser to
258
+ * `redirect_uri` with `error=access_denied`. Use this for "the user said
259
+ * no", not for "the user isn't signed in yet."
260
+ * - A `Response` — short-circuits the rest of the authorize flow and is
261
+ * returned to the browser as-is. Use this to redirect to a login page,
262
+ * render an interstitial, etc.
263
+ */
264
+ export type AuthenticateUserFn<User> = (request: Request) => Promise<{
265
+ user: User;
266
+ authorizedScope?: AbstractScope;
267
+ authenticationContext?: AuthenticationContext;
268
+ } | Response | null>;
269
+ /**
270
+ * Function to handle user consent during authorization.
271
+ *
272
+ * Called when the requested scope is not already covered by the user's
273
+ * pre-authorized scope. Return one of:
274
+ *
275
+ * - `{ approved: true, scope? }` — consent granted. `scope` optionally
276
+ * narrows the granted scope (RFC 6749 §3.3 allows partial grants).
277
+ * - `{ approved: false }` — consent denied. The framework redirects to
278
+ * `redirect_uri` with `error=access_denied`.
279
+ * - A `Response` — short-circuits the rest of the authorize flow and is
280
+ * returned to the browser as-is. Use this to render a consent page that
281
+ * later resubmits to the authorize endpoint with the user's decision.
282
+ */
283
+ export type HandleConsentFn<Client extends ClientInterface, S extends AbstractScope> = (client: Client, requestedScope: S | undefined, user: unknown) => Promise<{
284
+ approved: boolean;
285
+ scope?: S;
286
+ } | Response>;
287
+ /** Resolved endpoint URLs for a request (issuer-derived unless overridden). */
288
+ export interface ResolvedEndpoints {
289
+ /** Authorization endpoint URL, if resolved. */
290
+ authorization?: string;
291
+ /** Token endpoint URL, if resolved. */
292
+ token?: string;
293
+ /** Token revocation endpoint URL, if resolved. */
294
+ revocation?: string;
295
+ /** Token introspection endpoint URL, if resolved. */
296
+ introspection?: string;
297
+ /** Device authorization endpoint URL, if resolved. */
298
+ deviceAuthorization?: string;
299
+ /** JWKS endpoint URL, if resolved. */
300
+ jwks?: string;
301
+ /** OIDC UserInfo endpoint URL, if resolved. */
302
+ userinfo?: string;
303
+ /** OIDC RP-Initiated Logout end-session endpoint URL, if resolved. */
304
+ endSession?: string;
305
+ }
306
+ /**
307
+ * Every endpoint the authorization server serves, by name — the seven it
308
+ * advertises in its metadata (the {@link ResolvedEndpoints} keys) plus
309
+ * `metadata` and `oidcMetadata`, the two discovery documents that are served
310
+ * but never advertised. Index {@link ENDPOINT_PATHS} and
311
+ * {@link ENDPOINT_METHODS} with it to enumerate the whole surface.
312
+ */
313
+ export type EndpointKey = "authorization" | "token" | "revocation" | "introspection" | "deviceAuthorization" | "jwks" | "userinfo" | "endSession" | "metadata" | "oidcMetadata";
314
+ /**
315
+ * The path each endpoint is served from when the request context supplies only
316
+ * an `issuer` (so the endpoint URL is `${issuer}${path}`). Mount handlers at
317
+ * these paths — as the Hono adapter's `routes()` does — to match what the
318
+ * server advertises in its RFC 8414 metadata.
319
+ *
320
+ * Covers the whole served surface: the seven endpoints the server advertises,
321
+ * plus the two discovery documents (`metadata` for RFC 8414,
322
+ * `oidcMetadata` for OIDC Discovery) that are served but never advertised.
323
+ * Pair it with {@link ENDPOINT_METHODS} to enumerate path *and* verbs.
324
+ *
325
+ * @example Mount every endpoint yourself
326
+ * ```ts
327
+ * for (const key of Object.keys(ENDPOINT_PATHS) as (keyof typeof ENDPOINT_PATHS)[]) {
328
+ * app.on([...ENDPOINT_METHODS[key]], ENDPOINT_PATHS[key], handlerFor(key));
329
+ * }
330
+ * ```
331
+ */
332
+ export declare const ENDPOINT_PATHS: Readonly<Record<EndpointKey, string>>;
333
+ /**
334
+ * The HTTP methods each endpoint in {@link ENDPOINT_PATHS} answers — `POST` for
335
+ * the token-style endpoints, `GET` for authorize/JWKS/discovery, both for
336
+ * UserInfo. Read it instead of re-deriving verbs per endpoint, so a hand-rolled
337
+ * mount answers exactly what the built-in `routes()` does.
338
+ *
339
+ * @example
340
+ * ```ts
341
+ * app.on([...ENDPOINT_METHODS.userinfo], ENDPOINT_PATHS.userinfo, handler);
342
+ * ```
343
+ */
344
+ export declare const ENDPOINT_METHODS: Readonly<Record<EndpointKey, readonly string[]>>;
345
+ /**
346
+ * Authorization Server for issuing OAuth2 tokens.
347
+ *
348
+ * Handles OAuth2 endpoints including:
349
+ * - Token endpoint (POST /token)
350
+ * - Authorization endpoint (GET /authorize)
351
+ * - Revocation endpoint (POST /revoke) - RFC 7009
352
+ * - Introspection endpoint (POST /introspect) - RFC 7662
353
+ * - Device authorization endpoint (POST /device_authorization) - RFC 8628
354
+ * - Metadata endpoint (GET /.well-known/oauth-authorization-server) - RFC 8414
355
+ *
356
+ * Framework-agnostic: each `handle*Request` method takes a web `Request` and
357
+ * returns a `Response`, so an adapter routes its endpoints to them. Extends
358
+ * {@linkcode ResourceServer}, so the same instance also validates bearer
359
+ * tokens. A single instance serves every tenant/origin via the `resolve`
360
+ * callback in {@linkcode AuthorizationServerOptions}.
361
+ *
362
+ * The handlers throw {@linkcode HttpError} subclasses on failure (e.g.
363
+ * {@linkcode InvalidRequestError}, {@linkcode InvalidClientError},
364
+ * {@linkcode UnsupportedGrantTypeError}) and convert them to RFC 6749 §5.2
365
+ * error responses unless `throwOnError` is set.
366
+ *
367
+ * @template Client The client entity type.
368
+ * @template User The resource-owner entity type.
369
+ * @template S The scope type used across grants and metadata.
370
+ *
371
+ * @see https://datatracker.ietf.org/doc/html/rfc6749
372
+ *
373
+ * @example
374
+ * ```ts
375
+ * const server = new AuthorizationServer({
376
+ * resolve: () => ({ services, issuer: "https://auth.example.com" }),
377
+ * grants: { authorization_code: authCodeGrant, refresh_token: refreshGrant },
378
+ * });
379
+ *
380
+ * app.post("/token", (c) => server.handleTokenRequest(c.req.raw));
381
+ * ```
382
+ */
383
+ export declare class AuthorizationServer<Client extends ClientInterface, User, S extends AbstractScope = BasicScope> extends ResourceServer<Client, User, S> {
384
+ #private;
385
+ /** Grants the server supports, keyed by `grant_type`. */
386
+ grants: AuthorizationServerGrants<Client, User, S>;
387
+ /** Scopes advertised in RFC 8414 metadata, if configured. */
388
+ scopesSupported?: string[];
389
+ /** OIDC signing keys; the OIDC surface is active when set. */
390
+ signingKeys?: SigningKeyProvider;
391
+ /**
392
+ * Creates an authorization server from the given
393
+ * {@linkcode AuthorizationServerOptions}.
394
+ *
395
+ * @throws {Error} If any grant's map key does not equal its `grantType`.
396
+ * @throws {Error} If `requireOidc` is set without `signingKeys`.
397
+ */
398
+ constructor(options: AuthorizationServerOptions<Client, User, S>);
399
+ /**
400
+ * Whether this instance will actually serve the OIDC surface: `true` once
401
+ * `signingKeys` is set, which is what gates `id_token` issuance and the
402
+ * `/jwks`, `/userinfo`, and `openid-configuration` endpoints (they answer
403
+ * 404 while it is `false`).
404
+ *
405
+ * Read it in a readiness probe to keep an instance that booted without its
406
+ * signing key out of the load balancer instead of letting it 404 relying
407
+ * parties. It reports the provider this server configured — not that the
408
+ * provider can produce a key, which surfaces on first use — and it tracks
409
+ * the `signingKeys` field, so it is meaningful from construction onward and
410
+ * follows any later reassignment.
411
+ */
412
+ get oidcEnabled(): boolean;
413
+ /** Resolves the per-request {@link AuthorizationServerContext}. */
414
+ authorizationContext(request: Request): Promise<AuthorizationServerContext<Client, User, S>>;
415
+ /** The resolved endpoint URLs for a request. Used by {@link localAuthServerFetch}. */
416
+ resolveEndpoints(request: Request): Promise<ResolvedEndpoints>;
417
+ /**
418
+ * Converts a token to a bearer token response body.
419
+ */
420
+ bearerToken(token: Token<Client, User, S>, services: AuthorizationServerServices<Client, User, S>): TokenResponse;
421
+ /**
422
+ * Creates a token response. When the issuing `grant` is passed, an id_token
423
+ * is only minted for grants that represent an end-user authentication
424
+ * (`grant.issuesIdToken !== false`).
425
+ */
426
+ createTokenResponse(token: Token<Client, User, S>, context: AuthorizationServerContext<Client, User, S>, grant?: DispatchableGrant<Client, User, S>): Promise<Response>;
427
+ /**
428
+ * Applies `Cache-Control: no-store` and `Pragma: no-cache` headers to an
429
+ * error per RFC 6749 Section 5.2. The headers land on both the rethrown
430
+ * error (when {@link throwOnError} is true) and the generated response.
431
+ */
432
+ private addCacheHeaders;
433
+ /**
434
+ * Error-prepare callback for the endpoints that authenticate the client
435
+ * (token, revocation, introspection, device authorization). Attaches the
436
+ * RFC 6749 Section 5.2 cache headers, and — when client authentication was
437
+ * attempted via the `Authorization` header and failed with a 401 — the
438
+ * matching `WWW-Authenticate: Basic` challenge that RFC 6749 Section 5.2
439
+ * requires.
440
+ */
441
+ private prepareClientAuthError;
442
+ /**
443
+ * Handles a token request (POST /token).
444
+ * Supports multiple grant types based on the configured grants.
445
+ *
446
+ * A malformed request — wrong method, a content-type other than
447
+ * `application/x-www-form-urlencoded`, or an unsupported grant — is a 400
448
+ * `invalid_request`.
449
+ */
450
+ handleTokenRequest(request: Request): Promise<Response>;
451
+ /**
452
+ * Mint an OIDC id_token for a user-bound token whose scope includes
453
+ * `openid`, or `undefined` when the OIDC surface is off (no signing keys),
454
+ * the token has no user, the scope lacks `openid`, or no issuer resolved.
455
+ */
456
+ mintIdToken(token: Token<Client, User, S>, context: AuthorizationServerContext<Client, User, S>): Promise<string | undefined>;
457
+ /**
458
+ * Handles an OIDC discovery request (GET /.well-known/openid-configuration):
459
+ * the RFC 8414 metadata document including the OIDC fields. 404 when OIDC
460
+ * issuance is off (no signing keys), so relying parties fail fast instead of
461
+ * reading a document missing its REQUIRED OIDC members.
462
+ */
463
+ handleOidcMetadataRequest(request: Request): Promise<Response>;
464
+ /**
465
+ * Handles a JWKS request (GET /jwks): the public signing keys id_tokens and
466
+ * JWT access tokens verify against. 404 when OIDC issuance is off.
467
+ */
468
+ handleJwksRequest(_request: Request): Promise<Response>;
469
+ /**
470
+ * Handles an OIDC UserInfo request (GET/POST /userinfo): validates the
471
+ * bearer token (which must carry the `openid` scope and a user) and returns
472
+ * `sub` plus any configured `userClaims`.
473
+ *
474
+ * Failures follow RFC 6750 Section 3.1, which OIDC Core Section 5.3.3 defers
475
+ * to: a missing, malformed, or expired token is a 401 (`invalid_token`,
476
+ * omitted from the challenge when no credentials were presented at all),
477
+ * while a **valid** token that simply lacks the `openid` scope is a 403
478
+ * `insufficient_scope` whose challenge names `scope="openid"`. The
479
+ * distinction matters to relying parties — a 401 tells an RP its credential
480
+ * is bad, so answering one for a scope problem sends it to refresh a token
481
+ * that will fail again the same way.
482
+ */
483
+ handleUserInfoRequest(request: Request): Promise<Response>;
484
+ /**
485
+ * Handles an OIDC RP-Initiated Logout request (GET/POST /end_session).
486
+ *
487
+ * The server does not know what a session **is** — that is the app's — so
488
+ * `endSession` does the ending and this method does the protocol around it:
489
+ * identifying the relying party, authorizing the return trip, and shaping
490
+ * the response. `endSession` is always called, even when nothing else about
491
+ * the request checks out, because a logout that refuses to log anyone out is
492
+ * the worst possible failure mode for this endpoint.
493
+ *
494
+ * **Authorizing `post_logout_redirect_uri` is the whole security surface.**
495
+ * It is matched by **exact string** against the resolved client's
496
+ * {@link ClientInterface.postLogoutRedirectUris} — no patterns, no prefixes,
497
+ * unlike the authorization endpoint's redirect matching. A logout redirect
498
+ * carries no code to steal, but an unvalidated one is an open redirect on the
499
+ * IDP's own domain, which is a phishing primitive: the victim really did just
500
+ * come from your login page. When no client resolves, or the URI is not
501
+ * registered, the browser is **not** sent there — it goes to `fallback` if
502
+ * the app supplied one, or gets a bare 204.
503
+ *
504
+ * `id_token_hint` is verified against the signing keys but its expiry is
505
+ * ignored: by the time anyone logs out the id_token naming their session has
506
+ * usually expired, and it is a hint, not authority. `client_id` is accepted
507
+ * as the fallback identifier the spec allows. `state` rides along only to a
508
+ * URI that passed authorization.
509
+ *
510
+ * Wire the app's session teardown through the `endSession` **constructor
511
+ * option**; this method answers 404 without it, and the discovery document
512
+ * omits `end_session_endpoint` to match.
513
+ *
514
+ * @example
515
+ * ```ts
516
+ * const server = new AuthorizationServer({
517
+ * resolve,
518
+ * grants,
519
+ * signingKeys,
520
+ * endSession: async ({ subject }) => {
521
+ * if (subject) await sessions.deleteByUserId(subject);
522
+ * return { headers: { "Set-Cookie": clearSessionCookie() }, fallback: "/" };
523
+ * },
524
+ * });
525
+ * app.all("/end_session", (c) => server.handleEndSessionRequest(c.req.raw));
526
+ * ```
527
+ */
528
+ handleEndSessionRequest(request: Request): Promise<Response>;
529
+ /**
530
+ * Parses authorization request parameters from the query string.
531
+ *
532
+ * The authorization endpoint is GET-only (RFC 6749 Section 3.1 requires GET
533
+ * and only permits POST), so parameters are read from `url.searchParams`.
534
+ */
535
+ parseAuthorizeParameters(request: Request): AuthorizeParameters;
536
+ /**
537
+ * Handles an authorization request (GET /authorize).
538
+ * Used for the authorization code flow.
539
+ *
540
+ * Once the request has named a redirect URI the client registered, failures
541
+ * are reported to that URI as an RFC 6749 Section 4.1.2.1 error redirect;
542
+ * before that they are error responses from this endpoint, since there is no
543
+ * verified place to send the user back to.
544
+ *
545
+ * Requires a grant extending {@linkcode AuthorizationCodeGrant} registered
546
+ * under `authorization_code`; without one the endpoint answers 500
547
+ * `server_error` (or rethrows, with `throwOnError`).
548
+ *
549
+ * @param request The incoming request
550
+ * @param authenticateUser Function to authenticate the user
551
+ * @param handleConsent Optional function to handle user consent
552
+ * @returns A Response (redirect to client or error page)
553
+ */
554
+ handleAuthorizeRequest(request: Request, authenticateUser: AuthenticateUserFn<User>, handleConsent?: HandleConsentFn<Client, S>): Promise<Response>;
555
+ /**
556
+ * Authenticates a client from the credentials the request presents: Basic
557
+ * authentication (RFC 6749 Section 2.3.1) or the `client_id`/`client_secret`
558
+ * of `body`, the form body the endpoint already parsed. The grants
559
+ * authenticate through the same implementation, so a request that fails here
560
+ * fails identically at the token endpoint.
561
+ *
562
+ * @throws {InvalidClientError} If client authentication fails
563
+ */
564
+ authenticateClient(request: Request, body: FormData, services: AuthorizationServerServices<Client, User, S>): Promise<Client>;
565
+ /**
566
+ * Handles a token revocation request (POST /revoke).
567
+ *
568
+ * Per RFC 7009, requires client authentication and accepts:
569
+ * - token: The token to revoke (required)
570
+ * - token_type_hint: Hint about token type (optional)
571
+ *
572
+ * **A client can only revoke its own tokens.** RFC 7009 Section 2.1 requires
573
+ * the server to verify that the presented token was issued to the
574
+ * authenticated client; without that check any client that has observed a
575
+ * token value — a resource server it called, a shared browser, a log — could
576
+ * end another application's live sessions at will. A token belonging to a
577
+ * different client is left alone.
578
+ *
579
+ * Always returns 200 OK, even if the token was invalid, already revoked, or
580
+ * issued to another client: RFC 7009 Section 2.2 requires that answer so the
581
+ * endpoint cannot be used as an oracle for whether a token value is live or
582
+ * whose it is. That covers the token only: a malformed request — wrong
583
+ * method, a content-type other than `application/x-www-form-urlencoded`, or
584
+ * no `token` parameter — is a 400 `invalid_request`, as on the token
585
+ * endpoint.
586
+ *
587
+ * `token_type_hint` orders the lookup rather than restricting it, so a client
588
+ * that mislabels its token still gets it revoked.
589
+ *
590
+ * @see https://datatracker.ietf.org/doc/html/rfc7009
591
+ */
592
+ handleRevocationRequest(request: Request): Promise<Response>;
593
+ /**
594
+ * Handles a token introspection request (POST /introspect).
595
+ *
596
+ * Per RFC 7662, requires client authentication and returns information
597
+ * about the token including whether it is active.
598
+ * {@linkcode AuthorizationServerOptions.canIntrospectToken} controls which
599
+ * tokens an authenticated caller may inspect. A denial returns only
600
+ * `{ active: false }`; without a policy, all admitted clients may inspect
601
+ * any token, including separately authorized resource servers.
602
+ *
603
+ * Both access tokens and refresh tokens introspect. `token_type_hint` orders
604
+ * the lookup rather than restricting it (RFC 7662 Section 2.1 requires the
605
+ * other kind to be tried when the hinted lookup misses), so a mislabelled
606
+ * token still resolves. An active access token carries
607
+ * `token_type: "Bearer"`; a refresh token carries no `token_type`, since
608
+ * that field describes how an access token is presented, and its `exp` is
609
+ * the refresh token's own expiry.
610
+ *
611
+ * A token with no user — the client acting as its own resource owner, as
612
+ * the client credentials grant issues — carries no `sub` and no `username`;
613
+ * `client_id` identifies the machine. `sub` is optional in RFC 7662, and
614
+ * leaving it absent keeps `sub` an unambiguous "there is a resource owner"
615
+ * signal rather than overloading `client_id` into the subject namespace
616
+ * (RFC 9700 §4.15.1).
617
+ *
618
+ * A wrong method, or a content type other than
619
+ * `application/x-www-form-urlencoded`, is a 400 `invalid_request`, as on the
620
+ * token endpoint.
621
+ *
622
+ * @see https://datatracker.ietf.org/doc/html/rfc7662
623
+ */
624
+ handleIntrospectionRequest(request: Request): Promise<Response>;
625
+ /**
626
+ * Gets OAuth2 server metadata (RFC 8414).
627
+ *
628
+ * Returns metadata about this authorization server including supported
629
+ * grant types, endpoints, and capabilities.
630
+ *
631
+ * `code_challenge_methods_supported` is derived from the registered
632
+ * authorization code grant's own `challengeMethods`, so a server that
633
+ * registers an extra method (or drops `S256`) advertises what it will
634
+ * actually accept. It is omitted entirely when no authorization code grant
635
+ * is registered, since PKCE has nothing to apply to.
636
+ *
637
+ * `token_endpoint_auth_methods_supported` always includes `none`, the
638
+ * RFC 7591 method for a client with no secret. The token endpoint accepts it
639
+ * on every deployment and for every grant — a request carrying only
640
+ * `client_id` reaches `ClientServiceInterface.getAuthenticated` with no
641
+ * secret, which that interface's contract requires to resolve a public
642
+ * client (an authorization-code exchange carrying a `code_verifier` looks
643
+ * the client up with `get` instead when `requireClientAuthentication` is
644
+ * explicitly `false`) — and there is no option that turns it off, so it is not
645
+ * conditional on anything a caller configures. Which clients may use it is
646
+ * decided per client, by whether the client has a secret; discovery
647
+ * describes the endpoint, not the client population.
648
+ *
649
+ * @throws {ServerError} If the resolved context has no `issuer` — RFC 8414
650
+ * makes it REQUIRED and it is the field clients validate against.
651
+ * @see https://datatracker.ietf.org/doc/html/rfc8414#section-2
652
+ * @see https://datatracker.ietf.org/doc/html/rfc7591#section-2
653
+ */
654
+ getMetadata(context: AuthorizationServerContext<Client, User, S>): AuthorizationServerMetadata;
655
+ /**
656
+ * Handles a metadata request (GET /.well-known/oauth-authorization-server).
657
+ *
658
+ * Returns the authorization server metadata as JSON per RFC 8414.
659
+ *
660
+ * @see https://datatracker.ietf.org/doc/html/rfc8414
661
+ */
662
+ handleMetadataRequest(request: Request): Promise<Response>;
663
+ /**
664
+ * Handles a device authorization request (POST /device_authorization).
665
+ *
666
+ * Initiates the device authorization flow by generating a device_code
667
+ * and user_code that the user can use to authorize the request on
668
+ * a secondary device.
669
+ *
670
+ * Requires a grant extending {@linkcode DeviceAuthorizationGrant} registered
671
+ * under `urn:ietf:params:oauth:grant-type:device_code`, and a
672
+ * `verificationUri` on the resolved context; without either the endpoint
673
+ * answers 500 `server_error`. A wrong method, or a content type other than
674
+ * `application/x-www-form-urlencoded`, is a 400 `invalid_request`, as on the
675
+ * token endpoint.
676
+ *
677
+ * @see https://datatracker.ietf.org/doc/html/rfc8628#section-3.1
678
+ * @see https://datatracker.ietf.org/doc/html/rfc8628#section-3.2
679
+ */
680
+ handleDeviceAuthorizationRequest(request: Request): Promise<Response>;
681
+ }
682
+ /**
683
+ * Returns a `fetch`-compatible function that dispatches requests directly
684
+ * to the {@link AuthorizationServer}'s handlers in-process, bypassing the
685
+ * network.
686
+ *
687
+ * Use this to point a `DirectClient` at a co-located authorization
688
+ * server — the request flow becomes a plain method call, so token refresh
689
+ * (and every other client → server interaction) stays in-process.
690
+ *
691
+ * Routing is by pathname against the endpoints the server resolves for the
692
+ * request (so it follows per-request issuer/origin):
693
+ * - `POST {tokenEndpoint}` → `handleTokenRequest`
694
+ * - `POST {revocationEndpoint}` → `handleRevocationRequest`
695
+ * - `POST {introspectionEndpoint}` → `handleIntrospectionRequest`
696
+ * - `POST {deviceAuthorizationEndpoint}` → `handleDeviceAuthorizationRequest`
697
+ * - `GET /.well-known/oauth-authorization-server` → `handleMetadataRequest`
698
+ *
699
+ * The authorization endpoint is deliberately **not** routed: `/authorize`
700
+ * needs an `authenticateUser` (and optional `handleConsent`) callback this
701
+ * transport has no access to, and in real flows it's a browser navigation,
702
+ * never a call through the client's `fetch`. A request to it throws an
703
+ * actionable error pointing at `handleAuthorizeRequest`. Any other path also
704
+ * throws — the helper intentionally does not proxy arbitrary paths; if a call
705
+ * lands here unexpectedly, that's a wiring bug worth surfacing rather than
706
+ * silently forwarding.
707
+ */
708
+ export declare function localAuthServerFetch<Client extends ClientInterface, User, S extends AbstractScope>(authServer: AuthorizationServer<Client, User, S>): typeof fetch;
709
+ export { AbstractGrant } from "./grants/grant.js";
710
+ export type { DispatchableGrant, GrantOptions, GrantServices, } from "./grants/grant.js";
711
+ export { AuthorizationCodeGrant } from "./grants/authorization-code.js";
712
+ export type { PKCEClientCredentials } from "./grants/authorization-code.js";
713
+ export type { AuthorizationCodeGrantOptions, AuthorizationCodeGrantServices, GenerateAuthorizationCodeOptions, } from "./grants/authorization-code.js";
714
+ export { ClientCredentialsGrant } from "./grants/client-credentials.js";
715
+ export type { ClientCredentialsGrantOptions, ClientCredentialsGrantServices, } from "./grants/client-credentials.js";
716
+ export { createJwtAccessTokenGenerator, exportSigningKeyJwk, generateSigningKey, importSigningKeyJwk, RotatingSigningKeyProvider, type RotatingSigningKeyProviderOptions, type SigningKey, type SigningKeyProvider, signJwt, StaticSigningKeyProvider, verifyJwt, type VerifyJwtOptions, } from "./signing-keys.js";
717
+ export { RefreshTokenGrant } from "./grants/refresh-token.js";
718
+ export type { RefreshTokenGrantOptions, RefreshTokenGrantServices, TokenReuseEvent, } from "./grants/refresh-token.js";
719
+ export { PasswordGrant } from "./grants/password.js";
720
+ export type { PasswordGrantOptions, PasswordGrantServices, } from "./grants/password.js";
721
+ export { DeviceAuthorizationGrant } from "./grants/device-authorization.js";
722
+ export type { DeviceAuthorizationGrantOptions, DeviceAuthorizationGrantServices, } from "./grants/device-authorization.js";
723
+ export { AbstractTokenService, type AbstractTokenServiceOptions, type TokenServiceInterface, } from "./services/token.js";
724
+ export type { ClientServiceInterface } from "./services/client.js";
725
+ export { AbstractAuthorizationCodeService, type AbstractAuthorizationCodeServiceOptions, type AuthorizationCodeServiceInterface, } from "./services/authorization-code.js";
726
+ export type { DeviceAuthorizationServiceInterface } from "./services/device-authorization.js";
727
+ export type { UserServiceInterface } from "./services/user.js";
728
+ export type { AuthorizationCode, AuthorizeParameters, } from "../models/authorization-code.js";
729
+ export type { DeviceAuthorization } from "../models/device-authorization.js";
730
+ export type { AuthorizationServerMetadata, DeviceAuthorizationResponse, ErrorResponse, OAuth2ErrorCode, } from "../models/responses.js";
731
+ export { challengeMethods, CODE_VERIFIER_MAX_LENGTH, CODE_VERIFIER_MIN_LENGTH, CODE_VERIFIER_PATTERN, generateCodeChallenge, generateCodeVerifier, generateState, getChallengeMethod, validateCodeChallenge, validateCodeVerifier, verifyCodeChallenge, } from "../utils/pkce.js";
732
+ export type { ChallengeMethod, ChallengeMethods } from "../utils/pkce.js";
733
+ export { encodeBasicAuth, parseBasicAuth, tryParseBasicAuth, } from "../utils/basic-auth.js";
734
+ export type { BasicAuth } from "../utils/basic-auth.js";
735
+ export { checkRedirectUriPattern, isRedirectUriPattern, matchRedirectUri, } from "./redirect-uri.js";
736
+ export type { IsPublicSuffix, RedirectUriPatternRule, RedirectUriPatternViolation, } from "./redirect-uri.js";