mirror of
https://github.com/dtzp555-max/ocp.git
synced 2026-07-21 21:15:09 +00:00
fix: read OAuth token from Linux credentials file as fallback
On Linux (no macOS keychain), read ~/.claude/.credentials.json first. Falls through to macOS keychain if file not found. Fixes /ocp usage showing "No OAuth token" on Linux servers and RPi. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+10
@@ -43,6 +43,7 @@ import { randomUUID, timingSafeEqual } from "node:crypto";
|
|||||||
import { readFileSync, accessSync, constants } from "node:fs";
|
import { readFileSync, accessSync, constants } from "node:fs";
|
||||||
import { fileURLToPath } from "node:url";
|
import { fileURLToPath } from "node:url";
|
||||||
import { dirname, join } from "node:path";
|
import { dirname, join } from "node:path";
|
||||||
|
import { homedir } from "node:os";
|
||||||
|
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
const _pkg = JSON.parse(readFileSync(join(__dirname, "package.json"), "utf8"));
|
const _pkg = JSON.parse(readFileSync(join(__dirname, "package.json"), "utf8"));
|
||||||
@@ -687,6 +688,15 @@ let usageCache = { data: null, fetchedAt: 0 };
|
|||||||
const USAGE_CACHE_TTL = 300000; // 5 min
|
const USAGE_CACHE_TTL = 300000; // 5 min
|
||||||
|
|
||||||
function getOAuthToken() {
|
function getOAuthToken() {
|
||||||
|
// Try Linux file-based credentials first
|
||||||
|
try {
|
||||||
|
const credPath = join(homedir(), ".claude", ".credentials.json");
|
||||||
|
const creds = JSON.parse(readFileSync(credPath, "utf8"));
|
||||||
|
const token = creds?.claudeAiOauth?.accessToken;
|
||||||
|
if (token) return token;
|
||||||
|
} catch { /* fall through to macOS keychain */ }
|
||||||
|
|
||||||
|
// Try macOS keychain
|
||||||
try {
|
try {
|
||||||
const raw = execFileSync("security", [
|
const raw = execFileSync("security", [
|
||||||
"find-generic-password", "-s", "Claude Code-credentials", "-w"
|
"find-generic-password", "-s", "Claude Code-credentials", "-w"
|
||||||
|
|||||||
Reference in New Issue
Block a user