Skip to content

Commit 7d6d7fd

Browse files
hayemaxijustinmk3
andauthored
fix(codecatalyst): dev env logged out on load (#5196)
* fix(codecatalyst): dev env logged out on load Problem: We forget all connections without all codecatalyst scopes only (aws account + coca scopes). However, the stored credentials in dev environments do not have the account scopes, so we are forgetting it. Solution: Check for Q scopes explicitly. * Update packages/core/src/extension.ts Co-authored-by: Justin M. Keyes <[email protected]> --------- Co-authored-by: Justin M. Keyes <[email protected]>
1 parent 5381baf commit 7d6d7fd

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

packages/core/src/auth/secondaryAuth.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ export class SecondaryAuth<T extends Connection = Connection> {
197197
* Clears the connection in use without deleting it or logging out.
198198
*/
199199
public async forgetConnection() {
200+
getLogger().debug('running SecondaryAuth:forgetConnection()')
200201
await this.clearSavedConnection()
201202
await this.clearActiveConnection()
202203
}

packages/core/src/codecatalyst/activation.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ExtContext } from '../shared/extensions'
1010
import { CodeCatalystRemoteSourceProvider } from './repos/remoteSourceProvider'
1111
import { CodeCatalystCommands, codecatalystConnectionsCmd } from './commands'
1212
import { GitExtension } from '../shared/extensions/git'
13-
import { CodeCatalystAuthenticationProvider, defaultScopes } from './auth'
13+
import { CodeCatalystAuthenticationProvider } from './auth'
1414
import { registerDevfileWatcher, updateDevfileCommand } from './devfile'
1515
import { DevEnvClient } from '../shared/clients/devenvClient'
1616
import { watchRestartingDevEnvs } from './reconnect'
@@ -25,7 +25,7 @@ import { getLogger } from '../shared/logger/logger'
2525
import { DevEnvActivityStarter } from './devEnv'
2626
import { learnMoreCommand, onboardCommand, reauth } from './explorer'
2727
import { isInDevEnv } from '../shared/vscode/env'
28-
import { hasExactScopes } from '../auth/connection'
28+
import { hasScopes, scopesCodeWhispererCore } from '../auth/connection'
2929
import { SessionSeparationPrompt } from '../auth/auth'
3030

3131
const localize = nls.loadMessageBundle()
@@ -46,9 +46,10 @@ export async function activate(ctx: ExtContext): Promise<void> {
4646

4747
await authProvider.restore()
4848

49-
// Forget Amazon Q connections while we transition to separate auth sessions per extension
49+
// Forget Amazon Q connections while we transition to separate auth sessions per extension.
50+
// Note: credentials on disk in the dev env cannot have Q scopes, so it will never be forgotten.
5051
// TODO: Remove after some time?
51-
if (authProvider.isConnected() && !hasExactScopes(authProvider.activeConnection!, defaultScopes)) {
52+
if (authProvider.isConnected() && hasScopes(authProvider.activeConnection!, scopesCodeWhispererCore)) {
5253
await authProvider.secondaryAuth.forgetConnection()
5354
await SessionSeparationPrompt.instance.showForCommand('aws.codecatalyst.manageConnections')
5455
}

packages/core/src/extension.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ export async function activate(context: vscode.ExtensionContext) {
128128
// TODO: Remove after some time?
129129
for (const conn of await Auth.instance.listConnections()) {
130130
if (isSsoConnection(conn) && hasScopes(conn, codeWhispererCoreScopes)) {
131+
getLogger().debug(
132+
`forgetting connection: ${conn.id} with starturl/scopes: ${conn.startUrl} / %O`,
133+
conn.scopes
134+
)
131135
await Auth.instance.forgetConnection(conn)
132136
await SessionSeparationPrompt.instance.showForCommand('aws.toolkit.auth.manageConnections')
133137
}

0 commit comments

Comments
 (0)