skybridge 0.0.0-dev.a8fd02e → 0.0.0-dev.a919e42

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 (201) hide show
  1. package/README.md +1 -0
  2. package/dist/cli/build-helpers.d.ts +6 -2
  3. package/dist/cli/build-helpers.js +37 -12
  4. package/dist/cli/build-helpers.js.map +1 -1
  5. package/dist/cli/build-helpers.test.js +69 -3
  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-nodemon.d.ts +14 -0
  20. package/dist/cli/use-nodemon.js +71 -60
  21. package/dist/cli/use-nodemon.js.map +1 -1
  22. package/dist/cli/use-typescript-check.d.ts +8 -2
  23. package/dist/cli/use-typescript-check.js +70 -67
  24. package/dist/cli/use-typescript-check.js.map +1 -1
  25. package/dist/commands/build.d.ts +0 -2
  26. package/dist/commands/build.js +2 -61
  27. package/dist/commands/build.js.map +1 -1
  28. package/dist/commands/dev.d.ts +1 -0
  29. package/dist/commands/dev.js +34 -2
  30. package/dist/commands/dev.js.map +1 -1
  31. package/dist/server/auth/discovery.d.ts +30 -5
  32. package/dist/server/auth/discovery.js +34 -29
  33. package/dist/server/auth/discovery.js.map +1 -1
  34. package/dist/server/auth/discovery.test.js +12 -0
  35. package/dist/server/auth/discovery.test.js.map +1 -1
  36. package/dist/server/auth/providers/auth0.d.ts +18 -0
  37. package/dist/server/auth/providers/auth0.js +31 -0
  38. package/dist/server/auth/providers/auth0.js.map +1 -0
  39. package/dist/server/auth/providers/auth0.test.js +48 -0
  40. package/dist/server/auth/providers/auth0.test.js.map +1 -0
  41. package/dist/server/auth/providers/clerk.d.ts +14 -0
  42. package/dist/server/auth/providers/clerk.js +16 -0
  43. package/dist/server/auth/providers/clerk.js.map +1 -0
  44. package/dist/server/auth/providers/clerk.test.d.ts +1 -0
  45. package/dist/server/auth/providers/clerk.test.js +28 -0
  46. package/dist/server/auth/providers/clerk.test.js.map +1 -0
  47. package/dist/server/auth/providers/custom.d.ts +20 -2
  48. package/dist/server/auth/providers/custom.js +33 -12
  49. package/dist/server/auth/providers/custom.js.map +1 -1
  50. package/dist/server/auth/providers/custom.test.js +68 -25
  51. package/dist/server/auth/providers/custom.test.js.map +1 -1
  52. package/dist/server/auth/providers/descope.d.ts +9 -6
  53. package/dist/server/auth/providers/descope.js +38 -7
  54. package/dist/server/auth/providers/descope.js.map +1 -1
  55. package/dist/server/auth/providers/descope.test.js +40 -15
  56. package/dist/server/auth/providers/descope.test.js.map +1 -1
  57. package/dist/server/auth/providers/shared.d.ts +2 -0
  58. package/dist/server/auth/providers/shared.js +6 -0
  59. package/dist/server/auth/providers/shared.js.map +1 -0
  60. package/dist/server/auth/providers/shared.test.d.ts +1 -0
  61. package/dist/server/auth/providers/shared.test.js +10 -0
  62. package/dist/server/auth/providers/shared.test.js.map +1 -0
  63. package/dist/server/auth/providers/stytch.d.ts +2 -1
  64. package/dist/server/auth/providers/stytch.js +1 -5
  65. package/dist/server/auth/providers/stytch.js.map +1 -1
  66. package/dist/server/auth/providers/workos.d.ts +2 -1
  67. package/dist/server/auth/providers/workos.js +1 -5
  68. package/dist/server/auth/providers/workos.js.map +1 -1
  69. package/dist/server/auth/security-schemes.d.ts +23 -0
  70. package/dist/server/auth/security-schemes.js +64 -0
  71. package/dist/server/auth/security-schemes.js.map +1 -0
  72. package/dist/server/auth/security-schemes.test.d.ts +1 -0
  73. package/dist/server/auth/security-schemes.test.js +99 -0
  74. package/dist/server/auth/security-schemes.test.js.map +1 -0
  75. package/dist/server/auth/setup.d.ts +3 -1
  76. package/dist/server/auth/setup.js +64 -23
  77. package/dist/server/auth/setup.js.map +1 -1
  78. package/dist/server/auth/setup.test.js +291 -2
  79. package/dist/server/auth/setup.test.js.map +1 -1
  80. package/dist/server/auth/verify.d.ts +3 -2
  81. package/dist/server/auth/verify.js +2 -1
  82. package/dist/server/auth/verify.js.map +1 -1
  83. package/dist/server/auth/verify.test.js +13 -0
  84. package/dist/server/auth/verify.test.js.map +1 -1
  85. package/dist/server/host.d.ts +2 -0
  86. package/dist/server/host.js +11 -0
  87. package/dist/server/host.js.map +1 -0
  88. package/dist/server/host.test.d.ts +1 -0
  89. package/dist/server/host.test.js +13 -0
  90. package/dist/server/host.test.js.map +1 -0
  91. package/dist/server/index.d.ts +4 -1
  92. package/dist/server/index.js +4 -1
  93. package/dist/server/index.js.map +1 -1
  94. package/dist/server/server.d.ts +61 -9
  95. package/dist/server/server.js +208 -118
  96. package/dist/server/server.js.map +1 -1
  97. package/dist/server/skills-integration.test.d.ts +1 -0
  98. package/dist/server/skills-integration.test.js +63 -0
  99. package/dist/server/skills-integration.test.js.map +1 -0
  100. package/dist/server/skills.d.ts +23 -0
  101. package/dist/server/skills.js +178 -0
  102. package/dist/server/skills.js.map +1 -0
  103. package/dist/server/skills.test.d.ts +1 -0
  104. package/dist/server/skills.test.js +210 -0
  105. package/dist/server/skills.test.js.map +1 -0
  106. package/dist/server/view-name.test-d.d.ts +1 -0
  107. package/dist/server/view-name.test-d.js +8 -0
  108. package/dist/server/view-name.test-d.js.map +1 -0
  109. package/dist/server/view-resource-resolution.test.js +93 -10
  110. package/dist/server/view-resource-resolution.test.js.map +1 -1
  111. package/dist/server/viewsDevServer.js +4 -1
  112. package/dist/server/viewsDevServer.js.map +1 -1
  113. package/dist/test/view.test.js +70 -102
  114. package/dist/test/view.test.js.map +1 -1
  115. package/dist/web/bridges/adaptor.d.ts +51 -0
  116. package/dist/web/bridges/adaptor.js +330 -0
  117. package/dist/web/bridges/adaptor.js.map +1 -0
  118. package/dist/web/bridges/adaptor.test.d.ts +1 -0
  119. package/dist/web/bridges/adaptor.test.js +208 -0
  120. package/dist/web/bridges/adaptor.test.js.map +1 -0
  121. package/dist/web/bridges/apps-sdk/bridge.d.ts +6 -2
  122. package/dist/web/bridges/apps-sdk/bridge.js +15 -4
  123. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
  124. package/dist/web/bridges/apps-sdk/index.d.ts +0 -1
  125. package/dist/web/bridges/apps-sdk/index.js +0 -1
  126. package/dist/web/bridges/apps-sdk/index.js.map +1 -1
  127. package/dist/web/bridges/get-adaptor.d.ts +4 -4
  128. package/dist/web/bridges/get-adaptor.js +6 -11
  129. package/dist/web/bridges/get-adaptor.js.map +1 -1
  130. package/dist/web/bridges/get-adaptor.test.d.ts +1 -0
  131. package/dist/web/bridges/get-adaptor.test.js +32 -0
  132. package/dist/web/bridges/get-adaptor.test.js.map +1 -0
  133. package/dist/web/bridges/mcp-app/bridge.d.ts +13 -2
  134. package/dist/web/bridges/mcp-app/bridge.js +46 -4
  135. package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
  136. package/dist/web/bridges/mcp-app/bridge.test.d.ts +1 -0
  137. package/dist/web/bridges/mcp-app/bridge.test.js +17 -0
  138. package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -0
  139. package/dist/web/bridges/mcp-app/index.d.ts +0 -1
  140. package/dist/web/bridges/mcp-app/index.js +0 -1
  141. package/dist/web/bridges/mcp-app/index.js.map +1 -1
  142. package/dist/web/bridges/mcp-app/view-tools.test.js +5 -6
  143. package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -1
  144. package/dist/web/bridges/types.d.ts +10 -0
  145. package/dist/web/bridges/types.js +14 -1
  146. package/dist/web/bridges/types.js.map +1 -1
  147. package/dist/web/bridges/types.test.d.ts +1 -0
  148. package/dist/web/bridges/types.test.js +19 -0
  149. package/dist/web/bridges/types.test.js.map +1 -0
  150. package/dist/web/components/modal-provider.d.ts +1 -1
  151. package/dist/web/components/modal-provider.js +4 -3
  152. package/dist/web/components/modal-provider.js.map +1 -1
  153. package/dist/web/create-store.test.js +8 -5
  154. package/dist/web/create-store.test.js.map +1 -1
  155. package/dist/web/data-llm.d.ts +1 -1
  156. package/dist/web/data-llm.test.js +17 -5
  157. package/dist/web/data-llm.test.js.map +1 -1
  158. package/dist/web/hooks/use-call-tool.test.js +37 -23
  159. package/dist/web/hooks/use-call-tool.test.js.map +1 -1
  160. package/dist/web/hooks/use-display-mode.test.js +56 -20
  161. package/dist/web/hooks/use-display-mode.test.js.map +1 -1
  162. package/dist/web/hooks/use-download.test.js +11 -3
  163. package/dist/web/hooks/use-download.test.js.map +1 -1
  164. package/dist/web/hooks/use-files.test.js +10 -2
  165. package/dist/web/hooks/use-files.test.js.map +1 -1
  166. package/dist/web/hooks/use-layout.test.js +59 -26
  167. package/dist/web/hooks/use-layout.test.js.map +1 -1
  168. package/dist/web/hooks/use-open-external.test.js +13 -3
  169. package/dist/web/hooks/use-open-external.test.js.map +1 -1
  170. package/dist/web/hooks/use-request-close.test.js +35 -40
  171. package/dist/web/hooks/use-request-close.test.js.map +1 -1
  172. package/dist/web/hooks/use-request-modal.test.js +10 -0
  173. package/dist/web/hooks/use-request-modal.test.js.map +1 -1
  174. package/dist/web/hooks/use-request-size.test.js +35 -53
  175. package/dist/web/hooks/use-request-size.test.js.map +1 -1
  176. package/dist/web/hooks/use-set-open-in-app-url.test.js +28 -8
  177. package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
  178. package/dist/web/hooks/use-tool-info.test.js +37 -27
  179. package/dist/web/hooks/use-tool-info.test.js.map +1 -1
  180. package/dist/web/hooks/use-user.test.js +81 -35
  181. package/dist/web/hooks/use-user.test.js.map +1 -1
  182. package/dist/web/hooks/use-view-state.test.js +6 -2
  183. package/dist/web/hooks/use-view-state.test.js.map +1 -1
  184. package/dist/web/plugin/plugin.d.ts +6 -0
  185. package/dist/web/plugin/plugin.js +3 -3
  186. package/dist/web/plugin/plugin.js.map +1 -1
  187. package/package.json +21 -20
  188. package/dist/cli/resolve-views-dir.d.ts +0 -1
  189. package/dist/cli/resolve-views-dir.js.map +0 -1
  190. package/dist/server/auth/providers/stytch.test.js +0 -33
  191. package/dist/server/auth/providers/stytch.test.js.map +0 -1
  192. package/dist/server/auth/providers/workos.test.js +0 -41
  193. package/dist/server/auth/providers/workos.test.js.map +0 -1
  194. package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -29
  195. package/dist/web/bridges/apps-sdk/adaptor.js +0 -117
  196. package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
  197. package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -53
  198. package/dist/web/bridges/mcp-app/adaptor.js +0 -283
  199. package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
  200. /package/dist/{server/auth/providers/stytch.test.d.ts → cli/build-steps.test.d.ts} +0 -0
  201. /package/dist/server/auth/providers/{workos.test.d.ts → auth0.test.d.ts} +0 -0
