skybridge 0.0.0-dev.815d058 → 0.0.0-dev.8164d23

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 (325) hide show
  1. package/README.md +3 -0
  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/header.d.ts +1 -1
  13. package/dist/cli/resolve-skybridge-config.d.ts +5 -0
  14. package/dist/cli/{resolve-views-dir.js → resolve-skybridge-config.js} +4 -3
  15. package/dist/cli/resolve-skybridge-config.js.map +1 -0
  16. package/dist/cli/run-plain.d.ts +18 -0
  17. package/dist/cli/run-plain.js +89 -0
  18. package/dist/cli/run-plain.js.map +1 -0
  19. package/dist/cli/use-execute-steps.d.ts +1 -1
  20. package/dist/cli/use-nodemon.d.ts +14 -0
  21. package/dist/cli/use-nodemon.js +71 -60
  22. package/dist/cli/use-nodemon.js.map +1 -1
  23. package/dist/cli/use-typescript-check.d.ts +8 -2
  24. package/dist/cli/use-typescript-check.js +70 -67
  25. package/dist/cli/use-typescript-check.js.map +1 -1
  26. package/dist/commands/build.d.ts +0 -2
  27. package/dist/commands/build.js +2 -61
  28. package/dist/commands/build.js.map +1 -1
  29. package/dist/commands/dev.d.ts +1 -0
  30. package/dist/commands/dev.js +34 -2
  31. package/dist/commands/dev.js.map +1 -1
  32. package/dist/commands/start.js +2 -2
  33. package/dist/commands/start.js.map +1 -1
  34. package/dist/context-warnings.d.ts +5 -0
  35. package/dist/context-warnings.js +31 -0
  36. package/dist/context-warnings.js.map +1 -0
  37. package/dist/context-warnings.test.js +28 -0
  38. package/dist/context-warnings.test.js.map +1 -0
  39. package/dist/server/app.d.ts +177 -0
  40. package/dist/server/app.js +261 -0
  41. package/dist/server/app.js.map +1 -0
  42. package/dist/server/auth/discovery.d.ts +29 -7
  43. package/dist/server/auth/discovery.js +16 -11
  44. package/dist/server/auth/discovery.js.map +1 -1
  45. package/dist/server/auth/index.d.ts +17 -5
  46. package/dist/server/auth/index.js.map +1 -1
  47. package/dist/server/auth/providers/auth0.d.ts +33 -6
  48. package/dist/server/auth/providers/auth0.js +25 -12
  49. package/dist/server/auth/providers/auth0.js.map +1 -1
  50. package/dist/server/auth/providers/auth0.test.js +30 -13
  51. package/dist/server/auth/providers/auth0.test.js.map +1 -1
  52. package/dist/server/auth/providers/authplane.d.ts +49 -0
  53. package/dist/server/auth/providers/authplane.js +57 -0
  54. package/dist/server/auth/providers/authplane.js.map +1 -0
  55. package/dist/server/auth/providers/authplane.test.d.ts +1 -0
  56. package/dist/server/auth/providers/authplane.test.js +140 -0
  57. package/dist/server/auth/providers/authplane.test.js.map +1 -0
  58. package/dist/server/auth/providers/clerk.d.ts +39 -2
  59. package/dist/server/auth/providers/clerk.js +5 -6
  60. package/dist/server/auth/providers/clerk.js.map +1 -1
  61. package/dist/server/auth/providers/clerk.test.js +7 -25
  62. package/dist/server/auth/providers/clerk.test.js.map +1 -1
  63. package/dist/server/auth/providers/custom.d.ts +26 -3
  64. package/dist/server/auth/providers/custom.js +42 -14
  65. package/dist/server/auth/providers/custom.js.map +1 -1
  66. package/dist/server/auth/providers/custom.test.js +79 -12
  67. package/dist/server/auth/providers/custom.test.js.map +1 -1
  68. package/dist/server/auth/providers/descope.d.ts +40 -11
  69. package/dist/server/auth/providers/descope.js +38 -9
  70. package/dist/server/auth/providers/descope.js.map +1 -1
  71. package/dist/server/auth/providers/descope.test.js +42 -15
  72. package/dist/server/auth/providers/descope.test.js.map +1 -1
  73. package/dist/server/auth/providers/shared.d.ts +2 -0
  74. package/dist/server/auth/providers/shared.js +6 -0
  75. package/dist/server/auth/providers/shared.js.map +1 -0
  76. package/dist/server/auth/providers/shared.test.d.ts +1 -0
  77. package/dist/server/auth/providers/shared.test.js +10 -0
  78. package/dist/server/auth/providers/shared.test.js.map +1 -0
  79. package/dist/server/auth/providers/stytch.d.ts +15 -2
  80. package/dist/server/auth/providers/stytch.js +5 -6
  81. package/dist/server/auth/providers/stytch.js.map +1 -1
  82. package/dist/server/auth/providers/verify-spy.d.ts +12 -0
  83. package/dist/server/auth/providers/verify-spy.js +21 -0
  84. package/dist/server/auth/providers/verify-spy.js.map +1 -0
  85. package/dist/server/auth/providers/workos.d.ts +24 -2
  86. package/dist/server/auth/providers/workos.js +5 -6
  87. package/dist/server/auth/providers/workos.js.map +1 -1
  88. package/dist/server/auth/security-schemes.d.ts +23 -0
  89. package/dist/server/auth/security-schemes.js +64 -0
  90. package/dist/server/auth/security-schemes.js.map +1 -0
  91. package/dist/server/auth/security-schemes.test.d.ts +1 -0
  92. package/dist/server/auth/security-schemes.test.js +99 -0
  93. package/dist/server/auth/security-schemes.test.js.map +1 -0
  94. package/dist/server/auth/setup.d.ts +3 -1
  95. package/dist/server/auth/setup.js +66 -26
  96. package/dist/server/auth/setup.js.map +1 -1
  97. package/dist/server/auth/setup.test.js +342 -15
  98. package/dist/server/auth/setup.test.js.map +1 -1
  99. package/dist/server/auth/verify.d.ts +37 -3
  100. package/dist/server/auth/verify.js +27 -3
  101. package/dist/server/auth/verify.js.map +1 -1
  102. package/dist/server/auth/verify.test.js +49 -0
  103. package/dist/server/auth/verify.test.js.map +1 -1
  104. package/dist/server/auth-extra.test-d.js +70 -0
  105. package/dist/server/auth-extra.test-d.js.map +1 -0
  106. package/dist/server/auth.d.ts +42 -5
  107. package/dist/server/auth.js +3 -4
  108. package/dist/server/auth.js.map +1 -1
  109. package/dist/server/build-manifest.test.js +6 -5
  110. package/dist/server/build-manifest.test.js.map +1 -1
  111. package/dist/server/content-helpers.d.ts +1 -1
  112. package/dist/server/content-helpers.js.map +1 -1
  113. package/dist/server/express.d.ts +5 -3
  114. package/dist/server/express.js +8 -32
  115. package/dist/server/express.js.map +1 -1
  116. package/dist/server/express.test.js +130 -102
  117. package/dist/server/express.test.js.map +1 -1
  118. package/dist/server/host.d.ts +2 -0
  119. package/dist/server/host.js +11 -0
  120. package/dist/server/host.js.map +1 -0
  121. package/dist/server/host.test.d.ts +1 -0
  122. package/dist/server/host.test.js +13 -0
  123. package/dist/server/host.test.js.map +1 -0
  124. package/dist/server/index.d.ts +15 -8
  125. package/dist/server/index.js +8 -3
  126. package/dist/server/index.js.map +1 -1
  127. package/dist/server/mcp-errors.test.d.ts +1 -0
  128. package/dist/server/mcp-errors.test.js +37 -0
  129. package/dist/server/mcp-errors.test.js.map +1 -0
  130. package/dist/server/middleware.d.ts +35 -10
  131. package/dist/server/middleware.js +33 -0
  132. package/dist/server/middleware.js.map +1 -1
  133. package/dist/server/middleware.test-d.js +9 -9
  134. package/dist/server/middleware.test-d.js.map +1 -1
  135. package/dist/server/middleware.test.js +164 -98
  136. package/dist/server/middleware.test.js.map +1 -1
  137. package/dist/server/register-tool.test.d.ts +1 -0
  138. package/dist/server/register-tool.test.js +23 -0
  139. package/dist/server/register-tool.test.js.map +1 -0
  140. package/dist/server/server.d.ts +155 -137
  141. package/dist/server/server.js +281 -351
  142. package/dist/server/server.js.map +1 -1
  143. package/dist/server/skills-integration.test.d.ts +1 -0
  144. package/dist/server/skills-integration.test.js +79 -0
  145. package/dist/server/skills-integration.test.js.map +1 -0
  146. package/dist/server/skills.d.ts +27 -0
  147. package/dist/server/skills.js +188 -0
  148. package/dist/server/skills.js.map +1 -0
  149. package/dist/server/skills.test.d.ts +1 -0
  150. package/dist/server/skills.test.js +243 -0
  151. package/dist/server/skills.test.js.map +1 -0
  152. package/dist/server/tool-extra.test.d.ts +1 -0
  153. package/dist/server/tool-extra.test.js +72 -0
  154. package/dist/server/tool-extra.test.js.map +1 -0
  155. package/dist/server/view-name.test-d.d.ts +1 -0
  156. package/dist/server/view-name.test-d.js +8 -0
  157. package/dist/server/view-name.test-d.js.map +1 -0
  158. package/dist/server/view-resource-resolution.test.js +101 -17
  159. package/dist/server/view-resource-resolution.test.js.map +1 -1
  160. package/dist/server/viewsDevServer.js +4 -1
  161. package/dist/server/viewsDevServer.js.map +1 -1
  162. package/dist/standard-schema.d.ts +3 -0
  163. package/dist/standard-schema.js +2 -0
  164. package/dist/standard-schema.js.map +1 -0
  165. package/dist/test/utils.d.ts +9 -11
  166. package/dist/test/utils.js +18 -13
  167. package/dist/test/utils.js.map +1 -1
  168. package/dist/test/view.test.js +88 -120
  169. package/dist/test/view.test.js.map +1 -1
  170. package/dist/web/bridges/adaptor.d.ts +51 -0
  171. package/dist/web/bridges/adaptor.js +327 -0
  172. package/dist/web/bridges/adaptor.js.map +1 -0
  173. package/dist/web/bridges/adaptor.test.d.ts +1 -0
  174. package/dist/web/bridges/adaptor.test.js +225 -0
  175. package/dist/web/bridges/adaptor.test.js.map +1 -0
  176. package/dist/web/bridges/apps-sdk/bridge.d.ts +6 -2
  177. package/dist/web/bridges/apps-sdk/bridge.js +15 -4
  178. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
  179. package/dist/web/bridges/apps-sdk/index.d.ts +0 -1
  180. package/dist/web/bridges/apps-sdk/index.js +0 -1
  181. package/dist/web/bridges/apps-sdk/index.js.map +1 -1
  182. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +1 -1
  183. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +1 -1
  184. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
  185. package/dist/web/bridges/get-adaptor.d.ts +4 -4
  186. package/dist/web/bridges/get-adaptor.js +6 -11
  187. package/dist/web/bridges/get-adaptor.js.map +1 -1
  188. package/dist/web/bridges/get-adaptor.test.d.ts +1 -0
  189. package/dist/web/bridges/get-adaptor.test.js +32 -0
  190. package/dist/web/bridges/get-adaptor.test.js.map +1 -0
  191. package/dist/web/bridges/mcp-app/bridge.d.ts +13 -2
  192. package/dist/web/bridges/mcp-app/bridge.js +51 -7
  193. package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
  194. package/dist/web/bridges/mcp-app/bridge.test.d.ts +1 -0
  195. package/dist/web/bridges/mcp-app/bridge.test.js +17 -0
  196. package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -0
  197. package/dist/web/bridges/mcp-app/index.d.ts +0 -1
  198. package/dist/web/bridges/mcp-app/index.js +0 -1
  199. package/dist/web/bridges/mcp-app/index.js.map +1 -1
  200. package/dist/web/bridges/mcp-app/types.d.ts +2 -0
  201. package/dist/web/bridges/mcp-app/types.js.map +1 -1
  202. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +1 -1
  203. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +1 -1
  204. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
  205. package/dist/web/bridges/mcp-app/view-tools.test.js +5 -6
  206. package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -1
  207. package/dist/web/bridges/types.d.ts +27 -9
  208. package/dist/web/bridges/types.js +14 -1
  209. package/dist/web/bridges/types.js.map +1 -1
  210. package/dist/web/bridges/types.test.d.ts +1 -0
  211. package/dist/web/bridges/types.test.js +19 -0
  212. package/dist/web/bridges/types.test.js.map +1 -0
  213. package/dist/web/components/modal-provider.d.ts +1 -1
  214. package/dist/web/components/modal-provider.js +4 -3
  215. package/dist/web/components/modal-provider.js.map +1 -1
  216. package/dist/web/create-store.test.js +9 -6
  217. package/dist/web/create-store.test.js.map +1 -1
  218. package/dist/web/data-llm.d.ts +1 -1
  219. package/dist/web/data-llm.test.js +19 -6
  220. package/dist/web/data-llm.test.js.map +1 -1
  221. package/dist/web/generate-helpers.d.ts +13 -12
  222. package/dist/web/generate-helpers.js +10 -9
  223. package/dist/web/generate-helpers.js.map +1 -1
  224. package/dist/web/generate-helpers.test-d.js +3 -3
  225. package/dist/web/generate-helpers.test-d.js.map +1 -1
  226. package/dist/web/generate-helpers.test.js +2 -2
  227. package/dist/web/generate-helpers.test.js.map +1 -1
  228. package/dist/web/hooks/index.d.ts +2 -1
  229. package/dist/web/hooks/index.js +2 -1
  230. package/dist/web/hooks/index.js.map +1 -1
  231. package/dist/web/hooks/test/utils.d.ts +2 -1
  232. package/dist/web/hooks/test/utils.js +1 -1
  233. package/dist/web/hooks/test/utils.js.map +1 -1
  234. package/dist/web/hooks/use-call-tool.test.js +39 -25
  235. package/dist/web/hooks/use-call-tool.test.js.map +1 -1
  236. package/dist/web/hooks/use-display-mode.d.ts +1 -1
  237. package/dist/web/hooks/use-display-mode.js +1 -1
  238. package/dist/web/hooks/use-display-mode.js.map +1 -1
  239. package/dist/web/hooks/use-display-mode.test.js +57 -21
  240. package/dist/web/hooks/use-display-mode.test.js.map +1 -1
  241. package/dist/web/hooks/use-download.d.ts +1 -3
  242. package/dist/web/hooks/use-download.js +1 -2
  243. package/dist/web/hooks/use-download.js.map +1 -1
  244. package/dist/web/hooks/use-download.test.js +16 -8
  245. package/dist/web/hooks/use-download.test.js.map +1 -1
  246. package/dist/web/hooks/use-files.test.js +11 -3
  247. package/dist/web/hooks/use-files.test.js.map +1 -1
  248. package/dist/web/hooks/use-host.d.ts +22 -0
  249. package/dist/web/hooks/use-host.js +30 -0
  250. package/dist/web/hooks/use-host.js.map +1 -0
  251. package/dist/web/hooks/use-host.test.d.ts +1 -0
  252. package/dist/web/hooks/use-host.test.js +59 -0
  253. package/dist/web/hooks/use-host.test.js.map +1 -0
  254. package/dist/web/hooks/use-open-external.test.js +14 -4
  255. package/dist/web/hooks/use-open-external.test.js.map +1 -1
  256. package/dist/web/hooks/use-register-view-tool.d.ts +2 -3
  257. package/dist/web/hooks/use-register-view-tool.js.map +1 -1
  258. package/dist/web/hooks/use-request-close.test.js +35 -40
  259. package/dist/web/hooks/use-request-close.test.js.map +1 -1
  260. package/dist/web/hooks/use-request-modal.test.js +11 -1
  261. package/dist/web/hooks/use-request-modal.test.js.map +1 -1
  262. package/dist/web/hooks/use-request-size.d.ts +1 -1
  263. package/dist/web/hooks/use-request-size.js +1 -1
  264. package/dist/web/hooks/use-request-size.js.map +1 -1
  265. package/dist/web/hooks/use-request-size.test.js +35 -53
  266. package/dist/web/hooks/use-request-size.test.js.map +1 -1
  267. package/dist/web/hooks/use-set-open-in-app-url.test.js +29 -9
  268. package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
  269. package/dist/web/hooks/use-tool-info.d.ts +1 -20
  270. package/dist/web/hooks/use-tool-info.js +0 -1
  271. package/dist/web/hooks/use-tool-info.js.map +1 -1
  272. package/dist/web/hooks/use-tool-info.test-d.js +0 -5
  273. package/dist/web/hooks/use-tool-info.test-d.js.map +1 -1
  274. package/dist/web/hooks/use-tool-info.test.js +37 -32
  275. package/dist/web/hooks/use-tool-info.test.js.map +1 -1
  276. package/dist/web/hooks/use-user.d.ts +3 -2
  277. package/dist/web/hooks/use-user.js +4 -3
  278. package/dist/web/hooks/use-user.js.map +1 -1
  279. package/dist/web/hooks/use-user.test.js +84 -36
  280. package/dist/web/hooks/use-user.test.js.map +1 -1
  281. package/dist/web/hooks/use-view-state.js +19 -9
  282. package/dist/web/hooks/use-view-state.js.map +1 -1
  283. package/dist/web/hooks/use-view-state.test.js +38 -3
  284. package/dist/web/hooks/use-view-state.test.js.map +1 -1
  285. package/dist/web/hooks/use-viewport.d.ts +20 -0
  286. package/dist/web/hooks/use-viewport.js +21 -0
  287. package/dist/web/hooks/use-viewport.js.map +1 -0
  288. package/dist/web/hooks/use-viewport.test.d.ts +1 -0
  289. package/dist/web/hooks/use-viewport.test.js +109 -0
  290. package/dist/web/hooks/use-viewport.test.js.map +1 -0
  291. package/dist/web/index.d.ts +1 -0
  292. package/dist/web/index.js.map +1 -1
  293. package/dist/web/mount-view.d.ts +3 -2
  294. package/dist/web/mount-view.js +3 -2
  295. package/dist/web/mount-view.js.map +1 -1
  296. package/dist/web/plugin/plugin-build.test.d.ts +1 -0
  297. package/dist/web/plugin/plugin-build.test.js +54 -0
  298. package/dist/web/plugin/plugin-build.test.js.map +1 -0
  299. package/dist/web/plugin/plugin.d.ts +6 -0
  300. package/dist/web/plugin/plugin.js +18 -7
  301. package/dist/web/plugin/plugin.js.map +1 -1
  302. package/dist/web/plugin/plugin.test.d.ts +1 -0
  303. package/dist/web/plugin/plugin.test.js +61 -0
  304. package/dist/web/plugin/plugin.test.js.map +1 -0
  305. package/package.json +28 -23
  306. package/dist/cli/resolve-views-dir.d.ts +0 -1
  307. package/dist/cli/resolve-views-dir.js.map +0 -1
  308. package/dist/server/auth/providers/stytch.test.js +0 -33
  309. package/dist/server/auth/providers/stytch.test.js.map +0 -1
  310. package/dist/server/auth/providers/workos.test.js +0 -41
  311. package/dist/server/auth/providers/workos.test.js.map +0 -1
  312. package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -29
  313. package/dist/web/bridges/apps-sdk/adaptor.js +0 -117
  314. package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
  315. package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -53
  316. package/dist/web/bridges/mcp-app/adaptor.js +0 -283
  317. package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
  318. package/dist/web/hooks/use-layout.d.ts +0 -24
  319. package/dist/web/hooks/use-layout.js +0 -25
  320. package/dist/web/hooks/use-layout.js.map +0 -1
  321. package/dist/web/hooks/use-layout.test.js +0 -96
  322. package/dist/web/hooks/use-layout.test.js.map +0 -1
  323. /package/dist/{server/auth/providers/stytch.test.d.ts → cli/build-steps.test.d.ts} +0 -0
  324. /package/dist/{server/auth/providers/workos.test.d.ts → context-warnings.test.d.ts} +0 -0
  325. /package/dist/{web/hooks/use-layout.test.d.ts → server/auth-extra.test-d.d.ts} +0 -0
