kinde-testkit 0.6.1 → 0.7.1

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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getDefaultTestkit,
3
3
  startKindeTestkit
4
- } from "./chunk-GCOZVCZY.js";
4
+ } from "./chunk-IOP27RQ5.js";
5
5
 
6
6
  // src/handle.ts
7
7
  async function kindeTest(options) {
@@ -69,4 +69,4 @@ export {
69
69
  kindeTest,
70
70
  createKindeTestkitHandle
71
71
  };
72
- //# sourceMappingURL=chunk-U2D47SCY.js.map
72
+ //# sourceMappingURL=chunk-K5YNZAOM.js.map
package/dist/cli.js CHANGED
@@ -15,7 +15,7 @@ import {
15
15
  loadSeedFile,
16
16
  readCoverageDirectory,
17
17
  startKindeTestkit
18
- } from "./chunk-GCOZVCZY.js";
18
+ } from "./chunk-IOP27RQ5.js";
19
19
 
20
20
  // src/cli.ts
21
21
  import { spawnSync } from "child_process";
@@ -0,0 +1,98 @@
1
+ interface FailureRule {
2
+ path: string;
3
+ method?: string;
4
+ status?: number;
5
+ delayMs?: number;
6
+ hang?: boolean;
7
+ times?: number;
8
+ retryAfter?: number;
9
+ }
10
+ interface ActiveFailure {
11
+ id: string;
12
+ path: string;
13
+ method: string | null;
14
+ status: number | null;
15
+ delayMs: number;
16
+ hang: boolean;
17
+ remaining: number | null;
18
+ retryAfter: number;
19
+ hits: number;
20
+ }
21
+
22
+ type WebhookInvalidKind = "bad-signature" | "unknown-key" | "unsigned" | "stale";
23
+ type WebhookSource = "admin" | "api" | "user";
24
+ interface SendWebhookOptions {
25
+ type: string;
26
+ data?: Record<string, unknown>;
27
+ user?: string;
28
+ organization?: string;
29
+ role?: string;
30
+ permission?: string;
31
+ source?: WebhookSource;
32
+ ipAddress?: string;
33
+ to?: string;
34
+ duplicate?: number;
35
+ delayMs?: number;
36
+ invalid?: WebhookInvalidKind;
37
+ }
38
+ interface WebhookAttempt {
39
+ attempt: number;
40
+ status: number | null;
41
+ error: string | null;
42
+ durationMs: number;
43
+ }
44
+ interface WebhookDelivery {
45
+ webhookId: string;
46
+ eventId: string;
47
+ type: string;
48
+ url: string;
49
+ copy: number;
50
+ delivered: boolean;
51
+ attempts: WebhookAttempt[];
52
+ payload: Record<string, unknown>;
53
+ }
54
+
55
+ interface KindeSignInOptions {
56
+ /** Active organization, for users in more than one. */
57
+ org?: string;
58
+ /** Your app's login route. Default /api/auth/login, as in Kinde's Next.js SDK. */
59
+ loginPath?: string;
60
+ }
61
+ interface KindeSignOutOptions {
62
+ /** Your app's logout route. Default /api/auth/logout. */
63
+ logoutPath?: string;
64
+ }
65
+ interface KindeTokenRequest {
66
+ user?: string;
67
+ organization?: string;
68
+ subject?: string;
69
+ permissions?: string[];
70
+ roles?: string[];
71
+ expiresIn?: string | number;
72
+ invalid?: string;
73
+ m2m?: boolean;
74
+ clientId?: string;
75
+ scopes?: string[];
76
+ }
77
+ declare global {
78
+ namespace Cypress {
79
+ interface Chainable<Subject = any> {
80
+ /** Signs a seeded user in through your app's login route, with requests instead of the sign-in page. */
81
+ kindeSignIn(user: string, options?: KindeSignInOptions): Chainable<void>;
82
+ /** Opens your app's logout route. */
83
+ kindeSignOut(options?: KindeSignOutOptions): Chainable<void>;
84
+ /** Mints an access token from the testkit. */
85
+ kindeToken(options: KindeTokenRequest): Chainable<string>;
86
+ /** Makes a testkit endpoint fail, slow down or hang until the test ends. */
87
+ kindeInjectFailure(rule: FailureRule): Chainable<ActiveFailure>;
88
+ /** Removes the failures this test added. */
89
+ kindeClearFailures(): Chainable<void>;
90
+ /** Sends a signed webhook and yields the deliveries. */
91
+ kindeSendWebhook(options: SendWebhookOptions): Chainable<WebhookDelivery[]>;
92
+ /** Clears sessions, failures, webhook deliveries and Management API changes. */
93
+ kindeReset(): Chainable<void>;
94
+ }
95
+ }
96
+ }
97
+
98
+ export type { KindeSignInOptions, KindeSignOutOptions, KindeTokenRequest };
package/dist/cypress.cjs CHANGED
@@ -1495,6 +1495,19 @@ function renderOrganizationPicker(options) {
1495
1495
  function renderMessage(title, message2) {
1496
1496
  return layout(title, `<h1>${escapeHtml(title)}</h1><p>${escapeHtml(message2)}</p>`);
1497
1497
  }
1498
+ function renderDeviceCodeEntry(options = {}) {
1499
+ return layout(
1500
+ "Connect a device",
1501
+ `<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>`
1502
+ );
1503
+ }
1504
+ function renderDeviceConfirm(options) {
1505
+ const code = escapeHtml(options.userCode);
1506
+ return layout(
1507
+ "Connect a device",
1508
+ `<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>`
1509
+ );
1510
+ }
1498
1511
 
1499
1512
  // src/seed.ts
1500
1513
  function roleRecord(key, extra = {}) {
@@ -1810,6 +1823,8 @@ function featureFlagsFor(seed, organizationCode) {
1810
1823
  // src/oauth.ts
1811
1824
  var import_node_crypto4 = require("crypto");
1812
1825
  var CODE_LIFETIME_MS = 10 * 60 * 1e3;
1826
+ var DEVICE_CODE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
1827
+ var USER_CODE_ALPHABET = "BCDFGHJKLMNPQRSTVWXZ";
1813
1828
  var OAuthError = class extends Error {
1814
1829
  constructor(status, error, description) {
1815
1830
  super(description);
@@ -1820,24 +1835,49 @@ var OAuthError = class extends Error {
1820
1835
  error;
1821
1836
  };
1822
1837
  var AuthorizationServer = class {
1823
- constructor(testkit, seed, emit = () => void 0, directory, observe = () => void 0) {
1838
+ constructor(testkit, seed, emit = () => void 0, directory, observe = () => void 0, deviceOptions = {}) {
1824
1839
  this.testkit = testkit;
1825
1840
  this.seed = seed;
1826
1841
  this.emit = emit;
1827
1842
  this.directory = directory;
1828
1843
  this.observe = observe;
1844
+ this.deviceOptions = deviceOptions;
1829
1845
  }
1830
1846
  testkit;
1831
1847
  seed;
1832
1848
  emit;
1833
1849
  directory;
1834
1850
  observe;
1851
+ deviceOptions;
1835
1852
  codes = /* @__PURE__ */ new Map();
1836
1853
  refreshTokens = /* @__PURE__ */ new Map();
1837
1854
  signedUpUsers = /* @__PURE__ */ new Map();
1838
- async handle(req, res, url, readBody) {
1855
+ devices = /* @__PURE__ */ new Map();
1856
+ registeredClients = /* @__PURE__ */ new Map();
1857
+ async handle(req, res, url, readBody, readJson2 = async () => ({})) {
1839
1858
  const method = req.method ?? "GET";
1840
1859
  switch (`${method} ${url.pathname}`) {
1860
+ case "POST /oauth2/device/auth":
1861
+ this.deviceAuthorization(res, await readBody());
1862
+ return true;
1863
+ case "GET /device":
1864
+ this.devicePage(res, url.searchParams);
1865
+ return true;
1866
+ case "GET /device/sign-in":
1867
+ this.deviceSignIn(res, url.searchParams);
1868
+ return true;
1869
+ case "GET /device/complete":
1870
+ this.deviceComplete(res, url.searchParams);
1871
+ return true;
1872
+ case "POST /device/deny":
1873
+ this.deviceDeny(res, await readBody());
1874
+ return true;
1875
+ case "POST /oauth2/introspect":
1876
+ await this.introspect(req, res, await readBody());
1877
+ return true;
1878
+ case "POST /oauth2/register":
1879
+ this.register(res, await readJson2());
1880
+ return true;
1841
1881
  case "GET /oauth2/auth":
1842
1882
  this.authorize(res, url.searchParams);
1843
1883
  return true;
@@ -1985,8 +2025,14 @@ var AuthorizationServer = class {
1985
2025
  } else if (grantType === "refresh_token") {
1986
2026
  grant = this.redeemRefreshToken(form2, clientId);
1987
2027
  this.observe("session.refresh");
2028
+ } else if (grantType === DEVICE_CODE_GRANT) {
2029
+ grant = this.pollDevice(form2, clientId);
1988
2030
  } else {
1989
- throw new OAuthError(400, "unsupported_grant_type", `kinde-testkit supports authorization_code, refresh_token and client_credentials, not "${grantType ?? ""}".`);
2031
+ throw new OAuthError(
2032
+ 400,
2033
+ "unsupported_grant_type",
2034
+ `kinde-testkit supports authorization_code, refresh_token, client_credentials and ${DEVICE_CODE_GRANT}, not "${grantType ?? ""}".`
2035
+ );
1990
2036
  }
1991
2037
  sendJson(res, 200, await this.issueTokens(grant));
1992
2038
  } catch (error) {
@@ -2004,6 +2050,7 @@ var AuthorizationServer = class {
2004
2050
  const requested = (form2.scope ?? "").split(/\s+/).filter(Boolean);
2005
2051
  const granted = app?.scopes ? requested.length === 0 ? [...app.scopes] : requested.filter((scope) => app.scopes.includes(scope)) : requested;
2006
2052
  const audience = (form2.audience ?? "").split(/\s+/).filter(Boolean);
2053
+ this.checkAudience(app?.audience ?? null, audience);
2007
2054
  return {
2008
2055
  access_token: await this.testkit.m2mToken({
2009
2056
  clientId,
@@ -2022,6 +2069,201 @@ var AuthorizationServer = class {
2022
2069
  this.codes.clear();
2023
2070
  this.refreshTokens.clear();
2024
2071
  this.signedUpUsers.clear();
2072
+ this.devices.clear();
2073
+ this.registeredClients.clear();
2074
+ }
2075
+ /** A seeded application that lists audiences may only ask for those, as in Kinde, where each API must be authorized for the app. */
2076
+ checkAudience(allowed, requested) {
2077
+ if (!allowed) return;
2078
+ const refused = requested.find((audience) => !allowed.includes(audience));
2079
+ if (refused) {
2080
+ throw new OAuthError(
2081
+ 400,
2082
+ "invalid_request",
2083
+ `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.`
2084
+ );
2085
+ }
2086
+ }
2087
+ deviceAuthorization(res, form2) {
2088
+ try {
2089
+ const clientId = form2.client_id || DEFAULT_CLIENT_ID;
2090
+ const audience = (form2.audience ?? "").split(/\s+/).filter(Boolean);
2091
+ const app = this.seed.applications.find((a) => a.clientId === clientId);
2092
+ this.checkAudience(app?.audience ?? null, audience);
2093
+ const interval = this.deviceOptions.intervalSeconds ?? 5;
2094
+ const expiresIn = this.deviceOptions.expiresInSeconds ?? 600;
2095
+ const device = {
2096
+ deviceCode: `kinde_dc_${randomToken()}`,
2097
+ userCode: userCode(),
2098
+ clientId,
2099
+ scope: (form2.scope ?? "").split(/\s+/).filter(Boolean),
2100
+ audience,
2101
+ expiresAt: Date.now() + expiresIn * 1e3,
2102
+ interval,
2103
+ lastPollAt: 0,
2104
+ status: "pending",
2105
+ grant: null
2106
+ };
2107
+ this.devices.set(device.deviceCode, device);
2108
+ this.observe("session.device");
2109
+ const verification = `${this.testkit.issuer}/device`;
2110
+ sendJson(res, 200, {
2111
+ device_code: device.deviceCode,
2112
+ user_code: device.userCode,
2113
+ verification_uri: verification,
2114
+ verification_uri_complete: `${verification}?user_code=${device.userCode}`,
2115
+ expires_in: expiresIn,
2116
+ interval
2117
+ });
2118
+ } catch (error) {
2119
+ if (error instanceof OAuthError) return sendJson(res, error.status, { error: error.error, error_description: error.message });
2120
+ throw error;
2121
+ }
2122
+ }
2123
+ findDevice(userCode2) {
2124
+ const wanted = (userCode2 ?? "").toUpperCase().replace(/[^A-Z]/g, "");
2125
+ for (const device of this.devices.values()) {
2126
+ if (device.userCode === wanted && device.status === "pending" && device.expiresAt > Date.now()) return device;
2127
+ }
2128
+ return null;
2129
+ }
2130
+ devicePage(res, params) {
2131
+ const code = params.get("user_code");
2132
+ if (!code) return sendHtml(res, 200, renderDeviceCodeEntry());
2133
+ const device = this.findDevice(code);
2134
+ if (!device) return sendHtml(res, 400, renderDeviceCodeEntry({ userCode: code, error: "That code is unknown, expired or already used." }));
2135
+ sendHtml(res, 200, renderDeviceConfirm({ userCode: device.userCode, clientId: device.clientId }));
2136
+ }
2137
+ deviceSignIn(res, params) {
2138
+ const device = this.findDevice(params.get("user_code"));
2139
+ if (!device) return sendHtml(res, 400, renderDeviceCodeEntry({ error: "That code is unknown, expired or already used." }));
2140
+ const request = {
2141
+ clientId: device.clientId,
2142
+ redirectUri: `${this.testkit.issuer}/device/complete?user_code=${device.userCode}`,
2143
+ state: null,
2144
+ scope: device.scope,
2145
+ nonce: null,
2146
+ audience: device.audience,
2147
+ orgCode: null,
2148
+ loginHint: params.get("login_hint"),
2149
+ codeChallenge: null,
2150
+ codeChallengeMethod: null
2151
+ };
2152
+ sendHtml(res, 200, renderSignIn({ request: encodeRequest(request), users: this.loginPageUsers(), loginHint: request.loginHint ?? void 0 }));
2153
+ }
2154
+ deviceComplete(res, params) {
2155
+ const device = this.findDevice(params.get("user_code"));
2156
+ const pending = this.codes.get(params.get("code") ?? "");
2157
+ this.codes.delete(params.get("code") ?? "");
2158
+ if (!device || !pending || pending.clientId !== device.clientId) {
2159
+ return sendHtml(res, 400, renderMessage("Device not connected", "The code expired or was already used. Start again on the device."));
2160
+ }
2161
+ device.status = "approved";
2162
+ device.grant = { ...pending, scope: device.scope, audience: device.audience };
2163
+ sendHtml(res, 200, renderMessage("Device connected", "You can go back to your device. It signs in the next time it checks."));
2164
+ }
2165
+ deviceDeny(res, form2) {
2166
+ const device = this.findDevice(form2.user_code);
2167
+ if (device) device.status = "denied";
2168
+ sendHtml(res, 200, renderMessage("Device denied", "The device will not be signed in."));
2169
+ }
2170
+ /** Approves or denies a device without a browser. Used by POST /testkit/device. */
2171
+ resolveDevice(input) {
2172
+ const device = this.findDevice(input.userCode);
2173
+ if (!device) throw new OAuthError(400, "invalid_request", `No pending device has the user code "${input.userCode}".`);
2174
+ if (input.deny) {
2175
+ device.status = "denied";
2176
+ return;
2177
+ }
2178
+ if (!input.user) throw new OAuthError(400, "invalid_request", "Pass the user who approves the device.");
2179
+ const scenario = seedScenario(this.seed, { user: input.user, organization: input.organization ?? void 0 });
2180
+ device.status = "approved";
2181
+ device.grant = {
2182
+ clientId: device.clientId,
2183
+ scenario,
2184
+ scope: device.scope,
2185
+ audience: device.audience,
2186
+ nonce: null,
2187
+ authTime: Math.floor(Date.now() / 1e3)
2188
+ };
2189
+ }
2190
+ pollDevice(form2, clientId) {
2191
+ const device = this.devices.get(form2.device_code ?? "");
2192
+ if (!device || device.clientId !== clientId) {
2193
+ throw new OAuthError(400, "invalid_grant", "The device code is unknown or was issued to a different client.");
2194
+ }
2195
+ if (device.expiresAt <= Date.now()) {
2196
+ this.devices.delete(device.deviceCode);
2197
+ throw new OAuthError(400, "expired_token", "The device code has expired. Request a new one.");
2198
+ }
2199
+ if (device.status === "denied") {
2200
+ this.devices.delete(device.deviceCode);
2201
+ throw new OAuthError(400, "access_denied", "The user denied the device.");
2202
+ }
2203
+ if (device.status === "pending") {
2204
+ const now = Date.now();
2205
+ const tooSoon = device.lastPollAt > 0 && now - device.lastPollAt < device.interval * 1e3;
2206
+ device.lastPollAt = now;
2207
+ if (tooSoon) {
2208
+ device.interval += 5;
2209
+ throw new OAuthError(400, "slow_down", `Poll at most every ${device.interval} seconds.`);
2210
+ }
2211
+ throw new OAuthError(400, "authorization_pending", "The user has not finished signing in.");
2212
+ }
2213
+ this.devices.delete(device.deviceCode);
2214
+ this.observe("session.device-approved");
2215
+ return device.grant;
2216
+ }
2217
+ async introspect(req, res, form2) {
2218
+ const header = req.headers.authorization ?? "";
2219
+ if (!header.startsWith("Bearer ")) {
2220
+ return sendJson(res, 401, { error: "request_unauthorized", error_description: "The request could not be authorized. HTTP Authorization header missing." });
2221
+ }
2222
+ const bearer = header.slice(7);
2223
+ const token = form2.token ?? "";
2224
+ if (bearer === token) {
2225
+ return sendJson(res, 401, { error: "request_unauthorized", error_description: "The request could not be authorized. Bearer and introspection token are identical." });
2226
+ }
2227
+ try {
2228
+ await this.testkit.verify(bearer);
2229
+ } catch {
2230
+ return sendJson(res, 401, { error: "request_unauthorized", error_description: "The request could not be authorized. The Bearer token is not valid for this issuer." });
2231
+ }
2232
+ if (!token) return sendJson(res, 400, { error: "invalid_request", error_description: "Send the token to introspect in the token field." });
2233
+ this.observe("token.introspect");
2234
+ const refresh = this.refreshTokens.get(token);
2235
+ if (refresh) return sendJson(res, 200, { active: true, client_id: refresh.clientId });
2236
+ try {
2237
+ const claims = await this.testkit.verify(token);
2238
+ const aud = claims.aud === void 0 ? [] : Array.isArray(claims.aud) ? claims.aud : [claims.aud];
2239
+ sendJson(res, 200, { active: true, aud, client_id: claims.azp ?? null, exp: claims.exp, iat: claims.iat });
2240
+ } catch {
2241
+ sendJson(res, 200, { active: false });
2242
+ }
2243
+ }
2244
+ /** OAuth dynamic client registration (RFC 7591), which Kinde offers for MCP connectors. */
2245
+ register(res, body) {
2246
+ const input = typeof body === "object" && body !== null && !Array.isArray(body) ? body : {};
2247
+ const redirectUris = Array.isArray(input.redirect_uris) ? input.redirect_uris.filter((uri) => typeof uri === "string") : [];
2248
+ if (redirectUris.length === 0 || !redirectUris.every(isHttpUrl)) {
2249
+ return sendJson(res, 400, { error: "invalid_redirect_uri", error_description: "Redirect URI is not allowed for MCP connector registration" });
2250
+ }
2251
+ const client = {
2252
+ client_id: (0, import_node_crypto4.randomBytes)(16).toString("hex"),
2253
+ client_id_issued_at: Math.floor(Date.now() / 1e3),
2254
+ ...typeof input.client_name === "string" ? { client_name: input.client_name } : {},
2255
+ redirect_uris: redirectUris,
2256
+ grant_types: ["authorization_code", "refresh_token"],
2257
+ response_types: ["code"],
2258
+ token_endpoint_auth_method: "none"
2259
+ };
2260
+ this.registeredClients.set(client.client_id, client);
2261
+ this.observe("session.register");
2262
+ sendJson(res, 201, client);
2263
+ }
2264
+ /** Clients registered through /oauth2/register since the last reset. */
2265
+ registrations() {
2266
+ return [...this.registeredClients.values()];
2025
2267
  }
2026
2268
  redeemCode(form2, clientId) {
2027
2269
  const code = form2.code ?? "";
@@ -2226,6 +2468,9 @@ function isHttpUrl(value) {
2226
2468
  return false;
2227
2469
  }
2228
2470
  }
2471
+ function userCode() {
2472
+ return Array.from((0, import_node_crypto4.randomBytes)(8), (byte) => USER_CODE_ALPHABET[byte % USER_CODE_ALPHABET.length]).join("");
2473
+ }
2229
2474
  function randomToken() {
2230
2475
  return (0, import_node_crypto4.randomBytes)(32).toString("base64url");
2231
2476
  }
@@ -2424,7 +2669,8 @@ var Directory = class {
2424
2669
  isPasswordResetRequested: false,
2425
2670
  createdOn: (/* @__PURE__ */ new Date()).toISOString(),
2426
2671
  totalSignIns: 0,
2427
- lastSignedIn: null
2672
+ lastSignedIn: null,
2673
+ lastOrganizationSignIns: {}
2428
2674
  };
2429
2675
  this.userMeta.set(user.id, meta);
2430
2676
  }
@@ -2437,7 +2683,7 @@ var Directory = class {
2437
2683
  const meta = this.meta(user);
2438
2684
  meta.totalSignIns += 1;
2439
2685
  meta.lastSignedIn = (/* @__PURE__ */ new Date()).toISOString();
2440
- void organizationCode;
2686
+ if (organizationCode) meta.lastOrganizationSignIns[organizationCode] = meta.lastSignedIn;
2441
2687
  }
2442
2688
  createUser(input) {
2443
2689
  const user = createKindeUser({
@@ -2884,12 +3130,14 @@ var ManagementApi = class {
2884
3130
  username: null,
2885
3131
  last_name: user.familyName,
2886
3132
  first_name: user.givenName,
3133
+ full_name: [user.givenName, user.familyName].filter(Boolean).join(" ") || null,
2887
3134
  is_suspended: meta.isSuspended,
2888
3135
  picture: user.picture,
2889
3136
  total_sign_ins: meta.totalSignIns,
2890
3137
  failed_sign_ins: 0,
2891
3138
  last_signed_in: meta.lastSignedIn,
2892
3139
  created_on: meta.createdOn,
3140
+ last_organization_sign_ins: Object.entries(meta.lastOrganizationSignIns).map(([org_code, last_signed_in]) => ({ org_code, last_signed_in })),
2893
3141
  organizations: this.organizationsOf(user),
2894
3142
  identities: user.email ? [{ type: "email", identity: user.email }] : []
2895
3143
  };
@@ -2909,7 +3157,8 @@ var ManagementApi = class {
2909
3157
  handle: meta.handle,
2910
3158
  is_default: false,
2911
3159
  external_id: meta.externalId,
2912
- is_auto_membership_enabled: false
3160
+ is_auto_membership_enabled: false,
3161
+ created_on: meta.createdOn
2913
3162
  };
2914
3163
  }
2915
3164
  organizationEvent(org) {
@@ -2920,7 +3169,7 @@ var ManagementApi = class {
2920
3169
  return { id: role.id, key: role.key, name: role.name, description: role.description, is_default_role: role.isDefault };
2921
3170
  }
2922
3171
  permissionItem(permission) {
2923
- return { id: permission.id, key: permission.key, name: permission.name, description: permission.description };
3172
+ return { id: permission.id, key: permission.key, name: permission.name, description: permission.description, is_organization_role_assignable: false };
2924
3173
  }
2925
3174
  };
2926
3175
  function paginate(items, query) {
@@ -3415,7 +3664,8 @@ var COVERAGE_GROUPS = [
3415
3664
  { id: "session.refresh", label: "Refresh", hint: "Let the app refresh its session, or call the refresh_token grant." },
3416
3665
  { id: "session.sign-out", label: "Sign-out", hint: "Sign out through your app's logout route." },
3417
3666
  { id: "session.revoke", label: "Refresh token revoked", hint: "Call /oauth2/revoke, as some SDKs do on sign-out." },
3418
- { id: "session.silent", label: "Silent sign-in with no session", hint: "Send prompt=none and handle login_required." }
3667
+ { id: "session.silent", label: "Silent sign-in with no session", hint: "Send prompt=none and handle login_required." },
3668
+ { id: "session.device-approved", label: "Device sign-in", hint: "Run the device authorization flow and approve it with POST /testkit/device." }
3419
3669
  ]
3420
3670
  },
3421
3671
  {
@@ -3827,7 +4077,7 @@ async function startKindeTestkit(options = {}) {
3827
4077
  const directory = new Directory(seed);
3828
4078
  const webhooks = new WebhookDispatcher(testkit, seed, seed.webhooks, options.webhooks);
3829
4079
  webhooks.observe = observe;
3830
- const auth = new AuthorizationServer(testkit, seed, (type, user) => webhooks.emitForUser(type, user), directory, observe);
4080
+ const auth = new AuthorizationServer(testkit, seed, (type, user) => webhooks.emitForUser(type, user), directory, observe, options.device);
3831
4081
  const management = new ManagementApi(testkit, directory, webhooks);
3832
4082
  const account = new AccountApi(testkit, directory);
3833
4083
  const reset = () => {
@@ -3902,7 +4152,7 @@ async function handle(req, res, context) {
3902
4152
  }
3903
4153
  }
3904
4154
  }
3905
- if (await auth.handle(req, res, url, () => readForm(req))) return;
4155
+ if (await auth.handle(req, res, url, () => readForm(req), () => readJson(req))) return;
3906
4156
  if (await context.management.handle(req, res, url, async () => await readJson(req))) {
3907
4157
  if (res.statusCode === 401 || res.statusCode === 403) coverage.hit("api.management-denied");
3908
4158
  else if (res.statusCode < 400) coverage.hit(method === "GET" ? "api.management-read" : "api.management-write");
@@ -3962,6 +4212,21 @@ async function handle(req, res, context) {
3962
4212
  const removed = webhooks.removeEndpoint(decodeURIComponent(pathname.slice("/testkit/webhooks/endpoints/".length)));
3963
4213
  return sendJson4(res, removed ? 200 : 404, { ok: removed });
3964
4214
  }
4215
+ if (method === "POST" && pathname === "/testkit/device") {
4216
+ const input = await readJson(req);
4217
+ try {
4218
+ auth.resolveDevice({
4219
+ userCode: String(input.user_code ?? ""),
4220
+ user: typeof input.user === "string" ? input.user : void 0,
4221
+ organization: typeof input.organization === "string" ? input.organization : null,
4222
+ deny: input.action === "deny"
4223
+ });
4224
+ } catch (error) {
4225
+ if (error instanceof OAuthError) return sendJson4(res, error.status, { error: error.error, error_description: error.message });
4226
+ throw error;
4227
+ }
4228
+ return sendJson4(res, 200, { ok: true });
4229
+ }
3965
4230
  if (method === "POST" && pathname === "/testkit/reset") {
3966
4231
  context.reset();
3967
4232
  return sendJson4(res, 200, { ok: true });
@@ -4085,20 +4350,26 @@ function discovery(testkit) {
4085
4350
  const base = testkit.issuer;
4086
4351
  return {
4087
4352
  issuer: base,
4088
- authorization_endpoint: `${base}/oauth2/auth`,
4353
+ jwks_uri: `${base}/.well-known/jwks`,
4089
4354
  token_endpoint: `${base}/oauth2/token`,
4355
+ claims_supported: ["aud", "exp", "iat", "iss", "sub", "acr", "amr", "auth_time"],
4356
+ scopes_supported: ["address", "email", "offline", "openid", "phone", "profile"],
4090
4357
  userinfo_endpoint: `${base}/oauth2/v2/user_profile`,
4091
- end_session_endpoint: `${base}/logout`,
4092
4358
  revocation_endpoint: `${base}/oauth2/revoke`,
4093
- jwks_uri: `${base}/.well-known/jwks`,
4094
- response_types_supported: ["code"],
4095
- grant_types_supported: ["authorization_code", "refresh_token"],
4096
- code_challenge_methods_supported: ["S256", "plain"],
4359
+ end_session_endpoint: `${base}/logout`,
4360
+ grant_types_supported: ["authorization_code", "refresh_token", "client_credentials", "urn:ietf:params:oauth:grant-type:device_code"],
4361
+ registration_endpoint: `${base}/oauth2/register`,
4362
+ authorization_endpoint: `${base}/oauth2/auth`,
4363
+ introspection_endpoint: `${base}/oauth2/introspect`,
4097
4364
  subject_types_supported: ["public"],
4365
+ response_modes_supported: ["query"],
4366
+ response_types_supported: ["code"],
4367
+ device_authorization_endpoint: `${base}/oauth2/device/auth`,
4368
+ request_uri_parameter_supported: false,
4369
+ code_challenge_methods_supported: ["S256"],
4370
+ client_id_metadata_document_supported: false,
4098
4371
  id_token_signing_alg_values_supported: ["RS256"],
4099
- scopes_supported: ["openid", "profile", "email", "offline"],
4100
- token_endpoint_auth_methods_supported: ["client_secret_post", "client_secret_basic", "none"],
4101
- claims_supported: ["aud", "exp", "iat", "iss", "sub", "org_code", "permissions", "roles", "scp"]
4372
+ token_endpoint_auth_methods_supported: ["client_secret_post", "none"]
4102
4373
  };
4103
4374
  }
4104
4375
  async function issueToken(testkit, seed, body) {
@@ -1,4 +1,4 @@
1
- import { S as StartKindeTestkitOptions } from './server-ciWIscoQ.cjs';
1
+ import { S as StartKindeTestkitOptions } from './server-CcXI3vJ-.cjs';
2
2
  import 'jose';
3
3
 
4
4
  interface SetupKindeTestkitOptions {
package/dist/cypress.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { S as StartKindeTestkitOptions } from './server-BiODgeoB.js';
1
+ import { S as StartKindeTestkitOptions } from './server-Dghq0aLx.js';
2
2
  import './webhooks-DJyCsbdF.js';
3
3
  import 'jose';
4
4
 
package/dist/cypress.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  startKindeTestkit
3
- } from "./chunk-GCOZVCZY.js";
3
+ } from "./chunk-IOP27RQ5.js";
4
4
 
5
5
  // src/cypress.ts
6
6
  async function setupKindeTestkit(on, config, options = {}) {
@@ -1,5 +1,5 @@
1
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 { g as Directory, d as CoverageRecorder, A as ActivityLog } from './server-BiODgeoB.js';
2
+ import { h as Directory, d as CoverageRecorder, A as ActivityLog } from './server-Dghq0aLx.js';
3
3
 
4
4
  interface KindeTestAuth {
5
5
  token: string | null;
@@ -1,4 +1,4 @@
1
- import { x as KindePrincipal, y as KindeTestkit, F as FailureInjector, V as WebhookDispatcher, r as Directory, j as CoverageRecorder, f as ActivityLog, d as Scenario, J as ScenarioTokenOverrides, T as TestkitSeed } from './server-ciWIscoQ.cjs';
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-CcXI3vJ-.cjs';
2
2
 
3
3
  interface KindeTestAuth {
4
4
  token: string | null;