kinde-testkit 0.6.1 → 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 +11 -0
- package/README.md +37 -3
- package/dist/{chunk-U2D47SCY.js → chunk-2QJ7DTNL.js} +2 -2
- package/dist/{chunk-GCOZVCZY.js → chunk-JTAB2S44.js} +283 -16
- package/dist/chunk-JTAB2S44.js.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/cypress.cjs +282 -15
- package/dist/cypress.d.cts +1 -1
- package/dist/cypress.d.ts +1 -1
- package/dist/cypress.js +1 -1
- package/dist/{handle-Dh0UpIzG.d.ts → handle-E_BhdHx8.d.ts} +1 -1
- package/dist/{handle-BERQZCyH.d.cts → handle-estfqypp.d.cts} +1 -1
- package/dist/index.cjs +282 -15
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/jest.cjs +282 -15
- package/dist/jest.d.cts +3 -3
- package/dist/jest.d.ts +3 -3
- package/dist/jest.js +2 -2
- package/dist/{server-BiODgeoB.d.ts → server-B9fBcnyQ.d.ts} +10 -1
- package/dist/{server-ciWIscoQ.d.cts → server-CTBJXMac.d.cts} +10 -1
- package/dist/vitest.d.ts +3 -3
- package/dist/vitest.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-GCOZVCZY.js.map +0 -1
- /package/dist/{chunk-U2D47SCY.js.map → chunk-2QJ7DTNL.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -1861,6 +1861,19 @@ function renderOrganizationPicker(options) {
|
|
|
1861
1861
|
function renderMessage(title, message2) {
|
|
1862
1862
|
return layout(title, `<h1>${escapeHtml(title)}</h1><p>${escapeHtml(message2)}</p>`);
|
|
1863
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
|
+
}
|
|
1864
1877
|
|
|
1865
1878
|
// src/seed.ts
|
|
1866
1879
|
function roleRecord(key, extra = {}) {
|
|
@@ -2176,6 +2189,8 @@ function featureFlagsFor(seed, organizationCode) {
|
|
|
2176
2189
|
// src/oauth.ts
|
|
2177
2190
|
var import_node_crypto4 = require("crypto");
|
|
2178
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";
|
|
2179
2194
|
var OAuthError = class extends Error {
|
|
2180
2195
|
constructor(status, error, description) {
|
|
2181
2196
|
super(description);
|
|
@@ -2186,24 +2201,49 @@ var OAuthError = class extends Error {
|
|
|
2186
2201
|
error;
|
|
2187
2202
|
};
|
|
2188
2203
|
var AuthorizationServer = class {
|
|
2189
|
-
constructor(testkit, seed, emit = () => void 0, directory, observe = () => void 0) {
|
|
2204
|
+
constructor(testkit, seed, emit = () => void 0, directory, observe = () => void 0, deviceOptions = {}) {
|
|
2190
2205
|
this.testkit = testkit;
|
|
2191
2206
|
this.seed = seed;
|
|
2192
2207
|
this.emit = emit;
|
|
2193
2208
|
this.directory = directory;
|
|
2194
2209
|
this.observe = observe;
|
|
2210
|
+
this.deviceOptions = deviceOptions;
|
|
2195
2211
|
}
|
|
2196
2212
|
testkit;
|
|
2197
2213
|
seed;
|
|
2198
2214
|
emit;
|
|
2199
2215
|
directory;
|
|
2200
2216
|
observe;
|
|
2217
|
+
deviceOptions;
|
|
2201
2218
|
codes = /* @__PURE__ */ new Map();
|
|
2202
2219
|
refreshTokens = /* @__PURE__ */ new Map();
|
|
2203
2220
|
signedUpUsers = /* @__PURE__ */ new Map();
|
|
2204
|
-
|
|
2221
|
+
devices = /* @__PURE__ */ new Map();
|
|
2222
|
+
registeredClients = /* @__PURE__ */ new Map();
|
|
2223
|
+
async handle(req, res, url, readBody, readJson2 = async () => ({})) {
|
|
2205
2224
|
const method = req.method ?? "GET";
|
|
2206
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;
|
|
2207
2247
|
case "GET /oauth2/auth":
|
|
2208
2248
|
this.authorize(res, url.searchParams);
|
|
2209
2249
|
return true;
|
|
@@ -2351,8 +2391,14 @@ var AuthorizationServer = class {
|
|
|
2351
2391
|
} else if (grantType === "refresh_token") {
|
|
2352
2392
|
grant = this.redeemRefreshToken(form2, clientId);
|
|
2353
2393
|
this.observe("session.refresh");
|
|
2394
|
+
} else if (grantType === DEVICE_CODE_GRANT) {
|
|
2395
|
+
grant = this.pollDevice(form2, clientId);
|
|
2354
2396
|
} else {
|
|
2355
|
-
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
|
+
);
|
|
2356
2402
|
}
|
|
2357
2403
|
sendJson(res, 200, await this.issueTokens(grant));
|
|
2358
2404
|
} catch (error) {
|
|
@@ -2370,6 +2416,7 @@ var AuthorizationServer = class {
|
|
|
2370
2416
|
const requested = (form2.scope ?? "").split(/\s+/).filter(Boolean);
|
|
2371
2417
|
const granted = app?.scopes ? requested.length === 0 ? [...app.scopes] : requested.filter((scope) => app.scopes.includes(scope)) : requested;
|
|
2372
2418
|
const audience = (form2.audience ?? "").split(/\s+/).filter(Boolean);
|
|
2419
|
+
this.checkAudience(app?.audience ?? null, audience);
|
|
2373
2420
|
return {
|
|
2374
2421
|
access_token: await this.testkit.m2mToken({
|
|
2375
2422
|
clientId,
|
|
@@ -2388,6 +2435,201 @@ var AuthorizationServer = class {
|
|
|
2388
2435
|
this.codes.clear();
|
|
2389
2436
|
this.refreshTokens.clear();
|
|
2390
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()];
|
|
2391
2633
|
}
|
|
2392
2634
|
redeemCode(form2, clientId) {
|
|
2393
2635
|
const code = form2.code ?? "";
|
|
@@ -2592,6 +2834,9 @@ function isHttpUrl(value) {
|
|
|
2592
2834
|
return false;
|
|
2593
2835
|
}
|
|
2594
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
|
+
}
|
|
2595
2840
|
function randomToken() {
|
|
2596
2841
|
return (0, import_node_crypto4.randomBytes)(32).toString("base64url");
|
|
2597
2842
|
}
|
|
@@ -3781,7 +4026,8 @@ var COVERAGE_GROUPS = [
|
|
|
3781
4026
|
{ id: "session.refresh", label: "Refresh", hint: "Let the app refresh its session, or call the refresh_token grant." },
|
|
3782
4027
|
{ id: "session.sign-out", label: "Sign-out", hint: "Sign out through your app's logout route." },
|
|
3783
4028
|
{ id: "session.revoke", label: "Refresh token revoked", hint: "Call /oauth2/revoke, as some SDKs do on sign-out." },
|
|
3784
|
-
{ 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." }
|
|
3785
4031
|
]
|
|
3786
4032
|
},
|
|
3787
4033
|
{
|
|
@@ -4241,7 +4487,7 @@ async function startKindeTestkit(options = {}) {
|
|
|
4241
4487
|
const directory = new Directory(seed);
|
|
4242
4488
|
const webhooks = new WebhookDispatcher(testkit, seed, seed.webhooks, options.webhooks);
|
|
4243
4489
|
webhooks.observe = observe;
|
|
4244
|
-
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);
|
|
4245
4491
|
const management = new ManagementApi(testkit, directory, webhooks);
|
|
4246
4492
|
const account = new AccountApi(testkit, directory);
|
|
4247
4493
|
const reset = () => {
|
|
@@ -4316,7 +4562,7 @@ async function handle(req, res, context) {
|
|
|
4316
4562
|
}
|
|
4317
4563
|
}
|
|
4318
4564
|
}
|
|
4319
|
-
if (await auth.handle(req, res, url, () => readForm(req))) return;
|
|
4565
|
+
if (await auth.handle(req, res, url, () => readForm(req), () => readJson(req))) return;
|
|
4320
4566
|
if (await context.management.handle(req, res, url, async () => await readJson(req))) {
|
|
4321
4567
|
if (res.statusCode === 401 || res.statusCode === 403) coverage.hit("api.management-denied");
|
|
4322
4568
|
else if (res.statusCode < 400) coverage.hit(method === "GET" ? "api.management-read" : "api.management-write");
|
|
@@ -4376,6 +4622,21 @@ async function handle(req, res, context) {
|
|
|
4376
4622
|
const removed = webhooks.removeEndpoint(decodeURIComponent(pathname.slice("/testkit/webhooks/endpoints/".length)));
|
|
4377
4623
|
return sendJson4(res, removed ? 200 : 404, { ok: removed });
|
|
4378
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
|
+
}
|
|
4379
4640
|
if (method === "POST" && pathname === "/testkit/reset") {
|
|
4380
4641
|
context.reset();
|
|
4381
4642
|
return sendJson4(res, 200, { ok: true });
|
|
@@ -4499,20 +4760,26 @@ function discovery(testkit) {
|
|
|
4499
4760
|
const base = testkit.issuer;
|
|
4500
4761
|
return {
|
|
4501
4762
|
issuer: base,
|
|
4502
|
-
|
|
4763
|
+
jwks_uri: `${base}/.well-known/jwks`,
|
|
4503
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"],
|
|
4504
4767
|
userinfo_endpoint: `${base}/oauth2/v2/user_profile`,
|
|
4505
|
-
end_session_endpoint: `${base}/logout`,
|
|
4506
4768
|
revocation_endpoint: `${base}/oauth2/revoke`,
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
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`,
|
|
4511
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,
|
|
4512
4781
|
id_token_signing_alg_values_supported: ["RS256"],
|
|
4513
|
-
|
|
4514
|
-
token_endpoint_auth_methods_supported: ["client_secret_post", "client_secret_basic", "none"],
|
|
4515
|
-
claims_supported: ["aud", "exp", "iat", "iss", "sub", "org_code", "permissions", "roles", "scp"]
|
|
4782
|
+
token_endpoint_auth_methods_supported: ["client_secret_post", "none"]
|
|
4516
4783
|
};
|
|
4517
4784
|
}
|
|
4518
4785
|
async function issueToken(testkit, seed, body) {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { K as KindeOrganization, a as KindeUser, b as KindeMembership, c as KindeRole, A as AuthenticatedScenario, U as UnauthenticatedScenario, d as Scenario, T as TestkitSeed } from './server-
|
|
2
|
-
export { e as ActiveFailure, f as ActivityLog, B as BILLING_EVENT_TYPES, C as COVERAGE_GROUPS, g as CoverageGroup, h as CoverageGroupResult, i as CoverageItem, j as CoverageRecorder, k as CoverageReport, l as CoverageSnapshot, D as DEFAULT_AUTH_METHODS, m as DEFAULT_CLIENT_ID, n as DEFAULT_COVERAGE_DIRECTORY, o as DEFAULT_ISSUER, p as DEFAULT_M2M_CLIENT_ID, q as DEFAULT_SCOPES, r as
|
|
1
|
+
import { K as KindeOrganization, a as KindeUser, b as KindeMembership, c as KindeRole, A as AuthenticatedScenario, U as UnauthenticatedScenario, d as Scenario, T as TestkitSeed } from './server-CTBJXMac.cjs';
|
|
2
|
+
export { e as ActiveFailure, f as ActivityLog, B as BILLING_EVENT_TYPES, C as COVERAGE_GROUPS, g as CoverageGroup, h as CoverageGroupResult, i as CoverageItem, j as CoverageRecorder, k as CoverageReport, l as CoverageSnapshot, D as DEFAULT_AUTH_METHODS, m as DEFAULT_CLIENT_ID, n as DEFAULT_COVERAGE_DIRECTORY, o as DEFAULT_ISSUER, p as DEFAULT_M2M_CLIENT_ID, q as DEFAULT_SCOPES, r as DeviceFlowOptions, s as Directory, t as Duration, F as FailureInjector, u as FailureRule, I as INVALID_TOKEN_KINDS, v as IdTokenOptions, w as InvalidTokenKind, x as KindeApplication, y as KindePrincipal, z as KindeTestkit, E as KindeTestkitOptions, G as KindeTokenOptions, M as M2MTokenOptions, R as RequestEntry, H as ResolvedSeed, J as RunningKindeTestkit, L as ScenarioTokenOverrides, N as SendWebhookOptions, S as StartKindeTestkitOptions, O as TokenEntry, P as TokenObserver, W as WEBHOOK_EVENT_TYPES, Q as WebhookAttempt, V as WebhookDelivery, X as WebhookDispatcher, Y as WebhookEndpoint, Z as WebhookEndpointInput, _ as WebhookInvalidKind, $ as WebhookOptions, a0 as WebhookSource, a1 as buildReport, a2 as clearCoverageDirectory, a3 as createKindeToken, a4 as formatCoverageReport, a5 as getDefaultTestkit, a6 as mergeSnapshots, a7 as principalFromClaims, a8 as readCoverageDirectory, a9 as resolveSeed, aa as seedScenario, ab as startKindeTestkit } from './server-CTBJXMac.cjs';
|
|
3
3
|
import { ProtectedHeaderParameters, JWTPayload } from 'jose';
|
|
4
|
-
export { K as KindeTestAuth, a as KindeTestkitHandle, k as kindeTest } from './handle-
|
|
4
|
+
export { K as KindeTestAuth, a as KindeTestkitHandle, k as kindeTest } from './handle-estfqypp.cjs';
|
|
5
5
|
|
|
6
6
|
interface CreateKindeUserOptions {
|
|
7
7
|
id?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { K as KindeOrganization, a as KindeUser, b as KindeMembership, c as KindeRole, A as AuthenticatedScenario, U as UnauthenticatedScenario, S as Scenario, T as TestkitSeed } from './webhooks-DJyCsbdF.js';
|
|
2
2
|
export { d as ActiveFailure, B as BILLING_EVENT_TYPES, D as DEFAULT_AUTH_METHODS, e as DEFAULT_CLIENT_ID, f as DEFAULT_ISSUER, g as DEFAULT_M2M_CLIENT_ID, h as DEFAULT_SCOPES, i as Duration, F as FailureInjector, j as FailureRule, I as INVALID_TOKEN_KINDS, k as IdTokenOptions, l as InvalidTokenKind, m as KindeApplication, n as KindePrincipal, o as KindeTestkit, p as KindeTestkitOptions, q as KindeTokenOptions, M as M2MTokenOptions, R as ResolvedSeed, r as ScenarioTokenOverrides, s as SendWebhookOptions, t as TokenObserver, W as WEBHOOK_EVENT_TYPES, u as WebhookAttempt, v as WebhookDelivery, w as WebhookDispatcher, x as WebhookEndpoint, y as WebhookEndpointInput, z as WebhookInvalidKind, C as WebhookOptions, E as WebhookSource, G as createKindeToken, H as getDefaultTestkit, J as principalFromClaims, L as resolveSeed, N as seedScenario } from './webhooks-DJyCsbdF.js';
|
|
3
|
-
export { A as ActivityLog, C as COVERAGE_GROUPS, a as CoverageGroup, b as CoverageGroupResult, c as CoverageItem, d as CoverageRecorder, e as CoverageReport, f as CoverageSnapshot, D as DEFAULT_COVERAGE_DIRECTORY, g as Directory, R as RequestEntry,
|
|
3
|
+
export { A as ActivityLog, C as COVERAGE_GROUPS, a as CoverageGroup, b as CoverageGroupResult, c as CoverageItem, d as CoverageRecorder, e as CoverageReport, f as CoverageSnapshot, D as DEFAULT_COVERAGE_DIRECTORY, g as DeviceFlowOptions, h as Directory, R as RequestEntry, i as RunningKindeTestkit, S as StartKindeTestkitOptions, T as TokenEntry, j as buildReport, k as clearCoverageDirectory, l as formatCoverageReport, m as mergeSnapshots, r as readCoverageDirectory, s as startKindeTestkit } from './server-B9fBcnyQ.js';
|
|
4
4
|
import { ProtectedHeaderParameters, JWTPayload } from 'jose';
|
|
5
|
-
export { K as KindeTestAuth, a as KindeTestkitHandle, k as kindeTest } from './handle-
|
|
5
|
+
export { K as KindeTestAuth, a as KindeTestkitHandle, k as kindeTest } from './handle-E_BhdHx8.js';
|
|
6
6
|
|
|
7
7
|
interface CreateKindeUserOptions {
|
|
8
8
|
id?: string;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
kindeTest
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-2QJ7DTNL.js";
|
|
4
4
|
import {
|
|
5
5
|
inspectToken,
|
|
6
6
|
parseEnvFile,
|
|
@@ -45,7 +45,7 @@ import {
|
|
|
45
45
|
seedScenario,
|
|
46
46
|
startKindeTestkit,
|
|
47
47
|
toKindeRole
|
|
48
|
-
} from "./chunk-
|
|
48
|
+
} from "./chunk-JTAB2S44.js";
|
|
49
49
|
|
|
50
50
|
// src/scenario.ts
|
|
51
51
|
var ScenarioBuilder = class {
|