@@ -1,27 +1,55 @@
1
1
  import { discoverAuthorizationServer, } from "../discovery.js";
2
- /** Builds a complete {@link OAuthConfig} for a DCR-compatible IdP via discovery. */
2
+ import { createJwksVerifier } from "../verify.js";
3
+ /**
4
+ * Builds a complete {@link OAuthConfig} from an IdP's OAuth discovery document.
5
+ *
6
+ * @typeParam TExtra - Claims the IdP puts in the access token, reaching handlers
7
+ * as `extra.authInfo.extra`. The branded providers pass their documented claims;
8
+ * pass your own when wiring an IdP by hand.
9
+ */
3
10
  export async function customProvider(opts) {
4
11
  const discovered = await discoverAuthorizationServer(opts.issuer);
5
- // The IdP's own discovery must advertise DCR and a JWKS; overrides can't fake it.
6
- if (!discovered.registration_endpoint) {
7
- throw new Error(`${opts.issuer} is not DCR-compatible (no registration_endpoint); customProvider only supports DCR IdPs.`);
8
- }
12
+ // JWKS verification needs a signing-key URL; without it the server can't verify
13
+ // tokens. (`registration_endpoint` is optional per RFC 8414 — a no-DCR IdP simply
14
+ // omits it; a proxy like Alpic, or pre-registered clients, supply registration.)
9
15
  if (!discovered.jwks_uri) {
10
16
  throw new Error(`${opts.issuer} discovery has no jwks_uri; JWKS verification requires it.`);
11
17
  }
12
- // Overrides adjust only advertised metadata (e.g. proxied endpoints). The
13
- // trust anchor (issuer, jwks_uri) always comes from validated discovery.
14
- const { issuer: _issuer, jwks_uri: _jwks, ...overrides } = (opts.metadataOverrides ?? {});
15
- const oauthMetadata = { ...discovered, ...overrides };
18
+ // Overrides adjust only advertised metadata; the trust anchor (issuer, jwks_uri)
19
+ // always comes from validated discovery.
20
+ const { issuer: _issuer, jwks_uri: _jwks, ...overrides } = opts.metadataOverrides ?? {};
21
+ let advertised = discovered;
22
+ if (opts.authorizationServer) {
23
+ try {
24
+ advertised = await discoverAuthorizationServer(opts.authorizationServer);
25
+ }
26
+ catch (err) {
27
+ console.warn(`OAuth discovery failed for authorizationServer ${opts.authorizationServer}; advertising ${opts.issuer} metadata instead: ${err instanceof Error ? err.message : String(err)}`);
28
+ }
29
+ }
30
+ const base = { ...advertised, ...overrides };
31
+ const scopesSupported = opts.scopes ?? base.scopes_supported;
32
+ // serverUrl (skybridge-as-AS) overrides the advertised issuer, keeping the
33
+ // IdP as the token issuer. authorizationServer re-asserts its own URL so a
34
+ // failed AS discovery still points clients at the AS. serverUrl wins.
35
+ const advertisedIssuer = opts.serverUrl?.replace(/\/$/, "") ??
36
+ opts.authorizationServer?.replace(/\/$/, "");
37
+ const oauthMetadata = advertisedIssuer
38
+ ? {
39
+ ...base,
40
+ issuer: advertisedIssuer,
41
+ scopes_supported: scopesSupported,
42
+ }
43
+ : base;
16
44
  return {
17
45
  baseUrl: opts.baseUrl,
18
46
  oauthMetadata,
19
- verify: {
20
- issuer: discovered.issuer,
47
+ verifier: createJwksVerifier({
48
+ issuer: advertised.issuer,
21
49
  audience: opts.audience,
22
- jwksUri: discovered.jwks_uri,
23
- },
24
- scopesSupported: opts.scopes ?? oauthMetadata.scopes_supported,
50
+ jwksUri: advertised.jwks_uri ?? discovered.jwks_uri,
51
+ }),
52
+ scopesSupported,
25
53
  requiredScopes: opts.requiredScopes,
26
54
  };
27
55
  }
