skybridge 0.0.0-dev.fa77314 → 0.0.0-dev.fa95a7b

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 (355) hide show
  1. package/README.md +10 -7
  2. package/dist/cli/build-helpers.d.ts +6 -2
  3. package/dist/cli/build-helpers.js +39 -14
  4. package/dist/cli/build-helpers.js.map +1 -1
  5. package/dist/cli/build-helpers.test.js +73 -5
  6. package/dist/cli/build-helpers.test.js.map +1 -1
  7. package/dist/cli/build-steps.d.ts +2 -0
  8. package/dist/cli/build-steps.js +73 -0
  9. package/dist/cli/build-steps.js.map +1 -0
  10. package/dist/cli/build-steps.test.js +52 -0
  11. package/dist/cli/build-steps.test.js.map +1 -0
  12. package/dist/cli/detect-port.js +0 -1
  13. package/dist/cli/detect-port.js.map +1 -1
  14. package/dist/cli/header.d.ts +1 -1
  15. package/dist/cli/resolve-skybridge-config.d.ts +5 -0
  16. package/dist/cli/{resolve-views-dir.js → resolve-skybridge-config.js} +4 -3
  17. package/dist/cli/resolve-skybridge-config.js.map +1 -0
  18. package/dist/cli/run-plain.d.ts +18 -0
  19. package/dist/cli/run-plain.js +90 -0
  20. package/dist/cli/run-plain.js.map +1 -0
  21. package/dist/cli/use-execute-steps.d.ts +1 -1
  22. package/dist/cli/use-nodemon.d.ts +25 -1
  23. package/dist/cli/use-nodemon.js +96 -63
  24. package/dist/cli/use-nodemon.js.map +1 -1
  25. package/dist/cli/use-typescript-check.d.ts +8 -2
  26. package/dist/cli/use-typescript-check.js +70 -67
  27. package/dist/cli/use-typescript-check.js.map +1 -1
  28. package/dist/commands/build.d.ts +0 -2
  29. package/dist/commands/build.js +2 -61
  30. package/dist/commands/build.js.map +1 -1
  31. package/dist/commands/dev.d.ts +1 -0
  32. package/dist/commands/dev.js +38 -6
  33. package/dist/commands/dev.js.map +1 -1
  34. package/dist/commands/start.js +2 -2
  35. package/dist/commands/start.js.map +1 -1
  36. package/dist/context-warnings.d.ts +5 -0
  37. package/dist/context-warnings.js +31 -0
  38. package/dist/context-warnings.js.map +1 -0
  39. package/dist/context-warnings.test.js +28 -0
  40. package/dist/context-warnings.test.js.map +1 -0
  41. package/dist/server/app.d.ts +194 -0
  42. package/dist/server/app.js +266 -0
  43. package/dist/server/app.js.map +1 -0
  44. package/dist/server/app.test.js +97 -0
  45. package/dist/server/app.test.js.map +1 -0
  46. package/dist/server/auth/discovery.d.ts +29 -7
  47. package/dist/server/auth/discovery.js +16 -11
  48. package/dist/server/auth/discovery.js.map +1 -1
  49. package/dist/server/auth/index.d.ts +35 -5
  50. package/dist/server/auth/index.js.map +1 -1
  51. package/dist/server/auth/providers/auth0.d.ts +34 -7
  52. package/dist/server/auth/providers/auth0.js +29 -11
  53. package/dist/server/auth/providers/auth0.js.map +1 -1
  54. package/dist/server/auth/providers/auth0.test.js +31 -14
  55. package/dist/server/auth/providers/auth0.test.js.map +1 -1
  56. package/dist/server/auth/providers/authplane.d.ts +49 -0
  57. package/dist/server/auth/providers/authplane.js +57 -0
  58. package/dist/server/auth/providers/authplane.js.map +1 -0
  59. package/dist/server/auth/providers/authplane.test.js +143 -0
  60. package/dist/server/auth/providers/authplane.test.js.map +1 -0
  61. package/dist/server/auth/providers/clerk.d.ts +40 -3
  62. package/dist/server/auth/providers/clerk.js +5 -6
  63. package/dist/server/auth/providers/clerk.js.map +1 -1
  64. package/dist/server/auth/providers/clerk.test.js +7 -25
  65. package/dist/server/auth/providers/clerk.test.js.map +1 -1
  66. package/dist/server/auth/providers/custom.d.ts +27 -4
  67. package/dist/server/auth/providers/custom.js +46 -15
  68. package/dist/server/auth/providers/custom.js.map +1 -1
  69. package/dist/server/auth/providers/custom.test.js +86 -16
  70. package/dist/server/auth/providers/custom.test.js.map +1 -1
  71. package/dist/server/auth/providers/descope.d.ts +41 -11
  72. package/dist/server/auth/providers/descope.js +38 -8
  73. package/dist/server/auth/providers/descope.js.map +1 -1
  74. package/dist/server/auth/providers/descope.test.js +43 -16
  75. package/dist/server/auth/providers/descope.test.js.map +1 -1
  76. package/dist/server/auth/providers/shared.d.ts +2 -0
  77. package/dist/server/auth/providers/shared.js +6 -0
  78. package/dist/server/auth/providers/shared.js.map +1 -0
  79. package/dist/server/auth/providers/shared.test.js +10 -0
  80. package/dist/server/auth/providers/shared.test.js.map +1 -0
  81. package/dist/server/auth/providers/stytch.d.ts +16 -3
  82. package/dist/server/auth/providers/stytch.js +5 -6
  83. package/dist/server/auth/providers/stytch.js.map +1 -1
  84. package/dist/server/auth/providers/verify-spy.d.ts +12 -0
  85. package/dist/server/auth/providers/verify-spy.js +21 -0
  86. package/dist/server/auth/providers/verify-spy.js.map +1 -0
  87. package/dist/server/auth/providers/workos.d.ts +25 -3
  88. package/dist/server/auth/providers/workos.js +5 -6
  89. package/dist/server/auth/providers/workos.js.map +1 -1
  90. package/dist/server/auth/security-schemes.d.ts +23 -0
  91. package/dist/server/auth/security-schemes.js +64 -0
  92. package/dist/server/auth/security-schemes.js.map +1 -0
  93. package/dist/server/auth/security-schemes.test.js +99 -0
  94. package/dist/server/auth/security-schemes.test.js.map +1 -0
  95. package/dist/server/auth/setup.d.ts +3 -1
  96. package/dist/server/auth/setup.js +66 -26
  97. package/dist/server/auth/setup.js.map +1 -1
  98. package/dist/server/auth/setup.test.js +349 -20
  99. package/dist/server/auth/setup.test.js.map +1 -1
  100. package/dist/server/auth/verify.d.ts +37 -3
  101. package/dist/server/auth/verify.js +27 -3
  102. package/dist/server/auth/verify.js.map +1 -1
  103. package/dist/server/auth/verify.test.js +49 -0
  104. package/dist/server/auth/verify.test.js.map +1 -1
  105. package/dist/server/auth-extra.test-d.js +130 -0
  106. package/dist/server/auth-extra.test-d.js.map +1 -0
  107. package/dist/server/auth.d.ts +43 -6
  108. package/dist/server/auth.js +4 -5
  109. package/dist/server/auth.js.map +1 -1
  110. package/dist/server/build-manifest.test.js +7 -6
  111. package/dist/server/build-manifest.test.js.map +1 -1
  112. package/dist/server/content-helpers.d.ts +1 -1
  113. package/dist/server/content-helpers.js.map +1 -1
  114. package/dist/server/express.d.ts +23 -3
  115. package/dist/server/express.js +38 -32
  116. package/dist/server/express.js.map +1 -1
  117. package/dist/server/express.test.js +220 -103
  118. package/dist/server/express.test.js.map +1 -1
  119. package/dist/server/file-ref.d.ts +1 -1
  120. package/dist/server/file-ref.js +1 -1
  121. package/dist/server/file-ref.js.map +1 -1
  122. package/dist/server/host.d.ts +2 -0
  123. package/dist/server/host.js +11 -0
  124. package/dist/server/host.js.map +1 -0
  125. package/dist/server/host.test.d.ts +1 -0
  126. package/dist/server/host.test.js +13 -0
  127. package/dist/server/host.test.js.map +1 -0
  128. package/dist/server/index.d.ts +16 -9
  129. package/dist/server/index.js +9 -3
  130. package/dist/server/index.js.map +1 -1
  131. package/dist/server/mcp-errors.test.d.ts +1 -0
  132. package/dist/server/mcp-errors.test.js +41 -0
  133. package/dist/server/mcp-errors.test.js.map +1 -0
  134. package/dist/server/middleware.d.ts +35 -10
  135. package/dist/server/middleware.js +33 -0
  136. package/dist/server/middleware.js.map +1 -1
  137. package/dist/server/middleware.test-d.js +1 -1
  138. package/dist/server/middleware.test-d.js.map +1 -1
  139. package/dist/server/middleware.test.js +242 -134
  140. package/dist/server/middleware.test.js.map +1 -1
  141. package/dist/server/register-tool.test.d.ts +1 -0
  142. package/dist/server/register-tool.test.js +27 -0
  143. package/dist/server/register-tool.test.js.map +1 -0
  144. package/dist/server/server.d.ts +133 -116
  145. package/dist/server/server.js +251 -346
  146. package/dist/server/server.js.map +1 -1
  147. package/dist/server/skills-integration.test.d.ts +1 -0
  148. package/dist/server/skills-integration.test.js +86 -0
  149. package/dist/server/skills-integration.test.js.map +1 -0
  150. package/dist/server/skills.d.ts +27 -0
  151. package/dist/server/skills.js +188 -0
  152. package/dist/server/skills.js.map +1 -0
  153. package/dist/server/skills.test.d.ts +1 -0
  154. package/dist/server/skills.test.js +243 -0
  155. package/dist/server/skills.test.js.map +1 -0
  156. package/dist/server/templateHelper.d.ts +0 -3
  157. package/dist/server/templateHelper.js.map +1 -1
  158. package/dist/server/templates.generated.js +4 -8
  159. package/dist/server/templates.generated.js.map +1 -1
  160. package/dist/server/tool-extra.test.d.ts +1 -0
  161. package/dist/server/tool-extra.test.js +88 -0
  162. package/dist/server/tool-extra.test.js.map +1 -0
  163. package/dist/server/view-name.test-d.d.ts +1 -0
  164. package/dist/server/view-name.test-d.js +8 -0
  165. package/dist/server/view-name.test-d.js.map +1 -0
  166. package/dist/server/view-resource-resolution.test.js +105 -17
  167. package/dist/server/view-resource-resolution.test.js.map +1 -1
  168. package/dist/server/viewsDevServer.js +4 -1
  169. package/dist/server/viewsDevServer.js.map +1 -1
  170. package/dist/test/utils.d.ts +9 -11
  171. package/dist/test/utils.js +220 -201
  172. package/dist/test/utils.js.map +1 -1
  173. package/dist/test/view.test.js +105 -133
  174. package/dist/test/view.test.js.map +1 -1
  175. package/dist/views/index.d.ts +10 -0
  176. package/dist/views/index.js +3 -0
  177. package/dist/views/index.js.map +1 -0
  178. package/dist/{web/plugin → views}/scan-views.js +1 -1
  179. package/dist/views/scan-views.js.map +1 -0
  180. package/dist/views/scan-views.test.d.ts +1 -0
  181. package/dist/views/scan-views.test.js.map +1 -0
  182. package/dist/views/validate-view.d.ts +1 -0
  183. package/dist/{web/plugin → views}/validate-view.js +2 -2
  184. package/dist/views/validate-view.js.map +1 -0
  185. package/dist/views/validate-view.test.d.ts +1 -0
  186. package/dist/views/validate-view.test.js.map +1 -0
  187. package/dist/web/bridges/adaptor.d.ts +51 -0
  188. package/dist/web/bridges/adaptor.js +327 -0
  189. package/dist/web/bridges/adaptor.js.map +1 -0
  190. package/dist/web/bridges/adaptor.test.d.ts +1 -0
  191. package/dist/web/bridges/adaptor.test.js +225 -0
  192. package/dist/web/bridges/adaptor.test.js.map +1 -0
  193. package/dist/web/bridges/apps-sdk/bridge.d.ts +6 -2
  194. package/dist/web/bridges/apps-sdk/bridge.js +15 -4
  195. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
  196. package/dist/web/bridges/apps-sdk/index.d.ts +0 -1
  197. package/dist/web/bridges/apps-sdk/index.js +0 -1
  198. package/dist/web/bridges/apps-sdk/index.js.map +1 -1
  199. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +1 -1
  200. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +1 -1
  201. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
  202. package/dist/web/bridges/get-adaptor.d.ts +4 -4
  203. package/dist/web/bridges/get-adaptor.js +6 -11
  204. package/dist/web/bridges/get-adaptor.js.map +1 -1
  205. package/dist/web/bridges/get-adaptor.test.d.ts +1 -0
  206. package/dist/web/bridges/get-adaptor.test.js +32 -0
  207. package/dist/web/bridges/get-adaptor.test.js.map +1 -0
  208. package/dist/web/bridges/mcp-app/bridge.d.ts +13 -2
  209. package/dist/web/bridges/mcp-app/bridge.js +52 -8
  210. package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
  211. package/dist/web/bridges/mcp-app/bridge.test.d.ts +1 -0
  212. package/dist/web/bridges/mcp-app/bridge.test.js +17 -0
  213. package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -0
  214. package/dist/web/bridges/mcp-app/index.d.ts +0 -1
  215. package/dist/web/bridges/mcp-app/index.js +0 -1
  216. package/dist/web/bridges/mcp-app/index.js.map +1 -1
  217. package/dist/web/bridges/mcp-app/types.d.ts +2 -0
  218. package/dist/web/bridges/mcp-app/types.js.map +1 -1
  219. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +1 -1
  220. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +1 -1
  221. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
  222. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +1 -1
  223. package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
  224. package/dist/web/bridges/mcp-app/view-tools.test.js +6 -7
  225. package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -1
  226. package/dist/web/bridges/types.d.ts +27 -12
  227. package/dist/web/bridges/types.js +14 -1
  228. package/dist/web/bridges/types.js.map +1 -1
  229. package/dist/web/bridges/types.test.d.ts +1 -0
  230. package/dist/web/bridges/types.test.js +19 -0
  231. package/dist/web/bridges/types.test.js.map +1 -0
  232. package/dist/web/components/modal-provider.d.ts +1 -1
  233. package/dist/web/components/modal-provider.js +4 -3
  234. package/dist/web/components/modal-provider.js.map +1 -1
  235. package/dist/web/create-store.test.js +10 -7
  236. package/dist/web/create-store.test.js.map +1 -1
  237. package/dist/web/data-llm.d.ts +1 -1
  238. package/dist/web/data-llm.test.js +20 -7
  239. package/dist/web/data-llm.test.js.map +1 -1
  240. package/dist/web/generate-helpers.d.ts +22 -18
  241. package/dist/web/generate-helpers.js +19 -15
  242. package/dist/web/generate-helpers.js.map +1 -1
  243. package/dist/web/generate-helpers.test-d.js +3 -3
  244. package/dist/web/generate-helpers.test-d.js.map +1 -1
  245. package/dist/web/generate-helpers.test.js +2 -2
  246. package/dist/web/generate-helpers.test.js.map +1 -1
  247. package/dist/web/hooks/index.d.ts +2 -1
  248. package/dist/web/hooks/index.js +2 -1
  249. package/dist/web/hooks/index.js.map +1 -1
  250. package/dist/web/hooks/test/utils.d.ts +2 -1
  251. package/dist/web/hooks/test/utils.js +1 -1
  252. package/dist/web/hooks/test/utils.js.map +1 -1
  253. package/dist/web/hooks/use-call-tool.test.js +39 -25
  254. package/dist/web/hooks/use-call-tool.test.js.map +1 -1
  255. package/dist/web/hooks/use-display-mode.d.ts +1 -1
  256. package/dist/web/hooks/use-display-mode.js +1 -1
  257. package/dist/web/hooks/use-display-mode.js.map +1 -1
  258. package/dist/web/hooks/use-display-mode.test.js +57 -21
  259. package/dist/web/hooks/use-display-mode.test.js.map +1 -1
  260. package/dist/web/hooks/use-download.d.ts +1 -3
  261. package/dist/web/hooks/use-download.js +1 -2
  262. package/dist/web/hooks/use-download.js.map +1 -1
  263. package/dist/web/hooks/use-download.test.js +18 -10
  264. package/dist/web/hooks/use-download.test.js.map +1 -1
  265. package/dist/web/hooks/use-files.test.js +11 -3
  266. package/dist/web/hooks/use-files.test.js.map +1 -1
  267. package/dist/web/hooks/use-host.d.ts +22 -0
  268. package/dist/web/hooks/use-host.js +30 -0
  269. package/dist/web/hooks/use-host.js.map +1 -0
  270. package/dist/web/hooks/use-host.test.d.ts +1 -0
  271. package/dist/web/hooks/use-host.test.js +59 -0
  272. package/dist/web/hooks/use-host.test.js.map +1 -0
  273. package/dist/web/hooks/use-open-external.test.js +15 -5
  274. package/dist/web/hooks/use-open-external.test.js.map +1 -1
  275. package/dist/web/hooks/use-register-view-tool.d.ts +2 -3
  276. package/dist/web/hooks/use-register-view-tool.js.map +1 -1
  277. package/dist/web/hooks/use-request-close.test.js +35 -40
  278. package/dist/web/hooks/use-request-close.test.js.map +1 -1
  279. package/dist/web/hooks/use-request-modal.test.js +11 -1
  280. package/dist/web/hooks/use-request-modal.test.js.map +1 -1
  281. package/dist/web/hooks/use-request-size.d.ts +1 -1
  282. package/dist/web/hooks/use-request-size.js +1 -1
  283. package/dist/web/hooks/use-request-size.js.map +1 -1
  284. package/dist/web/hooks/use-request-size.test.js +35 -53
  285. package/dist/web/hooks/use-request-size.test.js.map +1 -1
  286. package/dist/web/hooks/use-set-open-in-app-url.test.js +26 -12
  287. package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
  288. package/dist/web/hooks/use-tool-info.d.ts +1 -20
  289. package/dist/web/hooks/use-tool-info.js +0 -1
  290. package/dist/web/hooks/use-tool-info.js.map +1 -1
  291. package/dist/web/hooks/use-tool-info.test-d.js +0 -5
  292. package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
  293. package/dist/web/hooks/use-tool-info.test.js +38 -33
  294. package/dist/web/hooks/use-tool-info.test.js.map +1 -1
  295. package/dist/web/hooks/use-user.d.ts +3 -2
  296. package/dist/web/hooks/use-user.js +4 -3
  297. package/dist/web/hooks/use-user.js.map +1 -1
  298. package/dist/web/hooks/use-user.test.js +85 -37
  299. package/dist/web/hooks/use-user.test.js.map +1 -1
  300. package/dist/web/hooks/use-view-state.js +19 -9
  301. package/dist/web/hooks/use-view-state.js.map +1 -1
  302. package/dist/web/hooks/use-view-state.test.js +39 -4
  303. package/dist/web/hooks/use-view-state.test.js.map +1 -1
  304. package/dist/web/hooks/use-viewport.d.ts +20 -0
  305. package/dist/web/hooks/use-viewport.js +21 -0
  306. package/dist/web/hooks/use-viewport.js.map +1 -0
  307. package/dist/web/hooks/use-viewport.test.d.ts +1 -0
  308. package/dist/web/hooks/use-viewport.test.js +109 -0
  309. package/dist/web/hooks/use-viewport.test.js.map +1 -0
  310. package/dist/web/mount-view.d.ts +3 -2
  311. package/dist/web/mount-view.js +5 -8
  312. package/dist/web/mount-view.js.map +1 -1
  313. package/package.json +31 -28
  314. package/dist/cli/resolve-views-dir.d.ts +0 -1
  315. package/dist/cli/resolve-views-dir.js.map +0 -1
  316. package/dist/server/auth/providers/stytch.test.js +0 -33
  317. package/dist/server/auth/providers/stytch.test.js.map +0 -1
  318. package/dist/server/auth/providers/workos.test.js +0 -41
  319. package/dist/server/auth/providers/workos.test.js.map +0 -1
  320. package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -29
  321. package/dist/web/bridges/apps-sdk/adaptor.js +0 -117
  322. package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
  323. package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -53
  324. package/dist/web/bridges/mcp-app/adaptor.js +0 -283
  325. package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
  326. package/dist/web/hooks/use-layout.d.ts +0 -24
  327. package/dist/web/hooks/use-layout.js +0 -25
  328. package/dist/web/hooks/use-layout.js.map +0 -1
  329. package/dist/web/hooks/use-layout.test.js +0 -96
  330. package/dist/web/hooks/use-layout.test.js.map +0 -1
  331. package/dist/web/plugin/data-llm.test.js +0 -81
  332. package/dist/web/plugin/data-llm.test.js.map +0 -1
  333. package/dist/web/plugin/plugin.d.ts +0 -33
  334. package/dist/web/plugin/plugin.js +0 -189
  335. package/dist/web/plugin/plugin.js.map +0 -1
  336. package/dist/web/plugin/scan-views.js.map +0 -1
  337. package/dist/web/plugin/scan-views.test.js.map +0 -1
  338. package/dist/web/plugin/transform-data-llm.d.ts +0 -12
  339. package/dist/web/plugin/transform-data-llm.js +0 -96
  340. package/dist/web/plugin/transform-data-llm.js.map +0 -1
  341. package/dist/web/plugin/transform-data-llm.test.js +0 -81
  342. package/dist/web/plugin/transform-data-llm.test.js.map +0 -1
  343. package/dist/web/plugin/validate-view.d.ts +0 -1
  344. package/dist/web/plugin/validate-view.js.map +0 -1
  345. package/dist/web/plugin/validate-view.test.js.map +0 -1
  346. /package/dist/{server/auth/providers/stytch.test.d.ts → cli/build-steps.test.d.ts} +0 -0
  347. /package/dist/{server/auth/providers/workos.test.d.ts → context-warnings.test.d.ts} +0 -0
  348. /package/dist/{web/hooks/use-layout.test.d.ts → server/app.test.d.ts} +0 -0
  349. /package/dist/{web/plugin/scan-views.test.d.ts → server/auth/providers/authplane.test.d.ts} +0 -0
  350. /package/dist/{web/plugin/transform-data-llm.test.d.ts → server/auth/providers/shared.test.d.ts} +0 -0
  351. /package/dist/{web/plugin/validate-view.test.d.ts → server/auth/security-schemes.test.d.ts} +0 -0
  352. /package/dist/{web/plugin/data-llm.test.d.ts → server/auth-extra.test-d.d.ts} +0 -0
  353. /package/dist/{web/plugin → views}/scan-views.d.ts +0 -0
  354. /package/dist/{web/plugin → views}/scan-views.test.js +0 -0
  355. /package/dist/{web/plugin → views}/validate-view.test.js +0 -0
