kinde-testkit 0.6.0 → 0.7.0
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/CHANGELOG.md +19 -0
- package/README.md +89 -3
- package/dist/chunk-2QJ7DTNL.js +72 -0
- package/dist/chunk-2QJ7DTNL.js.map +1 -0
- package/dist/chunk-33AHOLUN.js +183 -0
- package/dist/chunk-33AHOLUN.js.map +1 -0
- package/dist/chunk-JTAB2S44.js +3697 -0
- package/dist/chunk-JTAB2S44.js.map +1 -0
- package/dist/cli.js +50 -3561
- package/dist/cli.js.map +1 -0
- package/dist/cypress.cjs +286 -17
- package/dist/cypress.d.cts +2 -96
- package/dist/cypress.d.ts +3 -96
- package/dist/cypress.js +2 -3303
- package/dist/cypress.js.map +1 -1
- package/dist/handle-E_BhdHx8.d.ts +33 -0
- package/dist/handle-estfqypp.d.cts +32 -0
- package/dist/index.cjs +286 -17
- package/dist/index.d.cts +7 -607
- package/dist/index.d.ts +8 -607
- package/dist/index.js +51 -3577
- package/dist/index.js.map +1 -1
- package/dist/jest.cjs +286 -17
- package/dist/jest.d.cts +5 -555
- package/dist/jest.d.ts +6 -555
- package/dist/jest.js +4 -3373
- package/dist/jest.js.map +1 -1
- package/dist/playwright.d.ts +2 -54
- package/dist/server-B9fBcnyQ.d.ts +194 -0
- package/dist/server-CTBJXMac.d.cts +588 -0
- package/dist/vitest.d.ts +6 -555
- package/dist/vitest.js +5 -3376
- package/dist/vitest.js.map +1 -1
- package/dist/webhooks-DJyCsbdF.d.ts +397 -0
- package/package.json +3 -2
- package/dist/cypress-support.d.ts +0 -98
- package/dist/cypress.cjs.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/jest.cjs.map +0 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { n as KindePrincipal, o as KindeTestkit, F as FailureInjector, w as WebhookDispatcher, S as Scenario, r as ScenarioTokenOverrides, T as TestkitSeed } from './webhooks-DJyCsbdF.js';
|
|
2
|
+
import { h as Directory, d as CoverageRecorder, A as ActivityLog } from './server-B9fBcnyQ.js';
|
|
3
|
+
|
|
4
|
+
interface KindeTestAuth {
|
|
5
|
+
token: string | null;
|
|
6
|
+
headers: Record<string, string>;
|
|
7
|
+
principal: KindePrincipal | null;
|
|
8
|
+
request: {
|
|
9
|
+
headers: Record<string, string>;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
declare function kindeTest(options: {
|
|
13
|
+
scenario: Scenario;
|
|
14
|
+
testkit?: KindeTestkit;
|
|
15
|
+
token?: ScenarioTokenOverrides;
|
|
16
|
+
}): Promise<KindeTestAuth>;
|
|
17
|
+
interface KindeTestkitHandle {
|
|
18
|
+
readonly url: string;
|
|
19
|
+
readonly issuer: string;
|
|
20
|
+
readonly jwksUri: string;
|
|
21
|
+
readonly testkit: KindeTestkit;
|
|
22
|
+
readonly failures: FailureInjector;
|
|
23
|
+
readonly webhooks: WebhookDispatcher;
|
|
24
|
+
readonly directory: Directory;
|
|
25
|
+
readonly coverage: CoverageRecorder;
|
|
26
|
+
readonly activity: ActivityLog;
|
|
27
|
+
readonly certificatePath: string | null;
|
|
28
|
+
auth(scenario: Scenario, token?: ScenarioTokenOverrides): Promise<KindeTestAuth>;
|
|
29
|
+
loadSeed(seed: TestkitSeed): void;
|
|
30
|
+
reset(): void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { type KindeTestAuth as K, type KindeTestkitHandle as a, kindeTest as k };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { y as KindePrincipal, z as KindeTestkit, F as FailureInjector, X as WebhookDispatcher, s as Directory, j as CoverageRecorder, f as ActivityLog, d as Scenario, L as ScenarioTokenOverrides, T as TestkitSeed } from './server-CTBJXMac.cjs';
|
|
2
|
+
|
|
3
|
+
interface KindeTestAuth {
|
|
4
|
+
token: string | null;
|
|
5
|
+
headers: Record<string, string>;
|
|
6
|
+
principal: KindePrincipal | null;
|
|
7
|
+
request: {
|
|
8
|
+
headers: Record<string, string>;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
declare function kindeTest(options: {
|
|
12
|
+
scenario: Scenario;
|
|
13
|
+
testkit?: KindeTestkit;
|
|
14
|
+
token?: ScenarioTokenOverrides;
|
|
15
|
+
}): Promise<KindeTestAuth>;
|
|
16
|
+
interface KindeTestkitHandle {
|
|
17
|
+
readonly url: string;
|
|
18
|
+
readonly issuer: string;
|
|
19
|
+
readonly jwksUri: string;
|
|
20
|
+
readonly testkit: KindeTestkit;
|
|
21
|
+
readonly failures: FailureInjector;
|
|
22
|
+
readonly webhooks: WebhookDispatcher;
|
|
23
|
+
readonly directory: Directory;
|
|
24
|
+
readonly coverage: CoverageRecorder;
|
|
25
|
+
readonly activity: ActivityLog;
|
|
26
|
+
readonly certificatePath: string | null;
|
|
27
|
+
auth(scenario: Scenario, token?: ScenarioTokenOverrides): Promise<KindeTestAuth>;
|
|
28
|
+
loadSeed(seed: TestkitSeed): void;
|
|
29
|
+
reset(): void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { type KindeTestAuth as K, type KindeTestkitHandle as a, kindeTest as k };
|
package/dist/index.cjs
CHANGED
|
@@ -1332,6 +1332,8 @@ async function generateKeyPair(alg, options) {
|
|
|
1332
1332
|
var TestkitError = class extends Error {
|
|
1333
1333
|
code;
|
|
1334
1334
|
details;
|
|
1335
|
+
/** The message without the details list. */
|
|
1336
|
+
summary;
|
|
1335
1337
|
constructor(code, message2, details = []) {
|
|
1336
1338
|
super(details.length > 0 ? `${message2}
|
|
1337
1339
|
|
|
@@ -1339,6 +1341,7 @@ ${details.map((d) => ` - ${d}`).join("\n")}` : message2);
|
|
|
1339
1341
|
this.name = "TestkitError";
|
|
1340
1342
|
this.code = code;
|
|
1341
1343
|
this.details = details;
|
|
1344
|
+
this.summary = message2;
|
|
1342
1345
|
}
|
|
1343
1346
|
toString() {
|
|
1344
1347
|
return `${this.code}
|
|
@@ -1858,6 +1861,19 @@ function renderOrganizationPicker(options) {
|
|
|
1858
1861
|
function renderMessage(title, message2) {
|
|
1859
1862
|
return layout(title, `<h1>${escapeHtml(title)}</h1><p>${escapeHtml(message2)}</p>`);
|
|
1860
1863
|
}
|
|
1864
|
+
function renderDeviceCodeEntry(options = {}) {
|
|
1865
|
+
return layout(
|
|
1866
|
+
"Connect a device",
|
|
1867
|
+
`<h1>Connect a device</h1><p>Enter the code the device shows.</p>${options.error ? `<div class="error" role="alert">${escapeHtml(options.error)}</div>` : ""}<form method="get" action="/device"><label for="user_code">Code</label><input id="user_code" name="user_code" type="text" autocomplete="off" value="${escapeHtml(options.userCode ?? "")}" placeholder="ABCDEFGH" style="width:100%;height:42px;padding:0 12px;border-radius:8px;border:1px solid var(--line);background:transparent;color:var(--ink);font:inherit;letter-spacing:.2em"><button class="primary" type="submit">Continue</button></form>`
|
|
1868
|
+
);
|
|
1869
|
+
}
|
|
1870
|
+
function renderDeviceConfirm(options) {
|
|
1871
|
+
const code = escapeHtml(options.userCode);
|
|
1872
|
+
return layout(
|
|
1873
|
+
"Connect a device",
|
|
1874
|
+
`<h1>Connect a device</h1><p>A device using the app <strong>${escapeHtml(options.clientId)}</strong> wants to sign in. Check that it shows this code.</p><p class="note" style="font:600 20px/1 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.2em;text-align:center">${code}</p><form method="get" action="/device/sign-in"><input type="hidden" name="user_code" value="${code}"><button class="primary" type="submit">Continue</button></form><form method="post" action="/device/deny"><input type="hidden" name="user_code" value="${code}"><button class="option" type="submit" style="margin-top:8px;justify-content:center">Deny</button></form>`
|
|
1875
|
+
);
|
|
1876
|
+
}
|
|
1861
1877
|
|
|
1862
1878
|
// src/seed.ts
|
|
1863
1879
|
function roleRecord(key, extra = {}) {
|
|
@@ -2173,6 +2189,8 @@ function featureFlagsFor(seed, organizationCode) {
|
|
|
2173
2189
|
// src/oauth.ts
|
|
2174
2190
|
var import_node_crypto4 = require("crypto");
|
|
2175
2191
|
var CODE_LIFETIME_MS = 10 * 60 * 1e3;
|
|
2192
|
+
var DEVICE_CODE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
|
|
2193
|
+
var USER_CODE_ALPHABET = "BCDFGHJKLMNPQRSTVWXZ";
|
|
2176
2194
|
var OAuthError = class extends Error {
|
|
2177
2195
|
constructor(status, error, description) {
|
|
2178
2196
|
super(description);
|
|
@@ -2183,24 +2201,49 @@ var OAuthError = class extends Error {
|
|
|
2183
2201
|
error;
|
|
2184
2202
|
};
|
|
2185
2203
|
var AuthorizationServer = class {
|
|
2186
|
-
constructor(testkit, seed, emit = () => void 0, directory, observe = () => void 0) {
|
|
2204
|
+
constructor(testkit, seed, emit = () => void 0, directory, observe = () => void 0, deviceOptions = {}) {
|
|
2187
2205
|
this.testkit = testkit;
|
|
2188
2206
|
this.seed = seed;
|
|
2189
2207
|
this.emit = emit;
|
|
2190
2208
|
this.directory = directory;
|
|
2191
2209
|
this.observe = observe;
|
|
2210
|
+
this.deviceOptions = deviceOptions;
|
|
2192
2211
|
}
|
|
2193
2212
|
testkit;
|
|
2194
2213
|
seed;
|
|
2195
2214
|
emit;
|
|
2196
2215
|
directory;
|
|
2197
2216
|
observe;
|
|
2217
|
+
deviceOptions;
|
|
2198
2218
|
codes = /* @__PURE__ */ new Map();
|
|
2199
2219
|
refreshTokens = /* @__PURE__ */ new Map();
|
|
2200
2220
|
signedUpUsers = /* @__PURE__ */ new Map();
|
|
2201
|
-
|
|
2221
|
+
devices = /* @__PURE__ */ new Map();
|
|
2222
|
+
registeredClients = /* @__PURE__ */ new Map();
|
|
2223
|
+
async handle(req, res, url, readBody, readJson2 = async () => ({})) {
|
|
2202
2224
|
const method = req.method ?? "GET";
|
|
2203
2225
|
switch (`${method} ${url.pathname}`) {
|
|
2226
|
+
case "POST /oauth2/device/auth":
|
|
2227
|
+
this.deviceAuthorization(res, await readBody());
|
|
2228
|
+
return true;
|
|
2229
|
+
case "GET /device":
|
|
2230
|
+
this.devicePage(res, url.searchParams);
|
|
2231
|
+
return true;
|
|
2232
|
+
case "GET /device/sign-in":
|
|
2233
|
+
this.deviceSignIn(res, url.searchParams);
|
|
2234
|
+
return true;
|
|
2235
|
+
case "GET /device/complete":
|
|
2236
|
+
this.deviceComplete(res, url.searchParams);
|
|
2237
|
+
return true;
|
|
2238
|
+
case "POST /device/deny":
|
|
2239
|
+
this.deviceDeny(res, await readBody());
|
|
2240
|
+
return true;
|
|
2241
|
+
case "POST /oauth2/introspect":
|
|
2242
|
+
await this.introspect(req, res, await readBody());
|
|
2243
|
+
return true;
|
|
2244
|
+
case "POST /oauth2/register":
|
|
2245
|
+
this.register(res, await readJson2());
|
|
2246
|
+
return true;
|
|
2204
2247
|
case "GET /oauth2/auth":
|
|
2205
2248
|
this.authorize(res, url.searchParams);
|
|
2206
2249
|
return true;
|
|
@@ -2348,8 +2391,14 @@ var AuthorizationServer = class {
|
|
|
2348
2391
|
} else if (grantType === "refresh_token") {
|
|
2349
2392
|
grant = this.redeemRefreshToken(form2, clientId);
|
|
2350
2393
|
this.observe("session.refresh");
|
|
2394
|
+
} else if (grantType === DEVICE_CODE_GRANT) {
|
|
2395
|
+
grant = this.pollDevice(form2, clientId);
|
|
2351
2396
|
} else {
|
|
2352
|
-
throw new OAuthError(
|
|
2397
|
+
throw new OAuthError(
|
|
2398
|
+
400,
|
|
2399
|
+
"unsupported_grant_type",
|
|
2400
|
+
`kinde-testkit supports authorization_code, refresh_token, client_credentials and ${DEVICE_CODE_GRANT}, not "${grantType ?? ""}".`
|
|
2401
|
+
);
|
|
2353
2402
|
}
|
|
2354
2403
|
sendJson(res, 200, await this.issueTokens(grant));
|
|
2355
2404
|
} catch (error) {
|
|
@@ -2367,6 +2416,7 @@ var AuthorizationServer = class {
|
|
|
2367
2416
|
const requested = (form2.scope ?? "").split(/\s+/).filter(Boolean);
|
|
2368
2417
|
const granted = app?.scopes ? requested.length === 0 ? [...app.scopes] : requested.filter((scope) => app.scopes.includes(scope)) : requested;
|
|
2369
2418
|
const audience = (form2.audience ?? "").split(/\s+/).filter(Boolean);
|
|
2419
|
+
this.checkAudience(app?.audience ?? null, audience);
|
|
2370
2420
|
return {
|
|
2371
2421
|
access_token: await this.testkit.m2mToken({
|
|
2372
2422
|
clientId,
|
|
@@ -2385,6 +2435,201 @@ var AuthorizationServer = class {
|
|
|
2385
2435
|
this.codes.clear();
|
|
2386
2436
|
this.refreshTokens.clear();
|
|
2387
2437
|
this.signedUpUsers.clear();
|
|
2438
|
+
this.devices.clear();
|
|
2439
|
+
this.registeredClients.clear();
|
|
2440
|
+
}
|
|
2441
|
+
/** A seeded application that lists audiences may only ask for those, as in Kinde, where each API must be authorized for the app. */
|
|
2442
|
+
checkAudience(allowed, requested) {
|
|
2443
|
+
if (!allowed) return;
|
|
2444
|
+
const refused = requested.find((audience) => !allowed.includes(audience));
|
|
2445
|
+
if (refused) {
|
|
2446
|
+
throw new OAuthError(
|
|
2447
|
+
400,
|
|
2448
|
+
"invalid_request",
|
|
2449
|
+
`The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Requested audience '${refused}' has not been whitelisted by the OAuth 2.0 Client.`
|
|
2450
|
+
);
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
deviceAuthorization(res, form2) {
|
|
2454
|
+
try {
|
|
2455
|
+
const clientId = form2.client_id || DEFAULT_CLIENT_ID;
|
|
2456
|
+
const audience = (form2.audience ?? "").split(/\s+/).filter(Boolean);
|
|
2457
|
+
const app = this.seed.applications.find((a) => a.clientId === clientId);
|
|
2458
|
+
this.checkAudience(app?.audience ?? null, audience);
|
|
2459
|
+
const interval = this.deviceOptions.intervalSeconds ?? 5;
|
|
2460
|
+
const expiresIn = this.deviceOptions.expiresInSeconds ?? 600;
|
|
2461
|
+
const device = {
|
|
2462
|
+
deviceCode: `kinde_dc_${randomToken()}`,
|
|
2463
|
+
userCode: userCode(),
|
|
2464
|
+
clientId,
|
|
2465
|
+
scope: (form2.scope ?? "").split(/\s+/).filter(Boolean),
|
|
2466
|
+
audience,
|
|
2467
|
+
expiresAt: Date.now() + expiresIn * 1e3,
|
|
2468
|
+
interval,
|
|
2469
|
+
lastPollAt: 0,
|
|
2470
|
+
status: "pending",
|
|
2471
|
+
grant: null
|
|
2472
|
+
};
|
|
2473
|
+
this.devices.set(device.deviceCode, device);
|
|
2474
|
+
this.observe("session.device");
|
|
2475
|
+
const verification = `${this.testkit.issuer}/device`;
|
|
2476
|
+
sendJson(res, 200, {
|
|
2477
|
+
device_code: device.deviceCode,
|
|
2478
|
+
user_code: device.userCode,
|
|
2479
|
+
verification_uri: verification,
|
|
2480
|
+
verification_uri_complete: `${verification}?user_code=${device.userCode}`,
|
|
2481
|
+
expires_in: expiresIn,
|
|
2482
|
+
interval
|
|
2483
|
+
});
|
|
2484
|
+
} catch (error) {
|
|
2485
|
+
if (error instanceof OAuthError) return sendJson(res, error.status, { error: error.error, error_description: error.message });
|
|
2486
|
+
throw error;
|
|
2487
|
+
}
|
|
2488
|
+
}
|
|
2489
|
+
findDevice(userCode2) {
|
|
2490
|
+
const wanted = (userCode2 ?? "").toUpperCase().replace(/[^A-Z]/g, "");
|
|
2491
|
+
for (const device of this.devices.values()) {
|
|
2492
|
+
if (device.userCode === wanted && device.status === "pending" && device.expiresAt > Date.now()) return device;
|
|
2493
|
+
}
|
|
2494
|
+
return null;
|
|
2495
|
+
}
|
|
2496
|
+
devicePage(res, params) {
|
|
2497
|
+
const code = params.get("user_code");
|
|
2498
|
+
if (!code) return sendHtml(res, 200, renderDeviceCodeEntry());
|
|
2499
|
+
const device = this.findDevice(code);
|
|
2500
|
+
if (!device) return sendHtml(res, 400, renderDeviceCodeEntry({ userCode: code, error: "That code is unknown, expired or already used." }));
|
|
2501
|
+
sendHtml(res, 200, renderDeviceConfirm({ userCode: device.userCode, clientId: device.clientId }));
|
|
2502
|
+
}
|
|
2503
|
+
deviceSignIn(res, params) {
|
|
2504
|
+
const device = this.findDevice(params.get("user_code"));
|
|
2505
|
+
if (!device) return sendHtml(res, 400, renderDeviceCodeEntry({ error: "That code is unknown, expired or already used." }));
|
|
2506
|
+
const request = {
|
|
2507
|
+
clientId: device.clientId,
|
|
2508
|
+
redirectUri: `${this.testkit.issuer}/device/complete?user_code=${device.userCode}`,
|
|
2509
|
+
state: null,
|
|
2510
|
+
scope: device.scope,
|
|
2511
|
+
nonce: null,
|
|
2512
|
+
audience: device.audience,
|
|
2513
|
+
orgCode: null,
|
|
2514
|
+
loginHint: params.get("login_hint"),
|
|
2515
|
+
codeChallenge: null,
|
|
2516
|
+
codeChallengeMethod: null
|
|
2517
|
+
};
|
|
2518
|
+
sendHtml(res, 200, renderSignIn({ request: encodeRequest(request), users: this.loginPageUsers(), loginHint: request.loginHint ?? void 0 }));
|
|
2519
|
+
}
|
|
2520
|
+
deviceComplete(res, params) {
|
|
2521
|
+
const device = this.findDevice(params.get("user_code"));
|
|
2522
|
+
const pending = this.codes.get(params.get("code") ?? "");
|
|
2523
|
+
this.codes.delete(params.get("code") ?? "");
|
|
2524
|
+
if (!device || !pending || pending.clientId !== device.clientId) {
|
|
2525
|
+
return sendHtml(res, 400, renderMessage("Device not connected", "The code expired or was already used. Start again on the device."));
|
|
2526
|
+
}
|
|
2527
|
+
device.status = "approved";
|
|
2528
|
+
device.grant = { ...pending, scope: device.scope, audience: device.audience };
|
|
2529
|
+
sendHtml(res, 200, renderMessage("Device connected", "You can go back to your device. It signs in the next time it checks."));
|
|
2530
|
+
}
|
|
2531
|
+
deviceDeny(res, form2) {
|
|
2532
|
+
const device = this.findDevice(form2.user_code);
|
|
2533
|
+
if (device) device.status = "denied";
|
|
2534
|
+
sendHtml(res, 200, renderMessage("Device denied", "The device will not be signed in."));
|
|
2535
|
+
}
|
|
2536
|
+
/** Approves or denies a device without a browser. Used by POST /testkit/device. */
|
|
2537
|
+
resolveDevice(input) {
|
|
2538
|
+
const device = this.findDevice(input.userCode);
|
|
2539
|
+
if (!device) throw new OAuthError(400, "invalid_request", `No pending device has the user code "${input.userCode}".`);
|
|
2540
|
+
if (input.deny) {
|
|
2541
|
+
device.status = "denied";
|
|
2542
|
+
return;
|
|
2543
|
+
}
|
|
2544
|
+
if (!input.user) throw new OAuthError(400, "invalid_request", "Pass the user who approves the device.");
|
|
2545
|
+
const scenario2 = seedScenario(this.seed, { user: input.user, organization: input.organization ?? void 0 });
|
|
2546
|
+
device.status = "approved";
|
|
2547
|
+
device.grant = {
|
|
2548
|
+
clientId: device.clientId,
|
|
2549
|
+
scenario: scenario2,
|
|
2550
|
+
scope: device.scope,
|
|
2551
|
+
audience: device.audience,
|
|
2552
|
+
nonce: null,
|
|
2553
|
+
authTime: Math.floor(Date.now() / 1e3)
|
|
2554
|
+
};
|
|
2555
|
+
}
|
|
2556
|
+
pollDevice(form2, clientId) {
|
|
2557
|
+
const device = this.devices.get(form2.device_code ?? "");
|
|
2558
|
+
if (!device || device.clientId !== clientId) {
|
|
2559
|
+
throw new OAuthError(400, "invalid_grant", "The device code is unknown or was issued to a different client.");
|
|
2560
|
+
}
|
|
2561
|
+
if (device.expiresAt <= Date.now()) {
|
|
2562
|
+
this.devices.delete(device.deviceCode);
|
|
2563
|
+
throw new OAuthError(400, "expired_token", "The device code has expired. Request a new one.");
|
|
2564
|
+
}
|
|
2565
|
+
if (device.status === "denied") {
|
|
2566
|
+
this.devices.delete(device.deviceCode);
|
|
2567
|
+
throw new OAuthError(400, "access_denied", "The user denied the device.");
|
|
2568
|
+
}
|
|
2569
|
+
if (device.status === "pending") {
|
|
2570
|
+
const now = Date.now();
|
|
2571
|
+
const tooSoon = device.lastPollAt > 0 && now - device.lastPollAt < device.interval * 1e3;
|
|
2572
|
+
device.lastPollAt = now;
|
|
2573
|
+
if (tooSoon) {
|
|
2574
|
+
device.interval += 5;
|
|
2575
|
+
throw new OAuthError(400, "slow_down", `Poll at most every ${device.interval} seconds.`);
|
|
2576
|
+
}
|
|
2577
|
+
throw new OAuthError(400, "authorization_pending", "The user has not finished signing in.");
|
|
2578
|
+
}
|
|
2579
|
+
this.devices.delete(device.deviceCode);
|
|
2580
|
+
this.observe("session.device-approved");
|
|
2581
|
+
return device.grant;
|
|
2582
|
+
}
|
|
2583
|
+
async introspect(req, res, form2) {
|
|
2584
|
+
const header = req.headers.authorization ?? "";
|
|
2585
|
+
if (!header.startsWith("Bearer ")) {
|
|
2586
|
+
return sendJson(res, 401, { error: "request_unauthorized", error_description: "The request could not be authorized. HTTP Authorization header missing." });
|
|
2587
|
+
}
|
|
2588
|
+
const bearer = header.slice(7);
|
|
2589
|
+
const token = form2.token ?? "";
|
|
2590
|
+
if (bearer === token) {
|
|
2591
|
+
return sendJson(res, 401, { error: "request_unauthorized", error_description: "The request could not be authorized. Bearer and introspection token are identical." });
|
|
2592
|
+
}
|
|
2593
|
+
try {
|
|
2594
|
+
await this.testkit.verify(bearer);
|
|
2595
|
+
} catch {
|
|
2596
|
+
return sendJson(res, 401, { error: "request_unauthorized", error_description: "The request could not be authorized. The Bearer token is not valid for this issuer." });
|
|
2597
|
+
}
|
|
2598
|
+
if (!token) return sendJson(res, 400, { error: "invalid_request", error_description: "Send the token to introspect in the token field." });
|
|
2599
|
+
this.observe("token.introspect");
|
|
2600
|
+
const refresh = this.refreshTokens.get(token);
|
|
2601
|
+
if (refresh) return sendJson(res, 200, { active: true, client_id: refresh.clientId });
|
|
2602
|
+
try {
|
|
2603
|
+
const claims = await this.testkit.verify(token);
|
|
2604
|
+
const aud = claims.aud === void 0 ? [] : Array.isArray(claims.aud) ? claims.aud : [claims.aud];
|
|
2605
|
+
sendJson(res, 200, { active: true, aud, client_id: claims.azp ?? null, exp: claims.exp, iat: claims.iat });
|
|
2606
|
+
} catch {
|
|
2607
|
+
sendJson(res, 200, { active: false });
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2610
|
+
/** OAuth dynamic client registration (RFC 7591), which Kinde offers for MCP connectors. */
|
|
2611
|
+
register(res, body) {
|
|
2612
|
+
const input = typeof body === "object" && body !== null && !Array.isArray(body) ? body : {};
|
|
2613
|
+
const redirectUris = Array.isArray(input.redirect_uris) ? input.redirect_uris.filter((uri) => typeof uri === "string") : [];
|
|
2614
|
+
if (redirectUris.length === 0 || !redirectUris.every(isHttpUrl)) {
|
|
2615
|
+
return sendJson(res, 400, { error: "invalid_redirect_uri", error_description: "Redirect URI is not allowed for MCP connector registration" });
|
|
2616
|
+
}
|
|
2617
|
+
const client = {
|
|
2618
|
+
client_id: (0, import_node_crypto4.randomBytes)(16).toString("hex"),
|
|
2619
|
+
client_id_issued_at: Math.floor(Date.now() / 1e3),
|
|
2620
|
+
...typeof input.client_name === "string" ? { client_name: input.client_name } : {},
|
|
2621
|
+
redirect_uris: redirectUris,
|
|
2622
|
+
grant_types: ["authorization_code", "refresh_token"],
|
|
2623
|
+
response_types: ["code"],
|
|
2624
|
+
token_endpoint_auth_method: "none"
|
|
2625
|
+
};
|
|
2626
|
+
this.registeredClients.set(client.client_id, client);
|
|
2627
|
+
this.observe("session.register");
|
|
2628
|
+
sendJson(res, 201, client);
|
|
2629
|
+
}
|
|
2630
|
+
/** Clients registered through /oauth2/register since the last reset. */
|
|
2631
|
+
registrations() {
|
|
2632
|
+
return [...this.registeredClients.values()];
|
|
2388
2633
|
}
|
|
2389
2634
|
redeemCode(form2, clientId) {
|
|
2390
2635
|
const code = form2.code ?? "";
|
|
@@ -2589,6 +2834,9 @@ function isHttpUrl(value) {
|
|
|
2589
2834
|
return false;
|
|
2590
2835
|
}
|
|
2591
2836
|
}
|
|
2837
|
+
function userCode() {
|
|
2838
|
+
return Array.from((0, import_node_crypto4.randomBytes)(8), (byte) => USER_CODE_ALPHABET[byte % USER_CODE_ALPHABET.length]).join("");
|
|
2839
|
+
}
|
|
2592
2840
|
function randomToken() {
|
|
2593
2841
|
return (0, import_node_crypto4.randomBytes)(32).toString("base64url");
|
|
2594
2842
|
}
|
|
@@ -3778,7 +4026,8 @@ var COVERAGE_GROUPS = [
|
|
|
3778
4026
|
{ id: "session.refresh", label: "Refresh", hint: "Let the app refresh its session, or call the refresh_token grant." },
|
|
3779
4027
|
{ id: "session.sign-out", label: "Sign-out", hint: "Sign out through your app's logout route." },
|
|
3780
4028
|
{ id: "session.revoke", label: "Refresh token revoked", hint: "Call /oauth2/revoke, as some SDKs do on sign-out." },
|
|
3781
|
-
{ id: "session.silent", label: "Silent sign-in with no session", hint: "Send prompt=none and handle login_required." }
|
|
4029
|
+
{ id: "session.silent", label: "Silent sign-in with no session", hint: "Send prompt=none and handle login_required." },
|
|
4030
|
+
{ id: "session.device-approved", label: "Device sign-in", hint: "Run the device authorization flow and approve it with POST /testkit/device." }
|
|
3782
4031
|
]
|
|
3783
4032
|
},
|
|
3784
4033
|
{
|
|
@@ -4238,7 +4487,7 @@ async function startKindeTestkit(options = {}) {
|
|
|
4238
4487
|
const directory = new Directory(seed);
|
|
4239
4488
|
const webhooks = new WebhookDispatcher(testkit, seed, seed.webhooks, options.webhooks);
|
|
4240
4489
|
webhooks.observe = observe;
|
|
4241
|
-
const auth = new AuthorizationServer(testkit, seed, (type, user) => webhooks.emitForUser(type, user), directory, observe);
|
|
4490
|
+
const auth = new AuthorizationServer(testkit, seed, (type, user) => webhooks.emitForUser(type, user), directory, observe, options.device);
|
|
4242
4491
|
const management = new ManagementApi(testkit, directory, webhooks);
|
|
4243
4492
|
const account = new AccountApi(testkit, directory);
|
|
4244
4493
|
const reset = () => {
|
|
@@ -4313,7 +4562,7 @@ async function handle(req, res, context) {
|
|
|
4313
4562
|
}
|
|
4314
4563
|
}
|
|
4315
4564
|
}
|
|
4316
|
-
if (await auth.handle(req, res, url, () => readForm(req))) return;
|
|
4565
|
+
if (await auth.handle(req, res, url, () => readForm(req), () => readJson(req))) return;
|
|
4317
4566
|
if (await context.management.handle(req, res, url, async () => await readJson(req))) {
|
|
4318
4567
|
if (res.statusCode === 401 || res.statusCode === 403) coverage.hit("api.management-denied");
|
|
4319
4568
|
else if (res.statusCode < 400) coverage.hit(method === "GET" ? "api.management-read" : "api.management-write");
|
|
@@ -4373,6 +4622,21 @@ async function handle(req, res, context) {
|
|
|
4373
4622
|
const removed = webhooks.removeEndpoint(decodeURIComponent(pathname.slice("/testkit/webhooks/endpoints/".length)));
|
|
4374
4623
|
return sendJson4(res, removed ? 200 : 404, { ok: removed });
|
|
4375
4624
|
}
|
|
4625
|
+
if (method === "POST" && pathname === "/testkit/device") {
|
|
4626
|
+
const input = await readJson(req);
|
|
4627
|
+
try {
|
|
4628
|
+
auth.resolveDevice({
|
|
4629
|
+
userCode: String(input.user_code ?? ""),
|
|
4630
|
+
user: typeof input.user === "string" ? input.user : void 0,
|
|
4631
|
+
organization: typeof input.organization === "string" ? input.organization : null,
|
|
4632
|
+
deny: input.action === "deny"
|
|
4633
|
+
});
|
|
4634
|
+
} catch (error) {
|
|
4635
|
+
if (error instanceof OAuthError) return sendJson4(res, error.status, { error: error.error, error_description: error.message });
|
|
4636
|
+
throw error;
|
|
4637
|
+
}
|
|
4638
|
+
return sendJson4(res, 200, { ok: true });
|
|
4639
|
+
}
|
|
4376
4640
|
if (method === "POST" && pathname === "/testkit/reset") {
|
|
4377
4641
|
context.reset();
|
|
4378
4642
|
return sendJson4(res, 200, { ok: true });
|
|
@@ -4496,20 +4760,26 @@ function discovery(testkit) {
|
|
|
4496
4760
|
const base = testkit.issuer;
|
|
4497
4761
|
return {
|
|
4498
4762
|
issuer: base,
|
|
4499
|
-
|
|
4763
|
+
jwks_uri: `${base}/.well-known/jwks`,
|
|
4500
4764
|
token_endpoint: `${base}/oauth2/token`,
|
|
4765
|
+
claims_supported: ["aud", "exp", "iat", "iss", "sub", "acr", "amr", "auth_time"],
|
|
4766
|
+
scopes_supported: ["address", "email", "offline", "openid", "phone", "profile"],
|
|
4501
4767
|
userinfo_endpoint: `${base}/oauth2/v2/user_profile`,
|
|
4502
|
-
end_session_endpoint: `${base}/logout`,
|
|
4503
4768
|
revocation_endpoint: `${base}/oauth2/revoke`,
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4769
|
+
end_session_endpoint: `${base}/logout`,
|
|
4770
|
+
grant_types_supported: ["authorization_code", "refresh_token", "client_credentials", "urn:ietf:params:oauth:grant-type:device_code"],
|
|
4771
|
+
registration_endpoint: `${base}/oauth2/register`,
|
|
4772
|
+
authorization_endpoint: `${base}/oauth2/auth`,
|
|
4773
|
+
introspection_endpoint: `${base}/oauth2/introspect`,
|
|
4508
4774
|
subject_types_supported: ["public"],
|
|
4775
|
+
response_modes_supported: ["query"],
|
|
4776
|
+
response_types_supported: ["code"],
|
|
4777
|
+
device_authorization_endpoint: `${base}/oauth2/device/auth`,
|
|
4778
|
+
request_uri_parameter_supported: false,
|
|
4779
|
+
code_challenge_methods_supported: ["S256"],
|
|
4780
|
+
client_id_metadata_document_supported: false,
|
|
4509
4781
|
id_token_signing_alg_values_supported: ["RS256"],
|
|
4510
|
-
|
|
4511
|
-
token_endpoint_auth_methods_supported: ["client_secret_post", "client_secret_basic", "none"],
|
|
4512
|
-
claims_supported: ["aud", "exp", "iat", "iss", "sub", "org_code", "permissions", "roles", "scp"]
|
|
4782
|
+
token_endpoint_auth_methods_supported: ["client_secret_post", "none"]
|
|
4513
4783
|
};
|
|
4514
4784
|
}
|
|
4515
4785
|
async function issueToken(testkit, seed, body) {
|
|
@@ -4632,7 +4902,7 @@ function sendError(res, error) {
|
|
|
4632
4902
|
return;
|
|
4633
4903
|
}
|
|
4634
4904
|
if (error instanceof TestkitError) {
|
|
4635
|
-
sendJson4(res, 400, { error: error.code, error_description: error.
|
|
4905
|
+
sendJson4(res, 400, { error: error.code, error_description: error.summary, details: error.details });
|
|
4636
4906
|
return;
|
|
4637
4907
|
}
|
|
4638
4908
|
sendJson4(res, 500, {
|
|
@@ -4914,4 +5184,3 @@ function decodeEntities(value) {
|
|
|
4914
5184
|
startKindeTestkit,
|
|
4915
5185
|
toKindeRole
|
|
4916
5186
|
});
|
|
4917
|
-
//# sourceMappingURL=index.cjs.map
|