Skip to content

Commit 1fb7013

Browse files
authored
feat(auth): autofill last sso login info aws#7223
## Problem Customers hope we could auto-fill the url and region with the last used one. Actually there is a customer saying it would cause friction for their adoption ## Solution Memorize the url/region as a global state within VSCode and use them when they're present
1 parent c58c9e1 commit 1fb7013

File tree

6 files changed

+27
-6
lines changed

6 files changed

+27
-6
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "Memorize and autofill users' last Sso login profile"
4+
}

packages/core/src/login/webview/vue/amazonq/backend_amazonq.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ export class AmazonQLoginWebview extends CommonAuthWebview {
8080

8181
async startEnterpriseSetup(startUrl: string, region: string): Promise<AuthError | undefined> {
8282
getLogger().debug(`called startEnterpriseSetup() with startUrl: '${startUrl}', region: '${region}'`)
83+
await globals.globalState.update('recentSso', {
84+
startUrl: startUrl,
85+
region: region,
86+
})
8387
return await this.ssoSetup('startCodeWhispererEnterpriseSetup', async () => {
8488
this.storeMetricMetadata({
8589
credentialStartUrl: startUrl,

packages/core/src/login/webview/vue/backend.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,13 @@ export abstract class CommonAuthWebview extends VueWebview {
290290
return authEnabledFeatures.join(',')
291291
}
292292

293-
getDefaultStartUrl() {
294-
return DevSettings.instance.get('autofillStartUrl', '')
293+
getDefaultSsoProfile(): { startUrl: string; region: string } {
294+
const devSettings = DevSettings.instance.get('autofillStartUrl', '')
295+
if (devSettings) {
296+
return { startUrl: devSettings, region: 'us-east-1' }
297+
}
298+
299+
return globals.globalState.tryGet('recentSso', Object, { startUrl: '', region: 'us-east-1' })
295300
}
296301

297302
cancelAuthFlow() {

packages/core/src/login/webview/vue/login.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ export default defineComponent({
343343
regions: [] as Region[],
344344
startUrlError: '',
345345
startUrlWarning: '',
346-
selectedRegion: 'us-east-1',
346+
selectedRegion: '',
347347
startUrl: '',
348348
app: this.app,
349349
LoginOption,
@@ -353,7 +353,9 @@ export default defineComponent({
353353
}
354354
},
355355
async created() {
356-
this.startUrl = await this.getDefaultStartUrl()
356+
const defaultSso = await this.getDefaultSso()
357+
this.startUrl = defaultSso.startUrl
358+
this.selectedRegion = defaultSso.region
357359
await this.emitUpdate('created')
358360
},
359361
@@ -564,8 +566,8 @@ export default defineComponent({
564566
async updateExistingStartUrls() {
565567
this.existingStartUrls = (await client.listSsoConnections()).map((conn) => conn.startUrl)
566568
},
567-
async getDefaultStartUrl() {
568-
return await client.getDefaultStartUrl()
569+
async getDefaultSso() {
570+
return await client.getDefaultSsoProfile()
569571
},
570572
handleHelpLinkClick() {
571573
void client.emitUiClick('auth_helpLink')

packages/core/src/login/webview/vue/toolkit/backend_toolkit.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { setContext } from '../../../../shared/vscode/setContext'
2323
import { builderIdStartUrl } from '../../../../auth/sso/constants'
2424
import { RegionProfile } from '../../../../codewhisperer/models/model'
2525
import { ProfileSwitchIntent } from '../../../../codewhisperer/region/regionProfileManager'
26+
import globals from '../../../../shared/extensionGlobals'
2627

2728
export class ToolkitLoginWebview extends CommonAuthWebview {
2829
public override id: string = 'aws.toolkit.AmazonCommonAuth'
@@ -46,6 +47,10 @@ export class ToolkitLoginWebview extends CommonAuthWebview {
4647
credentialStartUrl: startUrl,
4748
isReAuth: false,
4849
}
50+
await globals.globalState.update('recentSso', {
51+
startUrl: startUrl,
52+
region: region,
53+
})
4954

5055
if (this.isCodeCatalystLogin) {
5156
return this.ssoSetup('startCodeCatalystSSOSetup', async () => {

packages/core/src/shared/globalState.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export type globalKey =
6969
| 'lastSelectedRegion'
7070
| 'lastOsStartTime'
7171
| 'recentCredentials'
72+
| 'recentSso'
7273
// List of regions enabled in AWS Explorer.
7374
| 'region'
7475
// TODO: implement this via `PromptSettings` instead of globalState.

0 commit comments

Comments
 (0)