Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

refactor(auth): share scan authentication modes (#582)

mldangelo-oai340a8dd45552
diff --git a/sdk/typescript/src/api.ts b/sdk/typescript/src/api.ts
index 55da505f5..8331229f3 100644
--- a/sdk/typescript/src/api.ts
+++ b/sdk/typescript/src/api.ts
@@ -226,7 +226,8 @@ export interface ScanOptions extends DeepScanOptions {
signal?: AbortSignal;
}
-export type ScanAuthMode = "auto" | "chatgpt" | "api-key";
+export const SCAN_AUTH_MODES = ["auto", "chatgpt", "api-key"] as const;
+export type ScanAuthMode = (typeof SCAN_AUTH_MODES)[number];
export type ScanAuthentication =
| {
@@ -2770,7 +2771,7 @@ export function scanAuthentication(
auth: ScanAuthMode = "auto",
modelProvider?: unknown,
): ScanAuthentication {
- if (auth !== "auto" && auth !== "chatgpt" && auth !== "api-key") {
+ if (!SCAN_AUTH_MODES.includes(auth)) {
throw new TypeError(
"Scan authentication mode must be auto, chatgpt, or api-key.",
);
diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.ts
index 6c59c2691..48ebb30a3 100644
--- a/sdk/typescript/src/cli.ts
+++ b/sdk/typescript/src/cli.ts
@@ -46,6 +46,7 @@ import {
CodexSecurity,
createSecurityInternal,
listRepositoryFindings,
+ SCAN_AUTH_MODES,
scanAuthentication,
type DeepScanOptions,
type ScanAuthMode,
@@ -2188,7 +2189,7 @@ export async function main(
options: z
.object({
auth: z
- .enum(["auto", "chatgpt", "api-key"])
+ .enum(SCAN_AUTH_MODES)
.default("auto")
.describe(
"Select ChatGPT, OPENAI_API_KEY/CODEX_API_KEY, or automatic authentication.",