Add enforcedAuthType setting (#6564)

This commit is contained in:
christine betts
2025-09-03 15:33:37 -07:00
committed by GitHub
parent 5cc23f0cd8
commit 987f08a619
10 changed files with 194 additions and 18 deletions

View File

@@ -8,6 +8,7 @@ import type { Config } from '@google/gemini-cli-core';
import { AuthType } from '@google/gemini-cli-core';
import { USER_SETTINGS_PATH } from './config/settings.js';
import { validateAuthMethod } from './config/auth.js';
import { type LoadedSettings } from './config/settings.js';
function getAuthTypeFromEnv(): AuthType | undefined {
if (process.env['GOOGLE_GENAI_USE_GCA'] === 'true') {
@@ -26,8 +27,21 @@ export async function validateNonInteractiveAuth(
configuredAuthType: AuthType | undefined,
useExternalAuth: boolean | undefined,
nonInteractiveConfig: Config,
settings: LoadedSettings,
) {
const effectiveAuthType = configuredAuthType || getAuthTypeFromEnv();
const enforcedType = settings.merged.security?.auth?.enforcedType;
if (enforcedType) {
const currentAuthType = getAuthTypeFromEnv();
if (currentAuthType !== enforcedType) {
console.error(
`The configured auth type is ${enforcedType}, but the current auth type is ${currentAuthType}. Please re-authenticate with the correct type.`,
);
process.exit(1);
}
}
const effectiveAuthType =
enforcedType || getAuthTypeFromEnv() || configuredAuthType;
if (!effectiveAuthType) {
console.error(