@@ -3,12 +3,30 @@ import type { OAuthConfig } from "../index.js";
3
3
  /** Options accepted by {@link customProvider} and the branded providers. */
4
4
  export type CustomProviderOptions = {
5
5
  issuer: string;
6
- audience: string;
6
+ /** Expected token `aud`. Omit to skip audience verification — only for IdPs
7
+ * that don't bind an audience (e.g. Clerk). Branded providers whose IdP does
8
+ * bind an audience re-require it in their own options. */
9
+ audience?: string;
7
10
  /** Omit to let the server infer the resource origin from request headers. */
8
11
  baseUrl?: string;
12
+ /** Advertise THIS server as the authorization server (skybridge-as-AS): the
13
+ * served AS metadata `issuer` and the PRM `authorization_servers` use this URL
14
+ * instead of the IdP's. Needed when skybridge must sit in the auth path — Auth0
15
+ * (the `audience` must be baked into `/authorize`) or the Alpic DCR proxy (Alpic
16
+ * injects the registration endpoint). Use the static public URL; `verify.issuer`
17
+ * stays the IdP (the token's real `iss`). */
18
+ serverUrl?: string;
19
+ /** Advertise this URL as the authorization server (served AS metadata `issuer`
20
+ * and PRM `authorization_servers`). Its own discovery document supplies the
21
+ * advertised endpoints, DCR registration, scopes and the `iss` tokens are
22
+ * verified against; only `jwks_uri` still comes from `issuer`'s document. Use
23
+ * when DCR/authorize/token live at a different URL than the discovery issuer
24
+ * (e.g. Descope's agentic URL vs. its base-project URL). `serverUrl` wins if
25
+ * both are set. */
26
+ authorizationServer?: string;
9
27
  scopes?: string[];
10
28
  requiredScopes?: string[];
11
29
  metadataOverrides?: Omit<Partial<OAuthMetadata>, "issuer">;
12
30
  };