@@ -1 +1 @@
1
- {"version":3,"file":"custom.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/custom.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,2BAA2B,GAC5B,MAAM,iBAAiB,CAAC;AAiBzB,oFAAoF;AACpF,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,IAA2B;IAE3B,MAAM,UAAU,GAAG,MAAM,2BAA2B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAElE,kFAAkF;IAClF,IAAI,CAAC,UAAU,CAAC,qBAAqB,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,CAAC,MAAM,2FAA2F,CAC1G,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,CAAC,MAAM,4DAA4D,CAC3E,CAAC;IACJ,CAAC;IAED,0EAA0E;IAC1E,yEAAyE;IACzE,MAAM,EACJ,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,KAAK,EACf,GAAG,SAAS,EACb,GAAG,CAAC,IAAI,CAAC,iBAAiB,IAAI,EAAE,CAAgC,CAAC;IAClE,MAAM,aAAa,GAAuB,EAAE,GAAG,UAAU,EAAE,GAAG,SAAS,EAAE,CAAC;IAE1E,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,aAAa;QACb,MAAM,EAAE;YACN,MAAM,EAAE,UAAU,CAAC,MAAM;YACzB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,OAAO,EAAE,UAAU,CAAC,QAAQ;SAC7B;QACD,eAAe,EAAE,IAAI,CAAC,MAAM,IAAI,aAAa,CAAC,gBAAgB;QAC9D,cAAc,EAAE,IAAI,CAAC,cAAc;KACpC,CAAC;AACJ,CAAC","sourcesContent":["import type { OAuthMetadata } from \"@modelcontextprotocol/sdk/shared/auth.js\";\nimport {\n type DiscoveredMetadata,\n discoverAuthorizationServer,\n} from \"../discovery.js\";\nimport type { OAuthConfig } from \"../index.js\";\n\n/** Options accepted by {@link customProvider} and the branded providers. */\nexport type CustomProviderOptions = {\n issuer: string;\n /** Expected token `aud`. Omit to skip audience verification — only for IdPs\n * that don't bind an audience (e.g. Clerk). Branded providers whose IdP does\n * bind an audience re-require it in their own options. */\n audience?: string;\n /** Omit to let the server infer the resource origin from request headers. */\n baseUrl?: string;\n scopes?: string[];\n requiredScopes?: string[];\n metadataOverrides?: Omit<Partial<OAuthMetadata>, \"issuer\">;\n};\n\n/** Builds a complete {@link OAuthConfig} for a DCR-compatible IdP via discovery. */\nexport async function customProvider(\n opts: CustomProviderOptions,\n): Promise<OAuthConfig> {\n const discovered = await discoverAuthorizationServer(opts.issuer);\n\n // The IdP's own discovery must advertise DCR and a JWKS; overrides can't fake it.\n if (!discovered.registration_endpoint) {\n throw new Error(\n `${opts.issuer} is not DCR-compatible (no registration_endpoint); customProvider only supports DCR IdPs.`,\n );\n }\n if (!discovered.jwks_uri) {\n throw new Error(\n `${opts.issuer} discovery has no jwks_uri; JWKS verification requires it.`,\n );\n }\n\n // Overrides adjust only advertised metadata (e.g. proxied endpoints). The\n // trust anchor (issuer, jwks_uri) always comes from validated discovery.\n const {\n issuer: _issuer,\n jwks_uri: _jwks,\n ...overrides\n } = (opts.metadataOverrides ?? {}) as Partial<DiscoveredMetadata>;\n const oauthMetadata: DiscoveredMetadata = { ...discovered, ...overrides };\n\n return {\n baseUrl: opts.baseUrl,\n oauthMetadata,\n verify: {\n issuer: discovered.issuer,\n audience: opts.audience,\n jwksUri: discovered.jwks_uri,\n },\n scopesSupported: opts.scopes ?? oauthMetadata.scopes_supported,\n requiredScopes: opts.requiredScopes,\n };\n}\n"]}
1
+ {"version":3,"file":"custom.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/custom.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,2BAA2B,GAC5B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,kBAAkB,EAAyB,MAAM,cAAc,CAAC;AA+BzE;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,IAA2B;IAE3B,MAAM,UAAU,GAAG,MAAM,2BAA2B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAElE,gFAAgF;IAChF,kFAAkF;IAClF,iFAAiF;IACjF,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,CAAC,MAAM,4DAA4D,CAC3E,CAAC;IACJ,CAAC;IAED,iFAAiF;IACjF,yCAAyC;IACzC,MAAM,EACJ,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,KAAK,EACf,GAAG,SAAS,EACb,GAAgC,IAAI,CAAC,iBAAiB,IAAI,EAAE,CAAC;IAC9D,IAAI,UAAU,GAAG,UAAU,CAAC;IAC5B,IAAI,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC7B,IAAI,CAAC;YACH,UAAU,GAAG,MAAM,2BAA2B,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAC3E,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,IAAI,CACV,kDAAkD,IAAI,CAAC,mBAAmB,iBAAiB,IAAI,CAAC,MAAM,sBAAsB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAC/K,CAAC;QACJ,CAAC;IACH,CAAC;IACD,MAAM,IAAI,GAAuB,EAAE,GAAG,UAAU,EAAE,GAAG,SAAS,EAAE,CAAC;IACjE,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,gBAAgB,CAAC;IAE7D,2EAA2E;IAC3E,2EAA2E;IAC3E,sEAAsE;IACtE,MAAM,gBAAgB,GACpB,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;QAClC,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC/C,MAAM,aAAa,GAAuB,gBAAgB;QACxD,CAAC,CAAC;YACE,GAAG,IAAI;YACP,MAAM,EAAE,gBAAgB;YACxB,gBAAgB,EAAE,eAAe;SAClC;QACH,CAAC,CAAC,IAAI,CAAC;IAET,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,aAAa;QACb,QAAQ,EAAE,kBAAkB,CAAS;YACnC,MAAM,EAAE,UAAU,CAAC,MAAM;YACzB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,OAAO,EAAE,UAAU,CAAC,QAAQ,IAAI,UAAU,CAAC,QAAQ;SACpD,CAAC;QACF,eAAe;QACf,cAAc,EAAE,IAAI,CAAC,cAAc;KACpC,CAAC;AACJ,CAAC","sourcesContent":["import type { OAuthMetadata } from \"@modelcontextprotocol/server\";\nimport type { ExtraClaims } from \"../../auth.js\";\nimport {\n type DiscoveredMetadata,\n discoverAuthorizationServer,\n} from \"../discovery.js\";\nimport type { OAuthConfig } from \"../index.js\";\nimport { createJwksVerifier, type RegisteredClaims } from \"../verify.js\";\n\n/** Options accepted by {@link customProvider} and the branded providers. */\nexport type CustomProviderOptions = {\n issuer: string;\n /** Expected token `aud`. Omit to skip audience verification — only for IdPs\n * that don't bind an audience (e.g. Clerk). Branded providers whose IdP does\n * bind an audience re-require it in their own options. */\n audience?: string;\n /** Omit to let the server infer the resource origin from request headers. */\n baseUrl?: string;\n /** Advertise THIS server as the authorization server (skybridge-as-AS): the\n * served AS metadata `issuer` and the PRM `authorization_servers` use this URL\n * instead of the IdP's. Needed when skybridge must sit in the auth path — Auth0\n * (the `audience` must be baked into `/authorize`) or the Alpic DCR proxy (Alpic\n * injects the registration endpoint). Use the static public URL; `verify.issuer`\n * stays the IdP (the token's real `iss`). */\n serverUrl?: string;\n /** Advertise this URL as the authorization server (served AS metadata `issuer`\n * and PRM `authorization_servers`). Its own discovery document supplies the\n * advertised endpoints, DCR registration, scopes and the `iss` tokens are\n * verified against; only `jwks_uri` still comes from `issuer`'s document. Use\n * when DCR/authorize/token live at a different URL than the discovery issuer\n * (e.g. Descope's agentic URL vs. its base-project URL). `serverUrl` wins if\n * both are set. */\n authorizationServer?: string;\n scopes?: string[];\n requiredScopes?: string[];\n metadataOverrides?: Omit<Partial<OAuthMetadata>, \"issuer\">;\n};\n\n/**\n * Builds a complete {@link OAuthConfig} from an IdP's OAuth discovery document.\n *\n * @typeParam TExtra - Claims the IdP puts in the access token, reaching handlers\n * as `extra.authInfo.extra`. The branded providers pass their documented claims;\n * pass your own when wiring an IdP by hand.\n */\nexport async function customProvider<TExtra extends ExtraClaims = ExtraClaims>(\n opts: CustomProviderOptions,\n): Promise<OAuthConfig<TExtra & RegisteredClaims>> {\n const discovered = await discoverAuthorizationServer(opts.issuer);\n\n // JWKS verification needs a signing-key URL; without it the server can't verify\n // tokens. (`registration_endpoint` is optional per RFC 8414 — a no-DCR IdP simply\n // omits it; a proxy like Alpic, or pre-registered clients, supply registration.)\n if (!discovered.jwks_uri) {\n throw new Error(\n `${opts.issuer} discovery has no jwks_uri; JWKS verification requires it.`,\n );\n }\n\n // Overrides adjust only advertised metadata; the trust anchor (issuer, jwks_uri)\n // always comes from validated discovery.\n const {\n issuer: _issuer,\n jwks_uri: _jwks,\n ...overrides\n }: Partial<DiscoveredMetadata> = opts.metadataOverrides ?? {};\n let advertised = discovered;\n if (opts.authorizationServer) {\n try {\n advertised = await discoverAuthorizationServer(opts.authorizationServer);\n } catch (err) {\n console.warn(\n `OAuth discovery failed for authorizationServer ${opts.authorizationServer}; advertising ${opts.issuer} metadata instead: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n }\n const base: DiscoveredMetadata = { ...advertised, ...overrides };\n const scopesSupported = opts.scopes ?? base.scopes_supported;\n\n // serverUrl (skybridge-as-AS) overrides the advertised issuer, keeping the\n // IdP as the token issuer. authorizationServer re-asserts its own URL so a\n // failed AS discovery still points clients at the AS. serverUrl wins.\n const advertisedIssuer =\n opts.serverUrl?.replace(/\\/$/, \"\") ??\n opts.authorizationServer?.replace(/\\/$/, \"\");\n const oauthMetadata: DiscoveredMetadata = advertisedIssuer\n ? {\n ...base,\n issuer: advertisedIssuer,\n scopes_supported: scopesSupported,\n }\n : base;\n\n return {\n baseUrl: opts.baseUrl,\n oauthMetadata,\n verifier: createJwksVerifier<TExtra>({\n issuer: advertised.issuer,\n audience: opts.audience,\n jwksUri: advertised.jwks_uri ?? discovered.jwks_uri,\n }),\n scopesSupported,\n requiredScopes: opts.requiredScopes,\n };\n}\n"]}
@@ -1,9 +1,15 @@
1
1
  // @vitest-environment node