@@ -1,11 +1,33 @@
1
- import { type OAuthMetadata } from "@modelcontextprotocol/sdk/shared/auth.js";
1
+ import { z } from "zod/v4";
2
2
  /**
3
- * Discovered AS metadata + `jwks_uri` — the SDK's `OAuthMetadata` omits it (its
4
- * OAuth client never verifies tokens), but we need it to verify token signatures
5
- * via JWKS, so we re-type the field for typed access.
3
+ * Discovery doc validated as OAuth AS metadata + `jwks_uri`. The SDK's
4
+ * `OAuthMetadataSchema` omits `jwks_uri` (its client never verifies tokens), but
5
+ * we need it for JWKS token verification, so we extend the schema to keep it.
6
6
  */
7
- export type DiscoveredMetadata = OAuthMetadata & {
8
- jwks_uri?: string;
9
- };
7
+ declare const DiscoverySchema: z.ZodObject<{
8
+ issuer: z.ZodString;
9
+ authorization_endpoint: z.ZodURL;
10
+ token_endpoint: z.ZodURL;
11
+ registration_endpoint: z.ZodOptional<z.ZodURL>;
12
+ scopes_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
13
+ response_types_supported: z.ZodArray<z.ZodString>;
14
+ response_modes_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
15
+ grant_types_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
16
+ token_endpoint_auth_methods_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
17
+ token_endpoint_auth_signing_alg_values_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
18
+ service_documentation: z.ZodOptional<z.ZodURL>;
19
+ revocation_endpoint: z.ZodOptional<z.ZodURL>;
20
+ revocation_endpoint_auth_methods_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
21
+ revocation_endpoint_auth_signing_alg_values_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
22
+ introspection_endpoint: z.ZodOptional<z.ZodString>;
23
+ introspection_endpoint_auth_methods_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
24
+ introspection_endpoint_auth_signing_alg_values_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
25
+ code_challenge_methods_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
26
+ client_id_metadata_document_supported: z.ZodOptional<z.ZodBoolean>;
27
+ authorization_response_iss_parameter_supported: z.ZodCatch<z.ZodOptional<z.ZodBoolean>>;
28
+ jwks_uri: z.ZodOptional<z.ZodString>;
29
+ }, z.core.$loose>;
30
+ export type DiscoveredMetadata = z.infer<typeof DiscoverySchema>;
10
31
  /** Fetches and validates an authorization server's discovery document. */
