@lifeaitools/clauth 1.5.10 → 1.5.11
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 +11 -1
- package/package.json +1 -1
package/cli/commands/serve.js
CHANGED
|
@@ -2505,7 +2505,16 @@ function createServer(initPassword, whitelist, port, tunnelHostnameInit = null,
|
|
|
2505
2505
|
// ── OAuth provider (self-contained for claude.ai MCP) ──────
|
|
2506
2506
|
const oauthClients = new Map(); // client_id → { client_secret, redirect_uris, client_name }
|
|
2507
2507
|
const oauthCodes = new Map(); // code → { client_id, redirect_uri, code_challenge, expires }
|
|
2508
|
-
|
|
2508
|
+
|
|
2509
|
+
// Persist tokens to disk so daemon restarts don't invalidate claude.ai sessions
|
|
2510
|
+
const TOKENS_FILE = path.join(os.tmpdir(), "clauth-oauth-tokens.json");
|
|
2511
|
+
function loadTokens() {
|
|
2512
|
+
try { return new Set(JSON.parse(fs.readFileSync(TOKENS_FILE, "utf8"))); } catch { return new Set(); }
|
|
2513
|
+
}
|
|
2514
|
+
function saveTokens(set) {
|
|
2515
|
+
try { fs.writeFileSync(TOKENS_FILE, JSON.stringify([...set])); } catch {}
|
|
2516
|
+
}
|
|
2517
|
+
const oauthTokens = loadTokens(); // active access tokens — persisted across restarts
|
|
2509
2518
|
|
|
2510
2519
|
// Pre-generate a stable client for claude.ai (shown at startup)
|
|
2511
2520
|
const OAUTH_CLIENT_ID = crypto.randomBytes(16).toString("hex");
|
|
@@ -2998,6 +3007,7 @@ function createServer(initPassword, whitelist, port, tunnelHostnameInit = null,
|
|
|
2998
3007
|
oauthCodes.delete(body.code);
|
|
2999
3008
|
const accessToken = crypto.randomBytes(32).toString("hex");
|
|
3000
3009
|
oauthTokens.add(accessToken);
|
|
3010
|
+
saveTokens(oauthTokens);
|
|
3001
3011
|
|
|
3002
3012
|
const logMsg = `[${new Date().toISOString()}] OAuth: token issued for client ${stored.client_id}\n`;
|
|
3003
3013
|
try { fs.appendFileSync(LOG_FILE, logMsg); } catch {}
|