2
2
  import http from "node:http";
3
- import { afterEach, describe, expect, it } from "vitest";
3
+ import { afterEach, describe, expect, it, vi } from "vitest";
4
4
  import { customProvider } from "./custom.js";
5
- let server;
6
- afterEach(() => server?.close());
5
+ import { lastJwksConfig as jwks } from "./verify-spy.js";
6
+ vi.mock("../verify.js", () => import("./verify-spy.js"));
7
+ const servers = [];
8
+ afterEach(() => {
9
+ for (const srv of servers.splice(0)) {
10
+ srv.close();
11
+ }
12
+ });
7
13
  function doc(origin, extra = {}) {
8
14
  return {
9
15
  issuer: origin,
@@ -28,7 +34,7 @@ async function serveDiscovery(extra = {}) {
28
34
  res.end(JSON.stringify(doc(origin, extra)));
29
35
  });
30
36
  await new Promise((resolve) => srv.listen(0, resolve));
31
- server = srv;
37
+ servers.push(srv);
32
38
  origin = `http://localhost:${srv.address().port}`;
33
39
  return origin;
34
40
  }
@@ -42,7 +48,7 @@ describe("customProvider", () => {
42
48
  scopes: ["openid"],
43
49
  });
44
50
  expect(config.baseUrl).toBe("https://app.example.test");
