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/cli.js
CHANGED
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
|
-
|
|
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(
|
|
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
|
}
|
|
@@ -3415,7 +3660,8 @@ var COVERAGE_GROUPS = [
|
|
|
3415
3660
|
{ id: "session.refresh", label: "Refresh", hint: "Let the app refresh its session, or call the refresh_token grant." },
|
|
3416
3661
|
{ id: "session.sign-out", label: "Sign-out", hint: "Sign out through your app's logout route." },
|
|
3417
3662
|
{ 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." }
|
|
3663
|
+
{ id: "session.silent", label: "Silent sign-in with no session", hint: "Send prompt=none and handle login_required." },
|
|
3664
|
+
{ id: "session.device-approved", label: "Device sign-in", hint: "Run the device authorization flow and approve it with POST /testkit/device." }
|
|
3419
3665
|
]
|
|
3420
3666
|
},
|
|
3421
3667
|
{
|
|
@@ -3827,7 +4073,7 @@ async function startKindeTestkit(options = {}) {
|
|
|
3827
4073
|
const directory = new Directory(seed);
|
|
3828
4074
|
const webhooks = new WebhookDispatcher(testkit, seed, seed.webhooks, options.webhooks);
|
|
3829
4075
|
webhooks.observe = observe;
|
|
3830
|
-
const auth = new AuthorizationServer(testkit, seed, (type, user) => webhooks.emitForUser(type, user), directory, observe);
|
|
4076
|
+
const auth = new AuthorizationServer(testkit, seed, (type, user) => webhooks.emitForUser(type, user), directory, observe, options.device);
|
|
3831
4077
|
const management = new ManagementApi(testkit, directory, webhooks);
|
|
3832
4078
|
const account = new AccountApi(testkit, directory);
|
|
3833
4079
|
const reset = () => {
|
|
@@ -3902,7 +4148,7 @@ async function handle(req, res, context) {
|
|
|
3902
4148
|
}
|
|
3903
4149
|
}
|
|
3904
4150
|
}
|
|
3905
|
-
if (await auth.handle(req, res, url, () => readForm(req))) return;
|
|
4151
|
+
if (await auth.handle(req, res, url, () => readForm(req), () => readJson(req))) return;
|
|
3906
4152
|
if (await context.management.handle(req, res, url, async () => await readJson(req))) {
|
|
3907
4153
|
if (res.statusCode === 401 || res.statusCode === 403) coverage.hit("api.management-denied");
|
|
3908
4154
|
else if (res.statusCode < 400) coverage.hit(method === "GET" ? "api.management-read" : "api.management-write");
|
|
@@ -3962,6 +4208,21 @@ async function handle(req, res, context) {
|
|
|
3962
4208
|
const removed = webhooks.removeEndpoint(decodeURIComponent(pathname.slice("/testkit/webhooks/endpoints/".length)));
|
|
3963
4209
|
return sendJson4(res, removed ? 200 : 404, { ok: removed });
|
|
3964
4210
|
}
|
|
4211
|
+
if (method === "POST" && pathname === "/testkit/device") {
|
|
4212
|
+
const input = await readJson(req);
|
|
4213
|
+
try {
|
|
4214
|
+
auth.resolveDevice({
|
|
4215
|
+
userCode: String(input.user_code ?? ""),
|
|
4216
|
+
user: typeof input.user === "string" ? input.user : void 0,
|
|
4217
|
+
organization: typeof input.organization === "string" ? input.organization : null,
|
|
4218
|
+
deny: input.action === "deny"
|
|
4219
|
+
});
|
|
4220
|
+
} catch (error) {
|
|
4221
|
+
if (error instanceof OAuthError) return sendJson4(res, error.status, { error: error.error, error_description: error.message });
|
|
4222
|
+
throw error;
|
|
4223
|
+
}
|
|
4224
|
+
return sendJson4(res, 200, { ok: true });
|
|
4225
|
+
}
|
|
3965
4226
|
if (method === "POST" && pathname === "/testkit/reset") {
|
|
3966
4227
|
context.reset();
|
|
3967
4228
|
return sendJson4(res, 200, { ok: true });
|
|
@@ -4085,20 +4346,26 @@ function discovery(testkit) {
|
|
|
4085
4346
|
const base = testkit.issuer;
|
|
4086
4347
|
return {
|
|
4087
4348
|
issuer: base,
|
|
4088
|
-
|
|
4349
|
+
jwks_uri: `${base}/.well-known/jwks`,
|
|
4089
4350
|
token_endpoint: `${base}/oauth2/token`,
|
|
4351
|
+
claims_supported: ["aud", "exp", "iat", "iss", "sub", "acr", "amr", "auth_time"],
|
|
4352
|
+
scopes_supported: ["address", "email", "offline", "openid", "phone", "profile"],
|
|
4090
4353
|
userinfo_endpoint: `${base}/oauth2/v2/user_profile`,
|
|
4091
|
-
end_session_endpoint: `${base}/logout`,
|
|
4092
4354
|
revocation_endpoint: `${base}/oauth2/revoke`,
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4355
|
+
end_session_endpoint: `${base}/logout`,
|
|
4356
|
+
grant_types_supported: ["authorization_code", "refresh_token", "client_credentials", "urn:ietf:params:oauth:grant-type:device_code"],
|
|
4357
|
+
registration_endpoint: `${base}/oauth2/register`,
|
|
4358
|
+
authorization_endpoint: `${base}/oauth2/auth`,
|
|
4359
|
+
introspection_endpoint: `${base}/oauth2/introspect`,
|
|
4097
4360
|
subject_types_supported: ["public"],
|
|
4361
|
+
response_modes_supported: ["query"],
|
|
4362
|
+
response_types_supported: ["code"],
|
|
4363
|
+
device_authorization_endpoint: `${base}/oauth2/device/auth`,
|
|
4364
|
+
request_uri_parameter_supported: false,
|
|
4365
|
+
code_challenge_methods_supported: ["S256"],
|
|
4366
|
+
client_id_metadata_document_supported: false,
|
|
4098
4367
|
id_token_signing_alg_values_supported: ["RS256"],
|
|
4099
|
-
|
|
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"]
|
|
4368
|
+
token_endpoint_auth_methods_supported: ["client_secret_post", "none"]
|
|
4102
4369
|
};
|
|
4103
4370
|
}
|
|
4104
4371
|
async function issueToken(testkit, seed, body) {
|
package/dist/cypress.d.cts
CHANGED
package/dist/cypress.d.ts
CHANGED
package/dist/cypress.js
CHANGED
|
@@ -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 {
|
|
2
|
+
import { h as Directory, d as CoverageRecorder, A as ActivityLog } from './server-B9fBcnyQ.js';
|
|
3
3
|
|
|
4
4
|
interface KindeTestAuth {
|
|
5
5
|
token: string | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { y as KindePrincipal, z as KindeTestkit, F as FailureInjector, X as WebhookDispatcher, s as Directory, j as CoverageRecorder, f as ActivityLog, d as Scenario, L as ScenarioTokenOverrides, T as TestkitSeed } from './server-CTBJXMac.cjs';
|
|
2
2
|
|
|
3
3
|
interface KindeTestAuth {
|
|
4
4
|
token: string | null;
|