kinde-testkit 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +89 -3
- package/dist/chunk-2QJ7DTNL.js +72 -0
- package/dist/chunk-2QJ7DTNL.js.map +1 -0
- package/dist/chunk-33AHOLUN.js +183 -0
- package/dist/chunk-33AHOLUN.js.map +1 -0
- package/dist/chunk-JTAB2S44.js +3697 -0
- package/dist/chunk-JTAB2S44.js.map +1 -0
- package/dist/cli.js +50 -3561
- package/dist/cli.js.map +1 -0
- package/dist/cypress.cjs +286 -17
- package/dist/cypress.d.cts +2 -96
- package/dist/cypress.d.ts +3 -96
- package/dist/cypress.js +2 -3303
- package/dist/cypress.js.map +1 -1
- package/dist/handle-E_BhdHx8.d.ts +33 -0
- package/dist/handle-estfqypp.d.cts +32 -0
- package/dist/index.cjs +286 -17
- package/dist/index.d.cts +7 -607
- package/dist/index.d.ts +8 -607
- package/dist/index.js +51 -3577
- package/dist/index.js.map +1 -1
- package/dist/jest.cjs +286 -17
- package/dist/jest.d.cts +5 -555
- package/dist/jest.d.ts +6 -555
- package/dist/jest.js +4 -3373
- package/dist/jest.js.map +1 -1
- package/dist/playwright.d.ts +2 -54
- package/dist/server-B9fBcnyQ.d.ts +194 -0
- package/dist/server-CTBJXMac.d.cts +588 -0
- package/dist/vitest.d.ts +6 -555
- package/dist/vitest.js +5 -3376
- package/dist/vitest.js.map +1 -1
- package/dist/webhooks-DJyCsbdF.d.ts +397 -0
- package/package.json +3 -2
- package/dist/cypress-support.d.ts +0 -98
- package/dist/cypress.cjs.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/jest.cjs.map +0 -1
package/dist/jest.cjs
CHANGED
|
@@ -994,6 +994,8 @@ function unique(values) {
|
|
|
994
994
|
var TestkitError = class extends Error {
|
|
995
995
|
code;
|
|
996
996
|
details;
|
|
997
|
+
/** The message without the details list. */
|
|
998
|
+
summary;
|
|
997
999
|
constructor(code, message2, details = []) {
|
|
998
1000
|
super(details.length > 0 ? `${message2}
|
|
999
1001
|
|
|
@@ -1001,6 +1003,7 @@ ${details.map((d) => ` - ${d}`).join("\n")}` : message2);
|
|
|
1001
1003
|
this.name = "TestkitError";
|
|
1002
1004
|
this.code = code;
|
|
1003
1005
|
this.details = details;
|
|
1006
|
+
this.summary = message2;
|
|
1004
1007
|
}
|
|
1005
1008
|
toString() {
|
|
1006
1009
|
return `${this.code}
|
|
@@ -1501,6 +1504,19 @@ function renderOrganizationPicker(options) {
|
|
|
1501
1504
|
function renderMessage(title, message2) {
|
|
1502
1505
|
return layout(title, `<h1>${escapeHtml(title)}</h1><p>${escapeHtml(message2)}</p>`);
|
|
1503
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
|
+
}
|
|
1504
1520
|
|
|
1505
1521
|
// src/seed.ts
|
|
1506
1522
|
function roleRecord(key, extra = {}) {
|
|
@@ -1816,6 +1832,8 @@ function featureFlagsFor(seed, organizationCode) {
|
|
|
1816
1832
|
// src/oauth.ts
|
|
1817
1833
|
var import_node_crypto4 = require("crypto");
|
|
1818
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";
|
|
1819
1837
|
var OAuthError = class extends Error {
|
|
1820
1838
|
constructor(status, error, description) {
|
|
1821
1839
|
super(description);
|
|
@@ -1826,24 +1844,49 @@ var OAuthError = class extends Error {
|
|
|
1826
1844
|
error;
|
|
1827
1845
|
};
|
|
1828
1846
|
var AuthorizationServer = class {
|
|
1829
|
-
constructor(testkit, seed, emit = () => void 0, directory, observe = () => void 0) {
|
|
1847
|
+
constructor(testkit, seed, emit = () => void 0, directory, observe = () => void 0, deviceOptions = {}) {
|
|
1830
1848
|
this.testkit = testkit;
|
|
1831
1849
|
this.seed = seed;
|
|
1832
1850
|
this.emit = emit;
|
|
1833
1851
|
this.directory = directory;
|
|
1834
1852
|
this.observe = observe;
|
|
1853
|
+
this.deviceOptions = deviceOptions;
|
|
1835
1854
|
}
|
|
1836
1855
|
testkit;
|
|
1837
1856
|
seed;
|
|
1838
1857
|
emit;
|
|
1839
1858
|
directory;
|
|
1840
1859
|
observe;
|
|
1860
|
+
deviceOptions;
|
|
1841
1861
|
codes = /* @__PURE__ */ new Map();
|
|
1842
1862
|
refreshTokens = /* @__PURE__ */ new Map();
|
|
1843
1863
|
signedUpUsers = /* @__PURE__ */ new Map();
|
|
1844
|
-
|
|
1864
|
+
devices = /* @__PURE__ */ new Map();
|
|
1865
|
+
registeredClients = /* @__PURE__ */ new Map();
|
|
1866
|
+
async handle(req, res, url, readBody, readJson2 = async () => ({})) {
|
|
1845
1867
|
const method = req.method ?? "GET";
|
|
1846
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;
|
|
1847
1890
|
case "GET /oauth2/auth":
|
|
1848
1891
|
this.authorize(res, url.searchParams);
|
|
1849
1892
|
return true;
|
|
@@ -1991,8 +2034,14 @@ var AuthorizationServer = class {
|
|
|
1991
2034
|
} else if (grantType === "refresh_token") {
|
|
1992
2035
|
grant = this.redeemRefreshToken(form2, clientId);
|
|
1993
2036
|
this.observe("session.refresh");
|
|
2037
|
+
} else if (grantType === DEVICE_CODE_GRANT) {
|
|
2038
|
+
grant = this.pollDevice(form2, clientId);
|
|
1994
2039
|
} else {
|
|
1995
|
-
throw new OAuthError(
|
|
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
|
+
);
|
|
1996
2045
|
}
|
|
1997
2046
|
sendJson(res, 200, await this.issueTokens(grant));
|
|
1998
2047
|
} catch (error) {
|
|
@@ -2010,6 +2059,7 @@ var AuthorizationServer = class {
|
|
|
2010
2059
|
const requested = (form2.scope ?? "").split(/\s+/).filter(Boolean);
|
|
2011
2060
|
const granted = app?.scopes ? requested.length === 0 ? [...app.scopes] : requested.filter((scope) => app.scopes.includes(scope)) : requested;
|
|
2012
2061
|
const audience = (form2.audience ?? "").split(/\s+/).filter(Boolean);
|
|
2062
|
+
this.checkAudience(app?.audience ?? null, audience);
|
|
2013
2063
|
return {
|
|
2014
2064
|
access_token: await this.testkit.m2mToken({
|
|
2015
2065
|
clientId,
|
|
@@ -2028,6 +2078,201 @@ var AuthorizationServer = class {
|
|
|
2028
2078
|
this.codes.clear();
|
|
2029
2079
|
this.refreshTokens.clear();
|
|
2030
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()];
|
|
2031
2276
|
}
|
|
2032
2277
|
redeemCode(form2, clientId) {
|
|
2033
2278
|
const code = form2.code ?? "";
|
|
@@ -2232,6 +2477,9 @@ function isHttpUrl(value) {
|
|
|
2232
2477
|
return false;
|
|
2233
2478
|
}
|
|
2234
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
|
+
}
|
|
2235
2483
|
function randomToken() {
|
|
2236
2484
|
return (0, import_node_crypto4.randomBytes)(32).toString("base64url");
|
|
2237
2485
|
}
|
|
@@ -3421,7 +3669,8 @@ var COVERAGE_GROUPS = [
|
|
|
3421
3669
|
{ id: "session.refresh", label: "Refresh", hint: "Let the app refresh its session, or call the refresh_token grant." },
|
|
3422
3670
|
{ id: "session.sign-out", label: "Sign-out", hint: "Sign out through your app's logout route." },
|
|
3423
3671
|
{ id: "session.revoke", label: "Refresh token revoked", hint: "Call /oauth2/revoke, as some SDKs do on sign-out." },
|
|
3424
|
-
{ id: "session.silent", label: "Silent sign-in with no session", hint: "Send prompt=none and handle login_required." }
|
|
3672
|
+
{ id: "session.silent", label: "Silent sign-in with no session", hint: "Send prompt=none and handle login_required." },
|
|
3673
|
+
{ id: "session.device-approved", label: "Device sign-in", hint: "Run the device authorization flow and approve it with POST /testkit/device." }
|
|
3425
3674
|
]
|
|
3426
3675
|
},
|
|
3427
3676
|
{
|
|
@@ -3833,7 +4082,7 @@ async function startKindeTestkit(options = {}) {
|
|
|
3833
4082
|
const directory = new Directory(seed);
|
|
3834
4083
|
const webhooks = new WebhookDispatcher(testkit, seed, seed.webhooks, options.webhooks);
|
|
3835
4084
|
webhooks.observe = observe;
|
|
3836
|
-
const auth = new AuthorizationServer(testkit, seed, (type, user) => webhooks.emitForUser(type, user), directory, observe);
|
|
4085
|
+
const auth = new AuthorizationServer(testkit, seed, (type, user) => webhooks.emitForUser(type, user), directory, observe, options.device);
|
|
3837
4086
|
const management = new ManagementApi(testkit, directory, webhooks);
|
|
3838
4087
|
const account = new AccountApi(testkit, directory);
|
|
3839
4088
|
const reset = () => {
|
|
@@ -3908,7 +4157,7 @@ async function handle(req, res, context) {
|
|
|
3908
4157
|
}
|
|
3909
4158
|
}
|
|
3910
4159
|
}
|
|
3911
|
-
if (await auth.handle(req, res, url, () => readForm(req))) return;
|
|
4160
|
+
if (await auth.handle(req, res, url, () => readForm(req), () => readJson(req))) return;
|
|
3912
4161
|
if (await context.management.handle(req, res, url, async () => await readJson(req))) {
|
|
3913
4162
|
if (res.statusCode === 401 || res.statusCode === 403) coverage.hit("api.management-denied");
|
|
3914
4163
|
else if (res.statusCode < 400) coverage.hit(method === "GET" ? "api.management-read" : "api.management-write");
|
|
@@ -3968,6 +4217,21 @@ async function handle(req, res, context) {
|
|
|
3968
4217
|
const removed = webhooks.removeEndpoint(decodeURIComponent(pathname.slice("/testkit/webhooks/endpoints/".length)));
|
|
3969
4218
|
return sendJson4(res, removed ? 200 : 404, { ok: removed });
|
|
3970
4219
|
}
|
|
4220
|
+
if (method === "POST" && pathname === "/testkit/device") {
|
|
4221
|
+
const input = await readJson(req);
|
|
4222
|
+
try {
|
|
4223
|
+
auth.resolveDevice({
|
|
4224
|
+
userCode: String(input.user_code ?? ""),
|
|
4225
|
+
user: typeof input.user === "string" ? input.user : void 0,
|
|
4226
|
+
organization: typeof input.organization === "string" ? input.organization : null,
|
|
4227
|
+
deny: input.action === "deny"
|
|
4228
|
+
});
|
|
4229
|
+
} catch (error) {
|
|
4230
|
+
if (error instanceof OAuthError) return sendJson4(res, error.status, { error: error.error, error_description: error.message });
|
|
4231
|
+
throw error;
|
|
4232
|
+
}
|
|
4233
|
+
return sendJson4(res, 200, { ok: true });
|
|
4234
|
+
}
|
|
3971
4235
|
if (method === "POST" && pathname === "/testkit/reset") {
|
|
3972
4236
|
context.reset();
|
|
3973
4237
|
return sendJson4(res, 200, { ok: true });
|
|
@@ -4091,20 +4355,26 @@ function discovery(testkit) {
|
|
|
4091
4355
|
const base = testkit.issuer;
|
|
4092
4356
|
return {
|
|
4093
4357
|
issuer: base,
|
|
4094
|
-
|
|
4358
|
+
jwks_uri: `${base}/.well-known/jwks`,
|
|
4095
4359
|
token_endpoint: `${base}/oauth2/token`,
|
|
4360
|
+
claims_supported: ["aud", "exp", "iat", "iss", "sub", "acr", "amr", "auth_time"],
|
|
4361
|
+
scopes_supported: ["address", "email", "offline", "openid", "phone", "profile"],
|
|
4096
4362
|
userinfo_endpoint: `${base}/oauth2/v2/user_profile`,
|
|
4097
|
-
end_session_endpoint: `${base}/logout`,
|
|
4098
4363
|
revocation_endpoint: `${base}/oauth2/revoke`,
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4364
|
+
end_session_endpoint: `${base}/logout`,
|
|
4365
|
+
grant_types_supported: ["authorization_code", "refresh_token", "client_credentials", "urn:ietf:params:oauth:grant-type:device_code"],
|
|
4366
|
+
registration_endpoint: `${base}/oauth2/register`,
|
|
4367
|
+
authorization_endpoint: `${base}/oauth2/auth`,
|
|
4368
|
+
introspection_endpoint: `${base}/oauth2/introspect`,
|
|
4103
4369
|
subject_types_supported: ["public"],
|
|
4370
|
+
response_modes_supported: ["query"],
|
|
4371
|
+
response_types_supported: ["code"],
|
|
4372
|
+
device_authorization_endpoint: `${base}/oauth2/device/auth`,
|
|
4373
|
+
request_uri_parameter_supported: false,
|
|
4374
|
+
code_challenge_methods_supported: ["S256"],
|
|
4375
|
+
client_id_metadata_document_supported: false,
|
|
4104
4376
|
id_token_signing_alg_values_supported: ["RS256"],
|
|
4105
|
-
|
|
4106
|
-
token_endpoint_auth_methods_supported: ["client_secret_post", "client_secret_basic", "none"],
|
|
4107
|
-
claims_supported: ["aud", "exp", "iat", "iss", "sub", "org_code", "permissions", "roles", "scp"]
|
|
4377
|
+
token_endpoint_auth_methods_supported: ["client_secret_post", "none"]
|
|
4108
4378
|
};
|
|
4109
4379
|
}
|
|
4110
4380
|
async function issueToken(testkit, seed, body) {
|
|
@@ -4227,7 +4497,7 @@ function sendError(res, error) {
|
|
|
4227
4497
|
return;
|
|
4228
4498
|
}
|
|
4229
4499
|
if (error instanceof TestkitError) {
|
|
4230
|
-
sendJson4(res, 400, { error: error.code, error_description: error.
|
|
4500
|
+
sendJson4(res, 400, { error: error.code, error_description: error.summary, details: error.details });
|
|
4231
4501
|
return;
|
|
4232
4502
|
}
|
|
4233
4503
|
sendJson4(res, 500, {
|
|
@@ -4315,4 +4585,3 @@ function useKindeTestkit(options = {}, hooks) {
|
|
|
4315
4585
|
kindeTest,
|
|
4316
4586
|
useKindeTestkit
|
|
4317
4587
|
});
|
|
4318
|
-
//# sourceMappingURL=jest.cjs.map
|