refactor(telemetry): Improve previous PR that allows telemetry to use the CLI auth and add testing (#14589)

This commit is contained in:
Marat Boshernitsan
2025-12-08 11:20:13 -08:00
committed by GitHub
parent 8651c53923
commit 4322137cee
6 changed files with 164 additions and 12 deletions
+15
View File
@@ -56,6 +56,7 @@ async function triggerPostAuthCallbacks(tokens: Credentials) {
client_secret: OAUTH_CLIENT_SECRET,
refresh_token: tokens.refresh_token ?? undefined, // Ensure null is not passed
type: 'authorized_user',
client_email: userAccountManager.getCachedGoogleAccount() ?? undefined,
};
// Execute all registered post-authentication callbacks.
@@ -255,6 +256,18 @@ async function initOauthClient(
'Failed to authenticate with user code.',
);
}
// Retrieve and cache Google Account ID after successful user code auth
try {
await fetchAndCacheUserInfo(client);
} catch (error) {
debugLogger.warn(
'Failed to retrieve Google Account ID during authentication:',
getErrorMessage(error),
);
}
await triggerPostAuthCallbacks(client.credentials);
} else {
const webLogin = await authWithWeb(client);
@@ -318,6 +331,8 @@ async function initOauthClient(
severity: 'info',
message: 'Authentication succeeded\n',
});
await triggerPostAuthCallbacks(client.credentials);
}
return client;