13
- /** Builds a complete {@link OAuthConfig} for a DCR-compatible IdP via discovery. */
31
+ /** Builds a complete {@link OAuthConfig} from an IdP's OAuth discovery document. */
14
32
  export declare function customProvider(opts: CustomProviderOptions): Promise<OAuthConfig>;
@@ -1,27 +1,48 @@
1
1
  import { discoverAuthorizationServer, } from "../discovery.js";
2
- /** Builds a complete {@link OAuthConfig} for a DCR-compatible IdP via discovery. */
2
+ /** Builds a complete {@link OAuthConfig} from an IdP's OAuth discovery document. */
3
3
  export async function customProvider(opts) {
4
4
  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
- }
5
+ // JWKS verification needs a signing-key URL; without it the server can't verify
6
+ // tokens. (`registration_endpoint` is optional per RFC 8414 — a no-DCR IdP simply
7
+ // omits it; a proxy like Alpic, or pre-registered clients, supply registration.)
9
8
  if (!discovered.jwks_uri) {
10
9
  throw new Error(`${opts.issuer} discovery has no jwks_uri; JWKS verification requires it.`);
11
10
  }
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 };
11
+ // Overrides adjust only advertised metadata; the trust anchor (issuer, jwks_uri)
12
+ // always comes from validated discovery.
13
+ const { issuer: _issuer, jwks_uri: _jwks, ...overrides } = opts.metadataOverrides ?? {};
14
+ let advertised = discovered;
15
+ if (opts.authorizationServer) {
16
+ try {
17
+ advertised = await discoverAuthorizationServer(opts.authorizationServer);
18
+ }
19
+ catch (err) {
20
+ console.warn(`OAuth discovery failed for authorizationServer ${opts.authorizationServer}; advertising ${opts.issuer} metadata instead: ${err instanceof Error ? err.message : String(err)}`);
21
+ }
22
+ }
23
+ const base = { ...advertised, ...overrides };
24
+ const scopesSupported = opts.scopes ?? base.scopes_supported;
25
+ // serverUrl (skybridge-as-AS) overrides the advertised issuer, keeping the
26
+ // IdP as the token issuer. authorizationServer re-asserts its own URL so a
27
+ // failed AS discovery still points clients at the AS. serverUrl wins.
28
+ const advertisedIssuer = opts.serverUrl?.replace(/\/$/, "") ??
29
+ opts.authorizationServer?.replace(/\/$/, "");
30
+ const oauthMetadata = advertisedIssuer
31
+ ? {
32
+ ...base,
33
+ issuer: advertisedIssuer,
34
+ scopes_supported: scopesSupported,
35
+ }
36
+ : base;
16
37
  return {
17
38
  baseUrl: opts.baseUrl,
18
39
  oauthMetadata,
19
40
  verify: {
20
- issuer: discovered.issuer,
41
+ issuer: advertised.issuer,
21
42
  audience: opts.audience,
22
- jwksUri: discovered.jwks_uri,
43
+ jwksUri: advertised.jwks_uri ?? discovered.jwks_uri,
23
44
  },
24
- scopesSupported: opts.scopes ?? oauthMetadata.scopes_supported,
45
+ scopesSupported,
25
46
  requiredScopes: opts.requiredScopes,
26
47
  };
