Skip to content

Commit a7d8511

Browse files
feat(core): remove unnecessary login verbiage from Code Assist auth (google-gemini#19861)
1 parent acb7f57 commit a7d8511

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

packages/core/src/code_assist/oauth2.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ async function initOauthClient(
271271

272272
await triggerPostAuthCallbacks(client.credentials);
273273
} else {
274-
const userConsent = await getConsentForOauth('Code Assist login required.');
274+
const userConsent = await getConsentForOauth('');
275275
if (!userConsent) {
276276
throw new FatalCancellationError('Authentication cancelled by user.');
277277
}
@@ -281,8 +281,7 @@ async function initOauthClient(
281281
coreEvents.emit(CoreEvent.UserFeedback, {
282282
severity: 'info',
283283
message:
284-
`\n\nCode Assist login required.\n` +
285-
`Attempting to open authentication page in your browser.\n` +
284+
`\n\nAttempting to open authentication page in your browser.\n` +
286285
`Otherwise navigate to:\n\n${webLogin.authUrl}\n\n\n`,
287286
});
288287
try {

packages/core/src/utils/authConsent.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,25 @@ describe('getConsentForOauth', () => {
5656
);
5757
});
5858

59+
it('should handle empty prompt correctly', async () => {
60+
const mockEmitConsentRequest = vi.spyOn(coreEvents, 'emitConsentRequest');
61+
vi.spyOn(coreEvents, 'listenerCount').mockReturnValue(1);
62+
63+
mockEmitConsentRequest.mockImplementation((payload) => {
64+
payload.onConfirm(true);
65+
});
66+
67+
await getConsentForOauth('');
68+
69+
expect(mockEmitConsentRequest).toHaveBeenCalledWith(
70+
expect.objectContaining({
71+
prompt: expect.stringMatching(
72+
/^Opening authentication page in your browser\./,
73+
),
74+
}),
75+
);
76+
});
77+
5978
it('should return false when user declines via UI', async () => {
6079
const mockEmitConsentRequest = vi.spyOn(coreEvents, 'emitConsentRequest');
6180
vi.spyOn(coreEvents, 'listenerCount').mockReturnValue(1);

packages/core/src/utils/authConsent.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import { isHeadlessMode } from './headless.js';
1515
* Handles both interactive and non-interactive (headless) modes.
1616
*/
1717
export async function getConsentForOauth(prompt: string): Promise<boolean> {
18-
const finalPrompt = prompt + ' Opening authentication page in your browser. ';
18+
const finalPrompt =
19+
(prompt ? prompt + ' ' : '') +
20+
'Opening authentication page in your browser. ';
1921

2022
if (isHeadlessMode()) {
2123
return getOauthConsentNonInteractive(finalPrompt);

0 commit comments

Comments
 (0)