@lifeaitools/clauth 1.5.17 → 1.5.18
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/cli/commands/serve.js +6 -101
- package/package.json +1 -1
package/cli/commands/serve.js
CHANGED
|
@@ -2885,107 +2885,12 @@ function createServer(initPassword, whitelist, port, tunnelHostnameInit = null,
|
|
|
2885
2885
|
return res.end(JSON.stringify({ error: "not_found" }));
|
|
2886
2886
|
}
|
|
2887
2887
|
|
|
2888
|
-
// ──
|
|
2889
|
-
if (method === "POST" && reqPath === "/register")
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
}
|
|
2895
|
-
const clientId = crypto.randomBytes(16).toString("hex");
|
|
2896
|
-
const clientSecret = crypto.randomBytes(32).toString("hex");
|
|
2897
|
-
const client = {
|
|
2898
|
-
client_id: clientId, client_secret: clientSecret,
|
|
2899
|
-
client_name: body.client_name || "unknown",
|
|
2900
|
-
redirect_uris: body.redirect_uris || [],
|
|
2901
|
-
grant_types: body.grant_types || ["authorization_code"],
|
|
2902
|
-
response_types: body.response_types || ["code"],
|
|
2903
|
-
token_endpoint_auth_method: body.token_endpoint_auth_method || "client_secret_post",
|
|
2904
|
-
};
|
|
2905
|
-
oauthClients.set(clientId, client);
|
|
2906
|
-
const logMsg = `[${new Date().toISOString()}] OAuth: registered client ${clientId} (${client.client_name})\n`;
|
|
2907
|
-
try { fs.appendFileSync(LOG_FILE, logMsg); } catch {}
|
|
2908
|
-
res.writeHead(201, { "Content-Type": "application/json", ...CORS });
|
|
2909
|
-
return res.end(JSON.stringify(client));
|
|
2910
|
-
}
|
|
2911
|
-
|
|
2912
|
-
// ── Authorization endpoint — auto-approve ──────────────
|
|
2913
|
-
if (method === "GET" && reqPath === "/authorize") {
|
|
2914
|
-
const clientId = url.searchParams.get("client_id");
|
|
2915
|
-
const redirectUri = url.searchParams.get("redirect_uri");
|
|
2916
|
-
const state = url.searchParams.get("state");
|
|
2917
|
-
const codeChallenge = url.searchParams.get("code_challenge");
|
|
2918
|
-
const codeChallengeMethod = url.searchParams.get("code_challenge_method");
|
|
2919
|
-
|
|
2920
|
-
if (!clientId || !redirectUri) {
|
|
2921
|
-
res.writeHead(400, { "Content-Type": "text/plain", ...CORS });
|
|
2922
|
-
return res.end("Missing client_id or redirect_uri");
|
|
2923
|
-
}
|
|
2924
|
-
|
|
2925
|
-
const code = crypto.randomBytes(32).toString("hex");
|
|
2926
|
-
oauthCodes.set(code, {
|
|
2927
|
-
client_id: clientId, redirect_uri: redirectUri,
|
|
2928
|
-
code_challenge: codeChallenge, code_challenge_method: codeChallengeMethod,
|
|
2929
|
-
expires: Date.now() + 300_000,
|
|
2930
|
-
});
|
|
2931
|
-
|
|
2932
|
-
const redirect = new URL(redirectUri);
|
|
2933
|
-
redirect.searchParams.set("code", code);
|
|
2934
|
-
if (state) redirect.searchParams.set("state", state);
|
|
2935
|
-
|
|
2936
|
-
const logMsg = `[${new Date().toISOString()}] OAuth: authorize → code issued for ${clientId}, redirecting to ${redirect.origin}\n`;
|
|
2937
|
-
try { fs.appendFileSync(LOG_FILE, logMsg); } catch {}
|
|
2938
|
-
res.writeHead(302, { Location: redirect.toString(), ...CORS });
|
|
2939
|
-
return res.end();
|
|
2940
|
-
}
|
|
2941
|
-
|
|
2942
|
-
// ── Token endpoint ──────────────────────────────────────
|
|
2943
|
-
if (method === "POST" && reqPath === "/token") {
|
|
2944
|
-
let body;
|
|
2945
|
-
const ct = req.headers["content-type"] || "";
|
|
2946
|
-
try {
|
|
2947
|
-
if (ct.includes("application/json")) {
|
|
2948
|
-
body = await readBody(req);
|
|
2949
|
-
} else {
|
|
2950
|
-
const raw = await readRawBody(req);
|
|
2951
|
-
body = Object.fromEntries(new URLSearchParams(raw));
|
|
2952
|
-
}
|
|
2953
|
-
} catch {
|
|
2954
|
-
res.writeHead(400, { "Content-Type": "application/json", ...CORS });
|
|
2955
|
-
return res.end(JSON.stringify({ error: "invalid_request" }));
|
|
2956
|
-
}
|
|
2957
|
-
|
|
2958
|
-
if (body.grant_type !== "authorization_code") {
|
|
2959
|
-
res.writeHead(400, { "Content-Type": "application/json", ...CORS });
|
|
2960
|
-
return res.end(JSON.stringify({ error: "unsupported_grant_type" }));
|
|
2961
|
-
}
|
|
2962
|
-
|
|
2963
|
-
const stored = oauthCodes.get(body.code);
|
|
2964
|
-
if (!stored || stored.expires < Date.now()) {
|
|
2965
|
-
oauthCodes.delete(body.code);
|
|
2966
|
-
res.writeHead(400, { "Content-Type": "application/json", ...CORS });
|
|
2967
|
-
return res.end(JSON.stringify({ error: "invalid_grant" }));
|
|
2968
|
-
}
|
|
2969
|
-
|
|
2970
|
-
// PKCE verification
|
|
2971
|
-
if (stored.code_challenge && body.code_verifier) {
|
|
2972
|
-
const computed = sha256base64url(body.code_verifier);
|
|
2973
|
-
if (computed !== stored.code_challenge) {
|
|
2974
|
-
oauthCodes.delete(body.code);
|
|
2975
|
-
res.writeHead(400, { "Content-Type": "application/json", ...CORS });
|
|
2976
|
-
return res.end(JSON.stringify({ error: "invalid_grant", error_description: "PKCE verification failed" }));
|
|
2977
|
-
}
|
|
2978
|
-
}
|
|
2979
|
-
|
|
2980
|
-
oauthCodes.delete(body.code);
|
|
2981
|
-
const accessToken = crypto.randomBytes(32).toString("hex");
|
|
2982
|
-
oauthTokens.add(accessToken);
|
|
2983
|
-
saveTokens(oauthTokens);
|
|
2984
|
-
|
|
2985
|
-
const logMsg = `[${new Date().toISOString()}] OAuth: token issued for client ${stored.client_id}\n`;
|
|
2986
|
-
try { fs.appendFileSync(LOG_FILE, logMsg); } catch {}
|
|
2987
|
-
res.writeHead(200, { "Content-Type": "application/json", ...CORS });
|
|
2988
|
-
return res.end(JSON.stringify({ access_token: accessToken, token_type: "Bearer", expires_in: 86400 }));
|
|
2888
|
+
// ── OAuth endpoints — disabled (well-known removed, these are dead paths) ──
|
|
2889
|
+
if ((method === "POST" && reqPath === "/register") ||
|
|
2890
|
+
(method === "GET" && reqPath === "/authorize") ||
|
|
2891
|
+
(method === "POST" && reqPath === "/token")) {
|
|
2892
|
+
res.writeHead(404, { "Content-Type": "application/json", ...CORS });
|
|
2893
|
+
return res.end(JSON.stringify({ error: "not_found" }));
|
|
2989
2894
|
}
|
|
2990
2895
|
|
|
2991
2896
|
// ── MCP path helpers ──
|