11
32
  export declare function discoverAuthorizationServer(issuer: string): Promise<DiscoveredMetadata>;
33
+ export {};
@@ -1,4 +1,13 @@
1
- import { OAuthMetadataSchema, } from "@modelcontextprotocol/sdk/shared/auth.js";
1
+ import { OAuthMetadataSchema } from "@modelcontextprotocol/core";
2
+ import { z } from "zod/v4";
3
+ /**
4
+ * Discovery doc validated as OAuth AS metadata + `jwks_uri`. The SDK's
5
+ * `OAuthMetadataSchema` omits `jwks_uri` (its client never verifies tokens), but
6
+ * we need it for JWKS token verification, so we extend the schema to keep it.
7
+ */
8
+ const DiscoverySchema = OAuthMetadataSchema.extend({
9
+ jwks_uri: z.string().optional(),
10
+ });
2
11
  const WELL_KNOWN = [
3
12
  "/.well-known/openid-configuration",
4
13
  "/.well-known/oauth-authorization-server",
@@ -22,22 +31,18 @@ export async function discoverAuthorizationServer(issuer) {
22
31
  if (!res.ok) {
23
32
  throw new Error(`HTTP ${res.status}`);
24
33
  }
25
- const parsed = OAuthMetadataSchema.safeParse(await res.json());
26
- if (!parsed.success) {
27
- throw new Error(`invalid metadata (${parsed.error.message})`);
28
- }
34
+ const meta = DiscoverySchema.parse(await res.json());
29
35
  // RFC 8414 §3.3: issuer must match the fetch origin (slash-insensitive).
30
- if (parsed.data.issuer.replace(/\/$/, "") !== base) {
31
- throw new Error(`issuer mismatch: ${parsed.data.issuer}`);
36
+ if (meta.issuer.replace(/\/$/, "") !== base) {
37
+ throw new Error(`issuer mismatch: ${meta.issuer}`);
32
38
  }
33
- const metadata = parsed.data;
34
39
  // Prefer the document that advertises DCR: some IdPs (e.g. Clerk) serve a
35
40
  // valid openid-configuration without `registration_endpoint` yet expose
36
41
  // it at oauth-authorization-server. Keep looking past a doc that omits it.
37
- if (metadata.registration_endpoint) {
38
- return metadata;
42
+ if (meta.registration_endpoint) {
43
+ return meta;
39
44
  }
40
- fallback ??= metadata;
45
+ fallback ??= meta;
41
46
  }
42
47
  catch (err) {
43
48
  errors.push(`${url}: ${err instanceof Error ? err.message : String(err)}`);
@@ -1 +1 @@
1
- {"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../../src/server/auth/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,GACpB,MAAM,0CAA0C,CAAC;AASlD,MAAM,UAAU,GAAG;IACjB,mCAAmC;IACnC,yCAAyC;CAC1C,CAAC;AAEF,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAElC,0EAA0E;AAC1E,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,MAAc;IAEd,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACvC,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,2EAA2E;IAC3E,8EAA8E;IAC9E,IAAI,QAAwC,CAAC;IAE7C,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC9B,MAAM,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC;QAC7B,4EAA4E;QAC5E,yEAAyE;QACzE,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;gBAC3B,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,oBAAoB,CAAC;aAClD,CAAC,CAAC;YACH,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;gBACZ,MAAM,IAAI,KAAK,CAAC,QAAQ,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;YACxC,CAAC;YACD,MAAM,MAAM,GAAG,mBAAmB,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;YAC/D,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,MAAM,IAAI,KAAK,CAAC,qBAAqB,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC;YAChE,CAAC;YACD,yEAAyE;YACzE,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC;gBACnD,MAAM,IAAI,KAAK,CAAC,oBAAoB,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;YAC5D,CAAC;YACD,MAAM,QAAQ,GAAG,MAAM,CAAC,IAA0B,CAAC;YACnD,0EAA0E;YAC1E,wEAAwE;YACxE,2EAA2E;YAC3E,IAAI,QAAQ,CAAC,qBAAqB,EAAE,CAAC;gBACnC,OAAO,QAAQ,CAAC;YAClB,CAAC;YACD,QAAQ,KAAK,QAAQ,CAAC;QACxB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,CAAC,IAAI,CACT,GAAG,GAAG,KAAK,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAC9D,CAAC;QACJ,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,8BAA8B,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAChF,CAAC","sourcesContent":["import {\n type OAuthMetadata,\n OAuthMetadataSchema,\n} from \"@modelcontextprotocol/sdk/shared/auth.js\";\n\n/**\n * Discovered AS metadata + `jwks_uri` — the SDK's `OAuthMetadata` omits it (its\n * OAuth client never verifies tokens), but we need it to verify token signatures\n * via JWKS, so we re-type the field for typed access.\n */\nexport type DiscoveredMetadata = OAuthMetadata & { jwks_uri?: string };\n\nconst WELL_KNOWN = [\n \"/.well-known/openid-configuration\",\n \"/.well-known/oauth-authorization-server\",\n];\n\nconst DISCOVERY_TIMEOUT_MS = 5000;\n\n/** Fetches and validates an authorization server's discovery document. */\nexport async function discoverAuthorizationServer(\n issuer: string,\n): Promise<DiscoveredMetadata> {\n const base = issuer.replace(/\\/$/, \"\");\n const errors: string[] = [];\n // First valid doc lacking a registration_endpoint, kept as a fallback so a\n // genuinely non-DCR IdP still resolves (and is rejected later by the caller).\n let fallback: DiscoveredMetadata | undefined;\n\n for (const path of WELL_KNOWN) {\n const url = `${base}${path}`;\n // Any failure (network/timeout, non-2xx, non-JSON, invalid metadata, issuer\n // mismatch) records a per-URL reason and falls through to the next path.\n try {\n const res = await fetch(url, {\n signal: AbortSignal.timeout(DISCOVERY_TIMEOUT_MS),\n });\n if (!res.ok) {\n throw new Error(`HTTP ${res.status}`);\n }\n const parsed = OAuthMetadataSchema.safeParse(await res.json());\n if (!parsed.success) {\n throw new Error(`invalid metadata (${parsed.error.message})`);\n }\n // RFC 8414 §3.3: issuer must match the fetch origin (slash-insensitive).\n if (parsed.data.issuer.replace(/\\/$/, \"\") !== base) {\n throw new Error(`issuer mismatch: ${parsed.data.issuer}`);\n }\n const metadata = parsed.data as DiscoveredMetadata;\n // Prefer the document that advertises DCR: some IdPs (e.g. Clerk) serve a\n // valid openid-configuration without `registration_endpoint` yet expose\n // it at oauth-authorization-server. Keep looking past a doc that omits it.\n if (metadata.registration_endpoint) {\n return metadata;\n }\n fallback ??= metadata;\n } catch (err) {\n errors.push(\n `${url}: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n }\n\n if (fallback) {\n return fallback;\n }\n throw new Error(`OAuth discovery failed for ${issuer}: ${errors.join(\"; \")}`);\n}\n"]}
1
+ {"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../../src/server/auth/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAE3B;;;;GAIG;AACH,MAAM,eAAe,GAAG,mBAAmB,CAAC,MAAM,CAAC;IACjD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAChC,CAAC,CAAC;AAGH,MAAM,UAAU,GAAG;IACjB,mCAAmC;IACnC,yCAAyC;CAC1C,CAAC;AAEF,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAElC,0EAA0E;AAC1E,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,MAAc;IAEd,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACvC,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,2EAA2E;IAC3E,8EAA8E;IAC9E,IAAI,QAAwC,CAAC;IAE7C,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC9B,MAAM,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC;QAC7B,4EAA4E;QAC5E,yEAAyE;QACzE,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;gBAC3B,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,oBAAoB,CAAC;aAClD,CAAC,CAAC;YACH,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;gBACZ,MAAM,IAAI,KAAK,CAAC,QAAQ,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;YACxC,CAAC;YACD,MAAM,IAAI,GAAG,eAAe,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;YACrD,yEAAyE;YACzE,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC;gBAC5C,MAAM,IAAI,KAAK,CAAC,oBAAoB,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;YACrD,CAAC;YACD,0EAA0E;YAC1E,wEAAwE;YACxE,2EAA2E;YAC3E,IAAI,IAAI,CAAC,qBAAqB,EAAE,CAAC;gBAC/B,OAAO,IAAI,CAAC;YACd,CAAC;YACD,QAAQ,KAAK,IAAI,CAAC;QACpB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,CAAC,IAAI,CACT,GAAG,GAAG,KAAK,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAC9D,CAAC;QACJ,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,8BAA8B,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAChF,CAAC","sourcesContent":["import { OAuthMetadataSchema } from \"@modelcontextprotocol/core\";\nimport { z } from \"zod/v4\";\n\n/**\n * Discovery doc validated as OAuth AS metadata + `jwks_uri`. The SDK's\n * `OAuthMetadataSchema` omits `jwks_uri` (its client never verifies tokens), but\n * we need it for JWKS token verification, so we extend the schema to keep it.\n */\nconst DiscoverySchema = OAuthMetadataSchema.extend({\n jwks_uri: z.string().optional(),\n});\nexport type DiscoveredMetadata = z.infer<typeof DiscoverySchema>;\n\nconst WELL_KNOWN = [\n \"/.well-known/openid-configuration\",\n \"/.well-known/oauth-authorization-server\",\n];\n\nconst DISCOVERY_TIMEOUT_MS = 5000;\n\n/** Fetches and validates an authorization server's discovery document. */\nexport async function discoverAuthorizationServer(\n issuer: string,\n): Promise<DiscoveredMetadata> {\n const base = issuer.replace(/\\/$/, \"\");\n const errors: string[] = [];\n // First valid doc lacking a registration_endpoint, kept as a fallback so a\n // genuinely non-DCR IdP still resolves (and is rejected later by the caller).\n let fallback: DiscoveredMetadata | undefined;\n\n for (const path of WELL_KNOWN) {\n const url = `${base}${path}`;\n // Any failure (network/timeout, non-2xx, non-JSON, invalid metadata, issuer\n // mismatch) records a per-URL reason and falls through to the next path.\n try {\n const res = await fetch(url, {\n signal: AbortSignal.timeout(DISCOVERY_TIMEOUT_MS),\n });\n if (!res.ok) {\n throw new Error(`HTTP ${res.status}`);\n }\n const meta = DiscoverySchema.parse(await res.json());\n // RFC 8414 §3.3: issuer must match the fetch origin (slash-insensitive).\n if (meta.issuer.replace(/\\/$/, \"\") !== base) {\n throw new Error(`issuer mismatch: ${meta.issuer}`);\n }\n // Prefer the document that advertises DCR: some IdPs (e.g. Clerk) serve a\n // valid openid-configuration without `registration_endpoint` yet expose\n // it at oauth-authorization-server. Keep looking past a doc that omits it.\n if (meta.registration_endpoint) {\n return meta;\n }\n fallback ??= meta;\n } catch (err) {\n errors.push(\n `${url}: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n }\n\n if (fallback) {\n return fallback;\n }\n throw new Error(`OAuth discovery failed for ${issuer}: ${errors.join(\"; \")}`);\n}\n"]}
@@ -1,7 +1,15 @@
1
- import type { OAuthMetadata } from "@modelcontextprotocol/sdk/shared/auth.js";
2
- import type { JwksVerifyConfig } from "./verify.js";
3
- /** Resource-server OAuth config for `SkybridgeServerOptions.oauth`. */
4
- export type OAuthConfig = {
1
+ import type { OAuthMetadata } from "@modelcontextprotocol/server";
2
+ import type { ExtraClaims, TokenVerifier } from "../auth.js";
3
+ /**
4
+ * Resource-server OAuth config for the `oauth` field of `SkybridgeConfig`.
5
+ *
6
+ * `TExtra` comes from the `verifier` and flows on to tool handlers and
7
+ * `mcpMiddleware`, so the claim shape is declared once by whoever checks the
8
+ * token. The branded providers set it from the claims their IdP documents.
9
+ *
10
+ * @typeParam TExtra - Claims the verifier populates in `AuthInfo["extra"]`.
11
+ */
12
+ export type OAuthConfig<TExtra extends ExtraClaims = ExtraClaims> = {
5
13
  /**
6
14
  * Public URL of this server; sets `resourceServerUrl` and the
7
15
  * `resource_metadata` URL. When omitted, it is inferred per request from
@@ -10,9 +18,31 @@ export type OAuthConfig = {
10
18
  baseUrl?: string;
11
19
  /** AS metadata served at `/.well-known/oauth-authorization-server`. */
12
20
  oauthMetadata: OAuthMetadata;
13
- verify: JwksVerifyConfig;
14
21
  /** Scopes advertised in protected-resource metadata. */
15
22
  scopesSupported?: string[];
16
23
  /** Server-wide required-scope floor. */
17
24
  requiredScopes?: string[];
25
+ /**
26
+ * Checks each bearer token. Build one with `createJwksVerifier` for a
27
+ * JWT-issuing IdP, or supply your own for opaque tokens.
28
+ */
29
+ verifier: TokenVerifier<TExtra>;
30
+ };
31
+ /**
32
+ * What the branded providers return: a deferred {@link OAuthConfig}. Discovery
33
+ * runs in `resolve`, so `oauth: auth0Provider(...)` at module scope performs
34
+ * no network access until `Skybridge.run`. Call `resolve` yourself
35
+ * (`await customProvider(...).resolve()`) when wiring the middleware by hand.
36
+ *
37
+ * This is an object rather than a bare `() => Promise<OAuthConfig>` on
38
+ * purpose. TypeScript defers, during the first inference pass, any argument
39
+ * that is a call to a generic function returning a function type. The
40
+ * providers are generic (`workosProvider<TCustom>`), so a function-shaped
41
+ * return written inline in `new Skybridge({ oauth: workosProvider(...) })`
42
+ * would be skipped and `TAuthExtra` would fall back to `ExtraClaims`, losing
43
+ * the claims typing in tool handlers. A non-function shape is inferred
44
+ * eagerly.
45
+ */
46
+ export type OAuthProvider<TExtra extends ExtraClaims = ExtraClaims> = {
47
+ resolve: () => Promise<OAuthConfig<TExtra>>;
18
48
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/auth/index.ts"],"names":[],"mappings":"","sourcesContent":["import type { OAuthMetadata } from \"@modelcontextprotocol/sdk/shared/auth.js\";\nimport type { JwksVerifyConfig } from \"./verify.js\";\n\n/** Resource-server OAuth config for `SkybridgeServerOptions.oauth`. */\nexport type OAuthConfig = {\n /**\n * Public URL of this server; sets `resourceServerUrl` and the\n * `resource_metadata` URL. When omitted, it is inferred per request from\n * `x-forwarded-host`/`origin`/`host` headers.\n */\n baseUrl?: string;\n /** AS metadata served at `/.well-known/oauth-authorization-server`. */\n oauthMetadata: OAuthMetadata;\n verify: JwksVerifyConfig;\n /** Scopes advertised in protected-resource metadata. */\n scopesSupported?: string[];\n /** Server-wide required-scope floor. */\n requiredScopes?: string[];\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/auth/index.ts"],"names":[],"mappings":"","sourcesContent":["import type { OAuthMetadata } from \"@modelcontextprotocol/server\";\nimport type { ExtraClaims, TokenVerifier } from \"../auth.js\";\n\n/**\n * Resource-server OAuth config for the `oauth` field of `SkybridgeConfig`.\n *\n * `TExtra` comes from the `verifier` and flows on to tool handlers and\n * `mcpMiddleware`, so the claim shape is declared once by whoever checks the\n * token. The branded providers set it from the claims their IdP documents.\n *\n * @typeParam TExtra - Claims the verifier populates in `AuthInfo[\"extra\"]`.\n */\nexport type OAuthConfig<TExtra extends ExtraClaims = ExtraClaims> = {\n /**\n * Public URL of this server; sets `resourceServerUrl` and the\n * `resource_metadata` URL. When omitted, it is inferred per request from\n * `x-forwarded-host`/`origin`/`host` headers.\n */\n baseUrl?: string;\n /** AS metadata served at `/.well-known/oauth-authorization-server`. */\n oauthMetadata: OAuthMetadata;\n /** Scopes advertised in protected-resource metadata. */\n scopesSupported?: string[];\n /** Server-wide required-scope floor. */\n requiredScopes?: string[];\n /**\n * Checks each bearer token. Build one with `createJwksVerifier` for a\n * JWT-issuing IdP, or supply your own for opaque tokens.\n */\n verifier: TokenVerifier<TExtra>;\n};\n\n/**\n * What the branded providers return: a deferred {@link OAuthConfig}. Discovery\n * runs in `resolve`, so `oauth: auth0Provider(...)` at module scope performs\n * no network access until `Skybridge.run`. Call `resolve` yourself\n * (`await customProvider(...).resolve()`) when wiring the middleware by hand.\n *\n * This is an object rather than a bare `() => Promise<OAuthConfig>` on\n * purpose. TypeScript defers, during the first inference pass, any argument\n * that is a call to a generic function returning a function type. The\n * providers are generic (`workosProvider<TCustom>`), so a function-shaped\n * return written inline in `new Skybridge({ oauth: workosProvider(...) })`\n * would be skipped and `TAuthExtra` would fall back to `ExtraClaims`, losing\n * the claims typing in tool handlers. A non-function shape is inferred\n * eagerly.\n */\nexport type OAuthProvider<TExtra extends ExtraClaims = ExtraClaims> = {\n resolve: () => Promise<OAuthConfig<TExtra>>;\n};\n"]}
@@ -1,13 +1,40 @@
1
- import type { OAuthConfig } from "../index.js";
1
+ import type { ExtraClaims } from "../../auth.js";
2
+ import type { OAuthProvider } from "../index.js";
3
+ import type { RegisteredClaims } from "../verify.js";
2
4
  import { type CustomProviderOptions } from "./custom.js";
5
+ /**
6
+ * Claims an Auth0 access token carries for a custom API audience. Auth0 puts no
7
+ * user attributes beyond the id in the token, so there is no `email`: call
8
+ * `/userinfo` for the profile. Custom claims must be namespaced (a bare `email`
9
+ * key is silently dropped), so add them through the type parameter under their
10
+ * full URI.
11
+ *
12
+ * @see https://auth0.com/docs/secure/tokens/access-tokens
13
+ * @see https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims
14
+ */
15
+ export type Auth0Claims = {
16
+ /** Authorized party: the client id the token was issued to. */
17
+ azp?: string;
18
+ /** Only when the API has RBAC and "Add Permissions in the Access Token" on. */
19
+ permissions?: string[];
20
+ /** Organization id, when the tenant uses Organizations. */
21
+ org_id?: string;
22
+ /** Organization name, when the tenant uses Organizations. */
23
+ org_name?: string;
24
+ };
3
25
  /**
4
26
  * OAuth provider for Auth0. `domain` is the tenant domain (e.g.
5
- * `acme.us.auth0.com`) or a custom domain. Requires Dynamic Client
6
- * Registration enabled on the tenant (`enable_dynamic_client_registration`).
7
- * `audience` is the registered API Identifier — Auth0 only issues a verifiable
8
- * JWT (rather than an opaque token) when the request targets that audience.
27
+ * `acme.us.auth0.com`); `audience` is the API Identifier; `serverUrl` is this
28
+ * server's public URL. Requires DCR enabled on the tenant.
29
+ *
30
+ * Auth0 can't use the client's resource indicator — `audience` must be *in* the
31
+ * authorize request. So it runs as skybridge-as-AS (`serverUrl`, see
32
+ * {@link customProvider}) and bakes `?audience=<id>` into the advertised
33
+ * `authorization_endpoint`. The token's `aud` is the API; `verify.issuer` stays
34
+ * Auth0 (the token's real `iss`).
9
35
  */
10
- export declare function auth0Provider(opts: {
36
+ export declare function auth0Provider<TCustom extends ExtraClaims = Record<never, never>>(opts: {
11
37
  domain: string;
12
38
  audience: string;
13
- } & Omit<CustomProviderOptions, "issuer" | "audience">): Promise<OAuthConfig>;
39
+ serverUrl: string;
40
+ } & Omit<CustomProviderOptions, "issuer" | "audience" | "baseUrl" | "serverUrl">): OAuthProvider<Auth0Claims & TCustom & RegisteredClaims>;
@@ -1,18 +1,36 @@
1
1
  import { customProvider } from "./custom.js";
2
- /** Normalises a bare host to an https issuer URL and strips a trailing slash. */
3
- function toIssuerUrl(domain) {
4
- const withScheme = /^https?:\/\//.test(domain) ? domain : `https://${domain}`;
5
- return withScheme.replace(/\/$/, "");
6
- }
2
+ import { toIssuerUrl } from "./shared.js";
7
3
  /**
8
4
  * OAuth provider for Auth0. `domain` is the tenant domain (e.g.
9
- * `acme.us.auth0.com`) or a custom domain. Requires Dynamic Client
10
- * Registration enabled on the tenant (`enable_dynamic_client_registration`).
11
- * `audience` is the registered API Identifier — Auth0 only issues a verifiable
12
- * JWT (rather than an opaque token) when the request targets that audience.
5
+ * `acme.us.auth0.com`); `audience` is the API Identifier; `serverUrl` is this
6
+ * server's public URL. Requires DCR enabled on the tenant.
7
+ *
8
+ * Auth0 can't use the client's resource indicator — `audience` must be *in* the
9
+ * authorize request. So it runs as skybridge-as-AS (`serverUrl`, see
10
+ * {@link customProvider}) and bakes `?audience=<id>` into the advertised
11
+ * `authorization_endpoint`. The token's `aud` is the API; `verify.issuer` stays
12
+ * Auth0 (the token's real `iss`).
13
13
  */
14
14
  export function auth0Provider(opts) {
15
- const { domain, ...rest } = opts;
16
- return customProvider({ issuer: toIssuerUrl(domain), ...rest });
15
+ const { domain, audience, ...rest } = opts;
16
+ const provider = customProvider({
17
+ issuer: toIssuerUrl(domain),
18
+ audience,
19
+ ...rest,
20
+ });
21
+ return {
22
+ resolve: async () => {
23
+ const config = await provider.resolve();
24
+ const authUrl = new URL(config.oauthMetadata.authorization_endpoint);
25
+ authUrl.searchParams.set("audience", audience);
26
+ return {
27
+ ...config,
28
+ oauthMetadata: {
29
+ ...config.oauthMetadata,
30
+ authorization_endpoint: authUrl.href,
31
+ },
32
+ };
33
+ },
34
+ };
17
35
  }
18
36
  //# sourceMappingURL=auth0.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth0.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/auth0.ts"],"names":[],"mappings":"AACA,OAAO,EAA8B,cAAc,EAAE,MAAM,aAAa,CAAC;AAEzE,iFAAiF;AACjF,SAAS,WAAW,CAAC,MAAc;IACjC,MAAM,UAAU,GAAG,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,MAAM,EAAE,CAAC;IAC9E,OAAO,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAC3B,IAGC;IAED,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IACjC,OAAO,cAAc,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;AAClE,CAAC","sourcesContent":["import type { OAuthConfig } from \"../index.js\";\nimport { type CustomProviderOptions, customProvider } from \"./custom.js\";\n\n/** Normalises a bare host to an https issuer URL and strips a trailing slash. */\nfunction toIssuerUrl(domain: string): string {\n const withScheme = /^https?:\\/\\//.test(domain) ? domain : `https://${domain}`;\n return withScheme.replace(/\\/$/, \"\");\n}\n\n/**\n * OAuth provider for Auth0. `domain` is the tenant domain (e.g.\n * `acme.us.auth0.com`) or a custom domain. Requires Dynamic Client\n * Registration enabled on the tenant (`enable_dynamic_client_registration`).\n * `audience` is the registered API Identifier — Auth0 only issues a verifiable\n * JWT (rather than an opaque token) when the request targets that audience.\n */\nexport function auth0Provider(\n opts: { domain: string; audience: string } & Omit<\n CustomProviderOptions,\n \"issuer\" | \"audience\"\n >,\n): Promise<OAuthConfig> {\n const { domain, ...rest } = opts;\n return customProvider({ issuer: toIssuerUrl(domain), ...rest });\n}\n"]}
1
+ {"version":3,"file":"auth0.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/auth0.ts"],"names":[],"mappings":"AAGA,OAAO,EAA8B,cAAc,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAuB1C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAG3B,IAGC;IAED,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IAC3C,MAAM,QAAQ,GAAG,cAAc,CAAwB;QACrD,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC;QAC3B,QAAQ;QACR,GAAG,IAAI;KACR,CAAC,CAAC;IACH,OAAO;QACL,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAC;YACxC,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,sBAAsB,CAAC,CAAC;YACrE,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;YAC/C,OAAO;gBACL,GAAG,MAAM;gBACT,aAAa,EAAE;oBACb,GAAG,MAAM,CAAC,aAAa;oBACvB,sBAAsB,EAAE,OAAO,CAAC,IAAI;iBACrC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { ExtraClaims } from \"../../auth.js\";\nimport type { OAuthProvider } from \"../index.js\";\nimport type { RegisteredClaims } from \"../verify.js\";\nimport { type CustomProviderOptions, customProvider } from \"./custom.js\";\nimport { toIssuerUrl } from \"./shared.js\";\n\n/**\n * Claims an Auth0 access token carries for a custom API audience. Auth0 puts no\n * user attributes beyond the id in the token, so there is no `email`: call\n * `/userinfo` for the profile. Custom claims must be namespaced (a bare `email`\n * key is silently dropped), so add them through the type parameter under their\n * full URI.\n *\n * @see https://auth0.com/docs/secure/tokens/access-tokens\n * @see https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims\n */\nexport type Auth0Claims = {\n /** Authorized party: the client id the token was issued to. */\n azp?: string;\n /** Only when the API has RBAC and \"Add Permissions in the Access Token\" on. */\n permissions?: string[];\n /** Organization id, when the tenant uses Organizations. */\n org_id?: string;\n /** Organization name, when the tenant uses Organizations. */\n org_name?: string;\n};\n\n/**\n * OAuth provider for Auth0. `domain` is the tenant domain (e.g.\n * `acme.us.auth0.com`); `audience` is the API Identifier; `serverUrl` is this\n * server's public URL. Requires DCR enabled on the tenant.\n *\n * Auth0 can't use the client's resource indicator — `audience` must be *in* the\n * authorize request. So it runs as skybridge-as-AS (`serverUrl`, see\n * {@link customProvider}) and bakes `?audience=<id>` into the advertised\n * `authorization_endpoint`. The token's `aud` is the API; `verify.issuer` stays\n * Auth0 (the token's real `iss`).\n */\nexport function auth0Provider<\n TCustom extends ExtraClaims = Record<never, never>,\n>(\n opts: { domain: string; audience: string; serverUrl: string } & Omit<\n CustomProviderOptions,\n \"issuer\" | \"audience\" | \"baseUrl\" | \"serverUrl\"\n >,\n): OAuthProvider<Auth0Claims & TCustom & RegisteredClaims> {\n const { domain, audience, ...rest } = opts;\n const provider = customProvider<Auth0Claims & TCustom>({\n issuer: toIssuerUrl(domain),\n audience,\n ...rest,\n });\n return {\n resolve: async () => {\n const config = await provider.resolve();\n const authUrl = new URL(config.oauthMetadata.authorization_endpoint);\n authUrl.searchParams.set(\"audience\", audience);\n return {\n ...config,\n oauthMetadata: {\n ...config.oauthMetadata,\n authorization_endpoint: authUrl.href,\n },\n };\n },\n };\n}\n"]}
@@ -1,33 +1,50 @@
1
1
  // @vitest-environment node
2
2
  import { afterEach, describe, expect, it, vi } from "vitest";
3
3
  import { auth0Provider } from "./auth0.js";
4
+ import { lastJwksConfig as jwks } from "./verify-spy.js";
5
+ vi.mock("../verify.js", () => import("./verify-spy.js"));
4
6
  afterEach(() => vi.restoreAllMocks());
5
- function discoveryDoc(issuer) {
7
+ function doc(issuer) {
6
8
  return {
7
9
  issuer,
8
10
  authorization_endpoint: `${issuer}/authorize`,
9
11
  token_endpoint: `${issuer}/oauth/token`,
10
12
  registration_endpoint: `${issuer}/oidc/register`,
11
13
  response_types_supported: ["code"],
12
- scopes_supported: ["openid"],
14
+ scopes_supported: ["openid", "profile", "email"],
13
15
  jwks_uri: `${issuer}/.well-known/jwks.json`,
14
16
  };
15
17
  }
16
- function mockDiscovery(issuer) {
17
- return vi.spyOn(globalThis, "fetch").mockResolvedValue(new Response(JSON.stringify(discoveryDoc(issuer)), {
18
- headers: { "content-type": "application/json" },
19
- }));
20
- }
21
18
  describe("auth0Provider", () => {
22
- it("builds the issuer from the tenant domain", async () => {
23
- const fetchSpy = mockDiscovery("https://acme.us.auth0.com");
19
+ it("advertises skybridge as the AS (static issuer) and bakes audience; verifies against Auth0", async () => {
20
+ const issuer = "https://acme.us.auth0.com";
21
+ vi.spyOn(globalThis, "fetch").mockResolvedValue(new Response(JSON.stringify(doc(issuer)), {
22
+ headers: { "content-type": "application/json" },
23
+ }));
24
24
  const config = await auth0Provider({
25
25
  domain: "acme.us.auth0.com",
26
- audience: "https://my-mcp-api",
27
- });
28
- expect(fetchSpy).toHaveBeenCalledWith("https://acme.us.auth0.com/.well-known/openid-configuration", expect.anything());
29
- expect(config.verify.issuer).toBe("https://acme.us.auth0.com");
30
- expect(config.verify.audience).toBe("https://my-mcp-api");
26
+ audience: "https://api.example.com/",
27
+ serverUrl: "https://app.example.com/",
28
+ scopes: ["openid", "profile", "email"],
29
+ }).resolve();
30
+ // skybridge is the advertised AS: static issuer = serverUrl (trailing slash stripped).
31
+ expect(config.oauthMetadata.issuer).toBe("https://app.example.com");
32
+ // AS metadata scopes match the advertised set (clients read scopes from here).
33
+ expect(config.oauthMetadata.scopes_supported).toEqual([
34
+ "openid",
35
+ "profile",
36
+ "email",
37
+ ]);
38
+ expect(config.scopesSupported).toEqual(["openid", "profile", "email"]);
39
+ // audience baked into the advertised authorize endpoint (still pointing at Auth0).
40
+ const url = new URL(config.oauthMetadata.authorization_endpoint);
41
+ expect(url.origin + url.pathname).toBe(`${issuer}/authorize`);
42
+ expect(url.searchParams.get("audience")).toBe("https://api.example.com/");
43
+ // baseUrl left unset so the PRM resource resolves per request (Alpic-safe).
44
+ expect(config.baseUrl).toBeUndefined();
45
+ // token verification still uses Auth0 as issuer + the API audience.
46
+ expect(jwks().issuer).toBe(issuer);
47
+ expect(jwks().audience).toBe("https://api.example.com/");
31
48
  });
32
49
  });
33
50
  //# sourceMappingURL=auth0.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth0.test.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/auth0.test.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,SAAS,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,eAAe,EAAE,CAAC,CAAC;AAEtC,SAAS,YAAY,CAAC,MAAc;IAClC,OAAO;QACL,MAAM;QACN,sBAAsB,EAAE,GAAG,MAAM,YAAY;QAC7C,cAAc,EAAE,GAAG,MAAM,cAAc;QACvC,qBAAqB,EAAE,GAAG,MAAM,gBAAgB;QAChD,wBAAwB,EAAE,CAAC,MAAM,CAAC;QAClC,gBAAgB,EAAE,CAAC,QAAQ,CAAC;QAC5B,QAAQ,EAAE,GAAG,MAAM,wBAAwB;KAC5C,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,MAAc;IACnC,OAAO,EAAE,CAAC,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,iBAAiB,CACpD,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,EAAE;QACjD,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;KAChD,CAAC,CACH,CAAC;AACJ,CAAC;AAED,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,0CAA0C,EAAE,KAAK,IAAI,EAAE;QACxD,MAAM,QAAQ,GAAG,aAAa,CAAC,2BAA2B,CAAC,CAAC;QAE5D,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC;YACjC,MAAM,EAAE,mBAAmB;YAC3B,QAAQ,EAAE,oBAAoB;SAC/B,CAAC,CAAC;QAEH,MAAM,CAAC,QAAQ,CAAC,CAAC,oBAAoB,CACnC,4DAA4D,EAC5D,MAAM,CAAC,QAAQ,EAAE,CAClB,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;QAC/D,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// @vitest-environment node\nimport { afterEach, describe, expect, it, vi } from \"vitest\";\nimport { auth0Provider } from \"./auth0.js\";\n\nafterEach(() => vi.restoreAllMocks());\n\nfunction discoveryDoc(issuer: string) {\n return {\n issuer,\n authorization_endpoint: `${issuer}/authorize`,\n token_endpoint: `${issuer}/oauth/token`,\n registration_endpoint: `${issuer}/oidc/register`,\n response_types_supported: [\"code\"],\n scopes_supported: [\"openid\"],\n jwks_uri: `${issuer}/.well-known/jwks.json`,\n };\n}\n\nfunction mockDiscovery(issuer: string) {\n return vi.spyOn(globalThis, \"fetch\").mockResolvedValue(\n new Response(JSON.stringify(discoveryDoc(issuer)), {\n headers: { \"content-type\": \"application/json\" },\n }),\n );\n}\n\ndescribe(\"auth0Provider\", () => {\n it(\"builds the issuer from the tenant domain\", async () => {\n const fetchSpy = mockDiscovery(\"https://acme.us.auth0.com\");\n\n const config = await auth0Provider({\n domain: \"acme.us.auth0.com\",\n audience: \"https://my-mcp-api\",\n });\n\n expect(fetchSpy).toHaveBeenCalledWith(\n \"https://acme.us.auth0.com/.well-known/openid-configuration\",\n expect.anything(),\n );\n expect(config.verify.issuer).toBe(\"https://acme.us.auth0.com\");\n expect(config.verify.audience).toBe(\"https://my-mcp-api\");\n });\n});\n"]}
1
+ {"version":3,"file":"auth0.test.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/auth0.test.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,cAAc,IAAI,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEzD,EAAE,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC;AAEzD,SAAS,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,eAAe,EAAE,CAAC,CAAC;AAEtC,SAAS,GAAG,CAAC,MAAc;IACzB,OAAO;QACL,MAAM;QACN,sBAAsB,EAAE,GAAG,MAAM,YAAY;QAC7C,cAAc,EAAE,GAAG,MAAM,cAAc;QACvC,qBAAqB,EAAE,GAAG,MAAM,gBAAgB;QAChD,wBAAwB,EAAE,CAAC,MAAM,CAAC;QAClC,gBAAgB,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC;QAChD,QAAQ,EAAE,GAAG,MAAM,wBAAwB;KAC5C,CAAC;AACJ,CAAC;AAED,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,2FAA2F,EAAE,KAAK,IAAI,EAAE;QACzG,MAAM,MAAM,GAAG,2BAA2B,CAAC;QAC3C,EAAE,CAAC,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,iBAAiB,CAC7C,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE;YACxC,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;SAChD,CAAC,CACH,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC;YACjC,MAAM,EAAE,mBAAmB;YAC3B,QAAQ,EAAE,0BAA0B;YACpC,SAAS,EAAE,0BAA0B;YACrC,MAAM,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC;SACvC,CAAC,CAAC,OAAO,EAAE,CAAC;QAEb,uFAAuF;QACvF,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;QACpE,+EAA+E;QAC/E,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,OAAO,CAAC;YACpD,QAAQ;YACR,SAAS;YACT,OAAO;SACR,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;QACvE,mFAAmF;QACnF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,sBAAsB,CAAC,CAAC;QACjE,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,MAAM,YAAY,CAAC,CAAC;QAC9D,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;QAC1E,4EAA4E;QAC5E,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,CAAC;QACvC,oEAAoE;QACpE,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACnC,MAAM,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// @vitest-environment node\nimport { afterEach, describe, expect, it, vi } from \"vitest\";\nimport { auth0Provider } from \"./auth0.js\";\nimport { lastJwksConfig as jwks } from \"./verify-spy.js\";\n\nvi.mock(\"../verify.js\", () => import(\"./verify-spy.js\"));\n\nafterEach(() => vi.restoreAllMocks());\n\nfunction doc(issuer: string) {\n return {\n issuer,\n authorization_endpoint: `${issuer}/authorize`,\n token_endpoint: `${issuer}/oauth/token`,\n registration_endpoint: `${issuer}/oidc/register`,\n response_types_supported: [\"code\"],\n scopes_supported: [\"openid\", \"profile\", \"email\"],\n jwks_uri: `${issuer}/.well-known/jwks.json`,\n };\n}\n\ndescribe(\"auth0Provider\", () => {\n it(\"advertises skybridge as the AS (static issuer) and bakes audience; verifies against Auth0\", async () => {\n const issuer = \"https://acme.us.auth0.com\";\n vi.spyOn(globalThis, \"fetch\").mockResolvedValue(\n new Response(JSON.stringify(doc(issuer)), {\n headers: { \"content-type\": \"application/json\" },\n }),\n );\n\n const config = await auth0Provider({\n domain: \"acme.us.auth0.com\",\n audience: \"https://api.example.com/\",\n serverUrl: \"https://app.example.com/\",\n scopes: [\"openid\", \"profile\", \"email\"],\n }).resolve();\n\n // skybridge is the advertised AS: static issuer = serverUrl (trailing slash stripped).\n expect(config.oauthMetadata.issuer).toBe(\"https://app.example.com\");\n // AS metadata scopes match the advertised set (clients read scopes from here).\n expect(config.oauthMetadata.scopes_supported).toEqual([\n \"openid\",\n \"profile\",\n \"email\",\n ]);\n expect(config.scopesSupported).toEqual([\"openid\", \"profile\", \"email\"]);\n // audience baked into the advertised authorize endpoint (still pointing at Auth0).\n const url = new URL(config.oauthMetadata.authorization_endpoint);\n expect(url.origin + url.pathname).toBe(`${issuer}/authorize`);\n expect(url.searchParams.get(\"audience\")).toBe(\"https://api.example.com/\");\n // baseUrl left unset so the PRM resource resolves per request (Alpic-safe).\n expect(config.baseUrl).toBeUndefined();\n // token verification still uses Auth0 as issuer + the API audience.\n expect(jwks().issuer).toBe(issuer);\n expect(jwks().audience).toBe(\"https://api.example.com/\");\n });\n});\n"]}
@@ -0,0 +1,49 @@
1
+ import type { ExtraClaims } from "../../auth.js";
2
+ import type { OAuthProvider } from "../index.js";
3
+ import type { RegisteredClaims } from "../verify.js";
4
+ import { type CustomProviderOptions } from "./custom.js";
5
+ /** Options accepted by {@link authplaneProvider}. */
6
+ export type AuthplaneProviderOptions = {
7
+ /**
8
+ * The authorization server's issuer identifier (RFC 8414 §2) — your
9
+ * Authplane deployment, e.g. `https://auth.acme.com` (or
10
+ * `http://localhost:9000` in local development).
11
+ */
12
+ issuer: string;
13
+ /**
14
+ * This server's resource identifier (RFC 9728 §1.2): the public URL clients
15
+ * reach, advertised as the `resource` field of its protected-resource
16
+ * metadata. Required, unlike the other providers.
17
+ *
18
+ * Authplane binds the access token's `aud` to the RFC 8707 `resource`
19
+ * parameter the client sends, and the client takes that value from the
20
+ * advertised metadata. Setting it explicitly gives the deployment one fixed
21
+ * identifier, which is what the audience is checked against.
22
+ *
23
+ * Resource identifiers are compared by exact string match, so give it in the
24
+ * form it will be advertised and register that same string in Authplane. RFC
25
+ * 8707 §2 asks for the most specific URI available, e.g.
26
+ * `https://acme.example.com/mcp`.
27
+ */
28
+ resource: string;
29
+ /**
30
+ * Expected token `aud`. Defaults to `resource`.
31
+ *
32
+ * RFC 8707 §2 lets an authorization server use the resource identifier
33
+ * verbatim as the audience or map it to another value; set this only for a
34
+ * resource configured in Authplane with such an override, and pass that
35
+ * value verbatim.
36
+ */
37
+ audience?: string;
38
+ } & Omit<CustomProviderOptions, "issuer" | "audience" | "baseUrl">;
39
+ /**
40
+ * OAuth provider for Authplane. `issuer` is the authorization server's issuer
41
+ * identifier and `resource` is this server's resource identifier, which also
42
+ * supplies the expected token audience.
43
+ *
44
+ * Dynamic Client Registration is supported natively, so no registration proxy
45
+ * is needed: clients register with Authplane directly and this server stays out
46
+ * of the authorization path. Pass `serverUrl` to advertise this server as the
47
+ * authorization server instead (see {@link customProvider}).
48
+ */
49
+ export declare function authplaneProvider<TCustom extends ExtraClaims = Record<never, never>>(opts: AuthplaneProviderOptions): OAuthProvider<TCustom & RegisteredClaims>;
@@ -0,0 +1,57 @@
1
+ import { customProvider } from "./custom.js";
2
+ /**
3
+ * Rejects anything that cannot serve as an OAuth identifier: RFC 8707 §2
4
+ * requires an absolute URI and forbids a fragment, and the discovery and
5
+ * protected-resource metadata URLs are both built from the scheme and host.
6
+ */
7
+ function parseIdentifier(value, option) {
8
+ let parsed;
9
+ try {
10
+ parsed = new URL(value);
11
+ }
12
+ catch {
13
+ throw new Error(`authplaneProvider: \`${option}\` must be an absolute URL, got ${JSON.stringify(value)}`);
14
+ }
15
+ if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
16
+ throw new Error(`authplaneProvider: \`${option}\` must use the http or https scheme, got ${JSON.stringify(value)}`);
17
+ }
18
+ if (!parsed.host) {
19
+ throw new Error(`authplaneProvider: \`${option}\` must include a host, got ${JSON.stringify(value)}`);
20
+ }
21
+ if (parsed.hash) {
22
+ throw new Error(`authplaneProvider: \`${option}\` must not include a fragment, got ${JSON.stringify(value)}`);
23
+ }
24
+ return parsed;
25
+ }
26
+ /**
27
+ * OAuth provider for Authplane. `issuer` is the authorization server's issuer
28
+ * identifier and `resource` is this server's resource identifier, which also
29
+ * supplies the expected token audience.
30
+ *
31
+ * Dynamic Client Registration is supported natively, so no registration proxy
32
+ * is needed: clients register with Authplane directly and this server stays out
33
+ * of the authorization path. Pass `serverUrl` to advertise this server as the
34
+ * authorization server instead (see {@link customProvider}).
35
+ */
36
+ export function authplaneProvider(opts) {
37
+ const { issuer, resource, audience, ...rest } = opts;
38
+ parseIdentifier(issuer, "issuer");
39
+ const parsedResource = parseIdentifier(resource, "resource");
40
+ // The advertised resource is the URL-normalised form of this value. Where
41
+ // normalisation would change the string — a bare origin gaining a root path,
42
+ // an uppercase host, an explicit default port — the configured and advertised
43
+ // identifiers would differ, and the audience check compares them exactly.
44
+ // Require the advertised form up front so the two always match.
45
+ if (parsedResource.href !== resource) {
46
+ throw new Error(`authplaneProvider: \`resource\` must be given in the form it will be advertised. ` +
47
+ `${JSON.stringify(resource)} is advertised as ${JSON.stringify(parsedResource.href)}. ` +
48
+ `Use ${JSON.stringify(parsedResource.href)}, or a path-qualified URL such as "https://acme.example.com/mcp", and register the same value in Authplane.`);
49
+ }
50
+ return customProvider({
51
+ issuer,
52
+ audience: audience ?? resource,
53
+ baseUrl: resource,
54
+ ...rest,
55
+ });
56
+ }
57
+ //# sourceMappingURL=authplane.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authplane.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/authplane.ts"],"names":[],"mappings":"AAGA,OAAO,EAA8B,cAAc,EAAE,MAAM,aAAa,CAAC;AAqCzE;;;;GAIG;AACH,SAAS,eAAe,CAAC,KAAa,EAAE,MAAc;IACpD,IAAI,MAAW,CAAC;IAChB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CACb,wBAAwB,MAAM,mCAAmC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CACzF,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QAChE,MAAM,IAAI,KAAK,CACb,wBAAwB,MAAM,6CAA6C,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CACnG,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CACb,wBAAwB,MAAM,+BAA+B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CACrF,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CACb,wBAAwB,MAAM,uCAAuC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAC7F,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAE/B,IAA8B;IAC9B,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IAErD,eAAe,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAClC,MAAM,cAAc,GAAG,eAAe,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IAE7D,0EAA0E;IAC1E,6EAA6E;IAC7E,8EAA8E;IAC9E,0EAA0E;IAC1E,gEAAgE;IAChE,IAAI,cAAc,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CACb,mFAAmF;YACjF,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,qBAAqB,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI;YACvF,OAAO,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,6GAA6G,CAC1J,CAAC;IACJ,CAAC;IAED,OAAO,cAAc,CAAU;QAC7B,MAAM;QACN,QAAQ,EAAE,QAAQ,IAAI,QAAQ;QAC9B,OAAO,EAAE,QAAQ;QACjB,GAAG,IAAI;KACR,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { ExtraClaims } from \"../../auth.js\";\nimport type { OAuthProvider } from \"../index.js\";\nimport type { RegisteredClaims } from \"../verify.js\";\nimport { type CustomProviderOptions, customProvider } from \"./custom.js\";\n\n/** Options accepted by {@link authplaneProvider}. */\nexport type AuthplaneProviderOptions = {\n /**\n * The authorization server's issuer identifier (RFC 8414 §2) — your\n * Authplane deployment, e.g. `https://auth.acme.com` (or\n * `http://localhost:9000` in local development).\n */\n issuer: string;\n /**\n * This server's resource identifier (RFC 9728 §1.2): the public URL clients\n * reach, advertised as the `resource` field of its protected-resource\n * metadata. Required, unlike the other providers.\n *\n * Authplane binds the access token's `aud` to the RFC 8707 `resource`\n * parameter the client sends, and the client takes that value from the\n * advertised metadata. Setting it explicitly gives the deployment one fixed\n * identifier, which is what the audience is checked against.\n *\n * Resource identifiers are compared by exact string match, so give it in the\n * form it will be advertised and register that same string in Authplane. RFC\n * 8707 §2 asks for the most specific URI available, e.g.\n * `https://acme.example.com/mcp`.\n */\n resource: string;\n /**\n * Expected token `aud`. Defaults to `resource`.\n *\n * RFC 8707 §2 lets an authorization server use the resource identifier\n * verbatim as the audience or map it to another value; set this only for a\n * resource configured in Authplane with such an override, and pass that\n * value verbatim.\n */\n audience?: string;\n} & Omit<CustomProviderOptions, \"issuer\" | \"audience\" | \"baseUrl\">;\n\n/**\n * Rejects anything that cannot serve as an OAuth identifier: RFC 8707 §2\n * requires an absolute URI and forbids a fragment, and the discovery and\n * protected-resource metadata URLs are both built from the scheme and host.\n */\nfunction parseIdentifier(value: string, option: string): URL {\n let parsed: URL;\n try {\n parsed = new URL(value);\n } catch {\n throw new Error(\n `authplaneProvider: \\`${option}\\` must be an absolute URL, got ${JSON.stringify(value)}`,\n );\n }\n if (parsed.protocol !== \"https:\" && parsed.protocol !== \"http:\") {\n throw new Error(\n `authplaneProvider: \\`${option}\\` must use the http or https scheme, got ${JSON.stringify(value)}`,\n );\n }\n if (!parsed.host) {\n throw new Error(\n `authplaneProvider: \\`${option}\\` must include a host, got ${JSON.stringify(value)}`,\n );\n }\n if (parsed.hash) {\n throw new Error(\n `authplaneProvider: \\`${option}\\` must not include a fragment, got ${JSON.stringify(value)}`,\n );\n }\n return parsed;\n}\n\n/**\n * OAuth provider for Authplane. `issuer` is the authorization server's issuer\n * identifier and `resource` is this server's resource identifier, which also\n * supplies the expected token audience.\n *\n * Dynamic Client Registration is supported natively, so no registration proxy\n * is needed: clients register with Authplane directly and this server stays out\n * of the authorization path. Pass `serverUrl` to advertise this server as the\n * authorization server instead (see {@link customProvider}).\n */\nexport function authplaneProvider<\n TCustom extends ExtraClaims = Record<never, never>,\n>(opts: AuthplaneProviderOptions): OAuthProvider<TCustom & RegisteredClaims> {\n const { issuer, resource, audience, ...rest } = opts;\n\n parseIdentifier(issuer, \"issuer\");\n const parsedResource = parseIdentifier(resource, \"resource\");\n\n // The advertised resource is the URL-normalised form of this value. Where\n // normalisation would change the string — a bare origin gaining a root path,\n // an uppercase host, an explicit default port — the configured and advertised\n // identifiers would differ, and the audience check compares them exactly.\n // Require the advertised form up front so the two always match.\n if (parsedResource.href !== resource) {\n throw new Error(\n `authplaneProvider: \\`resource\\` must be given in the form it will be advertised. ` +\n `${JSON.stringify(resource)} is advertised as ${JSON.stringify(parsedResource.href)}. ` +\n `Use ${JSON.stringify(parsedResource.href)}, or a path-qualified URL such as \"https://acme.example.com/mcp\", and register the same value in Authplane.`,\n );\n }\n\n return customProvider<TCustom>({\n issuer,\n audience: audience ?? resource,\n baseUrl: resource,\n ...rest,\n });\n}\n"]}