Skip to content

Commit e08eb59

Browse files
feat(core): Update all references to use new auth class using flare identity server for Amazon Q (#7088)
## Problem The business logic of auth-related features is complex and implemented separately for all IDEs. Flare/DEXP LSP server has implemented auth that can be reused for all IDEs. The source code was introduced already introduced in #6958 with activation and client updates in #7062. But the references to `AuthUtil` through the codebase weren't updated yet. ## Solution * Update all remaining references to `AuthUtil` in the codebase * All `toolkits` unit tests are passing * Disable telemetry and existing AuthUtil unit tests, to be updated in follow-up PR * `amazonq` and `web` unit tests still failing, to be addressed in follow-up PR **Note that CI is expected to fail for amazonq and web unit tests** --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license. --------- Co-authored-by: Justin M. Keyes <[email protected]>
1 parent 6bcc387 commit e08eb59

File tree

83 files changed

+925
-1024
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+925
-1024
lines changed

packages/amazonq/src/app/amazonqScan/app.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { Messenger } from './chat/controller/messenger/messenger'
1919
import { UIMessageListener } from './chat/views/actions/uiMessageListener'
2020
import { debounce } from 'lodash'
2121
import { Commands, placeholder } from 'aws-core-vscode/shared'
22+
import { auth2 } from 'aws-core-vscode/auth'
2223

2324
export function init(appContext: AmazonQAppInitContext) {
2425
const scanChatControllerEventEmitters: ScanChatControllerEventEmitters = {
@@ -52,7 +53,7 @@ export function init(appContext: AmazonQAppInitContext) {
5253
appContext.registerWebViewToAppMessagePublisher(new MessagePublisher<any>(scanChatUIInputEventEmitter), 'review')
5354

5455
const debouncedEvent = debounce(async () => {
55-
const authenticated = (await AuthUtil.instance.getChatAuthState()).amazonQ === 'connected'
56+
const authenticated = AuthUtil.instance.getAuthState() === 'connected'
5657
let authenticatingSessionID = ''
5758

5859
if (authenticated) {
@@ -67,7 +68,7 @@ export function init(appContext: AmazonQAppInitContext) {
6768
messenger.sendAuthenticationUpdate(authenticated, [authenticatingSessionID])
6869
}, 500)
6970

70-
AuthUtil.instance.secondaryAuth.onDidChangeActiveConnection(() => {
71+
AuthUtil.instance.onDidChangeConnectionState((e: auth2.AuthStateEvent) => {
7172
return debouncedEvent()
7273
})
7374
AuthUtil.instance.regionProfileManager.onDidChangeRegionProfile(() => {

packages/amazonq/src/app/amazonqScan/chat/controller/controller.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class ScanController {
104104
telemetry.amazonq_feedback.emit({
105105
featureId: 'amazonQReview',
106106
amazonqConversationId: this.sessionStorage.getSession().scanUuid,
107-
credentialStartUrl: AuthUtil.instance.startUrl,
107+
credentialStartUrl: AuthUtil.instance.connection?.startUrl,
108108
interactionType: data.vote,
109109
})
110110
})
@@ -122,8 +122,8 @@ export class ScanController {
122122
try {
123123
getLogger().debug(`Q - Review: Session created with id: ${session.tabID}`)
124124

125-
const authState = await AuthUtil.instance.getChatAuthState()
126-
if (authState.amazonQ !== 'connected') {
125+
const authState = AuthUtil.instance.getAuthState()
126+
if (authState !== 'connected') {
127127
void this.messenger.sendAuthNeededExceptionMessage(authState, tabID)
128128
session.isAuthenticating = true
129129
return
@@ -161,8 +161,8 @@ export class ScanController {
161161
return
162162
}
163163
// check that the session is authenticated
164-
const authState = await AuthUtil.instance.getChatAuthState()
165-
if (authState.amazonQ !== 'connected') {
164+
const authState = AuthUtil.instance.getAuthState()
165+
if (authState !== 'connected') {
166166
void this.messenger.sendAuthNeededExceptionMessage(authState, message.tabID)
167167
session.isAuthenticating = true
168168
return

packages/amazonq/src/app/amazonqScan/chat/controller/messenger/messenger.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import { AuthFollowUpType, AuthMessageDataMap } from 'aws-core-vscode/amazonq'
1212
import {
13-
FeatureAuthState,
1413
SecurityScanError,
1514
CodeWhispererConstants,
1615
SecurityScanStep,
@@ -34,6 +33,7 @@ import {
3433
import { i18n } from 'aws-core-vscode/shared'
3534
import { ScanAction, scanProgressMessage } from '../../../models/constants'
3635
import path from 'path'
36+
import { auth2 } from 'aws-core-vscode/auth'
3737

3838
export type UnrecoverableErrorType = 'no-project-found' | 'no-open-file-found' | 'invalid-file-type'
3939

@@ -78,19 +78,15 @@ export class Messenger {
7878
this.dispatcher.sendUpdatePromptProgress(new UpdatePromptProgressMessage(tabID, progressField))
7979
}
8080

81-
public async sendAuthNeededExceptionMessage(credentialState: FeatureAuthState, tabID: string) {
81+
public async sendAuthNeededExceptionMessage(credentialState: auth2.AuthState, tabID: string) {
8282
let authType: AuthFollowUpType = 'full-auth'
8383
let message = AuthMessageDataMap[authType].message
8484

85-
switch (credentialState.amazonQ) {
86-
case 'disconnected':
85+
switch (credentialState) {
86+
case 'notConnected':
8787
authType = 'full-auth'
8888
message = AuthMessageDataMap[authType].message
8989
break
90-
case 'unsupported':
91-
authType = 'use-supported-auth'
92-
message = AuthMessageDataMap[authType].message
93-
break
9490
case 'expired':
9591
authType = 're-auth'
9692
message = AuthMessageDataMap[authType].message

packages/amazonq/src/inlineChat/provider/inlineChatProvider.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,8 @@ export class InlineChatProvider {
123123

124124
const tabID = triggerEvent.tabID
125125

126-
const credentialsState = await AuthUtil.instance.getChatAuthState()
127-
if (
128-
!(credentialsState.codewhispererChat === 'connected' && credentialsState.codewhispererCore === 'connected')
129-
) {
126+
const credentialsState = AuthUtil.instance.getAuthState()
127+
if (credentialsState !== 'connected') {
130128
const { message } = extractAuthFollowUp(credentialsState)
131129
this.errorEmitter.fire()
132130
throw new ToolkitError(message)

packages/amazonq/src/lsp/activation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import vscode from 'vscode'
77
import { clientId, encryptionKey, startLanguageServer } from './client'
88
import { AmazonQLspInstaller } from './lspInstaller'
9-
import { lspSetupStage, ToolkitError } from 'aws-core-vscode/shared'
9+
import { lspSetupStage, ToolkitError, messages } from 'aws-core-vscode/shared'
1010
import { AuthUtil } from 'aws-core-vscode/codewhisperer'
1111
import { auth2 } from 'aws-core-vscode/auth'
1212

packages/amazonq/src/lsp/chat/messages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export function registerMessageListeners(
122122

123123
if (fullAuthTypes.includes(authType)) {
124124
try {
125-
await AuthUtil.instance.secondaryAuth.deleteConnection()
125+
await AuthUtil.instance.logout()
126126
} catch (e) {
127127
languageClient.error(
128128
`[VSCode Client] Failed to authenticate after AUTH_FOLLOW_UP_CLICKED: ${(e as Error).message}`

packages/amazonq/test/e2e/amazonq/utils/setup.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import { AuthUtil } from 'aws-core-vscode/codewhisperer'
66

77
export async function loginToIdC() {
8-
const authState = await AuthUtil.instance.getChatAuthState()
8+
const authState = AuthUtil.instance.getAuthState()
99
if (process.env['AWS_TOOLKIT_AUTOMATION'] === 'local') {
10-
if (authState.amazonQ !== 'connected') {
10+
if (authState !== 'connected') {
1111
throw new Error('You will need to login manually before running tests.')
1212
}
1313
return
@@ -22,5 +22,5 @@ export async function loginToIdC() {
2222
)
2323
}
2424

25-
await AuthUtil.instance.connectToEnterpriseSso(startUrl, region)
25+
await AuthUtil.instance.login(startUrl, region)
2626
}

packages/amazonq/test/unit/amazonq/lsp/chat/messages.test.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { LanguageClient } from 'vscode-languageclient'
88
import { AuthUtil } from 'aws-core-vscode/codewhisperer'
99
import { registerMessageListeners } from '../../../../../src/lsp/chat/messages'
1010
import { AmazonQChatViewProvider } from '../../../../../src/lsp/chat/webviewProvider'
11-
import { secondaryAuth, authConnection, AuthFollowUpType } from 'aws-core-vscode/amazonq'
11+
import { AuthFollowUpType } from 'aws-core-vscode/amazonq'
1212
import { messages } from 'aws-core-vscode/shared'
1313

1414
describe('registerMessageListeners', () => {
@@ -50,7 +50,7 @@ describe('registerMessageListeners', () => {
5050

5151
describe('AUTH_FOLLOW_UP_CLICKED', () => {
5252
let mockAuthUtil: AuthUtil
53-
let deleteConnectionStub: sinon.SinonStub
53+
let logoutStub: sinon.SinonStub
5454
let reauthenticateStub: sinon.SinonStub
5555

5656
const authFollowUpClickedCommand = 'authFollowUpClicked'
@@ -76,14 +76,12 @@ describe('registerMessageListeners', () => {
7676
}
7777

7878
beforeEach(() => {
79-
deleteConnectionStub = sandbox.stub().resolves()
8079
reauthenticateStub = sandbox.stub().resolves()
80+
logoutStub = sandbox.stub().resolves()
8181

8282
mockAuthUtil = {
8383
reauthenticate: reauthenticateStub,
84-
secondaryAuth: {
85-
deleteConnection: deleteConnectionStub,
86-
} as unknown as secondaryAuth.SecondaryAuth<authConnection.Connection>,
84+
logout: logoutStub,
8785
} as unknown as AuthUtil
8886

8987
sandbox.replaceGetter(AuthUtil, 'instance', () => mockAuthUtil)
@@ -98,7 +96,7 @@ describe('registerMessageListeners', () => {
9896
})
9997

10098
sinon.assert.calledOnce(reauthenticateStub)
101-
sinon.assert.notCalled(deleteConnectionStub)
99+
sinon.assert.notCalled(logoutStub)
102100
})
103101

104102
it('handles full authentication request', async () => {
@@ -110,7 +108,7 @@ describe('registerMessageListeners', () => {
110108
})
111109

112110
sinon.assert.notCalled(reauthenticateStub)
113-
sinon.assert.calledOnce(deleteConnectionStub)
111+
sinon.assert.calledOnce(logoutStub)
114112
})
115113

116114
it('logs error if re-authentication fails', async () => {
@@ -124,7 +122,7 @@ describe('registerMessageListeners', () => {
124122
it('logs error if full authentication fails', async () => {
125123
await testFailure({
126124
authType: 'full-auth',
127-
stubToReject: deleteConnectionStub,
125+
stubToReject: logoutStub,
128126
errorMessage: 'Failed to authenticate',
129127
})
130128
})

0 commit comments

Comments
 (0)