From 83805795070d603e7c3208fc598c94859c67ec65 Mon Sep 17 00:00:00 2001 From: Will Lo Date: Sun, 4 May 2025 23:01:27 -0700 Subject: [PATCH 1/3] feat(auth): memorize previous enterprise login profile --- .../src/login/webview/vue/amazonq/backend_amazonq.ts | 5 +++++ packages/core/src/login/webview/vue/backend.ts | 9 +++++++-- packages/core/src/login/webview/vue/login.vue | 10 ++++++---- .../src/login/webview/vue/toolkit/backend_toolkit.ts | 5 +++++ packages/core/src/shared/globalState.ts | 1 + 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/packages/core/src/login/webview/vue/amazonq/backend_amazonq.ts b/packages/core/src/login/webview/vue/amazonq/backend_amazonq.ts index 6ed152ab4ea..5854a810bef 100644 --- a/packages/core/src/login/webview/vue/amazonq/backend_amazonq.ts +++ b/packages/core/src/login/webview/vue/amazonq/backend_amazonq.ts @@ -27,6 +27,7 @@ import { randomUUID } from '../../../../shared/crypto' import globals from '../../../../shared/extensionGlobals' import { telemetry } from '../../../../shared/telemetry/telemetry' import { ProfileSwitchIntent } from '../../../../codewhisperer/region/regionProfileManager' +import { setContext } from '../../../../shared' const className = 'AmazonQLoginWebview' export class AmazonQLoginWebview extends CommonAuthWebview { @@ -80,6 +81,10 @@ export class AmazonQLoginWebview extends CommonAuthWebview { async startEnterpriseSetup(startUrl: string, region: string): Promise { getLogger().debug(`called startEnterpriseSetup() with startUrl: '${startUrl}', region: '${region}'`) + await globals.globalState.update('recentSso', { + startUrl: startUrl, + region: region, + }) return await this.ssoSetup('startCodeWhispererEnterpriseSetup', async () => { this.storeMetricMetadata({ credentialStartUrl: startUrl, diff --git a/packages/core/src/login/webview/vue/backend.ts b/packages/core/src/login/webview/vue/backend.ts index 9fc91589e91..c8f1f38d4d7 100644 --- a/packages/core/src/login/webview/vue/backend.ts +++ b/packages/core/src/login/webview/vue/backend.ts @@ -290,8 +290,13 @@ export abstract class CommonAuthWebview extends VueWebview { return authEnabledFeatures.join(',') } - getDefaultStartUrl() { - return DevSettings.instance.get('autofillStartUrl', '') + getDefaultSsoProfile(): { startUrl: string; region: string } { + const devSettings = DevSettings.instance.get('autofillStartUrl', '') + if (devSettings) { + return { startUrl: devSettings, region: 'us-east-1' } + } + + return globals.globalState.tryGet('recentSso', Object, { startUrl: '', region: 'us-east-1' }) } cancelAuthFlow() { diff --git a/packages/core/src/login/webview/vue/login.vue b/packages/core/src/login/webview/vue/login.vue index 50b1e244043..ddcd1d91c28 100644 --- a/packages/core/src/login/webview/vue/login.vue +++ b/packages/core/src/login/webview/vue/login.vue @@ -343,7 +343,7 @@ export default defineComponent({ regions: [] as Region[], startUrlError: '', startUrlWarning: '', - selectedRegion: 'us-east-1', + selectedRegion: '', startUrl: '', app: this.app, LoginOption, @@ -353,7 +353,9 @@ export default defineComponent({ } }, async created() { - this.startUrl = await this.getDefaultStartUrl() + const defaultSso = await this.getDefaultSso() + this.startUrl = defaultSso.startUrl + this.selectedRegion = defaultSso.region await this.emitUpdate('created') }, @@ -564,8 +566,8 @@ export default defineComponent({ async updateExistingStartUrls() { this.existingStartUrls = (await client.listSsoConnections()).map((conn) => conn.startUrl) }, - async getDefaultStartUrl() { - return await client.getDefaultStartUrl() + async getDefaultSso() { + return await client.getDefaultSsoProfile() }, handleHelpLinkClick() { void client.emitUiClick('auth_helpLink') diff --git a/packages/core/src/login/webview/vue/toolkit/backend_toolkit.ts b/packages/core/src/login/webview/vue/toolkit/backend_toolkit.ts index 3c2a9e2e8ec..4e4db35b9ad 100644 --- a/packages/core/src/login/webview/vue/toolkit/backend_toolkit.ts +++ b/packages/core/src/login/webview/vue/toolkit/backend_toolkit.ts @@ -23,6 +23,7 @@ import { setContext } from '../../../../shared/vscode/setContext' import { builderIdStartUrl } from '../../../../auth/sso/constants' import { RegionProfile } from '../../../../codewhisperer/models/model' import { ProfileSwitchIntent } from '../../../../codewhisperer/region/regionProfileManager' +import globals from '../../../../shared/extensionGlobals' export class ToolkitLoginWebview extends CommonAuthWebview { public override id: string = 'aws.toolkit.AmazonCommonAuth' @@ -46,6 +47,10 @@ export class ToolkitLoginWebview extends CommonAuthWebview { credentialStartUrl: startUrl, isReAuth: false, } + await globals.globalState.update('recentSso', { + startUrl: startUrl, + region: region, + }) if (this.isCodeCatalystLogin) { return this.ssoSetup('startCodeCatalystSSOSetup', async () => { diff --git a/packages/core/src/shared/globalState.ts b/packages/core/src/shared/globalState.ts index 6ecca56f90a..13db46b430a 100644 --- a/packages/core/src/shared/globalState.ts +++ b/packages/core/src/shared/globalState.ts @@ -69,6 +69,7 @@ export type globalKey = | 'lastSelectedRegion' | 'lastOsStartTime' | 'recentCredentials' + | 'recentSso' // List of regions enabled in AWS Explorer. | 'region' // TODO: implement this via `PromptSettings` instead of globalState. From 2a32af347847205e04a7d934e67069ffc43a0d0c Mon Sep 17 00:00:00 2001 From: Will Lo Date: Sun, 4 May 2025 23:02:50 -0700 Subject: [PATCH 2/3] changelog --- .../Feature-3fb0a20d-75e8-4141-a1a6-d8cfd9b7f3f0.json | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 packages/amazonq/.changes/next-release/Feature-3fb0a20d-75e8-4141-a1a6-d8cfd9b7f3f0.json diff --git a/packages/amazonq/.changes/next-release/Feature-3fb0a20d-75e8-4141-a1a6-d8cfd9b7f3f0.json b/packages/amazonq/.changes/next-release/Feature-3fb0a20d-75e8-4141-a1a6-d8cfd9b7f3f0.json new file mode 100644 index 00000000000..c6324a4570f --- /dev/null +++ b/packages/amazonq/.changes/next-release/Feature-3fb0a20d-75e8-4141-a1a6-d8cfd9b7f3f0.json @@ -0,0 +1,4 @@ +{ + "type": "Feature", + "description": "Memorize and autofill users' last Sso login profile" +} From 169aa177aa95de0473c460c9a7d3ebd1e7a69970 Mon Sep 17 00:00:00 2001 From: Will Lo Date: Sun, 4 May 2025 23:08:35 -0700 Subject: [PATCH 3/3] lint --- packages/core/src/login/webview/vue/amazonq/backend_amazonq.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/core/src/login/webview/vue/amazonq/backend_amazonq.ts b/packages/core/src/login/webview/vue/amazonq/backend_amazonq.ts index 5854a810bef..a83e99d04b7 100644 --- a/packages/core/src/login/webview/vue/amazonq/backend_amazonq.ts +++ b/packages/core/src/login/webview/vue/amazonq/backend_amazonq.ts @@ -27,7 +27,6 @@ import { randomUUID } from '../../../../shared/crypto' import globals from '../../../../shared/extensionGlobals' import { telemetry } from '../../../../shared/telemetry/telemetry' import { ProfileSwitchIntent } from '../../../../codewhisperer/region/regionProfileManager' -import { setContext } from '../../../../shared' const className = 'AmazonQLoginWebview' export class AmazonQLoginWebview extends CommonAuthWebview {