skybridge 0.0.0-dev.e4f73e5 → 0.0.0-dev.e50416a
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 +1 -0
- package/dist/cli/build-helpers.d.ts +3 -2
- package/dist/cli/build-helpers.js +22 -8
- package/dist/cli/build-helpers.js.map +1 -1
- package/dist/cli/build-helpers.test.js +46 -3
- package/dist/cli/build-helpers.test.js.map +1 -1
- package/dist/cli/build-steps.js +9 -4
- package/dist/cli/build-steps.js.map +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/use-execute-steps.d.ts +1 -1
- package/dist/cli/use-nodemon.js +1 -1
- package/dist/cli/use-nodemon.js.map +1 -1
- package/dist/commands/dev.js +2 -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 +31 -2
- package/dist/server/auth/providers/descope.js +13 -2
- 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 +66 -20
- package/dist/server/server.js +127 -17
- 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/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 +19 -3
- package/dist/test/view.test.js.map +1 -1
- package/dist/web/bridges/adaptor.js +17 -3
- package/dist/web/bridges/adaptor.js.map +1 -1
- package/dist/web/bridges/adaptor.test.js +32 -4
- package/dist/web/bridges/adaptor.test.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.js +5 -3
- package/dist/web/bridges/mcp-app/bridge.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/data-llm.test.js +9 -0
- 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-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-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 +31 -0
- 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 +8 -7
- package/dist/cli/resolve-views-dir.d.ts +0 -1
- package/dist/cli/resolve-views-dir.js.map +0 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { OAuthMetadata } from "@modelcontextprotocol/sdk/shared/auth.js";
|
|
2
|
+
import type { ExtraClaims } from "../../auth.js";
|
|
2
3
|
import type { OAuthConfig } from "../index.js";
|
|
4
|
+
import { type RegisteredClaims } from "../verify.js";
|
|
3
5
|
/** Options accepted by {@link customProvider} and the branded providers. */
|
|
4
6
|
export type CustomProviderOptions = {
|
|
5
7
|
issuer: string;
|
|
@@ -16,9 +18,23 @@ export type CustomProviderOptions = {
|
|
|
16
18
|
* injects the registration endpoint). Use the static public URL; `verify.issuer`
|
|
17
19
|
* stays the IdP (the token's real `iss`). */
|
|
18
20
|
serverUrl?: string;
|
|
21
|
+
/** Advertise this URL as the authorization server (served AS metadata `issuer`
|
|
22
|
+
* and PRM `authorization_servers`). Its own discovery document supplies the
|
|
23
|
+
* advertised endpoints, DCR registration, scopes and the `iss` tokens are
|
|
24
|
+
* verified against; only `jwks_uri` still comes from `issuer`'s document. Use
|
|
25
|
+
* when DCR/authorize/token live at a different URL than the discovery issuer
|
|
26
|
+
* (e.g. Descope's agentic URL vs. its base-project URL). `serverUrl` wins if
|
|
27
|
+
* both are set. */
|
|
28
|
+
authorizationServer?: string;
|
|
19
29
|
scopes?: string[];
|
|
20
30
|
requiredScopes?: string[];
|
|
21
31
|
metadataOverrides?: Omit<Partial<OAuthMetadata>, "issuer">;
|
|
22
32
|
};
|
|
23
|
-
/**
|
|
24
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Builds a complete {@link OAuthConfig} from an IdP's OAuth discovery document.
|
|
35
|
+
*
|
|
36
|
+
* @typeParam TExtra - Claims the IdP puts in the access token, reaching handlers
|
|
37
|
+
* as `extra.authInfo.extra`. The branded providers pass their documented claims;
|
|
38
|
+
* pass your own when wiring an IdP by hand.
|
|
39
|
+
*/
|
|
40
|
+
export declare function customProvider<TExtra extends ExtraClaims = ExtraClaims>(opts: CustomProviderOptions): Promise<OAuthConfig<TExtra & RegisteredClaims>>;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { discoverAuthorizationServer, } from "../discovery.js";
|
|
2
|
-
|
|
2
|
+
import { createJwksVerifier } from "../verify.js";
|
|
3
|
+
/**
|
|
4
|
+
* Builds a complete {@link OAuthConfig} from an IdP's OAuth discovery document.
|
|
5
|
+
*
|
|
6
|
+
* @typeParam TExtra - Claims the IdP puts in the access token, reaching handlers
|
|
7
|
+
* as `extra.authInfo.extra`. The branded providers pass their documented claims;
|
|
8
|
+
* pass your own when wiring an IdP by hand.
|
|
9
|
+
*/
|
|
3
10
|
export async function customProvider(opts) {
|
|
4
11
|
const discovered = await discoverAuthorizationServer(opts.issuer);
|
|
5
12
|
// JWKS verification needs a signing-key URL; without it the server can't verify
|
|
@@ -11,25 +18,37 @@ export async function customProvider(opts) {
|
|
|
11
18
|
// Overrides adjust only advertised metadata; the trust anchor (issuer, jwks_uri)
|
|
12
19
|
// always comes from validated discovery.
|
|
13
20
|
const { issuer: _issuer, jwks_uri: _jwks, ...overrides } = opts.metadataOverrides ?? {};
|
|
14
|
-
|
|
21
|
+
let advertised = discovered;
|
|
22
|
+
if (opts.authorizationServer) {
|
|
23
|
+
try {
|
|
24
|
+
advertised = await discoverAuthorizationServer(opts.authorizationServer);
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
console.warn(`OAuth discovery failed for authorizationServer ${opts.authorizationServer}; advertising ${opts.issuer} metadata instead: ${err instanceof Error ? err.message : String(err)}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const base = { ...advertised, ...overrides };
|
|
15
31
|
const scopesSupported = opts.scopes ?? base.scopes_supported;
|
|
16
|
-
// serverUrl
|
|
17
|
-
//
|
|
18
|
-
|
|
32
|
+
// serverUrl (skybridge-as-AS) overrides the advertised issuer, keeping the
|
|
33
|
+
// IdP as the token issuer. authorizationServer re-asserts its own URL so a
|
|
34
|
+
// failed AS discovery still points clients at the AS. serverUrl wins.
|
|
35
|
+
const advertisedIssuer = opts.serverUrl?.replace(/\/$/, "") ??
|
|
36
|
+
opts.authorizationServer?.replace(/\/$/, "");
|
|
37
|
+
const oauthMetadata = advertisedIssuer
|
|
19
38
|
? {
|
|
20
39
|
...base,
|
|
21
|
-
issuer:
|
|
40
|
+
issuer: advertisedIssuer,
|
|
22
41
|
scopes_supported: scopesSupported,
|
|
23
42
|
}
|
|
24
43
|
: base;
|
|
25
44
|
return {
|
|
26
45
|
baseUrl: opts.baseUrl,
|
|
27
46
|
oauthMetadata,
|
|
28
|
-
|
|
29
|
-
issuer:
|
|
47
|
+
verifier: createJwksVerifier({
|
|
48
|
+
issuer: advertised.issuer,
|
|
30
49
|
audience: opts.audience,
|
|
31
|
-
jwksUri: discovered.jwks_uri,
|
|
32
|
-
},
|
|
50
|
+
jwksUri: advertised.jwks_uri ?? discovered.jwks_uri,
|
|
51
|
+
}),
|
|
33
52
|
scopesSupported,
|
|
34
53
|
requiredScopes: opts.requiredScopes,
|
|
35
54
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/custom.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"custom.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/custom.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,2BAA2B,GAC5B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,kBAAkB,EAAyB,MAAM,cAAc,CAAC;AA+BzE;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,IAA2B;IAE3B,MAAM,UAAU,GAAG,MAAM,2BAA2B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAElE,gFAAgF;IAChF,kFAAkF;IAClF,iFAAiF;IACjF,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,CAAC,MAAM,4DAA4D,CAC3E,CAAC;IACJ,CAAC;IAED,iFAAiF;IACjF,yCAAyC;IACzC,MAAM,EACJ,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,KAAK,EACf,GAAG,SAAS,EACb,GAAgC,IAAI,CAAC,iBAAiB,IAAI,EAAE,CAAC;IAC9D,IAAI,UAAU,GAAG,UAAU,CAAC;IAC5B,IAAI,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC7B,IAAI,CAAC;YACH,UAAU,GAAG,MAAM,2BAA2B,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAC3E,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,IAAI,CACV,kDAAkD,IAAI,CAAC,mBAAmB,iBAAiB,IAAI,CAAC,MAAM,sBAAsB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAC/K,CAAC;QACJ,CAAC;IACH,CAAC;IACD,MAAM,IAAI,GAAuB,EAAE,GAAG,UAAU,EAAE,GAAG,SAAS,EAAE,CAAC;IACjE,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,gBAAgB,CAAC;IAE7D,2EAA2E;IAC3E,2EAA2E;IAC3E,sEAAsE;IACtE,MAAM,gBAAgB,GACpB,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;QAClC,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC/C,MAAM,aAAa,GAAuB,gBAAgB;QACxD,CAAC,CAAC;YACE,GAAG,IAAI;YACP,MAAM,EAAE,gBAAgB;YACxB,gBAAgB,EAAE,eAAe;SAClC;QACH,CAAC,CAAC,IAAI,CAAC;IAET,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,aAAa;QACb,QAAQ,EAAE,kBAAkB,CAAS;YACnC,MAAM,EAAE,UAAU,CAAC,MAAM;YACzB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,OAAO,EAAE,UAAU,CAAC,QAAQ,IAAI,UAAU,CAAC,QAAQ;SACpD,CAAC;QACF,eAAe;QACf,cAAc,EAAE,IAAI,CAAC,cAAc;KACpC,CAAC;AACJ,CAAC","sourcesContent":["import type { OAuthMetadata } from \"@modelcontextprotocol/sdk/shared/auth.js\";\nimport type { ExtraClaims } from \"../../auth.js\";\nimport {\n type DiscoveredMetadata,\n discoverAuthorizationServer,\n} from \"../discovery.js\";\nimport type { OAuthConfig } from \"../index.js\";\nimport { createJwksVerifier, type RegisteredClaims } from \"../verify.js\";\n\n/** Options accepted by {@link customProvider} and the branded providers. */\nexport type CustomProviderOptions = {\n issuer: string;\n /** Expected token `aud`. Omit to skip audience verification — only for IdPs\n * that don't bind an audience (e.g. Clerk). Branded providers whose IdP does\n * bind an audience re-require it in their own options. */\n audience?: string;\n /** Omit to let the server infer the resource origin from request headers. */\n baseUrl?: string;\n /** Advertise THIS server as the authorization server (skybridge-as-AS): the\n * served AS metadata `issuer` and the PRM `authorization_servers` use this URL\n * instead of the IdP's. Needed when skybridge must sit in the auth path — Auth0\n * (the `audience` must be baked into `/authorize`) or the Alpic DCR proxy (Alpic\n * injects the registration endpoint). Use the static public URL; `verify.issuer`\n * stays the IdP (the token's real `iss`). */\n serverUrl?: string;\n /** Advertise this URL as the authorization server (served AS metadata `issuer`\n * and PRM `authorization_servers`). Its own discovery document supplies the\n * advertised endpoints, DCR registration, scopes and the `iss` tokens are\n * verified against; only `jwks_uri` still comes from `issuer`'s document. Use\n * when DCR/authorize/token live at a different URL than the discovery issuer\n * (e.g. Descope's agentic URL vs. its base-project URL). `serverUrl` wins if\n * both are set. */\n authorizationServer?: string;\n scopes?: string[];\n requiredScopes?: string[];\n metadataOverrides?: Omit<Partial<OAuthMetadata>, \"issuer\">;\n};\n\n/**\n * Builds a complete {@link OAuthConfig} from an IdP's OAuth discovery document.\n *\n * @typeParam TExtra - Claims the IdP puts in the access token, reaching handlers\n * as `extra.authInfo.extra`. The branded providers pass their documented claims;\n * pass your own when wiring an IdP by hand.\n */\nexport async function customProvider<TExtra extends ExtraClaims = ExtraClaims>(\n opts: CustomProviderOptions,\n): Promise<OAuthConfig<TExtra & RegisteredClaims>> {\n const discovered = await discoverAuthorizationServer(opts.issuer);\n\n // JWKS verification needs a signing-key URL; without it the server can't verify\n // tokens. (`registration_endpoint` is optional per RFC 8414 — a no-DCR IdP simply\n // omits it; a proxy like Alpic, or pre-registered clients, supply registration.)\n if (!discovered.jwks_uri) {\n throw new Error(\n `${opts.issuer} discovery has no jwks_uri; JWKS verification requires it.`,\n );\n }\n\n // Overrides adjust only advertised metadata; the trust anchor (issuer, jwks_uri)\n // always comes from validated discovery.\n const {\n issuer: _issuer,\n jwks_uri: _jwks,\n ...overrides\n }: Partial<DiscoveredMetadata> = opts.metadataOverrides ?? {};\n let advertised = discovered;\n if (opts.authorizationServer) {\n try {\n advertised = await discoverAuthorizationServer(opts.authorizationServer);\n } catch (err) {\n console.warn(\n `OAuth discovery failed for authorizationServer ${opts.authorizationServer}; advertising ${opts.issuer} metadata instead: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n }\n const base: DiscoveredMetadata = { ...advertised, ...overrides };\n const scopesSupported = opts.scopes ?? base.scopes_supported;\n\n // serverUrl (skybridge-as-AS) overrides the advertised issuer, keeping the\n // IdP as the token issuer. authorizationServer re-asserts its own URL so a\n // failed AS discovery still points clients at the AS. serverUrl wins.\n const advertisedIssuer =\n opts.serverUrl?.replace(/\\/$/, \"\") ??\n opts.authorizationServer?.replace(/\\/$/, \"\");\n const oauthMetadata: DiscoveredMetadata = advertisedIssuer\n ? {\n ...base,\n issuer: advertisedIssuer,\n scopes_supported: scopesSupported,\n }\n : base;\n\n return {\n baseUrl: opts.baseUrl,\n oauthMetadata,\n verifier: createJwksVerifier<TExtra>({\n issuer: advertised.issuer,\n audience: opts.audience,\n jwksUri: advertised.jwks_uri ?? discovered.jwks_uri,\n }),\n scopesSupported,\n requiredScopes: opts.requiredScopes,\n };\n}\n"]}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
// @vitest-environment node
|
|
2
2
|
import http from "node:http";
|
|
3
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
4
4
|
import { customProvider } from "./custom.js";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { lastJwksConfig as jwks } from "./verify-spy.js";
|
|
6
|
+
vi.mock("../verify.js", () => import("./verify-spy.js"));
|
|
7
|
+
const servers = [];
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
for (const srv of servers.splice(0)) {
|
|
10
|
+
srv.close();
|
|
11
|
+
}
|
|
12
|
+
});
|
|
7
13
|
function doc(origin, extra = {}) {
|
|
8
14
|
return {
|
|
9
15
|
issuer: origin,
|
|
@@ -28,7 +34,7 @@ async function serveDiscovery(extra = {}) {
|
|
|
28
34
|
res.end(JSON.stringify(doc(origin, extra)));
|
|
29
35
|
});
|
|
30
36
|
await new Promise((resolve) => srv.listen(0, resolve));
|
|
31
|
-
|
|
37
|
+
servers.push(srv);
|
|
32
38
|
origin = `http://localhost:${srv.address().port}`;
|
|
33
39
|
return origin;
|
|
34
40
|
}
|
|
@@ -42,7 +48,7 @@ describe("customProvider", () => {
|
|
|
42
48
|
scopes: ["openid"],
|
|
43
49
|
});
|
|
44
50
|
expect(config.baseUrl).toBe("https://app.example.test");
|
|
45
|
-
expect(
|
|
51
|
+
expect(jwks()).toEqual({
|
|
46
52
|
issuer: base,
|
|
47
53
|
audience: "my-api",
|
|
48
54
|
jwksUri: `${base}/jwks`,
|
|
@@ -57,23 +63,23 @@ describe("customProvider", () => {
|
|
|
57
63
|
audience: "a",
|
|
58
64
|
metadataOverrides: { issuer: "https://evil.test" },
|
|
59
65
|
});
|
|
60
|
-
expect(
|
|
66
|
+
expect(jwks().issuer).toBe(base);
|
|
61
67
|
expect(config.oauthMetadata.issuer).toBe(base);
|
|
62
68
|
});
|
|
63
69
|
it("ignores a runtime jwks_uri override (keeps the discovered signing keys)", async () => {
|
|
64
70
|
const base = await serveDiscovery();
|
|
65
|
-
|
|
71
|
+
await customProvider({
|
|
66
72
|
issuer: base,
|
|
67
73
|
audience: "a",
|
|
68
74
|
metadataOverrides: { jwks_uri: "https://evil.test/keys" },
|
|
69
75
|
});
|
|
70
|
-
expect(
|
|
76
|
+
expect(jwks().jwksUri).toBe(`${base}/jwks`);
|
|
71
77
|
});
|
|
72
78
|
it("serves metadata without a registration_endpoint when the IdP has no DCR", async () => {
|
|
73
79
|
const base = await serveDiscovery({ registration_endpoint: undefined });
|
|
74
80
|
const config = await customProvider({ issuer: base, audience: "a" });
|
|
75
81
|
expect(config.oauthMetadata.registration_endpoint).toBeUndefined();
|
|
76
|
-
expect(
|
|
82
|
+
expect(jwks().issuer).toBe(base);
|
|
77
83
|
});
|
|
78
84
|
it("throws when discovery has no jwks_uri (token verification needs it)", async () => {
|
|
79
85
|
const base = await serveDiscovery({ jwks_uri: undefined });
|
|
@@ -91,7 +97,52 @@ describe("customProvider", () => {
|
|
|
91
97
|
expect(config.oauthMetadata.issuer).toBe("https://app.example.test");
|
|
92
98
|
expect(config.oauthMetadata.scopes_supported).toEqual(["openid"]);
|
|
93
99
|
// but the token's issuer is still verified against the IdP.
|
|
94
|
-
expect(
|
|
100
|
+
expect(jwks().issuer).toBe(base);
|
|
101
|
+
});
|
|
102
|
+
it("authorizationServer supplies the advertised metadata and the verified issuer", async () => {
|
|
103
|
+
const base = await serveDiscovery();
|
|
104
|
+
const as = await serveDiscovery({ scopes_supported: ["checkout"] });
|
|
105
|
+
const config = await customProvider({
|
|
106
|
+
issuer: base,
|
|
107
|
+
audience: "a",
|
|
108
|
+
authorizationServer: `${as}/`,
|
|
109
|
+
});
|
|
110
|
+
expect(config.oauthMetadata.issuer).toBe(as);
|
|
111
|
+
expect(config.oauthMetadata.authorization_endpoint).toBe(`${as}/authorize`);
|
|
112
|
+
expect(config.oauthMetadata.registration_endpoint).toBe(`${as}/register`);
|
|
113
|
+
expect(config.scopesSupported).toEqual(["checkout"]);
|
|
114
|
+
expect(jwks()).toEqual({
|
|
115
|
+
issuer: as,
|
|
116
|
+
audience: "a",
|
|
117
|
+
jwksUri: `${as}/jwks`,
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
it("falls back to the issuer's metadata when the authorizationServer is undiscoverable", async () => {
|
|
121
|
+
const base = await serveDiscovery();
|
|
122
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => { });
|
|
123
|
+
const config = await customProvider({
|
|
124
|
+
issuer: base,
|
|
125
|
+
audience: "a",
|
|
126
|
+
authorizationServer: `${base}/agentic/P1/MS1`,
|
|
127
|
+
});
|
|
128
|
+
expect(warn).toHaveBeenCalledOnce();
|
|
129
|
+
expect(config.oauthMetadata.issuer).toBe(`${base}/agentic/P1/MS1`);
|
|
130
|
+
expect(config.oauthMetadata.authorization_endpoint).toBe(`${base}/authorize`);
|
|
131
|
+
expect(jwks().issuer).toBe(base);
|
|
132
|
+
warn.mockRestore();
|
|
133
|
+
});
|
|
134
|
+
it("serverUrl takes precedence over authorizationServer", async () => {
|
|
135
|
+
const base = await serveDiscovery();
|
|
136
|
+
const as = await serveDiscovery();
|
|
137
|
+
const config = await customProvider({
|
|
138
|
+
issuer: base,
|
|
139
|
+
audience: "a",
|
|
140
|
+
serverUrl: "https://app.example.test/",
|
|
141
|
+
authorizationServer: as,
|
|
142
|
+
});
|
|
143
|
+
expect(config.oauthMetadata.issuer).toBe("https://app.example.test");
|
|
144
|
+
expect(config.oauthMetadata.token_endpoint).toBe(`${as}/token`);
|
|
145
|
+
expect(jwks().issuer).toBe(as);
|
|
95
146
|
});
|
|
96
147
|
it("applies metadataOverrides over discovered values", async () => {
|
|
97
148
|
const base = await serveDiscovery();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom.test.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/custom.test.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,IAAI,MAA+B,CAAC;AACpC,SAAS,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AAEjC,SAAS,GAAG,CAAC,MAAc,EAAE,QAAiC,EAAE;IAC9D,OAAO;QACL,MAAM,EAAE,MAAM;QACd,sBAAsB,EAAE,GAAG,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;SACnB,CAAC,CAAC;QACH,uDAAuD;QACvD,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;QACrE,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;QAClE,4DAA4D;QAC5D,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kDAAkD,EAAE,KAAK,IAAI,EAAE;QAChE,MAAM,IAAI,GAAG,MAAM,cAAc,EAAE,CAAC;QACpC,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC;YAClC,MAAM,EAAE,IAAI;YACZ,QAAQ,EAAE,GAAG;YACb,OAAO,EAAE,0BAA0B;YACnC,iBAAiB,EAAE,EAAE,cAAc,EAAE,wBAAwB,EAAE;SAChE,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// @vitest-environment node\nimport http from \"node:http\";\nimport { afterEach, describe, expect, it } from \"vitest\";\nimport { customProvider } from \"./custom.js\";\n\nlet server: http.Server | undefined;\nafterEach(() => server?.close());\n\nfunction doc(origin: string, extra: Record<string, unknown> = {}) {\n return {\n issuer: origin,\n authorization_endpoint: `${origin}/authorize`,\n token_endpoint: `${origin}/token`,\n registration_endpoint: `${origin}/register`,\n response_types_supported: [\"code\"],\n scopes_supported: [\"openid\", \"email\", \"profile\"],\n jwks_uri: `${origin}/jwks`,\n ...extra,\n };\n}\n\n// Serves the discovery doc (built from the live origin) at the OIDC well-known path.\nasync function serveDiscovery(extra: Record<string, unknown> = {}) {\n let origin = \"\";\n const srv = http.createServer((req, res) => {\n if (req.url !== \"/.well-known/openid-configuration\") {\n res.writeHead(404).end();\n return;\n }\n res.setHeader(\"content-type\", \"application/json\");\n res.end(JSON.stringify(doc(origin, extra)));\n });\n await new Promise<void>((resolve) => srv.listen(0, resolve));\n server = srv;\n origin = `http://localhost:${(srv.address() as { port: number }).port}`;\n return origin;\n}\n\ndescribe(\"customProvider\", () => {\n it(\"builds an OAuthConfig from discovery\", async () => {\n const base = await serveDiscovery();\n\n const config = await customProvider({\n issuer: base,\n audience: \"my-api\",\n baseUrl: \"https://app.example.test\",\n scopes: [\"openid\"],\n });\n\n expect(config.baseUrl).toBe(\"https://app.example.test\");\n expect(config.verify).toEqual({\n issuer: base,\n audience: \"my-api\",\n jwksUri: `${base}/jwks`,\n });\n expect(config.scopesSupported).toEqual([\"openid\"]);\n expect(config.oauthMetadata.registration_endpoint).toBe(`${base}/register`);\n });\n\n it(\"ignores a runtime issuer override (keeps the discovered trust anchor)\", async () => {\n const base = await serveDiscovery();\n const config = await customProvider({\n issuer: base,\n audience: \"a\",\n metadataOverrides: { issuer: \"https://evil.test\" } as never,\n });\n expect(config.verify.issuer).toBe(base);\n expect(config.oauthMetadata.issuer).toBe(base);\n });\n\n it(\"ignores a runtime jwks_uri override (keeps the discovered signing keys)\", async () => {\n const base = await serveDiscovery();\n const config = await customProvider({\n issuer: base,\n audience: \"a\",\n metadataOverrides: { jwks_uri: \"https://evil.test/keys\" } as never,\n });\n expect(config.verify.jwksUri).toBe(`${base}/jwks`);\n });\n\n it(\"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(\"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;AAC7C,OAAO,EAAE,cAAc,IAAI,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEzD,EAAE,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC;AAEzD,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;IACd,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,SAAS,GAAG,CAAC,MAAc,EAAE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AAM,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,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjC,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\";\nimport { lastJwksConfig as jwks } from \"./verify-spy.js\";\n\nvi.mock(\"../verify.js\", () => import(\"./verify-spy.js\"));\n\nconst servers: http.Server[] = [];\nafterEach(() => {\n for (const srv of servers.splice(0)) {\n srv.close();\n }\n});\n\nfunction doc(origin: string, extra: Record<string, unknown> = {}) {\n return {\n issuer: origin,\n authorization_endpoint: `${origin}/authorize`,\n token_endpoint: `${origin}/token`,\n registration_endpoint: `${origin}/register`,\n response_types_supported: [\"code\"],\n scopes_supported: [\"openid\", \"email\", \"profile\"],\n jwks_uri: `${origin}/jwks`,\n ...extra,\n };\n}\n\n// Serves the discovery doc (built from the live origin) at the OIDC well-known path.\nasync function serveDiscovery(extra: Record<string, unknown> = {}) {\n let origin = \"\";\n const srv = http.createServer((req, res) => {\n if (req.url !== \"/.well-known/openid-configuration\") {\n res.writeHead(404).end();\n return;\n }\n res.setHeader(\"content-type\", \"application/json\");\n res.end(JSON.stringify(doc(origin, extra)));\n });\n await new Promise<void>((resolve) => srv.listen(0, resolve));\n servers.push(srv);\n origin = `http://localhost:${(srv.address() as { port: number }).port}`;\n return origin;\n}\n\ndescribe(\"customProvider\", () => {\n it(\"builds an OAuthConfig from discovery\", async () => {\n const base = await serveDiscovery();\n\n const config = await customProvider({\n issuer: base,\n audience: \"my-api\",\n baseUrl: \"https://app.example.test\",\n scopes: [\"openid\"],\n });\n\n expect(config.baseUrl).toBe(\"https://app.example.test\");\n expect(jwks()).toEqual({\n issuer: base,\n audience: \"my-api\",\n jwksUri: `${base}/jwks`,\n });\n expect(config.scopesSupported).toEqual([\"openid\"]);\n expect(config.oauthMetadata.registration_endpoint).toBe(`${base}/register`);\n });\n\n it(\"ignores a runtime issuer override (keeps the discovered trust anchor)\", async () => {\n const base = await serveDiscovery();\n const config = await customProvider({\n issuer: base,\n audience: \"a\",\n metadataOverrides: { issuer: \"https://evil.test\" } as never,\n });\n expect(jwks().issuer).toBe(base);\n expect(config.oauthMetadata.issuer).toBe(base);\n });\n\n it(\"ignores a runtime jwks_uri override (keeps the discovered signing keys)\", async () => {\n const base = await serveDiscovery();\n await customProvider({\n issuer: base,\n audience: \"a\",\n metadataOverrides: { jwks_uri: \"https://evil.test/keys\" } as never,\n });\n expect(jwks().jwksUri).toBe(`${base}/jwks`);\n });\n\n it(\"serves metadata without a registration_endpoint when the IdP has no DCR\", async () => {\n const base = await serveDiscovery({ registration_endpoint: undefined });\n const config = await customProvider({ issuer: base, audience: \"a\" });\n expect(config.oauthMetadata.registration_endpoint).toBeUndefined();\n expect(jwks().issuer).toBe(base);\n });\n\n it(\"throws when discovery has no jwks_uri (token verification needs it)\", async () => {\n const base = await serveDiscovery({ jwks_uri: undefined });\n await expect(\n customProvider({ issuer: base, audience: \"a\" }),\n ).rejects.toThrow(/jwks_uri/);\n });\n\n it(\"serverUrl advertises this server as the AS, keeping the IdP as the token issuer\", async () => {\n const base = await serveDiscovery();\n const config = await customProvider({\n issuer: base,\n audience: \"a\",\n serverUrl: \"https://app.example.test/\",\n scopes: [\"openid\"],\n });\n // AS metadata + advertised scopes reflect this server.\n expect(config.oauthMetadata.issuer).toBe(\"https://app.example.test\");\n expect(config.oauthMetadata.scopes_supported).toEqual([\"openid\"]);\n // but the token's issuer is still verified against the IdP.\n expect(jwks().issuer).toBe(base);\n });\n\n it(\"authorizationServer supplies the advertised metadata and the verified issuer\", async () => {\n const base = await serveDiscovery();\n const as = await serveDiscovery({ scopes_supported: [\"checkout\"] });\n\n const config = await customProvider({\n issuer: base,\n audience: \"a\",\n authorizationServer: `${as}/`,\n });\n\n expect(config.oauthMetadata.issuer).toBe(as);\n expect(config.oauthMetadata.authorization_endpoint).toBe(`${as}/authorize`);\n expect(config.oauthMetadata.registration_endpoint).toBe(`${as}/register`);\n expect(config.scopesSupported).toEqual([\"checkout\"]);\n expect(jwks()).toEqual({\n issuer: as,\n audience: \"a\",\n jwksUri: `${as}/jwks`,\n });\n });\n\n it(\"falls back to the issuer's metadata when the authorizationServer is undiscoverable\", async () => {\n const base = await serveDiscovery();\n const warn = vi.spyOn(console, \"warn\").mockImplementation(() => {});\n\n const config = await customProvider({\n issuer: base,\n audience: \"a\",\n authorizationServer: `${base}/agentic/P1/MS1`,\n });\n\n expect(warn).toHaveBeenCalledOnce();\n expect(config.oauthMetadata.issuer).toBe(`${base}/agentic/P1/MS1`);\n expect(config.oauthMetadata.authorization_endpoint).toBe(\n `${base}/authorize`,\n );\n expect(jwks().issuer).toBe(base);\n warn.mockRestore();\n });\n\n it(\"serverUrl takes precedence over authorizationServer\", async () => {\n const base = await serveDiscovery();\n const as = await serveDiscovery();\n const config = await customProvider({\n issuer: base,\n audience: \"a\",\n serverUrl: \"https://app.example.test/\",\n authorizationServer: as,\n });\n expect(config.oauthMetadata.issuer).toBe(\"https://app.example.test\");\n expect(config.oauthMetadata.token_endpoint).toBe(`${as}/token`);\n expect(jwks().issuer).toBe(as);\n });\n\n it(\"applies metadataOverrides over discovered values\", async () => {\n const base = await serveDiscovery();\n const config = await customProvider({\n issuer: base,\n audience: \"a\",\n baseUrl: \"https://app.example.test\",\n metadataOverrides: { token_endpoint: \"https://override/token\" },\n });\n expect(config.oauthMetadata.token_endpoint).toBe(\"https://override/token\");\n });\n});\n"]}
|
|
@@ -1,5 +1,34 @@
|
|
|
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.
|
|
@@ -10,6 +39,6 @@ import { type CustomProviderOptions } from "./custom.js";
|
|
|
10
39
|
* the **Project ID** derived from the URL — Descope binds `aud` to [DCR client
|
|
11
40
|
* id, project id], not the server URL; pass `audience` to override.
|
|
12
41
|
*/
|
|
13
|
-
export declare function descopeProvider(opts: {
|
|
42
|
+
export declare function descopeProvider<TCustom extends ExtraClaims = Record<never, never>>(opts: {
|
|
14
43
|
url: string;
|
|
15
|
-
} & 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
|
|
@@ -23,10 +31,13 @@ function projectIdFromUrl(url) {
|
|
|
23
31
|
*/
|
|
24
32
|
export function descopeProvider(opts) {
|
|
25
33
|
const { url, audience, ...rest } = opts;
|
|
26
|
-
const
|
|
34
|
+
const asUrl = toAuthorizationServerUrl(url);
|
|
35
|
+
const projectId = projectIdFromUrl(asUrl);
|
|
36
|
+
const issuer = `${asUrl.slice(0, asUrl.indexOf("/agentic/"))}/${projectId}`;
|
|
27
37
|
return customProvider({
|
|
28
38
|
issuer,
|
|
29
|
-
audience: audience ??
|
|
39
|
+
audience: audience ?? projectId,
|
|
40
|
+
authorizationServer: asUrl,
|
|
30
41
|
...rest,
|
|
31
42
|
});
|
|
32
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
|
+
{"version":3,"file":"descope.test.js","sourceRoot":"","sources":["../../../../src/server/auth/providers/descope.test.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,cAAc,IAAI,IAAI,EAAE,MAAM,iBAAiB,CAAC;A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AG,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"]}
|