skybridge 0.0.0-dev.ecfdeac → 0.0.0-dev.ed29eee
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.
- package/README.md +2 -9
- package/dist/cli/build-helpers.d.ts +6 -2
- package/dist/cli/build-helpers.js +37 -12
- package/dist/cli/build-helpers.js.map +1 -1
- package/dist/cli/build-helpers.test.js +71 -3
- package/dist/cli/build-helpers.test.js.map +1 -1
- package/dist/cli/build-steps.d.ts +2 -0
- package/dist/cli/build-steps.js +73 -0
- package/dist/cli/build-steps.js.map +1 -0
- package/dist/cli/build-steps.test.d.ts +1 -0
- package/dist/cli/build-steps.test.js +52 -0
- package/dist/cli/build-steps.test.js.map +1 -0
- package/dist/cli/header.d.ts +1 -1
- package/dist/cli/resolve-skybridge-config.d.ts +5 -0
- package/dist/cli/{resolve-views-dir.js → resolve-skybridge-config.js} +4 -3
- package/dist/cli/resolve-skybridge-config.js.map +1 -0
- package/dist/cli/run-plain.d.ts +18 -0
- package/dist/cli/run-plain.js +89 -0
- package/dist/cli/run-plain.js.map +1 -0
- package/dist/cli/use-nodemon.d.ts +14 -0
- package/dist/cli/use-nodemon.js +71 -60
- package/dist/cli/use-nodemon.js.map +1 -1
- package/dist/cli/use-typescript-check.d.ts +8 -2
- package/dist/cli/use-typescript-check.js +70 -67
- package/dist/cli/use-typescript-check.js.map +1 -1
- package/dist/commands/build.d.ts +0 -2
- package/dist/commands/build.js +2 -61
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/dev.d.ts +1 -0
- package/dist/commands/dev.js +34 -2
- package/dist/commands/dev.js.map +1 -1
- package/dist/context-warnings.d.ts +5 -0
- package/dist/context-warnings.js +31 -0
- package/dist/context-warnings.js.map +1 -0
- package/dist/context-warnings.test.d.ts +1 -0
- package/dist/context-warnings.test.js +28 -0
- package/dist/context-warnings.test.js.map +1 -0
- package/dist/server/auth/index.d.ts +30 -4
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/auth/providers/auth0.d.ts +24 -2
- package/dist/server/auth/providers/auth0.js.map +1 -1
- package/dist/server/auth/providers/auth0.test.js +4 -2
- package/dist/server/auth/providers/auth0.test.js.map +1 -1
- package/dist/server/auth/providers/authplane.d.ts +49 -0
- package/dist/server/auth/providers/authplane.js +57 -0
- package/dist/server/auth/providers/authplane.js.map +1 -0
- package/dist/server/auth/providers/authplane.test.d.ts +1 -0
- package/dist/server/auth/providers/authplane.test.js +140 -0
- package/dist/server/auth/providers/authplane.test.js.map +1 -0
- package/dist/server/auth/providers/clerk.d.ts +39 -2
- package/dist/server/auth/providers/clerk.js +4 -1
- package/dist/server/auth/providers/clerk.js.map +1 -1
- package/dist/server/auth/providers/clerk.test.js +5 -3
- package/dist/server/auth/providers/clerk.test.js.map +1 -1
- package/dist/server/auth/providers/custom.d.ts +18 -2
- package/dist/server/auth/providers/custom.js +29 -10
- package/dist/server/auth/providers/custom.js.map +1 -1
- package/dist/server/auth/providers/custom.test.js +61 -10
- package/dist/server/auth/providers/custom.test.js.map +1 -1
- package/dist/server/auth/providers/descope.d.ts +36 -5
- package/dist/server/auth/providers/descope.js +18 -5
- package/dist/server/auth/providers/descope.js.map +1 -1
- package/dist/server/auth/providers/descope.test.js +42 -17
- package/dist/server/auth/providers/descope.test.js.map +1 -1
- package/dist/server/auth/providers/stytch.d.ts +15 -2
- package/dist/server/auth/providers/stytch.js +4 -1
- package/dist/server/auth/providers/stytch.js.map +1 -1
- package/dist/server/auth/providers/verify-spy.d.ts +12 -0
- package/dist/server/auth/providers/verify-spy.js +21 -0
- package/dist/server/auth/providers/verify-spy.js.map +1 -0
- package/dist/server/auth/providers/workos.d.ts +24 -2
- package/dist/server/auth/providers/workos.js +4 -1
- package/dist/server/auth/providers/workos.js.map +1 -1
- package/dist/server/auth/security-schemes.d.ts +23 -0
- package/dist/server/auth/security-schemes.js +64 -0
- package/dist/server/auth/security-schemes.js.map +1 -0
- package/dist/server/auth/security-schemes.test.d.ts +1 -0
- package/dist/server/auth/security-schemes.test.js +99 -0
- package/dist/server/auth/security-schemes.test.js.map +1 -0
- package/dist/server/auth/setup.d.ts +3 -1
- package/dist/server/auth/setup.js +65 -24
- package/dist/server/auth/setup.js.map +1 -1
- package/dist/server/auth/setup.test.js +328 -5
- package/dist/server/auth/setup.test.js.map +1 -1
- package/dist/server/auth/verify.d.ts +37 -3
- package/dist/server/auth/verify.js +26 -2
- package/dist/server/auth/verify.js.map +1 -1
- package/dist/server/auth/verify.test.js +49 -0
- package/dist/server/auth/verify.test.js.map +1 -1
- package/dist/server/auth-extra.test-d.d.ts +1 -0
- package/dist/server/auth-extra.test-d.js +82 -0
- package/dist/server/auth-extra.test-d.js.map +1 -0
- package/dist/server/auth.d.ts +39 -1
- package/dist/server/auth.js.map +1 -1
- package/dist/server/host.d.ts +2 -0
- package/dist/server/host.js +11 -0
- package/dist/server/host.js.map +1 -0
- package/dist/server/host.test.d.ts +1 -0
- package/dist/server/host.test.js +13 -0
- package/dist/server/host.test.js.map +1 -0
- package/dist/server/index.d.ts +11 -7
- package/dist/server/index.js +6 -2
- package/dist/server/index.js.map +1 -1
- package/dist/server/middleware.d.ts +31 -6
- package/dist/server/middleware.js +33 -0
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/middleware.test.js +37 -1
- package/dist/server/middleware.test.js.map +1 -1
- package/dist/server/server.d.ts +87 -25
- package/dist/server/server.js +221 -120
- package/dist/server/server.js.map +1 -1
- package/dist/server/skills-integration.test.d.ts +1 -0
- package/dist/server/skills-integration.test.js +79 -0
- package/dist/server/skills-integration.test.js.map +1 -0
- package/dist/server/skills.d.ts +29 -0
- package/dist/server/skills.js +195 -0
- package/dist/server/skills.js.map +1 -0
- package/dist/server/skills.test.d.ts +1 -0
- package/dist/server/skills.test.js +247 -0
- package/dist/server/skills.test.js.map +1 -0
- package/dist/server/view-name.test-d.d.ts +1 -0
- package/dist/server/view-name.test-d.js +8 -0
- package/dist/server/view-name.test-d.js.map +1 -0
- package/dist/server/view-resource-resolution.test.js +93 -10
- package/dist/server/view-resource-resolution.test.js.map +1 -1
- package/dist/server/viewsDevServer.js +4 -1
- package/dist/server/viewsDevServer.js.map +1 -1
- package/dist/test/utils.d.ts +3 -3
- package/dist/test/view.test.js +86 -102
- package/dist/test/view.test.js.map +1 -1
- package/dist/web/bridges/adaptor.d.ts +51 -0
- package/dist/web/bridges/adaptor.js +327 -0
- package/dist/web/bridges/adaptor.js.map +1 -0
- package/dist/web/bridges/adaptor.test.d.ts +1 -0
- package/dist/web/bridges/adaptor.test.js +225 -0
- package/dist/web/bridges/adaptor.test.js.map +1 -0
- package/dist/web/bridges/apps-sdk/bridge.d.ts +6 -2
- package/dist/web/bridges/apps-sdk/bridge.js +15 -4
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
- package/dist/web/bridges/apps-sdk/index.d.ts +0 -1
- package/dist/web/bridges/apps-sdk/index.js +0 -1
- package/dist/web/bridges/apps-sdk/index.js.map +1 -1
- package/dist/web/bridges/get-adaptor.d.ts +4 -4
- package/dist/web/bridges/get-adaptor.js +6 -11
- package/dist/web/bridges/get-adaptor.js.map +1 -1
- package/dist/web/bridges/get-adaptor.test.d.ts +1 -0
- package/dist/web/bridges/get-adaptor.test.js +32 -0
- package/dist/web/bridges/get-adaptor.test.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.d.ts +13 -2
- package/dist/web/bridges/mcp-app/bridge.js +51 -7
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.test.d.ts +1 -0
- package/dist/web/bridges/mcp-app/bridge.test.js +17 -0
- package/dist/web/bridges/mcp-app/bridge.test.js.map +1 -0
- package/dist/web/bridges/mcp-app/index.d.ts +0 -1
- package/dist/web/bridges/mcp-app/index.js +0 -1
- package/dist/web/bridges/mcp-app/index.js.map +1 -1
- package/dist/web/bridges/mcp-app/types.d.ts +2 -0
- package/dist/web/bridges/mcp-app/types.js.map +1 -1
- package/dist/web/bridges/mcp-app/view-tools.test.js +5 -6
- package/dist/web/bridges/mcp-app/view-tools.test.js.map +1 -1
- package/dist/web/bridges/types.d.ts +10 -0
- package/dist/web/bridges/types.js +14 -1
- package/dist/web/bridges/types.js.map +1 -1
- package/dist/web/bridges/types.test.d.ts +1 -0
- package/dist/web/bridges/types.test.js +19 -0
- package/dist/web/bridges/types.test.js.map +1 -0
- package/dist/web/components/modal-provider.d.ts +1 -1
- package/dist/web/components/modal-provider.js +4 -3
- package/dist/web/components/modal-provider.js.map +1 -1
- package/dist/web/create-store.test.js +8 -5
- package/dist/web/create-store.test.js.map +1 -1
- package/dist/web/data-llm.d.ts +1 -1
- package/dist/web/data-llm.test.js +18 -5
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/hooks/index.d.ts +1 -0
- package/dist/web/hooks/index.js +1 -0
- package/dist/web/hooks/index.js.map +1 -1
- package/dist/web/hooks/test/utils.d.ts +2 -1
- package/dist/web/hooks/test/utils.js +1 -1
- package/dist/web/hooks/test/utils.js.map +1 -1
- package/dist/web/hooks/use-call-tool.test.js +37 -23
- package/dist/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/web/hooks/use-display-mode.test.js +56 -20
- package/dist/web/hooks/use-display-mode.test.js.map +1 -1
- package/dist/web/hooks/use-download.test.js +11 -3
- package/dist/web/hooks/use-download.test.js.map +1 -1
- package/dist/web/hooks/use-files.test.js +10 -2
- package/dist/web/hooks/use-files.test.js.map +1 -1
- package/dist/web/hooks/use-host-info.d.ts +22 -0
- package/dist/web/hooks/use-host-info.js +30 -0
- package/dist/web/hooks/use-host-info.js.map +1 -0
- package/dist/web/hooks/use-host-info.test.d.ts +1 -0
- package/dist/web/hooks/use-host-info.test.js +59 -0
- package/dist/web/hooks/use-host-info.test.js.map +1 -0
- package/dist/web/hooks/use-layout.test.js +59 -26
- package/dist/web/hooks/use-layout.test.js.map +1 -1
- package/dist/web/hooks/use-open-external.test.js +13 -3
- package/dist/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/web/hooks/use-request-close.test.js +35 -40
- package/dist/web/hooks/use-request-close.test.js.map +1 -1
- package/dist/web/hooks/use-request-modal.test.js +10 -0
- package/dist/web/hooks/use-request-modal.test.js.map +1 -1
- package/dist/web/hooks/use-request-size.test.js +35 -53
- package/dist/web/hooks/use-request-size.test.js.map +1 -1
- package/dist/web/hooks/use-set-open-in-app-url.test.js +28 -8
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test.js +37 -27
- package/dist/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +81 -35
- package/dist/web/hooks/use-user.test.js.map +1 -1
- package/dist/web/hooks/use-view-state.js +19 -9
- package/dist/web/hooks/use-view-state.js.map +1 -1
- package/dist/web/hooks/use-view-state.test.js +37 -2
- package/dist/web/hooks/use-view-state.test.js.map +1 -1
- package/dist/web/plugin/plugin-build.test.d.ts +1 -0
- package/dist/web/plugin/plugin-build.test.js +54 -0
- package/dist/web/plugin/plugin-build.test.js.map +1 -0
- package/dist/web/plugin/plugin.d.ts +6 -0
- package/dist/web/plugin/plugin.js +18 -7
- package/dist/web/plugin/plugin.js.map +1 -1
- package/dist/web/plugin/plugin.test.d.ts +1 -0
- package/dist/web/plugin/plugin.test.js +61 -0
- package/dist/web/plugin/plugin.test.js.map +1 -0
- package/package.json +21 -20
- package/dist/cli/resolve-views-dir.d.ts +0 -1
- package/dist/cli/resolve-views-dir.js.map +0 -1
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +0 -29
- package/dist/web/bridges/apps-sdk/adaptor.js +0 -117
- package/dist/web/bridges/apps-sdk/adaptor.js.map +0 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +0 -53
- package/dist/web/bridges/mcp-app/adaptor.js +0 -283
- package/dist/web/bridges/mcp-app/adaptor.js.map +0 -1
|
@@ -1,13 +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";
|
|
5
|
+
/**
|
|
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
|
|
12
|
+
*/
|
|
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
|
+
};
|
|
3
32
|
/**
|
|
4
33
|
* OAuth provider for a Descope MCP Server. `url` is the MCP Server's **Discovery
|
|
5
34
|
* URL** (a.k.a. Issuer) from the console's Connection Information, e.g.
|
|
6
35
|
* `https://api.descope.com/v1/apps/agentic/<projectId>/<mcpServerId>` (or your
|
|
7
|
-
* custom domain). Requires DCR enabled on the MCP Server.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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.
|
|
10
41
|
*/
|
|
11
|
-
export declare function descopeProvider(opts: {
|
|
42
|
+
export declare function descopeProvider<TCustom extends ExtraClaims = Record<never, never>>(opts: {
|
|
12
43
|
url: string;
|
|
13
|
-
} & Omit<CustomProviderOptions, "issuer">): Promise<OAuthConfig
|
|
44
|
+
} & Omit<CustomProviderOptions, "issuer">): Promise<OAuthConfig<DescopeClaims & TCustom & RegisteredClaims>>;
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { customProvider } from "./custom.js";
|
|
2
|
+
/**
|
|
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
|
+
}
|
|
2
10
|
/**
|
|
3
11
|
* Derives the Descope Project ID from an MCP Server URL
|
|
4
12
|
* (`…/agentic/<projectId>/<mcpServerId>`). Descope binds the token `aud` to the
|
|
@@ -15,16 +23,21 @@ function projectIdFromUrl(url) {
|
|
|
15
23
|
* OAuth provider for a Descope MCP Server. `url` is the MCP Server's **Discovery
|
|
16
24
|
* URL** (a.k.a. Issuer) from the console's Connection Information, e.g.
|
|
17
25
|
* `https://api.descope.com/v1/apps/agentic/<projectId>/<mcpServerId>` (or your
|
|
18
|
-
* custom domain). Requires DCR enabled on the MCP Server.
|
|
19
|
-
*
|
|
20
|
-
*
|
|
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.
|
|
21
31
|
*/
|
|
22
32
|
export function descopeProvider(opts) {
|
|
23
33
|
const { url, audience, ...rest } = opts;
|
|
24
|
-
const
|
|
34
|
+
const asUrl = toAuthorizationServerUrl(url);
|
|
35
|
+
const projectId = projectIdFromUrl(asUrl);
|
|
36
|
+
const issuer = `${asUrl.slice(0, asUrl.indexOf("/agentic/"))}/${projectId}`;
|
|
25
37
|
return customProvider({
|
|
26
38
|
issuer,
|
|
27
|
-
audience: audience ??
|
|
39
|
+
audience: audience ?? projectId,
|
|
40
|
+
authorizationServer: asUrl,
|
|
28
41
|
...rest,
|
|
29
42
|
});
|
|
30
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"descope.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/descope.ts"],"names":[],"mappings":"
|
|
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,37 +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:
|
|
14
|
+
scopes_supported: scopes,
|
|
13
15
|
jwks_uri: `${issuer}/.well-known/jwks.json`,
|
|
14
16
|
};
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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("
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
expect(
|
|
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"] });
|
|
50
|
+
const config = await descopeProvider({
|
|
51
|
+
url: `${AGENTIC}/.well-known/openid-configuration`,
|
|
52
|
+
});
|
|
53
|
+
expect(config.oauthMetadata.issuer).toBe(AGENTIC);
|
|
54
|
+
expect(config.scopesSupported).toEqual(["checkout"]);
|
|
29
55
|
});
|
|
30
56
|
it("lets an explicit audience override the derived project id", async () => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
expect(config.verify.audience).toBe("custom");
|
|
57
|
+
mockDiscovery({ [PROJECT]: ["openid"], [AGENTIC]: ["checkout"] });
|
|
58
|
+
await descopeProvider({ url: AGENTIC, audience: "custom" });
|
|
59
|
+
expect(jwks().audience).toBe("custom");
|
|
35
60
|
});
|
|
36
61
|
});
|
|
37
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;
|
|
1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AC,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,eAAe,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;QAE5D,MAAM,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// @vitest-environment node\nimport { afterEach, describe, expect, it, vi } from \"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"]}
|
|
@@ -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>>;
|
|
@@ -8,6 +8,9 @@ import { toIssuerUrl } from "./shared.js";
|
|
|
8
8
|
*/
|
|
9
9
|
export function stytchProvider(opts) {
|
|
10
10
|
const { domain, ...rest } = opts;
|
|
11
|
-
return customProvider({
|
|
11
|
+
return customProvider({
|
|
12
|
+
issuer: toIssuerUrl(domain),
|
|
13
|
+
...rest,
|
|
14
|
+
});
|
|
12
15
|
}
|
|
13
16
|
//# sourceMappingURL=stytch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stytch.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/stytch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stytch.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/stytch.ts"],"names":[],"mappings":"AAGA,OAAO,EAA8B,cAAc,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAc1C;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAG5B,IAGC;IAED,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IACjC,OAAO,cAAc,CAAyB;QAC5C,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC;QAC3B,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\";\nimport { toIssuerUrl } from \"./shared.js\";\n\n/**\n * Claims a Stytch Connected Apps access token carries. Beyond the subject,\n * everything is project-configured through the client's access-token template.\n *\n * @see https://stytch.com/docs/api-reference/consumer/api/connected-apps/tokens/connected-app-access-token-object\n * @see https://stytch.com/docs/api/connected-apps-create\n */\nexport type StytchClaims = {\n /** Only when the client's access-token template adds it. */\n email?: string;\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 TCustom extends ExtraClaims = Record<never, never>,\n>(\n opts: { domain: string; audience: string } & Omit<\n CustomProviderOptions,\n \"issuer\" | \"audience\"\n >,\n): Promise<OAuthConfig<StytchClaims & TCustom & RegisteredClaims>> {\n const { domain, ...rest } = opts;\n return customProvider<StytchClaims & TCustom>({\n issuer: toIssuerUrl(domain),\n ...rest,\n });\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const createJwksVerifier: import("vitest").Mock<typeof import("../verify.js").createJwksVerifier>;
|
|
2
|
+
/**
|
|
3
|
+
* The JWKS parameters a provider handed to `createJwksVerifier`: the issuer and
|
|
4
|
+
* JWKS URL it derived from discovery, and the audience it expects. Substitute
|
|
5
|
+
* this module for `../verify.js` to assert on them:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* vi.mock("../verify.js", () => import("./verify-spy.js"));
|
|
9
|
+
* import { lastJwksConfig as jwks } from "./verify-spy.js";
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const lastJwksConfig: () => import("../verify.js").JwksVerifyConfig;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { vi } from "vitest";
|
|
2
|
+
const actual = await vi.importActual("../verify.js");
|
|
3
|
+
export const createJwksVerifier = vi.fn(actual.createJwksVerifier);
|
|
4
|
+
/**
|
|
5
|
+
* The JWKS parameters a provider handed to `createJwksVerifier`: the issuer and
|
|
6
|
+
* JWKS URL it derived from discovery, and the audience it expects. Substitute
|
|
7
|
+
* this module for `../verify.js` to assert on them:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* vi.mock("../verify.js", () => import("./verify-spy.js"));
|
|
11
|
+
* import { lastJwksConfig as jwks } from "./verify-spy.js";
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export const lastJwksConfig = () => {
|
|
15
|
+
const call = createJwksVerifier.mock.lastCall;
|
|
16
|
+
if (!call) {
|
|
17
|
+
throw new Error("createJwksVerifier was not called");
|
|
18
|
+
}
|
|
19
|
+
return call[0];
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=verify-spy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-spy.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/verify-spy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE5B,MAAM,MAAM,GACV,MAAM,EAAE,CAAC,YAAY,CAAgC,cAAc,CAAC,CAAC;AAEvE,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAEnE;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,MAAM,IAAI,GAAG,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC;IAC9C,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import { vi } from \"vitest\";\n\nconst actual =\n await vi.importActual<typeof import(\"../verify.js\")>(\"../verify.js\");\n\nexport const createJwksVerifier = vi.fn(actual.createJwksVerifier);\n\n/**\n * The JWKS parameters a provider handed to `createJwksVerifier`: the issuer and\n * JWKS URL it derived from discovery, and the audience it expects. Substitute\n * this module for `../verify.js` to assert on them:\n *\n * ```ts\n * vi.mock(\"../verify.js\", () => import(\"./verify-spy.js\"));\n * import { lastJwksConfig as jwks } from \"./verify-spy.js\";\n * ```\n */\nexport const lastJwksConfig = () => {\n const call = createJwksVerifier.mock.lastCall;\n if (!call) {\n throw new Error(\"createJwksVerifier was not called\");\n }\n return call[0];\n};\n"]}
|
|
@@ -1,11 +1,33 @@
|
|
|
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 WorkOS AuthKit access token carries. All optional: `org_id`, `role`
|
|
7
|
+
* and `permissions` appear only when an organization is selected at sign-in, and
|
|
8
|
+
* `email` only when a JWT template adds it.
|
|
9
|
+
*
|
|
10
|
+
* @see https://workos.com/docs/authkit/sessions/integrating-sessions/access-token
|
|
11
|
+
* @see https://workos.com/docs/authkit/jwt-templates
|
|
12
|
+
*/
|
|
13
|
+
export type WorkosClaims = {
|
|
14
|
+
/** Session id, used for signing out. */
|
|
15
|
+
sid?: string;
|
|
16
|
+
/** Organization selected at sign-in. */
|
|
17
|
+
org_id?: string;
|
|
18
|
+
/** Role of the selected organization membership. */
|
|
19
|
+
role?: string;
|
|
20
|
+
/** Permissions assigned to the role. */
|
|
21
|
+
permissions?: string[];
|
|
22
|
+
/** Only when a JWT template adds it; not a default AuthKit claim. */
|
|
23
|
+
email?: string;
|
|
24
|
+
};
|
|
3
25
|
/**
|
|
4
26
|
* OAuth provider for WorkOS AuthKit. `domain` is the AuthKit domain, e.g.
|
|
5
27
|
* `acme.authkit.app`. Requires DCR enabled in the WorkOS dashboard
|
|
6
28
|
* (Connect → Configuration). `audience` is the MCP server's Resource Indicator.
|
|
7
29
|
*/
|
|
8
|
-
export declare function workosProvider(opts: {
|
|
30
|
+
export declare function workosProvider<TCustom extends ExtraClaims = Record<never, never>>(opts: {
|
|
9
31
|
domain: string;
|
|
10
32
|
audience: string;
|
|
11
|
-
} & Omit<CustomProviderOptions, "issuer" | "audience">): Promise<OAuthConfig
|
|
33
|
+
} & Omit<CustomProviderOptions, "issuer" | "audience">): Promise<OAuthConfig<WorkosClaims & TCustom & RegisteredClaims>>;
|
|
@@ -7,6 +7,9 @@ import { toIssuerUrl } from "./shared.js";
|
|
|
7
7
|
*/
|
|
8
8
|
export function workosProvider(opts) {
|
|
9
9
|
const { domain, ...rest } = opts;
|
|
10
|
-
return customProvider({
|
|
10
|
+
return customProvider({
|
|
11
|
+
issuer: toIssuerUrl(domain),
|
|
12
|
+
...rest,
|
|
13
|
+
});
|
|
11
14
|
}
|
|
12
15
|
//# sourceMappingURL=workos.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workos.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/workos.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"workos.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/workos.ts"],"names":[],"mappings":"AAGA,OAAO,EAA8B,cAAc,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAuB1C;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAG5B,IAGC;IAED,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IACjC,OAAO,cAAc,CAAyB;QAC5C,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC;QAC3B,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\";\nimport { toIssuerUrl } from \"./shared.js\";\n\n/**\n * Claims a WorkOS AuthKit access token carries. All optional: `org_id`, `role`\n * and `permissions` appear only when an organization is selected at sign-in, and\n * `email` only when a JWT template adds it.\n *\n * @see https://workos.com/docs/authkit/sessions/integrating-sessions/access-token\n * @see https://workos.com/docs/authkit/jwt-templates\n */\nexport type WorkosClaims = {\n /** Session id, used for signing out. */\n sid?: string;\n /** Organization selected at sign-in. */\n org_id?: string;\n /** Role of the selected organization membership. */\n role?: string;\n /** Permissions assigned to the role. */\n permissions?: string[];\n /** Only when a JWT template adds it; not a default AuthKit claim. */\n email?: string;\n};\n\n/**\n * OAuth provider for WorkOS AuthKit. `domain` is the AuthKit domain, e.g.\n * `acme.authkit.app`. Requires DCR enabled in the WorkOS dashboard\n * (Connect → Configuration). `audience` is the MCP server's Resource Indicator.\n */\nexport function workosProvider<\n TCustom extends ExtraClaims = Record<never, never>,\n>(\n opts: { domain: string; audience: string } & Omit<\n CustomProviderOptions,\n \"issuer\" | \"audience\"\n >,\n): Promise<OAuthConfig<WorkosClaims & TCustom & RegisteredClaims>> {\n const { domain, ...rest } = opts;\n return customProvider<WorkosClaims & TCustom>({\n issuer: toIssuerUrl(domain),\n ...rest,\n });\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AuthInfo } from "../auth.js";
|
|
2
|
+
import type { SecurityScheme, ToolAuth } from "../server.js";
|
|
3
|
+
export declare function authToSecuritySchemes(auth: ToolAuth): SecurityScheme[];
|
|
4
|
+
export declare function securitySchemesAllowAnonymous(schemes: SecurityScheme[] | undefined): boolean;
|
|
5
|
+
export type SchemeFailure = {
|
|
6
|
+
error: "invalid_token" | "insufficient_scope";
|
|
7
|
+
description: string;
|
|
8
|
+
scopes: string[];
|
|
9
|
+
};
|
|
10
|
+
export declare function evaluateSecuritySchemes(schemes: SecurityScheme[] | undefined, authInfo: AuthInfo | undefined): SchemeFailure | undefined;
|
|
11
|
+
export declare function httpStatusForFailure(failure: SchemeFailure): 401 | 403;
|
|
12
|
+
export declare function clientPrefersInBandChallenge(userAgent: string | undefined): boolean;
|
|
13
|
+
export declare function wwwAuthenticateHeader(failure: SchemeFailure, resourceMetadataUrl?: string): string;
|
|
14
|
+
export declare function inBandChallengeResult(failure: SchemeFailure, resourceMetadataUrl?: string): {
|
|
15
|
+
isError: boolean;
|
|
16
|
+
content: {
|
|
17
|
+
type: "text";
|
|
18
|
+
text: string;
|
|
19
|
+
}[];
|
|
20
|
+
_meta: {
|
|
21
|
+
"mcp/www_authenticate": string[];
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { hostFromUserAgent } from "../host.js";
|
|
2
|
+
export function authToSecuritySchemes(auth) {
|
|
3
|
+
const oauth2 = {
|
|
4
|
+
type: "oauth2",
|
|
5
|
+
...(auth.scopes?.length ? { scopes: auth.scopes } : {}),
|
|
6
|
+
};
|
|
7
|
+
return auth.allowsAnonymous ? [{ type: "noauth" }, oauth2] : [oauth2];
|
|
8
|
+
}
|
|
9
|
+
export function securitySchemesAllowAnonymous(schemes) {
|
|
10
|
+
return !!schemes?.some((scheme) => scheme.type === "noauth");
|
|
11
|
+
}
|
|
12
|
+
export function evaluateSecuritySchemes(schemes, authInfo) {
|
|
13
|
+
if (securitySchemesAllowAnonymous(schemes) && !authInfo) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
const oauth2 = (schemes ?? []).filter((scheme) => scheme.type === "oauth2");
|
|
17
|
+
const required = oauth2.length ? oauth2 : [{ type: "oauth2" }];
|
|
18
|
+
const scopes = [
|
|
19
|
+
...new Set(required.flatMap((scheme) => scheme.scopes ?? [])),
|
|
20
|
+
];
|
|
21
|
+
if (!authInfo) {
|
|
22
|
+
return {
|
|
23
|
+
error: "invalid_token",
|
|
24
|
+
description: "Sign in to use this tool.",
|
|
25
|
+
scopes,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const satisfied = required.some((scheme) => (scheme.scopes ?? []).every((scope) => authInfo.scopes.includes(scope)));
|
|
29
|
+
return satisfied
|
|
30
|
+
? undefined
|
|
31
|
+
: {
|
|
32
|
+
error: "insufficient_scope",
|
|
33
|
+
description: "Missing required scope for this tool.",
|
|
34
|
+
scopes,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export function httpStatusForFailure(failure) {
|
|
38
|
+
return failure.error === "insufficient_scope" ? 403 : 401;
|
|
39
|
+
}
|
|
40
|
+
export function clientPrefersInBandChallenge(userAgent) {
|
|
41
|
+
return hostFromUserAgent(userAgent) === "openai";
|
|
42
|
+
}
|
|
43
|
+
export function wwwAuthenticateHeader(failure, resourceMetadataUrl) {
|
|
44
|
+
let header = `Bearer error="${failure.error}", error_description="${failure.description}"`;
|
|
45
|
+
if (failure.scopes.length) {
|
|
46
|
+
header += `, scope="${failure.scopes.join(" ")}"`;
|
|
47
|
+
}
|
|
48
|
+
if (resourceMetadataUrl) {
|
|
49
|
+
header += `, resource_metadata="${resourceMetadataUrl}"`;
|
|
50
|
+
}
|
|
51
|
+
return header;
|
|
52
|
+
}
|
|
53
|
+
export function inBandChallengeResult(failure, resourceMetadataUrl) {
|
|
54
|
+
return {
|
|
55
|
+
isError: true,
|
|
56
|
+
content: [{ type: "text", text: failure.description }],
|
|
57
|
+
_meta: {
|
|
58
|
+
"mcp/www_authenticate": [
|
|
59
|
+
wwwAuthenticateHeader(failure, resourceMetadataUrl),
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=security-schemes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security-schemes.js","sourceRoot":"","sources":["../../../src/server/auth/security-schemes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAG/C,MAAM,UAAU,qBAAqB,CAAC,IAAc;IAClD,MAAM,MAAM,GAAmB;QAC7B,IAAI,EAAE,QAAQ;QACd,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACxD,CAAC;IACF,OAAO,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,6BAA6B,CAC3C,OAAqC;IAErC,OAAO,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC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AK,oBAAoB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;AAC5D,CAAC;AAED,MAAM,UAAU,4BAA4B,CAC1C,SAA6B;IAE7B,OAAO,iBAAiB,CAAC,SAAS,CAAC,KAAK,QAAQ,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,OAAsB,EACtB,mBAA4B;IAE5B,IAAI,MAAM,GAAG,iBAAiB,OAAO,CAAC,KAAK,yBAAyB,OAAO,CAAC,WAAW,GAAG,CAAC;IAC3F,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QAC1B,MAAM,IAAI,YAAY,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IACpD,CAAC;IACD,IAAI,mBAAmB,EAAE,CAAC;QACxB,MAAM,IAAI,wBAAwB,mBAAmB,GAAG,CAAC;IAC3D,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,OAAsB,EACtB,mBAA4B;IAE5B,OAAO;QACL,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC;QAC/D,KAAK,EAAE;YACL,sBAAsB,EAAE;gBACtB,qBAAqB,CAAC,OAAO,EAAE,mBAAmB,CAAC;aACpD;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { AuthInfo } from \"../auth.js\";\nimport { hostFromUserAgent } from \"../host.js\";\nimport type { SecurityScheme, ToolAuth } from \"../server.js\";\n\nexport function authToSecuritySchemes(auth: ToolAuth): SecurityScheme[] {\n const oauth2: SecurityScheme = {\n type: \"oauth2\",\n ...(auth.scopes?.length ? { scopes: auth.scopes } : {}),\n };\n return auth.allowsAnonymous ? [{ type: \"noauth\" }, oauth2] : [oauth2];\n}\n\nexport function securitySchemesAllowAnonymous(\n schemes: SecurityScheme[] | undefined,\n): boolean {\n return !!schemes?.some((scheme) => scheme.type === \"noauth\");\n}\n\nexport type SchemeFailure = {\n error: \"invalid_token\" | \"insufficient_scope\";\n description: string;\n scopes: string[];\n};\n\nexport function evaluateSecuritySchemes(\n schemes: SecurityScheme[] | undefined,\n authInfo: AuthInfo | undefined,\n): SchemeFailure | undefined {\n if (securitySchemesAllowAnonymous(schemes) && !authInfo) {\n return undefined;\n }\n const oauth2 = (schemes ?? []).filter((scheme) => scheme.type === \"oauth2\");\n const required = oauth2.length ? oauth2 : [{ type: \"oauth2\" as const }];\n const scopes = [\n ...new Set(required.flatMap((scheme) => scheme.scopes ?? [])),\n ];\n if (!authInfo) {\n return {\n error: \"invalid_token\",\n description: \"Sign in to use this tool.\",\n scopes,\n };\n }\n const satisfied = required.some((scheme) =>\n (scheme.scopes ?? []).every((scope) => authInfo.scopes.includes(scope)),\n );\n return satisfied\n ? undefined\n : {\n error: \"insufficient_scope\",\n description: \"Missing required scope for this tool.\",\n scopes,\n };\n}\n\nexport function httpStatusForFailure(failure: SchemeFailure): 401 | 403 {\n return failure.error === \"insufficient_scope\" ? 403 : 401;\n}\n\nexport function clientPrefersInBandChallenge(\n userAgent: string | undefined,\n): boolean {\n return hostFromUserAgent(userAgent) === \"openai\";\n}\n\nexport function wwwAuthenticateHeader(\n failure: SchemeFailure,\n resourceMetadataUrl?: string,\n): string {\n let header = `Bearer error=\"${failure.error}\", error_description=\"${failure.description}\"`;\n if (failure.scopes.length) {\n header += `, scope=\"${failure.scopes.join(\" \")}\"`;\n }\n if (resourceMetadataUrl) {\n header += `, resource_metadata=\"${resourceMetadataUrl}\"`;\n }\n return header;\n}\n\nexport function inBandChallengeResult(\n failure: SchemeFailure,\n resourceMetadataUrl?: string,\n) {\n return {\n isError: true,\n content: [{ type: \"text\" as const, text: failure.description }],\n _meta: {\n \"mcp/www_authenticate\": [\n wwwAuthenticateHeader(failure, resourceMetadataUrl),\n ],\n },\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { authToSecuritySchemes, clientPrefersInBandChallenge, evaluateSecuritySchemes, securitySchemesAllowAnonymous, wwwAuthenticateHeader, } from "./security-schemes.js";
|
|
3
|
+
describe("clientPrefersInBandChallenge", () => {
|
|
4
|
+
it("detects ChatGPT / OpenAI user agents", () => {
|
|
5
|
+
expect(clientPrefersInBandChallenge("openai-mcp/1.0")).toBe(true);
|
|
6
|
+
expect(clientPrefersInBandChallenge("ChatGPT")).toBe(true);
|
|
7
|
+
expect(clientPrefersInBandChallenge("Claude-User/1.0")).toBe(false);
|
|
8
|
+
expect(clientPrefersInBandChallenge(undefined)).toBe(false);
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
describe("authToSecuritySchemes", () => {
|
|
12
|
+
it("maps the auth shorthand", () => {
|
|
13
|
+
expect(authToSecuritySchemes({ allowsAnonymous: true })).toEqual([
|
|
14
|
+
{ type: "noauth" },
|
|
15
|
+
{ type: "oauth2" },
|
|
16
|
+
]);
|
|
17
|
+
expect(authToSecuritySchemes({})).toEqual([{ type: "oauth2" }]);
|
|
18
|
+
expect(authToSecuritySchemes({ scopes: ["checkout"] })).toEqual([
|
|
19
|
+
{ type: "oauth2", scopes: ["checkout"] },
|
|
20
|
+
]);
|
|
21
|
+
expect(authToSecuritySchemes({ allowsAnonymous: true, scopes: ["checkout"] })).toEqual([{ type: "noauth" }, { type: "oauth2", scopes: ["checkout"] }]);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
const authInfo = (scopes) => ({
|
|
25
|
+
token: "t",
|
|
26
|
+
clientId: "c",
|
|
27
|
+
scopes,
|
|
28
|
+
});
|
|
29
|
+
describe("securitySchemesAllowAnonymous", () => {
|
|
30
|
+
it("is true only when a noauth scheme is present", () => {
|
|
31
|
+
expect(securitySchemesAllowAnonymous([{ type: "noauth" }])).toBe(true);
|
|
32
|
+
expect(securitySchemesAllowAnonymous([{ type: "noauth" }, { type: "oauth2" }])).toBe(true);
|
|
33
|
+
expect(securitySchemesAllowAnonymous([{ type: "oauth2" }])).toBe(false);
|
|
34
|
+
expect(securitySchemesAllowAnonymous(undefined)).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe("evaluateSecuritySchemes", () => {
|
|
38
|
+
it("lets anonymous callers through a noauth tool", () => {
|
|
39
|
+
const schemes = [{ type: "noauth" }, { type: "oauth2" }];
|
|
40
|
+
expect(evaluateSecuritySchemes(schemes, undefined)).toBeUndefined();
|
|
41
|
+
});
|
|
42
|
+
it("enforces oauth2 scopes on a public tool once a token is present", () => {
|
|
43
|
+
const schemes = [
|
|
44
|
+
{ type: "noauth" },
|
|
45
|
+
{ type: "oauth2", scopes: ["checkout"] },
|
|
46
|
+
];
|
|
47
|
+
expect(evaluateSecuritySchemes(schemes, undefined)).toBeUndefined();
|
|
48
|
+
expect(evaluateSecuritySchemes(schemes, authInfo(["openid"]))?.error).toBe("insufficient_scope");
|
|
49
|
+
expect(evaluateSecuritySchemes(schemes, authInfo(["checkout"]))).toBeUndefined();
|
|
50
|
+
});
|
|
51
|
+
it("fails an oauth2-only tool with no token (invalid_token / 401)", () => {
|
|
52
|
+
expect(evaluateSecuritySchemes([{ type: "oauth2" }], undefined)?.error).toBe("invalid_token");
|
|
53
|
+
});
|
|
54
|
+
it("fails when the token is missing a required scope (insufficient_scope / 403)", () => {
|
|
55
|
+
const schemes = [
|
|
56
|
+
{ type: "oauth2", scopes: ["checkout"] },
|
|
57
|
+
];
|
|
58
|
+
expect(evaluateSecuritySchemes(schemes, authInfo(["openid"]))?.error).toBe("insufficient_scope");
|
|
59
|
+
});
|
|
60
|
+
it("passes when the token carries every required scope", () => {
|
|
61
|
+
const schemes = [
|
|
62
|
+
{ type: "oauth2", scopes: ["checkout"] },
|
|
63
|
+
];
|
|
64
|
+
expect(evaluateSecuritySchemes(schemes, authInfo(["openid", "checkout"]))).toBeUndefined();
|
|
65
|
+
});
|
|
66
|
+
it("treats an undeclared tool as auth-required, satisfied by any valid token", () => {
|
|
67
|
+
expect(evaluateSecuritySchemes(undefined, undefined)?.error).toBe("invalid_token");
|
|
68
|
+
expect(evaluateSecuritySchemes(undefined, authInfo([]))).toBeUndefined();
|
|
69
|
+
});
|
|
70
|
+
it("carries the tool's required scopes on the failure", () => {
|
|
71
|
+
const schemes = [
|
|
72
|
+
{ type: "oauth2", scopes: ["checkout"] },
|
|
73
|
+
];
|
|
74
|
+
expect(evaluateSecuritySchemes(schemes, undefined)?.scopes).toEqual([
|
|
75
|
+
"checkout",
|
|
76
|
+
]);
|
|
77
|
+
expect(evaluateSecuritySchemes(schemes, authInfo(["openid"]))?.scopes).toEqual(["checkout"]);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
describe("wwwAuthenticateHeader", () => {
|
|
81
|
+
it("names the required scopes so the client can step up", () => {
|
|
82
|
+
const header = wwwAuthenticateHeader({
|
|
83
|
+
error: "insufficient_scope",
|
|
84
|
+
description: "Missing required scope for this tool.",
|
|
85
|
+
scopes: ["checkout"],
|
|
86
|
+
});
|
|
87
|
+
expect(header).toContain('error="insufficient_scope"');
|
|
88
|
+
expect(header).toContain('scope="checkout"');
|
|
89
|
+
});
|
|
90
|
+
it("omits the scope parameter when there are none", () => {
|
|
91
|
+
const header = wwwAuthenticateHeader({
|
|
92
|
+
error: "invalid_token",
|
|
93
|
+
description: "Sign in to use this tool.",
|
|
94
|
+
scopes: [],
|
|
95
|
+
});
|
|
96
|
+
expect(header).not.toContain("scope=");
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
//# sourceMappingURL=security-schemes.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security-schemes.test.js","sourceRoot":"","sources":["../../../src/server/auth/security-schemes.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,M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nC,KAAK,EAAE,oBAAoB;YAC3B,WAAW,EAAE,uCAAuC;YACpD,MAAM,EAAE,CAAC,UAAU,CAAC;SACrB,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,4BAA4B,CAAC,CAAC;QACvD,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,MAAM,GAAG,qBAAqB,CAAC;YACnC,KAAK,EAAE,eAAe;YACtB,WAAW,EAAE,2BAA2B;YACxC,MAAM,EAAE,EAAE;SACX,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport type { AuthInfo } from \"../auth.js\";\nimport type { SecurityScheme } from \"../server.js\";\nimport {\n authToSecuritySchemes,\n clientPrefersInBandChallenge,\n evaluateSecuritySchemes,\n securitySchemesAllowAnonymous,\n wwwAuthenticateHeader,\n} from \"./security-schemes.js\";\n\ndescribe(\"clientPrefersInBandChallenge\", () => {\n it(\"detects ChatGPT / OpenAI user agents\", () => {\n expect(clientPrefersInBandChallenge(\"openai-mcp/1.0\")).toBe(true);\n expect(clientPrefersInBandChallenge(\"ChatGPT\")).toBe(true);\n expect(clientPrefersInBandChallenge(\"Claude-User/1.0\")).toBe(false);\n expect(clientPrefersInBandChallenge(undefined)).toBe(false);\n });\n});\n\ndescribe(\"authToSecuritySchemes\", () => {\n it(\"maps the auth shorthand\", () => {\n expect(authToSecuritySchemes({ allowsAnonymous: true })).toEqual([\n { type: \"noauth\" },\n { type: \"oauth2\" },\n ]);\n expect(authToSecuritySchemes({})).toEqual([{ type: \"oauth2\" }]);\n expect(authToSecuritySchemes({ scopes: [\"checkout\"] })).toEqual([\n { type: \"oauth2\", scopes: [\"checkout\"] },\n ]);\n expect(\n authToSecuritySchemes({ allowsAnonymous: true, scopes: [\"checkout\"] }),\n ).toEqual([{ type: \"noauth\" }, { type: \"oauth2\", scopes: [\"checkout\"] }]);\n });\n});\n\nconst authInfo = (scopes: string[]): AuthInfo => ({\n token: \"t\",\n clientId: \"c\",\n scopes,\n});\n\ndescribe(\"securitySchemesAllowAnonymous\", () => {\n it(\"is true only when a noauth scheme is present\", () => {\n expect(securitySchemesAllowAnonymous([{ type: \"noauth\" }])).toBe(true);\n expect(\n securitySchemesAllowAnonymous([{ type: \"noauth\" }, { type: \"oauth2\" }]),\n ).toBe(true);\n expect(securitySchemesAllowAnonymous([{ type: \"oauth2\" }])).toBe(false);\n expect(securitySchemesAllowAnonymous(undefined)).toBe(false);\n });\n});\n\ndescribe(\"evaluateSecuritySchemes\", () => {\n it(\"lets anonymous callers through a noauth tool\", () => {\n const schemes: SecurityScheme[] = [{ type: \"noauth\" }, { type: \"oauth2\" }];\n expect(evaluateSecuritySchemes(schemes, undefined)).toBeUndefined();\n });\n\n it(\"enforces oauth2 scopes on a public tool once a token is present\", () => {\n const schemes: SecurityScheme[] = [\n { type: \"noauth\" },\n { type: \"oauth2\", scopes: [\"checkout\"] },\n ];\n expect(evaluateSecuritySchemes(schemes, undefined)).toBeUndefined();\n expect(evaluateSecuritySchemes(schemes, authInfo([\"openid\"]))?.error).toBe(\n \"insufficient_scope\",\n );\n expect(\n evaluateSecuritySchemes(schemes, authInfo([\"checkout\"])),\n ).toBeUndefined();\n });\n\n it(\"fails an oauth2-only tool with no token (invalid_token / 401)\", () => {\n expect(\n evaluateSecuritySchemes([{ type: \"oauth2\" }], undefined)?.error,\n ).toBe(\"invalid_token\");\n });\n\n it(\"fails when the token is missing a required scope (insufficient_scope / 403)\", () => {\n const schemes: SecurityScheme[] = [\n { type: \"oauth2\", scopes: [\"checkout\"] },\n ];\n expect(evaluateSecuritySchemes(schemes, authInfo([\"openid\"]))?.error).toBe(\n \"insufficient_scope\",\n );\n });\n\n it(\"passes when the token carries every required scope\", () => {\n const schemes: SecurityScheme[] = [\n { type: \"oauth2\", scopes: [\"checkout\"] },\n ];\n expect(\n evaluateSecuritySchemes(schemes, authInfo([\"openid\", \"checkout\"])),\n ).toBeUndefined();\n });\n\n it(\"treats an undeclared tool as auth-required, satisfied by any valid token\", () => {\n expect(evaluateSecuritySchemes(undefined, undefined)?.error).toBe(\n \"invalid_token\",\n );\n expect(evaluateSecuritySchemes(undefined, authInfo([]))).toBeUndefined();\n });\n\n it(\"carries the tool's required scopes on the failure\", () => {\n const schemes: SecurityScheme[] = [\n { type: \"oauth2\", scopes: [\"checkout\"] },\n ];\n expect(evaluateSecuritySchemes(schemes, undefined)?.scopes).toEqual([\n \"checkout\",\n ]);\n expect(\n evaluateSecuritySchemes(schemes, authInfo([\"openid\"]))?.scopes,\n ).toEqual([\"checkout\"]);\n });\n});\n\ndescribe(\"wwwAuthenticateHeader\", () => {\n it(\"names the required scopes so the client can step up\", () => {\n const header = wwwAuthenticateHeader({\n error: \"insufficient_scope\",\n description: \"Missing required scope for this tool.\",\n scopes: [\"checkout\"],\n });\n expect(header).toContain('error=\"insufficient_scope\"');\n expect(header).toContain('scope=\"checkout\"');\n });\n\n it(\"omits the scope parameter when there are none\", () => {\n const header = wwwAuthenticateHeader({\n error: \"invalid_token\",\n description: \"Sign in to use this tool.\",\n scopes: [],\n });\n expect(header).not.toContain(\"scope=\");\n });\n});\n"]}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { Express } from "express";
|
|
2
|
+
import type { SecurityScheme } from "../server.js";
|
|
2
3
|
import type { OAuthConfig } from "./index.js";
|
|
4
|
+
export type ResourceMetadataUrlResolver = (getHeader: (key: string) => string | undefined) => string;
|
|
3
5
|
/** Mounts the well-known OAuth metadata and bearer auth on `/mcp`. */
|
|
4
|
-
export declare function setupOAuth(app: Express, config: OAuthConfig):
|
|
6
|
+
export declare function setupOAuth(app: Express, config: OAuthConfig<Record<string, unknown>>, schemesByTool: Map<string, SecurityScheme[] | undefined>): ResourceMetadataUrlResolver;
|