Skip to content

Commit 743cf11

Browse files
feat(IDE-10199): prompt existing builder id signout on new builder id
Problem: When a user is already signed in to their Builder ID, but they want to use a different one, they are not able to use a different ID. This is confusing since nothing happens when they try to add another one. Solution: When attempting to add a new Builder ID but one already exists, this will prompt the user to choose if they wish to sign out of the existing one, and will then complete the builder id verification process. Signed-off-by: Nikolas Komonen <[email protected]>
1 parent 1ddf52a commit 743cf11

File tree

2 files changed

+40
-23
lines changed

2 files changed

+40
-23
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": "Option to sign out of existing Builder ID when adding a new one"
4+
}

src/credentials/auth.ts

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -770,9 +770,7 @@ const switchConnections = Commands.register('aws.auth.switchConnections', (auth:
770770
}
771771
})
772772

773-
async function signout(auth: Auth) {
774-
const conn = auth.activeConnection
775-
773+
async function signout(auth: Auth, conn: Connection | undefined = auth.activeConnection) {
776774
if (conn?.type === 'sso') {
777775
// TODO: does deleting the connection make sense UX-wise?
778776
// this makes it disappear from the list of available connections
@@ -865,39 +863,54 @@ export async function createStartUrlPrompter(title: string, ignoreScopes = true)
865863
export async function createBuilderIdConnection(auth: Auth) {
866864
const newProfile = createBuilderIdProfile()
867865
const existingConn = (await auth.listConnections()).find(isBuilderIdConnection)
868-
if (existingConn && !hasScopes(existingConn, newProfile.scopes)) {
869-
return migrateBuilderId(auth, existingConn, newProfile)
866+
if (!existingConn) {
867+
return auth.createConnection(newProfile)
870868
}
871869

872-
return existingConn ?? (await auth.createConnection(newProfile))
870+
const userResponse = await promptLogoutExistingBuilderIdConnection()
871+
if (userResponse !== 'signout') {
872+
throw new CancellationError('user')
873+
}
874+
875+
await signout(auth, existingConn)
876+
877+
return auth.createConnection(newProfile)
878+
}
879+
880+
/**
881+
* Prompts the user to log out of an existing Builder ID connection.
882+
*
883+
* @returns The name of the action performed by the user
884+
*/
885+
async function promptLogoutExistingBuilderIdConnection(): Promise<'signout' | 'cancel'> {
886+
const items: DataQuickPickItem<'signout' | 'cancel'>[] = [
887+
{
888+
data: 'signout',
889+
label: `Currently signed in with ${getIdeProperties().company} Builder ID. Sign out to add another?`,
890+
detail: `This will sign out of your current ${
891+
getIdeProperties().company
892+
} Builder ID and open the sign-in page in browser.`,
893+
},
894+
{ data: 'cancel', label: 'Cancel' },
895+
]
896+
const resp = await showQuickPick(items, {
897+
title: `Sign in to different ${getIdeProperties().company} Builder ID`,
898+
buttons: createCommonButtons() as vscode.QuickInputButton[],
899+
})
900+
901+
return resp === undefined ? 'cancel' : resp
873902
}
874903

875904
Commands.register('aws.auth.help', async () => {
876905
vscode.env.openExternal(vscode.Uri.parse(authHelpUrl))
877906
telemetry.aws_help.emit()
878907
})
908+
879909
Commands.register('aws.auth.signout', () => {
880910
telemetry.ui_click.emit({ elementId: 'devtools_signout' })
881-
882911
return signout(Auth.instance)
883912
})
884913

885-
// XXX: right now users can only have 1 builder id connection, so de-dupe
886-
// This logic can be removed or re-purposed once we have access to identities
887-
async function migrateBuilderId(auth: Auth, existingConn: SsoConnection, newProfile: SsoProfile) {
888-
const newConn = await auth.createConnection(newProfile)
889-
const shouldUseConnection = auth.activeConnection?.id === existingConn.id
890-
await auth.deleteConnection(existingConn).catch(err => {
891-
getLogger().warn(`auth: failed to remove old connection "${existingConn.id}": %s`, err)
892-
})
893-
894-
if (shouldUseConnection) {
895-
return auth.useConnection(newConn)
896-
}
897-
898-
return newConn
899-
}
900-
901914
const addConnection = Commands.register('aws.auth.addConnection', async () => {
902915
const c9IamItem = createIamItem()
903916
c9IamItem.detail =

0 commit comments

Comments
 (0)