fix: googlechat gog oauth token loading

This commit is contained in:
iHildy committed 2026-01-26 18:45:09 -06:00
1 parent abe242a3bb
commit 3c1114d0e8
3 files changed
+43 -18

No files matched your search

+12
View File
@@ -543,6 +543,16 @@ export const googlechatPlugin: ChannelPlugin<ResolvedGoogleChatAccount> = {
const configured = entry.configured === true;
if (!enabled || !configured) return [];
const issues = [];
if (entry.oauthFromGog && entry.userCredentialSource === "none") {
issues.push({
channel: "googlechat",
accountId,
kind: "auth",
message:
"Google Chat OAuth is set to reuse gog, but no gog OAuth credentials were detected.",
fix: "Ensure gog is installed and the keyring is unlocked (set GOG_KEYRING_PASSWORD), or set oauthRefreshToken/oauthClientFile manually.",
});
}
if (!entry.audience) {
issues.push({
channel: "googlechat",
@@ -584,6 +594,8 @@ export const googlechatPlugin: ChannelPlugin<ResolvedGoogleChatAccount> = {
enabled: account.enabled,
configured: account.credentialSource !== "none",
credentialSource: account.credentialSource,
oauthFromGog: account.config.oauthFromGog ?? false,
userCredentialSource: account.userCredentialSource,
audienceType: account.config.audienceType,
audience: account.config.audience,
webhookPath: account.config.webhookPath,
+28 -16
View File
@@ -109,25 +109,37 @@ export function readGogRefreshTokenSync(params: {
const cached = tokenCache.get(cacheKey);
if (cached) return cached;
let stdout = "";
try {
stdout = execFileSync("gog", ["auth", "tokens", "--json"], {
encoding: "utf8",
stdio: ["ignore", "pipe", "pipe"],
});
} catch {
return null;
}
const env = {
...process.env,
...(params.gogAccount?.trim() ? { GOG_ACCOUNT: params.gogAccount.trim() } : {}),
...(params.gogClient?.trim() ? { GOG_CLIENT: params.gogClient.trim() } : {}),
};
let parsed: unknown;
try {
parsed = JSON.parse(stdout);
} catch {
return null;
}
const runGogJson = (args: string[]): unknown | null => {
try {
const stdout = execFileSync("gog", ["--no-input", ...args], {
encoding: "utf8",
stdio: ["ignore", "pipe", "pipe"],
timeout: 3000,
env,
});
return JSON.parse(stdout);
} catch {
return null;
}
};
const parsed = runGogJson(["auth", "tokens", "list", "--json"]);
const tokens: GogTokenEntry[] = [];
collectTokens(parsed, tokens);
if (parsed) {
collectTokens(parsed, tokens);
}
if (tokens.length === 0) {
const exported = runGogJson(["auth", "tokens", "export", "--json"]);
if (exported) {
collectTokens(exported, tokens);
}
}
if (tokens.length === 0) return null;
const target = params.gogAccount?.trim().toLowerCase();