45
- expect(config.verify).toEqual({
51
+ expect(jwks()).toEqual({
46
52
  issuer: base,
47
53
  audience: "my-api",
48
54
  jwksUri: `${base}/jwks`,
@@ -57,25 +63,86 @@ describe("customProvider", () => {
57
63
  audience: "a",
58
64
  metadataOverrides: { issuer: "https://evil.test" },
59
65
  });
60
- expect(config.verify.issuer).toBe(base);
66
+ expect(jwks().issuer).toBe(base);
61
67
  expect(config.oauthMetadata.issuer).toBe(base);
62
68
  });
63
69
  it("ignores a runtime jwks_uri override (keeps the discovered signing keys)", async () => {
64
70
  const base = await serveDiscovery();
65
- const config = await customProvider({
71
+ await customProvider({
66
72
  issuer: base,
67
73
  audience: "a",
68
74
  metadataOverrides: { jwks_uri: "https://evil.test/keys" },
69
75
  });
70
- expect(config.verify.jwksUri).toBe(`${base}/jwks`);
76
+ expect(jwks().jwksUri).toBe(`${base}/jwks`);
71
77
  });
72
- it("rejects a non-DCR IdP even if an override supplies registration_endpoint", async () => {
78
+ it("serves metadata without a registration_endpoint when the IdP has no DCR", async () => {
73
79
  const base = await serveDiscovery({ registration_endpoint: undefined });
74
- await expect(customProvider({
80
+ const config = await customProvider({ issuer: base, audience: "a" });
81
+ expect(config.oauthMetadata.registration_endpoint).toBeUndefined();
82
+ expect(jwks().issuer).toBe(base);
83
+ });
84
+ it("throws when discovery has no jwks_uri (token verification needs it)", async () => {
85
+ const base = await serveDiscovery({ jwks_uri: undefined });
86
+ await expect(customProvider({ issuer: base, audience: "a" })).rejects.toThrow(/jwks_uri/);
87
+ });
88
+ it("serverUrl advertises this server as the AS, keeping the IdP as the token issuer", async () => {
89
+ const base = await serveDiscovery();
90
+ const config = await customProvider({
91
+ issuer: base,
92
+ audience: "a",
93
+ serverUrl: "https://app.example.test/",
94
+ scopes: ["openid"],
95
+ });
96
+ // AS metadata + advertised scopes reflect this server.
97
+ expect(config.oauthMetadata.issuer).toBe("https://app.example.test");
98
+ expect(config.oauthMetadata.scopes_supported).toEqual(["openid"]);
99
+ // but the token's issuer is still verified against the IdP.
100
+ expect(jwks().issuer).toBe(base);
101
+ });
102
+ it("authorizationServer supplies the advertised metadata and the verified issuer", async () => {
103
+ const base = await serveDiscovery();
104
+ const as = await serveDiscovery({ scopes_supported: ["checkout"] });
105
+ const config = await customProvider({
106
+ issuer: base,
107
+ audience: "a",
108
+ authorizationServer: `${as}/`,
109
+ });
110
+ expect(config.oauthMetadata.issuer).toBe(as);
111
+ expect(config.oauthMetadata.authorization_endpoint).toBe(`${as}/authorize`);
112
+ expect(config.oauthMetadata.registration_endpoint).toBe(`${as}/register`);
113
+ expect(config.scopesSupported).toEqual(["checkout"]);
114
+ expect(jwks()).toEqual({
115
+ issuer: as,
116
+ audience: "a",
117
+ jwksUri: `${as}/jwks`,
118
+ });
119
+ });
120
+ it("falls back to the issuer's metadata when the authorizationServer is undiscoverable", async () => {
121
+ const base = await serveDiscovery();
122
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => { });
123
+ const config = await customProvider({
75
124
  issuer: base,
76
125
  audience: "a",
77
- metadataOverrides: { registration_endpoint: `${base}/register` },
78
- })).rejects.toThrow(/not DCR-compatible/);
126
+ authorizationServer: `${base}/agentic/P1/MS1`,
127
+ });
128
+ expect(warn).toHaveBeenCalledOnce();
129
+ expect(config.oauthMetadata.issuer).toBe(`${base}/agentic/P1/MS1`);
130
+ expect(config.oauthMetadata.authorization_endpoint).toBe(`${base}/authorize`);
131
+ expect(jwks().issuer).toBe(base);
132
+ warn.mockRestore();
133
+ });
134
+ it("serverUrl takes precedence over authorizationServer", async () => {
135
+ const base = await serveDiscovery();
136
+ const as = await serveDiscovery();
137
+ const config = await customProvider({
138
+ issuer: base,
139
+ audience: "a",
140
+ serverUrl: "https://app.example.test/",
141
+ authorizationServer: as,
142
+ });
143
+ expect(config.oauthMetadata.issuer).toBe("https://app.example.test");
144
+ expect(config.oauthMetadata.token_endpoint).toBe(`${as}/token`);
145
+ expect(jwks().issuer).toBe(as);
79
146
  });
80
147
  it("applies metadataOverrides over discovered values", async () => {
81
148
  const base = await serveDiscovery();
@@ -1 +1 @@
1
- {"version":3,"file":"custom.test.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/custom.test.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,IAAI,MAA+B,CAAC;AACpC,SAAS,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AAEjC,SAAS,GAAG,CAAC,MAAc,EAAE,QAAiC,EAAE;IAC9D,OAAO;QACL,MAAM,EAAE,MAAM;QACd,sBAAsB,EAAE,GAAG,MAAM,YAAY;QAC7C,cAAc,EAAE,GAAG,MAAM,QAAQ;QACjC,qBAAqB,EAAE,GAAG,MAAM,WAAW;QAC3C,wBAAwB,EAAE,CAAC,MAAM,CAAC;QAClC,gBAAgB,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC;QAChD,QAAQ,EAAE,GAAG,MAAM,OAAO;QAC1B,GAAG,KAAK;KACT,CAAC;AACJ,CAAC;AAED,qFAAqF;AACrF,KAAK,UAAU,cAAc,CAAC,QAAiC,EA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BAAqB,EAAE,SAAS,EAAE,CAAC,CAAC;QACxE,MAAM,MAAM,CACV,cAAc,CAAC;YACb,MAAM,EAAE,IAAI;YACZ,QAAQ,EAAE,GAAG;YACb,iBAAiB,EAAE,EAAE,qBAAqB,EAAE,GAAG,IAAI,WAAW,EAAE;SACjE,CAAC,CACH,CAAC,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kDAAkD,EAAE,KAAK,IAAI,EAAE;QAChE,MAAM,IAAI,GAAG,MAAM,cAAc,EAAE,CAAC;QACpC,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC;YAClC,MAAM,EAAE,IAAI;YACZ,QAAQ,EAAE,GAAG;YACb,OAAO,EAAE,0BAA0B;YACnC,iBAAiB,EAAE,EAAE,cAAc,EAAE,wBAAwB,EAAE;SAChE,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// @vitest-environment node\nimport http from \"node:http\";\nimport { afterEach, describe, expect, it } from \"vitest\";\nimport { customProvider } from \"./custom.js\";\n\nlet server: http.Server | undefined;\nafterEach(() => server?.close());\n\nfunction doc(origin: string, extra: Record<string, unknown> = {}) {\n return {\n issuer: origin,\n authorization_endpoint: `${origin}/authorize`,\n token_endpoint: `${origin}/token`,\n registration_endpoint: `${origin}/register`,\n response_types_supported: [\"code\"],\n scopes_supported: [\"openid\", \"email\", \"profile\"],\n jwks_uri: `${origin}/jwks`,\n ...extra,\n };\n}\n\n// Serves the discovery doc (built from the live origin) at the OIDC well-known path.\nasync function serveDiscovery(extra: Record<string, unknown> = {}) {\n let origin = \"\";\n const srv = http.createServer((req, res) => {\n if (req.url !== \"/.well-known/openid-configuration\") {\n res.writeHead(404).end();\n return;\n }\n res.setHeader(\"content-type\", \"application/json\");\n res.end(JSON.stringify(doc(origin, extra)));\n });\n await new Promise<void>((resolve) => srv.listen(0, resolve));\n server = srv;\n origin = `http://localhost:${(srv.address() as { port: number }).port}`;\n return origin;\n}\n\ndescribe(\"customProvider\", () => {\n it(\"builds an OAuthConfig from discovery\", async () => {\n const base = await serveDiscovery();\n\n const config = await customProvider({\n issuer: base,\n audience: \"my-api\",\n baseUrl: \"https://app.example.test\",\n scopes: [\"openid\"],\n });\n\n expect(config.baseUrl).toBe(\"https://app.example.test\");\n expect(config.verify).toEqual({\n issuer: base,\n audience: \"my-api\",\n jwksUri: `${base}/jwks`,\n });\n expect(config.scopesSupported).toEqual([\"openid\"]);\n expect(config.oauthMetadata.registration_endpoint).toBe(`${base}/register`);\n });\n\n it(\"ignores a runtime issuer override (keeps the discovered trust anchor)\", async () => {\n const base = await serveDiscovery();\n const config = await customProvider({\n issuer: base,\n audience: \"a\",\n metadataOverrides: { issuer: \"https://evil.test\" } as never,\n });\n expect(config.verify.issuer).toBe(base);\n expect(config.oauthMetadata.issuer).toBe(base);\n });\n\n it(\"ignores a runtime jwks_uri override (keeps the discovered signing keys)\", async () => {\n const base = await serveDiscovery();\n const config = await customProvider({\n issuer: base,\n audience: \"a\",\n metadataOverrides: { jwks_uri: \"https://evil.test/keys\" } as never,\n });\n expect(config.verify.jwksUri).toBe(`${base}/jwks`);\n });\n\n it(\"rejects a non-DCR IdP even if an override supplies registration_endpoint\", async () => {\n const base = await serveDiscovery({ registration_endpoint: undefined });\n await expect(\n customProvider({\n issuer: base,\n audience: \"a\",\n metadataOverrides: { registration_endpoint: `${base}/register` },\n }),\n ).rejects.toThrow(/not DCR-compatible/);\n });\n\n it(\"applies metadataOverrides over discovered values\", async () => {\n const base = await serveDiscovery();\n const config = await customProvider({\n issuer: base,\n audience: \"a\",\n baseUrl: \"https://app.example.test\",\n metadataOverrides: { token_endpoint: \"https://override/token\" },\n });\n expect(config.oauthMetadata.token_endpoint).toBe(\"https://override/token\");\n });\n});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;SAChE,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// @vitest-environment node\nimport http from \"node:http\";\nimport { afterEach, describe, expect, it, vi } from \"vitest\";\nimport { customProvider } from \"./custom.js\";\nimport { lastJwksConfig as jwks } from \"./verify-spy.js\";\n\nvi.mock(\"../verify.js\", () => import(\"./verify-spy.js\"));\n\nconst servers: http.Server[] = [];\nafterEach(() => {\n for (const srv of servers.splice(0)) {\n srv.close();\n }\n});\n\nfunction doc(origin: string, extra: Record<string, unknown> = {}) {\n return {\n issuer: origin,\n authorization_endpoint: `${origin}/authorize`,\n token_endpoint: `${origin}/token`,\n registration_endpoint: `${origin}/register`,\n response_types_supported: [\"code\"],\n scopes_supported: [\"openid\", \"email\", \"profile\"],\n jwks_uri: `${origin}/jwks`,\n ...extra,\n };\n}\n\n// Serves the discovery doc (built from the live origin) at the OIDC well-known path.\nasync function serveDiscovery(extra: Record<string, unknown> = {}) {\n let origin = \"\";\n const srv = http.createServer((req, res) => {\n if (req.url !== \"/.well-known/openid-configuration\") {\n res.writeHead(404).end();\n return;\n }\n res.setHeader(\"content-type\", \"application/json\");\n res.end(JSON.stringify(doc(origin, extra)));\n });\n await new Promise<void>((resolve) => srv.listen(0, resolve));\n servers.push(srv);\n origin = `http://localhost:${(srv.address() as { port: number }).port}`;\n return origin;\n}\n\ndescribe(\"customProvider\", () => {\n it(\"builds an OAuthConfig from discovery\", async () => {\n const base = await serveDiscovery();\n\n const config = await customProvider({\n issuer: base,\n audience: \"my-api\",\n baseUrl: \"https://app.example.test\",\n scopes: [\"openid\"],\n });\n\n expect(config.baseUrl).toBe(\"https://app.example.test\");\n expect(jwks()).toEqual({\n issuer: base,\n audience: \"my-api\",\n jwksUri: `${base}/jwks`,\n });\n expect(config.scopesSupported).toEqual([\"openid\"]);\n expect(config.oauthMetadata.registration_endpoint).toBe(`${base}/register`);\n });\n\n it(\"ignores a runtime issuer override (keeps the discovered trust anchor)\", async () => {\n const base = await serveDiscovery();\n const config = await customProvider({\n issuer: base,\n audience: \"a\",\n metadataOverrides: { issuer: \"https://evil.test\" } as never,\n });\n expect(jwks().issuer).toBe(base);\n expect(config.oauthMetadata.issuer).toBe(base);\n });\n\n it(\"ignores a runtime jwks_uri override (keeps the discovered signing keys)\", async () => {\n const base = await serveDiscovery();\n await customProvider({\n issuer: base,\n audience: \"a\",\n metadataOverrides: { jwks_uri: \"https://evil.test/keys\" } as never,\n });\n expect(jwks().jwksUri).toBe(`${base}/jwks`);\n });\n\n it(\"serves metadata without a registration_endpoint when the IdP has no DCR\", async () => {\n const base = await serveDiscovery({ registration_endpoint: undefined });\n const config = await customProvider({ issuer: base, audience: \"a\" });\n expect(config.oauthMetadata.registration_endpoint).toBeUndefined();\n expect(jwks().issuer).toBe(base);\n });\n\n it(\"throws when discovery has no jwks_uri (token verification needs it)\", async () => {\n const base = await serveDiscovery({ jwks_uri: undefined });\n await expect(\n customProvider({ issuer: base, audience: \"a\" }),\n ).rejects.toThrow(/jwks_uri/);\n });\n\n it(\"serverUrl advertises this server as the AS, keeping the IdP as the token issuer\", async () => {\n const base = await serveDiscovery();\n const config = await customProvider({\n issuer: base,\n audience: \"a\",\n serverUrl: \"https://app.example.test/\",\n scopes: [\"openid\"],\n });\n // AS metadata + advertised scopes reflect this server.\n expect(config.oauthMetadata.issuer).toBe(\"https://app.example.test\");\n expect(config.oauthMetadata.scopes_supported).toEqual([\"openid\"]);\n // but the token's issuer is still verified against the IdP.\n expect(jwks().issuer).toBe(base);\n });\n\n it(\"authorizationServer supplies the advertised metadata and the verified issuer\", async () => {\n const base = await serveDiscovery();\n const as = await serveDiscovery({ scopes_supported: [\"checkout\"] });\n\n const config = await customProvider({\n issuer: base,\n audience: \"a\",\n authorizationServer: `${as}/`,\n });\n\n expect(config.oauthMetadata.issuer).toBe(as);\n expect(config.oauthMetadata.authorization_endpoint).toBe(`${as}/authorize`);\n expect(config.oauthMetadata.registration_endpoint).toBe(`${as}/register`);\n expect(config.scopesSupported).toEqual([\"checkout\"]);\n expect(jwks()).toEqual({\n issuer: as,\n audience: \"a\",\n jwksUri: `${as}/jwks`,\n });\n });\n\n it(\"falls back to the issuer's metadata when the authorizationServer is undiscoverable\", async () => {\n const base = await serveDiscovery();\n const warn = vi.spyOn(console, \"warn\").mockImplementation(() => {});\n\n const config = await customProvider({\n issuer: base,\n audience: \"a\",\n authorizationServer: `${base}/agentic/P1/MS1`,\n });\n\n expect(warn).toHaveBeenCalledOnce();\n expect(config.oauthMetadata.issuer).toBe(`${base}/agentic/P1/MS1`);\n expect(config.oauthMetadata.authorization_endpoint).toBe(\n `${base}/authorize`,\n );\n expect(jwks().issuer).toBe(base);\n warn.mockRestore();\n });\n\n it(\"serverUrl takes precedence over authorizationServer\", async () => {\n const base = await serveDiscovery();\n const as = await serveDiscovery();\n const config = await customProvider({\n issuer: base,\n audience: \"a\",\n serverUrl: \"https://app.example.test/\",\n authorizationServer: as,\n });\n expect(config.oauthMetadata.issuer).toBe(\"https://app.example.test\");\n expect(config.oauthMetadata.token_endpoint).toBe(`${as}/token`);\n expect(jwks().issuer).toBe(as);\n });\n\n it(\"applies metadataOverrides over discovered values\", async () => {\n const base = await serveDiscovery();\n const config = await customProvider({\n issuer: base,\n audience: \"a\",\n baseUrl: \"https://app.example.test\",\n metadataOverrides: { token_endpoint: \"https://override/token\" },\n });\n expect(config.oauthMetadata.token_endpoint).toBe(\"https://override/token\");\n });\n});\n"]}
@@ -1,15 +1,44 @@
1
+ import type { ExtraClaims } from "../../auth.js";
1
2
  import type { OAuthConfig } from "../index.js";
3
+ import type { RegisteredClaims } from "../verify.js";
2
4
  import { type CustomProviderOptions } from "./custom.js";
3
5
  /**
4
- * OAuth provider for a Descope MCP Server. `mcpServerId` is the MCP Server's
5
- * ID (the `MS`-prefixed Resource ID from the console's MCP Servers section),
6
- * not a generic Inbound App or client ID. Requires DCR enabled on the MCP
7
- * Server. `audience` is the Descope **Project ID** — Descope binds the token
8
- * `aud` to [DCR client id, project id], not the server URL. Custom-domain Descope
9
- * tenants should use `customProvider({ issuer })` directly with the full discovery URL.
6
+ * Claims a Descope session JWT carries. Roles and permissions are nested per
7
+ * tenant when the project uses tenants, and flat otherwise. `email` arrives only
8
+ * through a Custom Claims flow action or a JWT template.
9
+ *
10
+ * @see https://docs.descope.com/authorization/session-management
11
+ * @see https://docs.descope.com/management/token/jwt-templates
10
12
  */
11
- export declare function descopeProvider(opts: {
12
- projectId: string;
13
- mcpServerId: string;
14
- audience: string;
15
- } & Omit<CustomProviderOptions, "issuer" | "audience">): Promise<OAuthConfig>;
13
+ export type DescopeClaims = {
14
+ /** Authentication methods used, e.g. `["otp"]`. */
15
+ amr?: string[];
16
+ /** Descope Resource Name: where the token is stored. */
17
+ drn?: string;
18
+ /** The user's active tenant. */
19
+ dct?: string;
20
+ /** Associated tenants, keyed by tenant id. */
21
+ tenants?: Record<string, {
22
+ roles?: string[];
23
+ permissions?: string[];
24
+ }>;
25
+ /** Roles, when the project has no tenants. */
26
+ roles?: string[];
27
+ /** Permissions, when the project has no tenants. */
28
+ permissions?: string[];
29
+ /** Only via a Custom Claims action or JWT template; not a default claim. */
30
+ email?: string;
31
+ };
32
+ /**
33
+ * OAuth provider for a Descope MCP Server. `url` is the MCP Server's **Discovery
34
+ * URL** (a.k.a. Issuer) from the console's Connection Information, e.g.
35
+ * `https://api.descope.com/v1/apps/agentic/<projectId>/<mcpServerId>` (or your
36
+ * custom domain). Requires DCR enabled on the MCP Server. For Descope with DCR
37
+ * disabled and Alpic's DCR proxy, use {@link customProvider} with `serverUrl`
38
+ * instead (see `examples/auth-descope-alpic`). The token `audience` defaults to
39
+ * the **Project ID** derived from the URL — Descope binds `aud` to [DCR client
40
+ * id, project id], not the server URL; pass `audience` to override.
41
+ */
42
+ export declare function descopeProvider<TCustom extends ExtraClaims = Record<never, never>>(opts: {
43
+ url: string;
44
+ } & Omit<CustomProviderOptions, "issuer">): Promise<OAuthConfig<DescopeClaims & TCustom & RegisteredClaims>>;
@@ -1,15 +1,44 @@
1
1
  import { customProvider } from "./custom.js";
2
2
  /**
3
- * OAuth provider for a Descope MCP Server. `mcpServerId` is the MCP Server's
4
- * ID (the `MS`-prefixed Resource ID from the console's MCP Servers section),
5
- * not a generic Inbound App or client ID. Requires DCR enabled on the MCP
6
- * Server. `audience` is the Descope **Project ID** — Descope binds the token
7
- * `aud` to [DCR client id, project id], not the server URL. Custom-domain Descope
8
- * tenants should use `customProvider({ issuer })` directly with the full discovery URL.
3
+ * Turns the console's Discovery URL into the authorization server's base URL:
4
+ * drops a `/.well-known/openid-configuration` (or `oauth-authorization-server`)
5
+ * suffix, since discovery appends that path itself, and any trailing slash.
6
+ */
7
+ function toAuthorizationServerUrl(discoveryUrl) {
8
+ return discoveryUrl.replace(/\/\.well-known\/[^?#]*$/, "").replace(/\/$/, "");
9
+ }
10
+ /**
11
+ * Derives the Descope Project ID from an MCP Server URL
12
+ * (`…/agentic/<projectId>/<mcpServerId>`). Descope binds the token `aud` to the
13
+ * project id, so it doubles as the audience.
14
+ */
15
+ function projectIdFromUrl(url) {
16
+ const projectId = url.match(/\/agentic\/([^/]+)\/[^/]+/)?.[1];
17
+ if (!projectId) {
18
+ throw new Error(`Could not derive the Descope project id from "${url}"; pass an explicit \`audience\`.`);
19
+ }
20
+ return projectId;
21
+ }
22
+ /**
23
+ * OAuth provider for a Descope MCP Server. `url` is the MCP Server's **Discovery
24
+ * URL** (a.k.a. Issuer) from the console's Connection Information, e.g.
25
+ * `https://api.descope.com/v1/apps/agentic/<projectId>/<mcpServerId>` (or your
26
+ * custom domain). Requires DCR enabled on the MCP Server. For Descope with DCR
27
+ * disabled and Alpic's DCR proxy, use {@link customProvider} with `serverUrl`
28
+ * instead (see `examples/auth-descope-alpic`). The token `audience` defaults to
29
+ * the **Project ID** derived from the URL — Descope binds `aud` to [DCR client
30
+ * id, project id], not the server URL; pass `audience` to override.
9
31
  */
10
32
  export function descopeProvider(opts) {
11
- const { projectId, mcpServerId, ...rest } = opts;
12
- const issuer = `https://api.descope.com/v1/apps/agentic/${projectId}/${mcpServerId}`;
13
- return customProvider({ issuer, ...rest });
33
+ const { url, audience, ...rest } = opts;
34
+ const asUrl = toAuthorizationServerUrl(url);
35
+ const projectId = projectIdFromUrl(asUrl);
36
+ const issuer = `${asUrl.slice(0, asUrl.indexOf("/agentic/"))}/${projectId}`;
37
+ return customProvider({
38
+ issuer,
39
+ audience: audience ?? projectId,
40
+ authorizationServer: asUrl,
41
+ ...rest,
42
+ });
14
43
  }
15
44
  //# sourceMappingURL=descope.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"descope.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/descope.ts"],"names":[],"mappings":"AACA,OAAO,EAA8B,cAAc,EAAE,MAAM,aAAa,CAAC;AAEzE;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAC7B,IAGC;IAED,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IACjD,MAAM,MAAM,GAAG,2CAA2C,SAAS,IAAI,WAAW,EAAE,CAAC;IACrF,OAAO,cAAc,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["import type { OAuthConfig } from \"../index.js\";\nimport { type CustomProviderOptions, customProvider } from \"./custom.js\";\n\n/**\n * OAuth provider for a Descope MCP Server. `mcpServerId` is the MCP Server's\n * ID (the `MS`-prefixed Resource ID from the console's MCP Servers section),\n * not a generic Inbound App or client ID. Requires DCR enabled on the MCP\n * Server. `audience` is the Descope **Project ID** — Descope binds the token\n * `aud` to [DCR client id, project id], not the server URL. Custom-domain Descope\n * tenants should use `customProvider({ issuer })` directly with the full discovery URL.\n */\nexport function descopeProvider(\n opts: { projectId: string; mcpServerId: string; audience: string } & Omit<\n CustomProviderOptions,\n \"issuer\" | \"audience\"\n >,\n): Promise<OAuthConfig> {\n const { projectId, mcpServerId, ...rest } = opts;\n const issuer = `https://api.descope.com/v1/apps/agentic/${projectId}/${mcpServerId}`;\n return customProvider({ issuer, ...rest });\n}\n"]}
1
+ {"version":3,"file":"descope.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/descope.ts"],"names":[],"mappings":"AAGA,OAAO,EAA8B,cAAc,EAAE,MAAM,aAAa,CAAC;AA2BzE;;;;GAIG;AACH,SAAS,wBAAwB,CAAC,YAAoB;IACpD,OAAO,YAAY,CAAC,OAAO,CAAC,yBAAyB,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAChF,CAAC;AAED;;;;GAIG;AACH,SAAS,gBAAgB,CAAC,GAAW;IACnC,MAAM,SAAS,GAAG,GAAG,CAAC,KAAK,CAAC,2BAA2B,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC9D,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,iDAAiD,GAAG,mCAAmC,CACxF,CAAC;IACJ,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAG7B,IAA6D;IAE7D,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IACxC,MAAM,KAAK,GAAG,wBAAwB,CAAC,GAAG,CAAC,CAAC;IAC5C,MAAM,SAAS,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,IAAI,SAAS,EAAE,CAAC;IAC5E,OAAO,cAAc,CAA0B;QAC7C,MAAM;QACN,QAAQ,EAAE,QAAQ,IAAI,SAAS;QAC/B,mBAAmB,EAAE,KAAK;QAC1B,GAAG,IAAI;KACR,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { ExtraClaims } from \"../../auth.js\";\nimport type { OAuthConfig } from \"../index.js\";\nimport type { RegisteredClaims } from \"../verify.js\";\nimport { type CustomProviderOptions, customProvider } from \"./custom.js\";\n\n/**\n * Claims a Descope session JWT carries. Roles and permissions are nested per\n * tenant when the project uses tenants, and flat otherwise. `email` arrives only\n * through a Custom Claims flow action or a JWT template.\n *\n * @see https://docs.descope.com/authorization/session-management\n * @see https://docs.descope.com/management/token/jwt-templates\n */\nexport type DescopeClaims = {\n /** Authentication methods used, e.g. `[\"otp\"]`. */\n amr?: string[];\n /** Descope Resource Name: where the token is stored. */\n drn?: string;\n /** The user's active tenant. */\n dct?: string;\n /** Associated tenants, keyed by tenant id. */\n tenants?: Record<string, { roles?: string[]; permissions?: string[] }>;\n /** Roles, when the project has no tenants. */\n roles?: string[];\n /** Permissions, when the project has no tenants. */\n permissions?: string[];\n /** Only via a Custom Claims action or JWT template; not a default claim. */\n email?: string;\n};\n\n/**\n * Turns the console's Discovery URL into the authorization server's base URL:\n * drops a `/.well-known/openid-configuration` (or `oauth-authorization-server`)\n * suffix, since discovery appends that path itself, and any trailing slash.\n */\nfunction toAuthorizationServerUrl(discoveryUrl: string): string {\n return discoveryUrl.replace(/\\/\\.well-known\\/[^?#]*$/, \"\").replace(/\\/$/, \"\");\n}\n\n/**\n * Derives the Descope Project ID from an MCP Server URL\n * (`…/agentic/<projectId>/<mcpServerId>`). Descope binds the token `aud` to the\n * project id, so it doubles as the audience.\n */\nfunction projectIdFromUrl(url: string): string {\n const projectId = url.match(/\\/agentic\\/([^/]+)\\/[^/]+/)?.[1];\n if (!projectId) {\n throw new Error(\n `Could not derive the Descope project id from \"${url}\"; pass an explicit \\`audience\\`.`,\n );\n }\n return projectId;\n}\n\n/**\n * OAuth provider for a Descope MCP Server. `url` is the MCP Server's **Discovery\n * URL** (a.k.a. Issuer) from the console's Connection Information, e.g.\n * `https://api.descope.com/v1/apps/agentic/<projectId>/<mcpServerId>` (or your\n * custom domain). Requires DCR enabled on the MCP Server. For Descope with DCR\n * disabled and Alpic's DCR proxy, use {@link customProvider} with `serverUrl`\n * instead (see `examples/auth-descope-alpic`). The token `audience` defaults to\n * the **Project ID** derived from the URL — Descope binds `aud` to [DCR client\n * id, project id], not the server URL; pass `audience` to override.\n */\nexport function descopeProvider<\n TCustom extends ExtraClaims = Record<never, never>,\n>(\n opts: { url: string } & Omit<CustomProviderOptions, \"issuer\">,\n): Promise<OAuthConfig<DescopeClaims & TCustom & RegisteredClaims>> {\n const { url, audience, ...rest } = opts;\n const asUrl = toAuthorizationServerUrl(url);\n const projectId = projectIdFromUrl(asUrl);\n const issuer = `${asUrl.slice(0, asUrl.indexOf(\"/agentic/\"))}/${projectId}`;\n return customProvider<DescopeClaims & TCustom>({\n issuer,\n audience: audience ?? projectId,\n authorizationServer: asUrl,\n ...rest,\n });\n}\n"]}
@@ -1,35 +1,62 @@
1
1
  // @vitest-environment node
2
2
  import { afterEach, describe, expect, it, vi } from "vitest";
3
3
  import { descopeProvider } from "./descope.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 discoveryDoc(issuer, scopes) {
6
8
  return {
7
9
  issuer,
8
10
  authorization_endpoint: `${issuer}/authorize`,
9
11
  token_endpoint: `${issuer}/token`,
10
12
  registration_endpoint: `${issuer}/register`,
11
13
  response_types_supported: ["code"],
12
- scopes_supported: ["openid"],
14
+ scopes_supported: scopes,
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
- }));
18
+ const PROJECT = "https://api.descope.com/v1/apps/P123";
19
+ const AGENTIC = "https://api.descope.com/v1/apps/agentic/P123/MS456";
20
+ function mockDiscovery(docs) {
21
+ return vi
22
+ .spyOn(globalThis, "fetch")
23
+ .mockImplementation(async (input) => {
24
+ const url = String(input);
25
+ const entry = Object.entries(docs).find(([issuer]) => url === `${issuer}/.well-known/openid-configuration`);
26
+ if (entry === undefined) {
27
+ return new Response(null, { status: 404 });
28
+ }
29
+ return new Response(JSON.stringify(discoveryDoc(...entry)), {
30
+ headers: { "content-type": "application/json" },
31
+ });
32
+ });
20
33
  }
21
34
  describe("descopeProvider", () => {
22
- it("builds the MCP Server issuer from projectId and mcpServerId", async () => {
23
- const issuer = "https://api.descope.com/v1/apps/agentic/P123/MS456";
24
- const fetchSpy = mockDiscovery(issuer);
35
+ it("verifies against the agentic issuer it advertises", async () => {
36
+ const fetchSpy = mockDiscovery({
37
+ [PROJECT]: ["openid", "profile", "email", "phone"],
38
+ [AGENTIC]: ["checkout"],
39
+ });
40
+ const config = await descopeProvider({ url: AGENTIC });
41
+ expect(fetchSpy).toHaveBeenCalledWith(`${PROJECT}/.well-known/openid-configuration`, expect.anything());
42
+ expect(jwks().issuer).toBe(AGENTIC);
43
+ expect(jwks().audience).toBe("P123");
44
+ expect(config.oauthMetadata.issuer).toBe(AGENTIC);
45
+ expect(config.oauthMetadata.registration_endpoint).toBe(`${AGENTIC}/register`);
46
+ expect(config.scopesSupported).toEqual(["checkout"]);
47
+ });
48
+ it("accepts a URL carrying the well-known suffix", async () => {
49
+ mockDiscovery({ [PROJECT]: ["openid"], [AGENTIC]: ["checkout"] });
25
50
  const config = await descopeProvider({
26
- projectId: "P123",
27
- mcpServerId: "MS456",
28
- audience: "https://mcp.example.com",
51
+ url: `${AGENTIC}/.well-known/openid-configuration`,
29
52
  });
30
- expect(fetchSpy).toHaveBeenCalledWith(`${issuer}/.well-known/openid-configuration`, expect.anything());
31
- expect(config.verify.issuer).toBe(issuer);
32
- expect(config.verify.audience).toBe("https://mcp.example.com");
53
+ expect(config.oauthMetadata.issuer).toBe(AGENTIC);
54
+ expect(config.scopesSupported).toEqual(["checkout"]);
55
+ });
56
+ it("lets an explicit audience override the derived project id", async () => {
57
+ mockDiscovery({ [PROJECT]: ["openid"], [AGENTIC]: ["checkout"] });
58
+ await descopeProvider({ url: AGENTIC, audience: "custom" });
59
+ expect(jwks().audience).toBe("custom");
33
60
  });
34
61
  });
35
62
  //# sourceMappingURL=descope.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"descope.test.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/descope.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,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,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,QAAQ;QACjC,qBAAqB,EAAE,GAAG,MAAM,WAAW;QAC3C,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,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,6DAA6D,EAAE,KAAK,IAAI,EAAE;QAC3E,MAAM,MAAM,GAAG,oDAAoD,CAAC;QACpE,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;QAEvC,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC;YACnC,SAAS,EAAE,MAAM;YACjB,WAAW,EAAE,OAAO;YACpB,QAAQ,EAAE,yBAAyB;SACpC,CAAC,CAAC;QAEH,MAAM,CAAC,QAAQ,CAAC,CAAC,oBAAoB,CACnC,GAAG,MAAM,mCAAmC,EAC5C,MAAM,CAAC,QAAQ,EAAE,CAClB,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1C,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// @vitest-environment node\nimport { afterEach, describe, expect, it, vi } from \"vitest\";\nimport { descopeProvider } from \"./descope.js\";\n\nafterEach(() => vi.restoreAllMocks());\n\nfunction discoveryDoc(issuer: string) {\n return {\n issuer,\n authorization_endpoint: `${issuer}/authorize`,\n token_endpoint: `${issuer}/token`,\n registration_endpoint: `${issuer}/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(\"descopeProvider\", () => {\n it(\"builds the MCP Server issuer from projectId and mcpServerId\", async () => {\n const issuer = \"https://api.descope.com/v1/apps/agentic/P123/MS456\";\n const fetchSpy = mockDiscovery(issuer);\n\n const config = await descopeProvider({\n projectId: \"P123\",\n mcpServerId: \"MS456\",\n audience: \"https://mcp.example.com\",\n });\n\n expect(fetchSpy).toHaveBeenCalledWith(\n `${issuer}/.well-known/openid-configuration`,\n expect.anything(),\n );\n expect(config.verify.issuer).toBe(issuer);\n expect(config.verify.audience).toBe(\"https://mcp.example.com\");\n });\n});\n"]}
1
+ {"version":3,"file":"descope.test.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/descope.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,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,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,YAAY,CAAC,MAAc,EAAE,MAAgB;IACpD,OAAO;QACL,MAAM;QACN,sBAAsB,EAAE,GAAG,MAAM,YAAY;QAC7C,cAAc,EAAE,GAAG,MAAM,QAAQ;QACjC,qBAAqB,EAAE,GAAG,MAAM,WAAW;QAC3C,wBAAwB,EAAE,CAAC,MAAM,CAAC;QAClC,gBAAgB,EAAE,MAAM;QACxB,QAAQ,EAAE,GAAG,MAAM,wBAAwB;KAC5C,CAAC;AACJ,CAAC;AAED,MAAM,OAAO,GAAG,sCAAsC,CAAC;AACvD,MAAM,OAAO,GAAG,oDAAoD,CAAC;AAErE,SAAS,aAAa,CAAC,IAA8B;IACnD,OAAO,EAAE;SACN,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC;SAC1B,kBAAkB,CAAC,KAAK,EAAE,KAAwB,EAAE,EAAE;QACrD,M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\"vitest\";\nimport { descopeProvider } from \"./descope.js\";\nimport { lastJwksConfig as jwks } from \"./verify-spy.js\";\n\nvi.mock(\"../verify.js\", () => import(\"./verify-spy.js\"));\n\nafterEach(() => vi.restoreAllMocks());\n\nfunction discoveryDoc(issuer: string, scopes: string[]) {\n return {\n issuer,\n authorization_endpoint: `${issuer}/authorize`,\n token_endpoint: `${issuer}/token`,\n registration_endpoint: `${issuer}/register`,\n response_types_supported: [\"code\"],\n scopes_supported: scopes,\n jwks_uri: `${issuer}/.well-known/jwks.json`,\n };\n}\n\nconst PROJECT = \"https://api.descope.com/v1/apps/P123\";\nconst AGENTIC = \"https://api.descope.com/v1/apps/agentic/P123/MS456\";\n\nfunction mockDiscovery(docs: Record<string, string[]>) {\n return vi\n .spyOn(globalThis, \"fetch\")\n .mockImplementation(async (input: RequestInfo | URL) => {\n const url = String(input);\n const entry = Object.entries(docs).find(\n ([issuer]) => url === `${issuer}/.well-known/openid-configuration`,\n );\n if (entry === undefined) {\n return new Response(null, { status: 404 });\n }\n return new Response(JSON.stringify(discoveryDoc(...entry)), {\n headers: { \"content-type\": \"application/json\" },\n });\n });\n}\n\ndescribe(\"descopeProvider\", () => {\n it(\"verifies against the agentic issuer it advertises\", async () => {\n const fetchSpy = mockDiscovery({\n [PROJECT]: [\"openid\", \"profile\", \"email\", \"phone\"],\n [AGENTIC]: [\"checkout\"],\n });\n\n const config = await descopeProvider({ url: AGENTIC });\n\n expect(fetchSpy).toHaveBeenCalledWith(\n `${PROJECT}/.well-known/openid-configuration`,\n expect.anything(),\n );\n expect(jwks().issuer).toBe(AGENTIC);\n expect(jwks().audience).toBe(\"P123\");\n expect(config.oauthMetadata.issuer).toBe(AGENTIC);\n expect(config.oauthMetadata.registration_endpoint).toBe(\n `${AGENTIC}/register`,\n );\n expect(config.scopesSupported).toEqual([\"checkout\"]);\n });\n\n it(\"accepts a URL carrying the well-known suffix\", async () => {\n mockDiscovery({ [PROJECT]: [\"openid\"], [AGENTIC]: [\"checkout\"] });\n\n const config = await descopeProvider({\n url: `${AGENTIC}/.well-known/openid-configuration`,\n });\n\n expect(config.oauthMetadata.issuer).toBe(AGENTIC);\n expect(config.scopesSupported).toEqual([\"checkout\"]);\n });\n\n it(\"lets an explicit audience override the derived project id\", async () => {\n mockDiscovery({ [PROJECT]: [\"openid\"], [AGENTIC]: [\"checkout\"] });\n\n await descopeProvider({ url: AGENTIC, audience: \"custom\" });\n\n expect(jwks().audience).toBe(\"custom\");\n });\n});\n"]}
@@ -0,0 +1,2 @@
1
+ /** Normalises a bare host to an https issuer URL and strips a trailing slash. */
2
+ export declare function toIssuerUrl(domain: string): string;
@@ -0,0 +1,6 @@
1
+ /** Normalises a bare host to an https issuer URL and strips a trailing slash. */
2
+ export function toIssuerUrl(domain) {
3
+ const withScheme = /^https?:\/\//.test(domain) ? domain : `https://${domain}`;
4
+ return withScheme.replace(/\/$/, "");
5
+ }
6
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/shared.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,MAAM,UAAU,WAAW,CAAC,MAAc;IACxC,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","sourcesContent":["/** Normalises a bare host to an https issuer URL and strips a trailing slash. */\nexport function toIssuerUrl(domain: string): string {\n const withScheme = /^https?:\\/\\//.test(domain) ? domain : `https://${domain}`;\n return withScheme.replace(/\\/$/, \"\");\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { toIssuerUrl } from "./shared.js";
3
+ describe("toIssuerUrl", () => {
4
+ it("adds https to a bare host, preserves an explicit scheme, strips a trailing slash", () => {
5
+ expect(toIssuerUrl("acme.authkit.app")).toBe("https://acme.authkit.app");
6
+ expect(toIssuerUrl("https://acme.authkit.app/")).toBe("https://acme.authkit.app");
7
+ expect(toIssuerUrl("http://localhost:3000")).toBe("http://localhost:3000");
8
+ });
9
+ });
10
+ //# sourceMappingURL=shared.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.test.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/shared.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,EAAE,CAAC,kFAAkF,EAAE,GAAG,EAAE;QAC1F,MAAM,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;QACzE,MAAM,CAAC,WAAW,CAAC,2BAA2B,CAAC,CAAC,CAAC,IAAI,CACnD,0BAA0B,CAC3B,CAAC;QACF,MAAM,CAAC,WAAW,CAAC,uBAAuB,CAAC,CAAC,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport { toIssuerUrl } from \"./shared.js\";\n\ndescribe(\"toIssuerUrl\", () => {\n it(\"adds https to a bare host, preserves an explicit scheme, strips a trailing slash\", () => {\n expect(toIssuerUrl(\"acme.authkit.app\")).toBe(\"https://acme.authkit.app\");\n expect(toIssuerUrl(\"https://acme.authkit.app/\")).toBe(\n \"https://acme.authkit.app\",\n );\n expect(toIssuerUrl(\"http://localhost:3000\")).toBe(\"http://localhost:3000\");\n });\n});\n"]}
@@ -1,12 +1,25 @@
1
+ import type { ExtraClaims } from "../../auth.js";
1
2
  import type { OAuthConfig } from "../index.js";
3
+ import type { RegisteredClaims } from "../verify.js";
2
4
  import { type CustomProviderOptions } from "./custom.js";
5
+ /**
6
+ * Claims a Stytch Connected Apps access token carries. Beyond the subject,
7
+ * everything is project-configured through the client's access-token template.
8
+ *
9
+ * @see https://stytch.com/docs/api-reference/consumer/api/connected-apps/tokens/connected-app-access-token-object
10
+ * @see https://stytch.com/docs/api/connected-apps-create
11
+ */
12
+ export type StytchClaims = {
13
+ /** Only when the client's access-token template adds it. */
14
+ email?: string;
15
+ };
3
16
  /**
4
17
  * OAuth provider for Stytch Connected Apps. `domain` is the project domain,
5
18
  * e.g. `acme.customers.stytch.dev`, or a configured custom domain. Requires
6
19
  * DCR enabled in the Stytch dashboard. `audience` is the Stytch Project ID
7
20
  * (the default token audience).
8
21
  */
9
- export declare function stytchProvider(opts: {
22
+ export declare function stytchProvider<TCustom extends ExtraClaims = Record<never, never>>(opts: {
10
23
  domain: string;
11
24
  audience: string;
12
- } & Omit<CustomProviderOptions, "issuer" | "audience">): Promise<OAuthConfig>;
25
+ } & Omit<CustomProviderOptions, "issuer" | "audience">): Promise<OAuthConfig<StytchClaims & TCustom & RegisteredClaims>>;
@@ -1,9 +1,5 @@
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 Stytch Connected Apps. `domain` is the project domain,
9
5
  * e.g. `acme.customers.stytch.dev`, or a configured custom domain. Requires
@@ -12,6 +8,9 @@ function toIssuerUrl(domain) {
12
8
  */
13
9
  export function stytchProvider(opts) {
14
10
  const { domain, ...rest } = opts;
15
- return customProvider({ issuer: toIssuerUrl(domain), ...rest });
11
+ return customProvider({
12
+ issuer: toIssuerUrl(domain),
13
+ ...rest,
14
+ });
16
15
  }
17
16
  //# sourceMappingURL=stytch.js.map