27
48
  }
@@ -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;AAczB,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 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":"AACA,OAAO,EAEL,2BAA2B,GAC5B,MAAM,iBAAiB,CAAC;AAgCzB,oFAAoF;AACpF,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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AU,CAAC,MAAM;YACzB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,OAAO,EAAE,UAAU,CAAC,QAAQ,IAAI,UAAU,CAAC,QAAQ;SACpD;QACD,eAAe;QACf,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 /** 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/** Builds a complete {@link OAuthConfig} from an IdP's OAuth discovery document. */\nexport async function customProvider(\n opts: CustomProviderOptions,\n): Promise<OAuthConfig> {\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 verify: {\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,13 @@
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
+ const servers = [];
6
+ afterEach(() => {
7
+ for (const srv of servers.splice(0)) {
8
+ srv.close();
9
+ }
10
+ });
7
11
  function doc(origin, extra = {}) {
8
12
  return {
9
13
  issuer: origin,
@@ -28,7 +32,7 @@ async function serveDiscovery(extra = {}) {
28
32
  res.end(JSON.stringify(doc(origin, extra)));
29
33
  });
30
34
  await new Promise((resolve) => srv.listen(0, resolve));
31
- server = srv;
35
+ servers.push(srv);
32
36
  origin = `http://localhost:${srv.address().port}`;
33
37
  return origin;
34
38
  }
@@ -50,54 +54,93 @@ describe("customProvider", () => {
50
54
  expect(config.scopesSupported).toEqual(["openid"]);
51
55
  expect(config.oauthMetadata.registration_endpoint).toBe(`${base}/register`);
52
56
  });
53
- it("defaults scopesSupported to the discovered scopes", async () => {
57
+ it("ignores a runtime issuer override (keeps the discovered trust anchor)", async () => {
54
58
  const base = await serveDiscovery();
55
59
  const config = await customProvider({
56
60
  issuer: base,
57
61
  audience: "a",
58
- baseUrl: "https://app.example.test",
62
+ metadataOverrides: { issuer: "https://evil.test" },
59
63
  });
60
- expect(config.scopesSupported).toEqual(["openid", "email", "profile"]);
64
+ expect(config.verify.issuer).toBe(base);
65
+ expect(config.oauthMetadata.issuer).toBe(base);
61
66
  });
62
- it("allows omitting baseUrl (server infers it from headers)", async () => {
67
+ it("ignores a runtime jwks_uri override (keeps the discovered signing keys)", async () => {
63
68
  const base = await serveDiscovery();
69
+ const config = await customProvider({
70
+ issuer: base,
71
+ audience: "a",
72
+ metadataOverrides: { jwks_uri: "https://evil.test/keys" },
73
+ });
74
+ expect(config.verify.jwksUri).toBe(`${base}/jwks`);
75
+ });
76
+ it("serves metadata without a registration_endpoint when the IdP has no DCR", async () => {
77
+ const base = await serveDiscovery({ registration_endpoint: undefined });
64
78
  const config = await customProvider({ issuer: base, audience: "a" });
65
- expect(config.baseUrl).toBeUndefined();
79
+ expect(config.oauthMetadata.registration_endpoint).toBeUndefined();
80
+ expect(config.verify.issuer).toBe(base);
66
81
  });
67
- it("ignores a runtime issuer override (keeps the discovered trust anchor)", async () => {
82
+ it("throws when discovery has no jwks_uri (token verification needs it)", async () => {
83
+ const base = await serveDiscovery({ jwks_uri: undefined });
84
+ await expect(customProvider({ issuer: base, audience: "a" })).rejects.toThrow(/jwks_uri/);
85
+ });
86
+ it("serverUrl advertises this server as the AS, keeping the IdP as the token issuer", async () => {
68
87
  const base = await serveDiscovery();
69
88
  const config = await customProvider({
70
89
  issuer: base,
71
90
  audience: "a",
72
- metadataOverrides: { issuer: "https://evil.test" },
91
+ serverUrl: "https://app.example.test/",
92
+ scopes: ["openid"],
73
93
  });
94
+ // AS metadata + advertised scopes reflect this server.
95
+ expect(config.oauthMetadata.issuer).toBe("https://app.example.test");
96
+ expect(config.oauthMetadata.scopes_supported).toEqual(["openid"]);
97
+ // but the token's issuer is still verified against the IdP.
74
98
  expect(config.verify.issuer).toBe(base);
75
- expect(config.oauthMetadata.issuer).toBe(base);
76
99
  });
77
- it("ignores a runtime jwks_uri override (keeps the discovered signing keys)", async () => {
100
+ it("authorizationServer supplies the advertised metadata and the verified issuer", async () => {
78
101
  const base = await serveDiscovery();
102
+ const as = await serveDiscovery({ scopes_supported: ["checkout"] });
79
103
  const config = await customProvider({
80
104
  issuer: base,
81
105
  audience: "a",
82
- metadataOverrides: { jwks_uri: "https://evil.test/keys" },
106
+ authorizationServer: `${as}/`,
107
+ });
108
+ expect(config.oauthMetadata.issuer).toBe(as);
109
+ expect(config.oauthMetadata.authorization_endpoint).toBe(`${as}/authorize`);
110
+ expect(config.oauthMetadata.registration_endpoint).toBe(`${as}/register`);
111
+ expect(config.scopesSupported).toEqual(["checkout"]);
112
+ expect(config.verify).toEqual({
113
+ issuer: as,
114
+ audience: "a",
115
+ jwksUri: `${as}/jwks`,
83
116
  });
84
- expect(config.verify.jwksUri).toBe(`${base}/jwks`);
85
117
  });
86
- it("rejects a non-DCR IdP (no registration_endpoint)", async () => {
87
- const base = await serveDiscovery({ registration_endpoint: undefined });
88
- await expect(customProvider({
118
+ it("falls back to the issuer's metadata when the authorizationServer is undiscoverable", async () => {
119
+ const base = await serveDiscovery();
120
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => { });
121
+ const config = await customProvider({
89
122
  issuer: base,
90
123
  audience: "a",
91
- baseUrl: "https://app.example.test",
92
- })).rejects.toThrow(/not DCR-compatible/);
124
+ authorizationServer: `${base}/agentic/P1/MS1`,
125
+ });
126
+ expect(warn).toHaveBeenCalledOnce();
127
+ expect(config.oauthMetadata.issuer).toBe(`${base}/agentic/P1/MS1`);
128
+ expect(config.oauthMetadata.authorization_endpoint).toBe(`${base}/authorize`);
129
+ expect(config.verify.issuer).toBe(base);
130
+ warn.mockRestore();
93
131
  });
94
- it("rejects a non-DCR IdP even if an override supplies registration_endpoint", async () => {
95
- const base = await serveDiscovery({ registration_endpoint: undefined });
96
- await expect(customProvider({
132
+ it("serverUrl takes precedence over authorizationServer", async () => {
133
+ const base = await serveDiscovery();
134
+ const as = await serveDiscovery();
135
+ const config = await customProvider({
97
136
  issuer: base,
98
137
  audience: "a",
99
- metadataOverrides: { registration_endpoint: `${base}/register` },
100
- })).rejects.toThrow(/not DCR-compatible/);
138
+ serverUrl: "https://app.example.test/",
139
+ authorizationServer: as,
140
+ });
141
+ expect(config.oauthMetadata.issuer).toBe("https://app.example.test");
142
+ expect(config.oauthMetadata.token_endpoint).toBe(`${as}/token`);
143
+ expect(config.verify.issuer).toBe(as);
101
144
  });
102
145
  it("applies metadataOverrides over discovered values", async () => {
103
146
  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,I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C;QACxE,MAAM,MAAM,CACV,cAAc,CAAC;YACb,MAAM,EAAE,IAAI;YACZ,QAAQ,EAAE,GAAG;YACb,OAAO,EAAE,0BAA0B;SACpC,CAAC,CACH,CAAC,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0EAA0E,EAAE,KAAK,IAAI,EAAE;QACxF,MAAM,IAAI,GAAG,MAAM,cAAc,CAAC,EAAE,qBAAqB,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(\"defaults scopesSupported to the discovered scopes\", async () => {\n const base = await serveDiscovery();\n const config = await customProvider({\n issuer: base,\n audience: \"a\",\n baseUrl: \"https://app.example.test\",\n });\n expect(config.scopesSupported).toEqual([\"openid\", \"email\", \"profile\"]);\n });\n\n it(\"allows omitting baseUrl (server infers it from headers)\", async () => {\n const base = await serveDiscovery();\n const config = await customProvider({ issuer: base, audience: \"a\" });\n expect(config.baseUrl).toBeUndefined();\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 (no registration_endpoint)\", async () => {\n const base = await serveDiscovery({ registration_endpoint: undefined });\n await expect(\n customProvider({\n issuer: base,\n audience: \"a\",\n baseUrl: \"https://app.example.test\",\n }),\n ).rejects.toThrow(/not DCR-compatible/);\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});\n"]}
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,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,OAAO,GAAkB,EAAE,CAAC;AAClC,SAAS,CAAC,GAAG,EAAE;IACb,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;QACpC,GAAG,CAAC,KAAK,EAAE,CAAC;I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QAAQ,EAAE,GAAG;YACb,SAAS,EAAE,2BAA2B;YACtC,mBAAmB,EAAE,EAAE;SACxB,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;QACrE,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QAChE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACxC,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, vi } from \"vitest\";\nimport { customProvider } from \"./custom.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(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(\"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(config.verify.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(config.verify.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(config.verify).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(config.verify.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(config.verify.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,12 +1,15 @@
1
1
  import type { OAuthConfig } from "../index.js";
2
2
  import { type CustomProviderOptions } from "./custom.js";
3
3
  /**
4
- * OAuth provider for Descope MCP Server (agentic Inbound App). Builds the
5
- * issuer from `projectId` and `appId`. Requires DCR enabled on the Inbound
6
- * App. `audience` is the MCP server URL. Custom-domain Descope tenants should
7
- * use `customProvider({ issuer })` directly with the full discovery URL.
4
+ * OAuth provider for a Descope MCP Server. `url` is the MCP Server's **Discovery
5
+ * URL** (a.k.a. Issuer) from the console's Connection Information, e.g.
6
+ * `https://api.descope.com/v1/apps/agentic/<projectId>/<mcpServerId>` (or your
7
+ * custom domain). Requires DCR enabled on the MCP Server. For Descope with DCR
8
+ * disabled and Alpic's DCR proxy, use {@link customProvider} with `serverUrl`
9
+ * instead (see `examples/auth-descope-alpic`). The token `audience` defaults to
10
+ * the **Project ID** derived from the URL — Descope binds `aud` to [DCR client
11
+ * id, project id], not the server URL; pass `audience` to override.
8
12
  */
9
13
  export declare function descopeProvider(opts: {
10
- projectId: string;
11
- appId: string;
14
+ url: string;
12
15
  } & Omit<CustomProviderOptions, "issuer">): Promise<OAuthConfig>;
@@ -1,13 +1,44 @@
1
1
  import { customProvider } from "./custom.js";
2
2
  /**
3
- * OAuth provider for Descope MCP Server (agentic Inbound App). Builds the
4
- * issuer from `projectId` and `appId`. Requires DCR enabled on the Inbound
5
- * App. `audience` is the MCP server URL. Custom-domain Descope tenants should
6
- * 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.
7
31
  */
8
32
  export function descopeProvider(opts) {
9
- const { projectId, appId, ...rest } = opts;
10
- const issuer = `https://api.descope.com/v1/apps/agentic/${projectId}/${appId}`;
11
- 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
+ });
12
43
  }
13
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;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC7B,IAGC;IAED,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IAC3C,MAAM,MAAM,GAAG,2CAA2C,SAAS,IAAI,KAAK,EAAE,CAAC;IAC/E,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 Descope MCP Server (agentic Inbound App). Builds the\n * issuer from `projectId` and `appId`. Requires DCR enabled on the Inbound\n * App. `audience` is the MCP server URL. Custom-domain Descope tenants should\n * use `customProvider({ issuer })` directly with the full discovery URL.\n */\nexport function descopeProvider(\n opts: { projectId: string; appId: string } & Omit<\n CustomProviderOptions,\n \"issuer\"\n >,\n): Promise<OAuthConfig> {\n const { projectId, appId, ...rest } = opts;\n const issuer = `https://api.descope.com/v1/apps/agentic/${projectId}/${appId}`;\n return customProvider({ issuer, ...rest });\n}\n"]}
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;;;;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,CAC7B,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,CAAC;QACpB,MAAM;QACN,QAAQ,EAAE,QAAQ,IAAI,SAAS;QAC/B,mBAAmB,EAAE,KAAK;QAC1B,GAAG,IAAI;KACR,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { OAuthConfig } from \"../index.js\";\nimport { type CustomProviderOptions, customProvider } from \"./custom.js\";\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 opts: { url: string } & Omit<CustomProviderOptions, \"issuer\">,\n): Promise<OAuthConfig> {\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({\n issuer,\n audience: audience ?? projectId,\n authorizationServer: asUrl,\n ...rest,\n });\n}\n"]}
@@ -2,34 +2,59 @@
2
2
  import { afterEach, describe, expect, it, vi } from "vitest";
3
3
  import { descopeProvider } from "./descope.js";
4
4
  afterEach(() => vi.restoreAllMocks());
5
- function discoveryDoc(issuer) {
5
+ function discoveryDoc(issuer, scopes) {
6
6
  return {
7
7
  issuer,
8
8
  authorization_endpoint: `${issuer}/authorize`,
9
9
  token_endpoint: `${issuer}/token`,
10
10
  registration_endpoint: `${issuer}/register`,
11
11
  response_types_supported: ["code"],
12
- scopes_supported: ["openid"],
12
+ scopes_supported: scopes,
13
13
  jwks_uri: `${issuer}/.well-known/jwks.json`,
14
14
  };
15
15
  }
16
- function mockDiscovery(issuer) {
17
- return vi.spyOn(globalThis, "fetch").mockResolvedValue(new Response(JSON.stringify(discoveryDoc(issuer)), {
18
- headers: { "content-type": "application/json" },
19
- }));
16
+ const PROJECT = "https://api.descope.com/v1/apps/P123";
17
+ const AGENTIC = "https://api.descope.com/v1/apps/agentic/P123/MS456";
18
+ function mockDiscovery(docs) {
19
+ return vi
20
+ .spyOn(globalThis, "fetch")
21
+ .mockImplementation(async (input) => {
22
+ const url = String(input);
23
+ const entry = Object.entries(docs).find(([issuer]) => url === `${issuer}/.well-known/openid-configuration`);
24
+ if (entry === undefined) {
25
+ return new Response(null, { status: 404 });
26
+ }
27
+ return new Response(JSON.stringify(discoveryDoc(...entry)), {
28
+ headers: { "content-type": "application/json" },
29
+ });
30
+ });
20
31
  }
21
32
  describe("descopeProvider", () => {
22
- it("builds the agentic inbound-app issuer from projectId and appId", async () => {
23
- const issuer = "https://api.descope.com/v1/apps/agentic/P123/MS456";
24
- const fetchSpy = mockDiscovery(issuer);
33
+ it("verifies against the agentic issuer it advertises", async () => {
34
+ const fetchSpy = mockDiscovery({
35
+ [PROJECT]: ["openid", "profile", "email", "phone"],
36
+ [AGENTIC]: ["checkout"],
37
+ });
38
+ const config = await descopeProvider({ url: AGENTIC });
39
+ expect(fetchSpy).toHaveBeenCalledWith(`${PROJECT}/.well-known/openid-configuration`, expect.anything());
40
+ expect(config.verify.issuer).toBe(AGENTIC);
41
+ expect(config.verify.audience).toBe("P123");
42
+ expect(config.oauthMetadata.issuer).toBe(AGENTIC);
43
+ expect(config.oauthMetadata.registration_endpoint).toBe(`${AGENTIC}/register`);
44
+ expect(config.scopesSupported).toEqual(["checkout"]);
45
+ });
46
+ it("accepts a URL carrying the well-known suffix", async () => {
47
+ mockDiscovery({ [PROJECT]: ["openid"], [AGENTIC]: ["checkout"] });
25
48
  const config = await descopeProvider({
26
- projectId: "P123",
27
- appId: "MS456",
28
- audience: "https://mcp.example.com",
49
+ url: `${AGENTIC}/.well-known/openid-configuration`,
29
50
  });
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");
51
+ expect(config.oauthMetadata.issuer).toBe(AGENTIC);
52
+ expect(config.scopesSupported).toEqual(["checkout"]);
53
+ });
54
+ it("lets an explicit audience override the derived project id", async () => {
55
+ mockDiscovery({ [PROJECT]: ["openid"], [AGENTIC]: ["checkout"] });
56
+ const config = await descopeProvider({ url: AGENTIC, audience: "custom" });
57
+ expect(config.verify.audience).toBe("custom");
33
58
  });
34
59
  });
35
60
  //# 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,gEAAgE,EAAE,KAAK,IAAI,EAAE;QAC9E,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,KAAK,EAAE,OAAO;YACd,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 agentic inbound-app issuer from projectId and appId\", 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 appId: \"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;AAE/C,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,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,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AC,aAAa,CAAC,qBAAqB,CAAC,CAAC,IAAI,CACrD,GAAG,OAAO,WAAW,CACtB,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8CAA8C,EAAE,KAAK,IAAI,EAAE;QAC5D,aAAa,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QAElE,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC;YACnC,GAAG,EAAE,GAAG,OAAO,mCAAmC;SACnD,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAClD,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2DAA2D,EAAE,KAAK,IAAI,EAAE;QACzE,aAAa,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QAElE,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;QAE3E,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChD,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, 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(config.verify.issuer).toBe(AGENTIC);\n expect(config.verify.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 const config = await descopeProvider({ url: AGENTIC, audience: \"custom\" });\n\n expect(config.verify.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"]}
@@ -8,4 +8,5 @@ import { type CustomProviderOptions } from "./custom.js";
8
8
  */
9
9
  export declare function stytchProvider(opts: {
10
10
  domain: string;
11
- } & Omit<CustomProviderOptions, "issuer">): Promise<OAuthConfig>;
11
+ audience: string;
12
+ } & Omit<CustomProviderOptions, "issuer" | "audience">): Promise<OAuthConfig>;
@@ -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
@@ -1 +1 @@
1
- {"version":3,"file":"stytch.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/stytch.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;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAC5B,IAAgE;IAEhE,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 Stytch Connected Apps. `domain` is the project domain,\n * e.g. `acme.customers.stytch.dev`, or a configured custom domain. Requires\n * DCR enabled in the Stytch dashboard. `audience` is the Stytch Project ID\n * (the default token audience).\n */\nexport function stytchProvider(\n opts: { domain: string } & Omit<CustomProviderOptions, \"issuer\">,\n): Promise<OAuthConfig> {\n const { domain, ...rest } = opts;\n return customProvider({ issuer: toIssuerUrl(domain), ...rest });\n}\n"]}
1
+ {"version":3,"file":"stytch.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/stytch.ts"],"names":[],"mappings":"AACA,OAAO,EAA8B,cAAc,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAC5B,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\";\nimport { toIssuerUrl } from \"./shared.js\";\n\n/**\n * OAuth provider for Stytch Connected Apps. `domain` is the project domain,\n * e.g. `acme.customers.stytch.dev`, or a configured custom domain. Requires\n * DCR enabled in the Stytch dashboard. `audience` is the Stytch Project ID\n * (the default token audience).\n */\nexport function stytchProvider(\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"]}
@@ -7,4 +7,5 @@ import { type CustomProviderOptions } from "./custom.js";
7
7
  */
8
8
  export declare function workosProvider(opts: {
9
9
  domain: string;
10
- } & Omit<CustomProviderOptions, "issuer">): Promise<OAuthConfig>;
10
+ audience: string;
11
+ } & Omit<CustomProviderOptions, "issuer" | "audience">): Promise<OAuthConfig>;
@@ -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 WorkOS AuthKit. `domain` is the AuthKit domain, e.g.
9
5
  * `acme.authkit.app`. Requires DCR enabled in the WorkOS dashboard