refactor(auth): Refactor non-interactive mode auth validation & refresh (#15679)

This commit is contained in:
Shreya Keshive
2025-12-30 11:09:00 -05:00
committed by GitHub
parent fb22f5b8ee
commit 1e08b150f7
5 changed files with 56 additions and 65 deletions
+23 -12
View File
@@ -401,18 +401,28 @@ export async function main() {
settings.merged.security?.auth?.selectedType &&
!settings.merged.security?.auth?.useExternal
) {
// Validate authentication here because the sandbox will interfere with the Oauth2 web redirect.
try {
const err = validateAuthMethod(
settings.merged.security.auth.selectedType,
);
if (err) {
throw new Error(err);
}
if (partialConfig.isInteractive()) {
// Validate authentication here because the sandbox will interfere with the Oauth2 web redirect.
const err = validateAuthMethod(
settings.merged.security.auth.selectedType,
);
if (err) {
throw new Error(err);
}
await partialConfig.refreshAuth(
settings.merged.security.auth.selectedType,
);
await partialConfig.refreshAuth(
settings.merged.security.auth.selectedType,
);
} else {
const authType = await validateNonInteractiveAuth(
settings.merged.security?.auth?.selectedType,
settings.merged.security?.auth?.useExternal,
partialConfig,
settings,
);
await partialConfig.refreshAuth(authType);
}
} catch (err) {
debugLogger.error('Error authenticating:', err);
await runExitCleanup();
@@ -667,12 +677,13 @@ export async function main() {
),
);
const nonInteractiveConfig = await validateNonInteractiveAuth(
const authType = await validateNonInteractiveAuth(
settings.merged.security?.auth?.selectedType,
settings.merged.security?.auth?.useExternal,
config,
settings,
);
await config.refreshAuth(authType);
if (config.getDebugMode()) {
debugLogger.log('Session ID: %s', sessionId);
@@ -684,7 +695,7 @@ export async function main() {
initializeOutputListenersAndFlush();
await runNonInteractive({
config: nonInteractiveConfig,
config,
settings,
input,
prompt_id,