fix(auth): strip line breaks from pasted keys

This commit is contained in:
Peter Steinberger
2026-02-09 11:25:54 -06:00
parent fb8c653f53
commit 42a07791c4
15 changed files with 293 additions and 30 deletions

View File

@@ -1,4 +1,5 @@
import type { AuthProfileCredential, AuthProfileStore } from "./types.js";
import { normalizeSecretInput } from "../../utils/normalize-secret-input.js";
import { normalizeProviderId } from "../model-selection.js";
import {
ensureAuthProfileStore,
@@ -49,8 +50,19 @@ export function upsertAuthProfile(params: {
credential: AuthProfileCredential;
agentDir?: string;
}): void {
const credential =
params.credential.type === "api_key"
? {
...params.credential,
...(typeof params.credential.key === "string"
? { key: normalizeSecretInput(params.credential.key) }
: {}),
}
: params.credential.type === "token"
? { ...params.credential, token: normalizeSecretInput(params.credential.token) }
: params.credential;
const store = ensureAuthProfileStore(params.agentDir);
store.profiles[params.profileId] = params.credential;
store.profiles[params.profileId] = credential;
saveAuthProfileStore(store, params.agentDir);
}