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.
package/dist/jest.cjs CHANGED
@@ -1504,6 +1504,19 @@ function renderOrganizationPicker(options) {
1504
1504
  function renderMessage(title, message2) {
1505
1505
  return layout(title, `<h1>${escapeHtml(title)}</h1><p>${escapeHtml(message2)}</p>`);
1506
1506
  }
1507
+ function renderDeviceCodeEntry(options = {}) {
1508
+ return layout(
1509
+ "Connect a device",
1510
+ `<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>`
1511
+ );
1512
+ }
1513
+ function renderDeviceConfirm(options) {
1514
+ const code = escapeHtml(options.userCode);
1515
+ return layout(
1516
+ "Connect a device",
1517
+ `<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>`
1518
+ );
1519
+ }
1507
1520
 
1508
1521
  // src/seed.ts
1509
1522
  function roleRecord(key, extra = {}) {
@@ -1819,6 +1832,8 @@ function featureFlagsFor(seed, organizationCode) {
1819
1832
  // src/oauth.ts
1820
1833
  var import_node_crypto4 = require("crypto");
1821
1834
  var CODE_LIFETIME_MS = 10 * 60 * 1e3;
1835
+ var DEVICE_CODE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
1836
+ var USER_CODE_ALPHABET = "BCDFGHJKLMNPQRSTVWXZ";
1822
1837
  var OAuthError = class extends Error {
1823
1838
  constructor(status, error, description) {
1824
1839
  super(description);
@@ -1829,24 +1844,49 @@ var OAuthError = class extends Error {
1829
1844
  error;
1830
1845
  };
1831
1846
  var AuthorizationServer = class {
1832
- constructor(testkit, seed, emit = () => void 0, directory, observe = () => void 0) {
1847
+ constructor(testkit, seed, emit = () => void 0, directory, observe = () => void 0, deviceOptions = {}) {
1833
1848
  this.testkit = testkit;
1834
1849
  this.seed = seed;
1835
1850
  this.emit = emit;
1836
1851
  this.directory = directory;
1837
1852
  this.observe = observe;
1853
+ this.deviceOptions = deviceOptions;
1838
1854
  }
1839
1855
  testkit;
1840
1856
  seed;
1841
1857
  emit;
1842
1858
  directory;
1843
1859
  observe;
1860
+ deviceOptions;
1844
1861
  codes = /* @__PURE__ */ new Map();
1845
1862
  refreshTokens = /* @__PURE__ */ new Map();
1846
1863
  signedUpUsers = /* @__PURE__ */ new Map();
1847
- async handle(req, res, url, readBody) {
1864
+ devices = /* @__PURE__ */ new Map();
1865
+ registeredClients = /* @__PURE__ */ new Map();
1866
+ async handle(req, res, url, readBody, readJson2 = async () => ({})) {
1848
1867
  const method = req.method ?? "GET";
1849
1868
  switch (`${method} ${url.pathname}`) {
1869
+ case "POST /oauth2/device/auth":
1870
+ this.deviceAuthorization(res, await readBody());
1871
+ return true;
1872
+ case "GET /device":
1873
+ this.devicePage(res, url.searchParams);
1874
+ return true;
1875
+ case "GET /device/sign-in":
1876
+ this.deviceSignIn(res, url.searchParams);
1877
+ return true;
1878
+ case "GET /device/complete":
1879
+ this.deviceComplete(res, url.searchParams);
1880
+ return true;
1881
+ case "POST /device/deny":
1882
+ this.deviceDeny(res, await readBody());
1883
+ return true;
1884
+ case "POST /oauth2/introspect":
1885
+ await this.introspect(req, res, await readBody());
1886
+ return true;
1887
+ case "POST /oauth2/register":
1888
+ this.register(res, await readJson2());
1889
+ return true;
1850
1890
  case "GET /oauth2/auth":
1851
1891
  this.authorize(res, url.searchParams);
1852
1892
  return true;
@@ -1994,8 +2034,14 @@ var AuthorizationServer = class {
1994
2034
  } else if (grantType === "refresh_token") {
1995
2035
  grant = this.redeemRefreshToken(form2, clientId);
1996
2036
  this.observe("session.refresh");
2037
+ } else if (grantType === DEVICE_CODE_GRANT) {
2038
+ grant = this.pollDevice(form2, clientId);
1997
2039
  } else {
1998
- throw new OAuthError(400, "unsupported_grant_type", `kinde-testkit supports authorization_code, refresh_token and client_credentials, not "${grantType ?? ""}".`);
2040
+ throw new OAuthError(
2041
+ 400,
2042
+ "unsupported_grant_type",
2043
+ `kinde-testkit supports authorization_code, refresh_token, client_credentials and ${DEVICE_CODE_GRANT}, not "${grantType ?? ""}".`
2044
+ );
1999
2045
  }
2000
2046
  sendJson(res, 200, await this.issueTokens(grant));
2001
2047
  } catch (error) {
@@ -2013,6 +2059,7 @@ var AuthorizationServer = class {
2013
2059
  const requested = (form2.scope ?? "").split(/\s+/).filter(Boolean);
2014
2060
  const granted = app?.scopes ? requested.length === 0 ? [...app.scopes] : requested.filter((scope) => app.scopes.includes(scope)) : requested;
2015
2061
  const audience = (form2.audience ?? "").split(/\s+/).filter(Boolean);
2062
+ this.checkAudience(app?.audience ?? null, audience);
2016
2063
  return {
2017
2064
  access_token: await this.testkit.m2mToken({
2018
2065
  clientId,
@@ -2031,6 +2078,201 @@ var AuthorizationServer = class {
2031
2078
  this.codes.clear();
2032
2079
  this.refreshTokens.clear();
2033
2080
  this.signedUpUsers.clear();
2081
+ this.devices.clear();
2082
+ this.registeredClients.clear();
2083
+ }
2084
+ /** A seeded application that lists audiences may only ask for those, as in Kinde, where each API must be authorized for the app. */
2085
+ checkAudience(allowed, requested) {
2086
+ if (!allowed) return;
2087
+ const refused = requested.find((audience) => !allowed.includes(audience));
2088
+ if (refused) {
2089
+ throw new OAuthError(
2090
+ 400,
2091
+ "invalid_request",
2092
+ `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.`
2093
+ );
2094
+ }
2095
+ }
2096
+ deviceAuthorization(res, form2) {
2097
+ try {
2098
+ const clientId = form2.client_id || DEFAULT_CLIENT_ID;
2099
+ const audience = (form2.audience ?? "").split(/\s+/).filter(Boolean);
2100
+ const app = this.seed.applications.find((a) => a.clientId === clientId);
2101
+ this.checkAudience(app?.audience ?? null, audience);
2102
+ const interval = this.deviceOptions.intervalSeconds ?? 5;
2103
+ const expiresIn = this.deviceOptions.expiresInSeconds ?? 600;
2104
+ const device = {
2105
+ deviceCode: `kinde_dc_${randomToken()}`,
2106
+ userCode: userCode(),
2107
+ clientId,
2108
+ scope: (form2.scope ?? "").split(/\s+/).filter(Boolean),
2109
+ audience,
2110
+ expiresAt: Date.now() + expiresIn * 1e3,
2111
+ interval,
2112
+ lastPollAt: 0,
2113
+ status: "pending",
2114
+ grant: null
2115
+ };
2116
+ this.devices.set(device.deviceCode, device);
2117
+ this.observe("session.device");
2118
+ const verification = `${this.testkit.issuer}/device`;
2119
+ sendJson(res, 200, {
2120
+ device_code: device.deviceCode,
2121
+ user_code: device.userCode,
2122
+ verification_uri: verification,
2123
+ verification_uri_complete: `${verification}?user_code=${device.userCode}`,
2124
+ expires_in: expiresIn,
2125
+ interval
2126
+ });
2127
+ } catch (error) {
2128
+ if (error instanceof OAuthError) return sendJson(res, error.status, { error: error.error, error_description: error.message });
2129
+ throw error;
2130
+ }
2131
+ }
2132
+ findDevice(userCode2) {
2133
+ const wanted = (userCode2 ?? "").toUpperCase().replace(/[^A-Z]/g, "");
2134
+ for (const device of this.devices.values()) {
2135
+ if (device.userCode === wanted && device.status === "pending" && device.expiresAt > Date.now()) return device;
2136
+ }
2137
+ return null;
2138
+ }
2139
+ devicePage(res, params) {
2140
+ const code = params.get("user_code");
2141
+ if (!code) return sendHtml(res, 200, renderDeviceCodeEntry());
2142
+ const device = this.findDevice(code);
2143
+ if (!device) return sendHtml(res, 400, renderDeviceCodeEntry({ userCode: code, error: "That code is unknown, expired or already used." }));
2144
+ sendHtml(res, 200, renderDeviceConfirm({ userCode: device.userCode, clientId: device.clientId }));
2145
+ }
2146
+ deviceSignIn(res, params) {
2147
+ const device = this.findDevice(params.get("user_code"));
2148
+ if (!device) return sendHtml(res, 400, renderDeviceCodeEntry({ error: "That code is unknown, expired or already used." }));
2149
+ const request = {
2150
+ clientId: device.clientId,
2151
+ redirectUri: `${this.testkit.issuer}/device/complete?user_code=${device.userCode}`,
2152
+ state: null,
2153
+ scope: device.scope,
2154
+ nonce: null,
2155
+ audience: device.audience,
2156
+ orgCode: null,
2157
+ loginHint: params.get("login_hint"),
2158
+ codeChallenge: null,
2159
+ codeChallengeMethod: null
2160
+ };
2161
+ sendHtml(res, 200, renderSignIn({ request: encodeRequest(request), users: this.loginPageUsers(), loginHint: request.loginHint ?? void 0 }));
2162
+ }
2163
+ deviceComplete(res, params) {
2164
+ const device = this.findDevice(params.get("user_code"));
2165
+ const pending = this.codes.get(params.get("code") ?? "");
2166
+ this.codes.delete(params.get("code") ?? "");
2167
+ if (!device || !pending || pending.clientId !== device.clientId) {
2168
+ return sendHtml(res, 400, renderMessage("Device not connected", "The code expired or was already used. Start again on the device."));
2169
+ }
2170
+ device.status = "approved";
2171
+ device.grant = { ...pending, scope: device.scope, audience: device.audience };
2172
+ sendHtml(res, 200, renderMessage("Device connected", "You can go back to your device. It signs in the next time it checks."));
2173
+ }
2174
+ deviceDeny(res, form2) {
2175
+ const device = this.findDevice(form2.user_code);
2176
+ if (device) device.status = "denied";
2177
+ sendHtml(res, 200, renderMessage("Device denied", "The device will not be signed in."));
2178
+ }
2179
+ /** Approves or denies a device without a browser. Used by POST /testkit/device. */
2180
+ resolveDevice(input) {
2181
+ const device = this.findDevice(input.userCode);
2182
+ if (!device) throw new OAuthError(400, "invalid_request", `No pending device has the user code "${input.userCode}".`);
2183
+ if (input.deny) {
2184
+ device.status = "denied";
2185
+ return;
2186
+ }
2187
+ if (!input.user) throw new OAuthError(400, "invalid_request", "Pass the user who approves the device.");
2188
+ const scenario = seedScenario(this.seed, { user: input.user, organization: input.organization ?? void 0 });
2189
+ device.status = "approved";
2190
+ device.grant = {
2191
+ clientId: device.clientId,
2192
+ scenario,
2193
+ scope: device.scope,
2194
+ audience: device.audience,
2195
+ nonce: null,
2196
+ authTime: Math.floor(Date.now() / 1e3)
2197
+ };
2198
+ }
2199
+ pollDevice(form2, clientId) {
2200
+ const device = this.devices.get(form2.device_code ?? "");
2201
+ if (!device || device.clientId !== clientId) {
2202
+ throw new OAuthError(400, "invalid_grant", "The device code is unknown or was issued to a different client.");
2203
+ }
2204
+ if (device.expiresAt <= Date.now()) {
2205
+ this.devices.delete(device.deviceCode);
2206
+ throw new OAuthError(400, "expired_token", "The device code has expired. Request a new one.");
2207
+ }
2208
+ if (device.status === "denied") {
2209
+ this.devices.delete(device.deviceCode);
2210
+ throw new OAuthError(400, "access_denied", "The user denied the device.");
2211
+ }
2212
+ if (device.status === "pending") {
2213
+ const now = Date.now();
2214
+ const tooSoon = device.lastPollAt > 0 && now - device.lastPollAt < device.interval * 1e3;
2215
+ device.lastPollAt = now;
2216
+ if (tooSoon) {
2217
+ device.interval += 5;
2218
+ throw new OAuthError(400, "slow_down", `Poll at most every ${device.interval} seconds.`);
2219
+ }
2220
+ throw new OAuthError(400, "authorization_pending", "The user has not finished signing in.");
2221
+ }
2222
+ this.devices.delete(device.deviceCode);
2223
+ this.observe("session.device-approved");
2224
+ return device.grant;
2225
+ }
2226
+ async introspect(req, res, form2) {
2227
+ const header = req.headers.authorization ?? "";
2228
+ if (!header.startsWith("Bearer ")) {
2229
+ return sendJson(res, 401, { error: "request_unauthorized", error_description: "The request could not be authorized. HTTP Authorization header missing." });
2230
+ }
2231
+ const bearer = header.slice(7);
2232
+ const token = form2.token ?? "";
2233
+ if (bearer === token) {
2234
+ return sendJson(res, 401, { error: "request_unauthorized", error_description: "The request could not be authorized. Bearer and introspection token are identical." });
2235
+ }
2236
+ try {
2237
+ await this.testkit.verify(bearer);
2238
+ } catch {
2239
+ return sendJson(res, 401, { error: "request_unauthorized", error_description: "The request could not be authorized. The Bearer token is not valid for this issuer." });
2240
+ }
2241
+ if (!token) return sendJson(res, 400, { error: "invalid_request", error_description: "Send the token to introspect in the token field." });
2242
+ this.observe("token.introspect");
2243
+ const refresh = this.refreshTokens.get(token);
2244
+ if (refresh) return sendJson(res, 200, { active: true, client_id: refresh.clientId });
2245
+ try {
2246
+ const claims = await this.testkit.verify(token);
2247
+ const aud = claims.aud === void 0 ? [] : Array.isArray(claims.aud) ? claims.aud : [claims.aud];
2248
+ sendJson(res, 200, { active: true, aud, client_id: claims.azp ?? null, exp: claims.exp, iat: claims.iat });
2249
+ } catch {
2250
+ sendJson(res, 200, { active: false });
2251
+ }
2252
+ }
2253
+ /** OAuth dynamic client registration (RFC 7591), which Kinde offers for MCP connectors. */
2254
+ register(res, body) {
2255
+ const input = typeof body === "object" && body !== null && !Array.isArray(body) ? body : {};
2256
+ const redirectUris = Array.isArray(input.redirect_uris) ? input.redirect_uris.filter((uri) => typeof uri === "string") : [];
2257
+ if (redirectUris.length === 0 || !redirectUris.every(isHttpUrl)) {
2258
+ return sendJson(res, 400, { error: "invalid_redirect_uri", error_description: "Redirect URI is not allowed for MCP connector registration" });
2259
+ }
2260
+ const client = {
2261
+ client_id: (0, import_node_crypto4.randomBytes)(16).toString("hex"),
2262
+ client_id_issued_at: Math.floor(Date.now() / 1e3),
2263
+ ...typeof input.client_name === "string" ? { client_name: input.client_name } : {},
2264
+ redirect_uris: redirectUris,
2265
+ grant_types: ["authorization_code", "refresh_token"],
2266
+ response_types: ["code"],
2267
+ token_endpoint_auth_method: "none"
2268
+ };
2269
+ this.registeredClients.set(client.client_id, client);
2270
+ this.observe("session.register");
2271
+ sendJson(res, 201, client);
2272
+ }
2273
+ /** Clients registered through /oauth2/register since the last reset. */
2274
+ registrations() {
2275
+ return [...this.registeredClients.values()];
2034
2276
  }
2035
2277
  redeemCode(form2, clientId) {
2036
2278
  const code = form2.code ?? "";
@@ -2235,6 +2477,9 @@ function isHttpUrl(value) {
2235
2477
  return false;
2236
2478
  }
2237
2479
  }
2480
+ function userCode() {
2481
+ return Array.from((0, import_node_crypto4.randomBytes)(8), (byte) => USER_CODE_ALPHABET[byte % USER_CODE_ALPHABET.length]).join("");
2482
+ }
2238
2483
  function randomToken() {
2239
2484
  return (0, import_node_crypto4.randomBytes)(32).toString("base64url");
2240
2485
  }
@@ -2433,7 +2678,8 @@ var Directory = class {
2433
2678
  isPasswordResetRequested: false,
2434
2679
  createdOn: (/* @__PURE__ */ new Date()).toISOString(),
2435
2680
  totalSignIns: 0,
2436
- lastSignedIn: null
2681
+ lastSignedIn: null,
2682
+ lastOrganizationSignIns: {}
2437
2683
  };
2438
2684
  this.userMeta.set(user.id, meta);
2439
2685
  }
@@ -2446,7 +2692,7 @@ var Directory = class {
2446
2692
  const meta = this.meta(user);
2447
2693
  meta.totalSignIns += 1;
2448
2694
  meta.lastSignedIn = (/* @__PURE__ */ new Date()).toISOString();
2449
- void organizationCode;
2695
+ if (organizationCode) meta.lastOrganizationSignIns[organizationCode] = meta.lastSignedIn;
2450
2696
  }
2451
2697
  createUser(input) {
2452
2698
  const user = createKindeUser({
@@ -2893,12 +3139,14 @@ var ManagementApi = class {
2893
3139
  username: null,
2894
3140
  last_name: user.familyName,
2895
3141
  first_name: user.givenName,
3142
+ full_name: [user.givenName, user.familyName].filter(Boolean).join(" ") || null,
2896
3143
  is_suspended: meta.isSuspended,
2897
3144
  picture: user.picture,
2898
3145
  total_sign_ins: meta.totalSignIns,
2899
3146
  failed_sign_ins: 0,
2900
3147
  last_signed_in: meta.lastSignedIn,
2901
3148
  created_on: meta.createdOn,
3149
+ last_organization_sign_ins: Object.entries(meta.lastOrganizationSignIns).map(([org_code, last_signed_in]) => ({ org_code, last_signed_in })),
2902
3150
  organizations: this.organizationsOf(user),
2903
3151
  identities: user.email ? [{ type: "email", identity: user.email }] : []
2904
3152
  };
@@ -2918,7 +3166,8 @@ var ManagementApi = class {
2918
3166
  handle: meta.handle,
2919
3167
  is_default: false,
2920
3168
  external_id: meta.externalId,
2921
- is_auto_membership_enabled: false
3169
+ is_auto_membership_enabled: false,
3170
+ created_on: meta.createdOn
2922
3171
  };
2923
3172
  }
2924
3173
  organizationEvent(org) {
@@ -2929,7 +3178,7 @@ var ManagementApi = class {
2929
3178
  return { id: role.id, key: role.key, name: role.name, description: role.description, is_default_role: role.isDefault };
2930
3179
  }
2931
3180
  permissionItem(permission) {
2932
- return { id: permission.id, key: permission.key, name: permission.name, description: permission.description };
3181
+ return { id: permission.id, key: permission.key, name: permission.name, description: permission.description, is_organization_role_assignable: false };
2933
3182
  }
2934
3183
  };
2935
3184
  function paginate(items, query) {
@@ -3424,7 +3673,8 @@ var COVERAGE_GROUPS = [
3424
3673
  { id: "session.refresh", label: "Refresh", hint: "Let the app refresh its session, or call the refresh_token grant." },
3425
3674
  { id: "session.sign-out", label: "Sign-out", hint: "Sign out through your app's logout route." },
3426
3675
  { id: "session.revoke", label: "Refresh token revoked", hint: "Call /oauth2/revoke, as some SDKs do on sign-out." },
3427
- { id: "session.silent", label: "Silent sign-in with no session", hint: "Send prompt=none and handle login_required." }
3676
+ { id: "session.silent", label: "Silent sign-in with no session", hint: "Send prompt=none and handle login_required." },
3677
+ { id: "session.device-approved", label: "Device sign-in", hint: "Run the device authorization flow and approve it with POST /testkit/device." }
3428
3678
  ]
3429
3679
  },
3430
3680
  {
@@ -3836,7 +4086,7 @@ async function startKindeTestkit(options = {}) {
3836
4086
  const directory = new Directory(seed);
3837
4087
  const webhooks = new WebhookDispatcher(testkit, seed, seed.webhooks, options.webhooks);
3838
4088
  webhooks.observe = observe;
3839
- const auth = new AuthorizationServer(testkit, seed, (type, user) => webhooks.emitForUser(type, user), directory, observe);
4089
+ const auth = new AuthorizationServer(testkit, seed, (type, user) => webhooks.emitForUser(type, user), directory, observe, options.device);
3840
4090
  const management = new ManagementApi(testkit, directory, webhooks);
3841
4091
  const account = new AccountApi(testkit, directory);
3842
4092
  const reset = () => {
@@ -3911,7 +4161,7 @@ async function handle(req, res, context) {
3911
4161
  }
3912
4162
  }
3913
4163
  }
3914
- if (await auth.handle(req, res, url, () => readForm(req))) return;
4164
+ if (await auth.handle(req, res, url, () => readForm(req), () => readJson(req))) return;
3915
4165
  if (await context.management.handle(req, res, url, async () => await readJson(req))) {
3916
4166
  if (res.statusCode === 401 || res.statusCode === 403) coverage.hit("api.management-denied");
3917
4167
  else if (res.statusCode < 400) coverage.hit(method === "GET" ? "api.management-read" : "api.management-write");
@@ -3971,6 +4221,21 @@ async function handle(req, res, context) {
3971
4221
  const removed = webhooks.removeEndpoint(decodeURIComponent(pathname.slice("/testkit/webhooks/endpoints/".length)));
3972
4222
  return sendJson4(res, removed ? 200 : 404, { ok: removed });
3973
4223
  }
4224
+ if (method === "POST" && pathname === "/testkit/device") {
4225
+ const input = await readJson(req);
4226
+ try {
4227
+ auth.resolveDevice({
4228
+ userCode: String(input.user_code ?? ""),
4229
+ user: typeof input.user === "string" ? input.user : void 0,
4230
+ organization: typeof input.organization === "string" ? input.organization : null,
4231
+ deny: input.action === "deny"
4232
+ });
4233
+ } catch (error) {
4234
+ if (error instanceof OAuthError) return sendJson4(res, error.status, { error: error.error, error_description: error.message });
4235
+ throw error;
4236
+ }
4237
+ return sendJson4(res, 200, { ok: true });
4238
+ }
3974
4239
  if (method === "POST" && pathname === "/testkit/reset") {
3975
4240
  context.reset();
3976
4241
  return sendJson4(res, 200, { ok: true });
@@ -4094,20 +4359,26 @@ function discovery(testkit) {
4094
4359
  const base = testkit.issuer;
4095
4360
  return {
4096
4361
  issuer: base,
4097
- authorization_endpoint: `${base}/oauth2/auth`,
4362
+ jwks_uri: `${base}/.well-known/jwks`,
4098
4363
  token_endpoint: `${base}/oauth2/token`,
4364
+ claims_supported: ["aud", "exp", "iat", "iss", "sub", "acr", "amr", "auth_time"],
4365
+ scopes_supported: ["address", "email", "offline", "openid", "phone", "profile"],
4099
4366
  userinfo_endpoint: `${base}/oauth2/v2/user_profile`,
4100
- end_session_endpoint: `${base}/logout`,
4101
4367
  revocation_endpoint: `${base}/oauth2/revoke`,
4102
- jwks_uri: `${base}/.well-known/jwks`,
4103
- response_types_supported: ["code"],
4104
- grant_types_supported: ["authorization_code", "refresh_token"],
4105
- code_challenge_methods_supported: ["S256", "plain"],
4368
+ end_session_endpoint: `${base}/logout`,
4369
+ grant_types_supported: ["authorization_code", "refresh_token", "client_credentials", "urn:ietf:params:oauth:grant-type:device_code"],
4370
+ registration_endpoint: `${base}/oauth2/register`,
4371
+ authorization_endpoint: `${base}/oauth2/auth`,
4372
+ introspection_endpoint: `${base}/oauth2/introspect`,
4106
4373
  subject_types_supported: ["public"],
4374
+ response_modes_supported: ["query"],
4375
+ response_types_supported: ["code"],
4376
+ device_authorization_endpoint: `${base}/oauth2/device/auth`,
4377
+ request_uri_parameter_supported: false,
4378
+ code_challenge_methods_supported: ["S256"],
4379
+ client_id_metadata_document_supported: false,
4107
4380
  id_token_signing_alg_values_supported: ["RS256"],
4108
- scopes_supported: ["openid", "profile", "email", "offline"],
4109
- token_endpoint_auth_methods_supported: ["client_secret_post", "client_secret_basic", "none"],
4110
- claims_supported: ["aud", "exp", "iat", "iss", "sub", "org_code", "permissions", "roles", "scp"]
4381
+ token_endpoint_auth_methods_supported: ["client_secret_post", "none"]
4111
4382
  };
4112
4383
  }
4113
4384
  async function issueToken(testkit, seed, body) {
package/dist/jest.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- import { a as KindeTestkitHandle } from './handle-BERQZCyH.cjs';
2
- export { K as KindeTestAuth, k as kindeTest } from './handle-BERQZCyH.cjs';
3
- import { S as StartKindeTestkitOptions } from './server-ciWIscoQ.cjs';
1
+ import { a as KindeTestkitHandle } from './handle-QF340J2E.cjs';
2
+ export { K as KindeTestAuth, k as kindeTest } from './handle-QF340J2E.cjs';
3
+ import { S as StartKindeTestkitOptions } from './server-CcXI3vJ-.cjs';
4
4
  import 'jose';
5
5
 
6
6
  type Hook = (fn: () => Promise<void>, timeout?: number) => void;
package/dist/jest.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { a as KindeTestkitHandle } from './handle-Dh0UpIzG.js';
2
- export { K as KindeTestAuth, k as kindeTest } from './handle-Dh0UpIzG.js';
3
- import { S as StartKindeTestkitOptions } from './server-BiODgeoB.js';
1
+ import { a as KindeTestkitHandle } from './handle-DxF0uwza.js';
2
+ export { K as KindeTestAuth, k as kindeTest } from './handle-DxF0uwza.js';
3
+ import { S as StartKindeTestkitOptions } from './server-Dghq0aLx.js';
4
4
  import './webhooks-DJyCsbdF.js';
5
5
  import 'jose';
6
6
 
package/dist/jest.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  createKindeTestkitHandle,
3
3
  kindeTest
4
- } from "./chunk-U2D47SCY.js";
5
- import "./chunk-GCOZVCZY.js";
4
+ } from "./chunk-K5YNZAOM.js";
5
+ import "./chunk-IOP27RQ5.js";
6
6
 
7
7
  // src/jest.ts
8
8
  function useKindeTestkit(options = {}, hooks) {
@@ -291,6 +291,8 @@ interface UserMeta {
291
291
  createdOn: string;
292
292
  totalSignIns: number;
293
293
  lastSignedIn: string | null;
294
+ /** Last sign-in time per organization code. */
295
+ lastOrganizationSignIns: Record<string, string>;
294
296
  }
295
297
  interface OrganizationMeta {
296
298
  externalId: string | null;
@@ -338,6 +340,13 @@ declare class Directory {
338
340
  deletePermission(id: string): SeedPermission | undefined;
339
341
  }
340
342
 
343
+ interface DeviceFlowOptions {
344
+ /** Seconds a client must wait between polls. Kinde uses 5. Set 0 in tests that poll in a loop. */
345
+ intervalSeconds?: number;
346
+ /** Seconds before the device code expires. Kinde uses 600. */
347
+ expiresInSeconds?: number;
348
+ }
349
+
341
350
  interface FailureRule {
342
351
  path: string;
343
352
  method?: string;
@@ -555,6 +564,8 @@ interface StartKindeTestkitOptions {
555
564
  https?: boolean | {
556
565
  certDirectory?: string;
557
566
  };
567
+ /** Device authorization flow timing. Kinde uses a 5 second interval and 600 second codes. */
568
+ device?: DeviceFlowOptions;
558
569
  }
559
570
  interface RunningKindeTestkit {
560
571
  url: string;
@@ -576,4 +587,4 @@ interface RunningKindeTestkit {
576
587
  }
577
588
  declare function startKindeTestkit(options?: StartKindeTestkitOptions): Promise<RunningKindeTestkit>;
578
589
 
579
- export { type WebhookSource as $, type AuthenticatedScenario as A, BILLING_EVENT_TYPES as B, COVERAGE_GROUPS as C, DEFAULT_AUTH_METHODS as D, type KindeTokenOptions as E, FailureInjector as F, type ResolvedSeed as G, type RunningKindeTestkit as H, INVALID_TOKEN_KINDS as I, type ScenarioTokenOverrides as J, type KindeOrganization as K, type SendWebhookOptions as L, type M2MTokenOptions as M, type TokenEntry as N, type TokenObserver as O, type WebhookAttempt as P, type WebhookDelivery as Q, type RequestEntry as R, type StartKindeTestkitOptions as S, type TestkitSeed as T, type UnauthenticatedScenario as U, WebhookDispatcher as V, WEBHOOK_EVENT_TYPES as W, type WebhookEndpoint as X, type WebhookEndpointInput as Y, type WebhookInvalidKind as Z, type WebhookOptions as _, type KindeUser as a, buildReport as a0, clearCoverageDirectory as a1, createKindeToken as a2, formatCoverageReport as a3, getDefaultTestkit as a4, mergeSnapshots as a5, principalFromClaims as a6, readCoverageDirectory as a7, resolveSeed as a8, seedScenario as a9, startKindeTestkit as aa, type KindeMembership as b, type KindeRole as c, type Scenario as d, type ActiveFailure as e, ActivityLog as f, type CoverageGroup as g, type CoverageGroupResult as h, type CoverageItem as i, CoverageRecorder as j, type CoverageReport as k, type CoverageSnapshot as l, DEFAULT_CLIENT_ID as m, DEFAULT_COVERAGE_DIRECTORY as n, DEFAULT_ISSUER as o, DEFAULT_M2M_CLIENT_ID as p, DEFAULT_SCOPES as q, Directory as r, type Duration as s, type FailureRule as t, type IdTokenOptions as u, type InvalidTokenKind as v, type KindeApplication as w, type KindePrincipal as x, KindeTestkit as y, type KindeTestkitOptions as z };
590
+ export { type WebhookOptions as $, type AuthenticatedScenario as A, BILLING_EVENT_TYPES as B, COVERAGE_GROUPS as C, DEFAULT_AUTH_METHODS as D, type KindeTestkitOptions as E, FailureInjector as F, type KindeTokenOptions as G, type ResolvedSeed as H, INVALID_TOKEN_KINDS as I, type RunningKindeTestkit as J, type KindeOrganization as K, type ScenarioTokenOverrides as L, type M2MTokenOptions as M, type SendWebhookOptions as N, type TokenEntry as O, type TokenObserver as P, type WebhookAttempt as Q, type RequestEntry as R, type StartKindeTestkitOptions as S, type TestkitSeed as T, type UnauthenticatedScenario as U, type WebhookDelivery as V, WEBHOOK_EVENT_TYPES as W, WebhookDispatcher as X, type WebhookEndpoint as Y, type WebhookEndpointInput as Z, type WebhookInvalidKind as _, type KindeUser as a, type WebhookSource as a0, buildReport as a1, clearCoverageDirectory as a2, createKindeToken as a3, formatCoverageReport as a4, getDefaultTestkit as a5, mergeSnapshots as a6, principalFromClaims as a7, readCoverageDirectory as a8, resolveSeed as a9, seedScenario as aa, startKindeTestkit as ab, type KindeMembership as b, type KindeRole as c, type Scenario as d, type ActiveFailure as e, ActivityLog as f, type CoverageGroup as g, type CoverageGroupResult as h, type CoverageItem as i, CoverageRecorder as j, type CoverageReport as k, type CoverageSnapshot as l, DEFAULT_CLIENT_ID as m, DEFAULT_COVERAGE_DIRECTORY as n, DEFAULT_ISSUER as o, DEFAULT_M2M_CLIENT_ID as p, DEFAULT_SCOPES as q, type DeviceFlowOptions as r, Directory as s, type Duration as t, type FailureRule as u, type IdTokenOptions as v, type InvalidTokenKind as w, type KindeApplication as x, type KindePrincipal as y, KindeTestkit as z };
@@ -7,6 +7,8 @@ interface UserMeta {
7
7
  createdOn: string;
8
8
  totalSignIns: number;
9
9
  lastSignedIn: string | null;
10
+ /** Last sign-in time per organization code. */
11
+ lastOrganizationSignIns: Record<string, string>;
10
12
  }
11
13
  interface OrganizationMeta {
12
14
  externalId: string | null;
@@ -54,6 +56,13 @@ declare class Directory {
54
56
  deletePermission(id: string): SeedPermission | undefined;
55
57
  }
56
58
 
59
+ interface DeviceFlowOptions {
60
+ /** Seconds a client must wait between polls. Kinde uses 5. Set 0 in tests that poll in a loop. */
61
+ intervalSeconds?: number;
62
+ /** Seconds before the device code expires. Kinde uses 600. */
63
+ expiresInSeconds?: number;
64
+ }
65
+
57
66
  interface RequestEntry {
58
67
  at: string;
59
68
  method: string;
@@ -161,6 +170,8 @@ interface StartKindeTestkitOptions {
161
170
  https?: boolean | {
162
171
  certDirectory?: string;
163
172
  };
173
+ /** Device authorization flow timing. Kinde uses a 5 second interval and 600 second codes. */
174
+ device?: DeviceFlowOptions;
164
175
  }
165
176
  interface RunningKindeTestkit {
166
177
  url: string;
@@ -182,4 +193,4 @@ interface RunningKindeTestkit {
182
193
  }
183
194
  declare function startKindeTestkit(options?: StartKindeTestkitOptions): Promise<RunningKindeTestkit>;
184
195
 
185
- export { ActivityLog as A, COVERAGE_GROUPS as C, DEFAULT_COVERAGE_DIRECTORY as D, type RequestEntry as R, type StartKindeTestkitOptions as S, type TokenEntry as T, type CoverageGroup as a, type CoverageGroupResult as b, type CoverageItem as c, CoverageRecorder as d, type CoverageReport as e, type CoverageSnapshot as f, Directory as g, type RunningKindeTestkit as h, buildReport as i, clearCoverageDirectory as j, formatCoverageReport as k, mergeSnapshots as m, readCoverageDirectory as r, startKindeTestkit as s };
196
+ export { ActivityLog as A, COVERAGE_GROUPS as C, DEFAULT_COVERAGE_DIRECTORY as D, type RequestEntry as R, type StartKindeTestkitOptions as S, type TokenEntry as T, type CoverageGroup as a, type CoverageGroupResult as b, type CoverageItem as c, CoverageRecorder as d, type CoverageReport as e, type CoverageSnapshot as f, type DeviceFlowOptions as g, Directory as h, type RunningKindeTestkit as i, buildReport as j, clearCoverageDirectory as k, formatCoverageReport as l, mergeSnapshots as m, readCoverageDirectory as r, startKindeTestkit as s };
package/dist/vitest.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { a as KindeTestkitHandle } from './handle-Dh0UpIzG.js';
2
- export { K as KindeTestAuth, k as kindeTest } from './handle-Dh0UpIzG.js';
3
- import { S as StartKindeTestkitOptions } from './server-BiODgeoB.js';
1
+ import { a as KindeTestkitHandle } from './handle-DxF0uwza.js';
2
+ export { K as KindeTestAuth, k as kindeTest } from './handle-DxF0uwza.js';
3
+ import { S as StartKindeTestkitOptions } from './server-Dghq0aLx.js';
4
4
  import './webhooks-DJyCsbdF.js';
5
5
  import 'jose';
6
6
 
package/dist/vitest.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  createKindeTestkitHandle,
3
3
  kindeTest
4
- } from "./chunk-U2D47SCY.js";
5
- import "./chunk-GCOZVCZY.js";
4
+ } from "./chunk-K5YNZAOM.js";
5
+ import "./chunk-IOP27RQ5.js";
6
6
 
7
7
  // src/vitest.ts
8
8
  import { afterAll, beforeAll } from "vitest";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kinde-testkit",
3
- "version": "0.6.1",
3
+ "version": "0.7.1",
4
4
  "description": "Test Kinde-authenticated apps offline: a local issuer with a real sign-in flow, Kinde-shaped tokens, reusable auth scenarios, and Vitest and Playwright helpers.",
5
5
  "license": "MIT",
6
6
  "author": "Shola Jegede <jegedeshola@gmail.com>",