diff options
Diffstat (limited to 'packages/core/src')
| -rw-r--r-- | packages/core/src/code_assist/oauth2.test.ts | 8 | ||||
| -rw-r--r-- | packages/core/src/code_assist/oauth2.ts | 19 |
2 files changed, 11 insertions, 16 deletions
diff --git a/packages/core/src/code_assist/oauth2.test.ts b/packages/core/src/code_assist/oauth2.test.ts index a7dc3ab8..4661f49a 100644 --- a/packages/core/src/code_assist/oauth2.test.ts +++ b/packages/core/src/code_assist/oauth2.test.ts @@ -212,9 +212,7 @@ describe('oauth2', () => { }; (readline.createInterface as Mock).mockReturnValue(mockReadline); - const consoleErrorSpy = vi - .spyOn(console, 'error') - .mockImplementation(() => {}); + const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); const client = await getOauthClient( AuthType.LOGIN_WITH_GOOGLE, @@ -226,7 +224,7 @@ describe('oauth2', () => { // Verify the auth flow expect(mockGenerateCodeVerifierAsync).toHaveBeenCalled(); expect(mockGenerateAuthUrl).toHaveBeenCalled(); - expect(consoleErrorSpy).toHaveBeenCalledWith( + expect(consoleLogSpy).toHaveBeenCalledWith( expect.stringContaining(mockAuthUrl), ); expect(mockReadline.question).toHaveBeenCalledWith( @@ -240,7 +238,7 @@ describe('oauth2', () => { }); expect(mockSetCredentials).toHaveBeenCalledWith(mockTokens); - consoleErrorSpy.mockRestore(); + consoleLogSpy.mockRestore(); }); describe('in Cloud Shell', () => { diff --git a/packages/core/src/code_assist/oauth2.ts b/packages/core/src/code_assist/oauth2.ts index d5f28880..48449b5e 100644 --- a/packages/core/src/code_assist/oauth2.ts +++ b/packages/core/src/code_assist/oauth2.ts @@ -163,38 +163,35 @@ async function authWithUserCode(client: OAuth2Client): Promise<boolean> { code_challenge: codeVerifier.codeChallenge, state, }); - console.error('Please visit the following URL to authorize the application:'); - console.error(''); - console.error(authUrl); - console.error(''); + console.log('Please visit the following URL to authorize the application:'); + console.log(''); + console.log(authUrl); + console.log(''); const code = await new Promise<string>((resolve) => { const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); - rl.question('Enter the authorization code: ', (answer) => { + rl.question('Enter the authorization code: ', (code) => { rl.close(); - resolve(answer.trim()); + resolve(code.trim()); }); }); if (!code) { console.error('Authorization code is required.'); return false; - } else { - console.error(`Received authorization code: "${code}"`); } try { - const response = await client.getToken({ + const { tokens } = await client.getToken({ code, codeVerifier: codeVerifier.codeVerifier, redirect_uri: redirectUri, }); - client.setCredentials(response.tokens); + client.setCredentials(tokens); } catch (_error) { - // Consider logging the error. return false; } return true; |
