@@ -770,9 +770,7 @@ const switchConnections = Commands.register('aws.auth.switchConnections', (auth:
770
770
}
771
771
} )
772
772
773
- async function signout ( auth : Auth ) {
774
- const conn = auth . activeConnection
775
-
773
+ async function signout ( auth : Auth , conn : Connection | undefined = auth . activeConnection ) {
776
774
if ( conn ?. type === 'sso' ) {
777
775
// TODO: does deleting the connection make sense UX-wise?
778
776
// this makes it disappear from the list of available connections
@@ -865,39 +863,54 @@ export async function createStartUrlPrompter(title: string, ignoreScopes = true)
865
863
export async function createBuilderIdConnection ( auth : Auth ) {
866
864
const newProfile = createBuilderIdProfile ( )
867
865
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 )
870
868
}
871
869
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
873
902
}
874
903
875
904
Commands . register ( 'aws.auth.help' , async ( ) => {
876
905
vscode . env . openExternal ( vscode . Uri . parse ( authHelpUrl ) )
877
906
telemetry . aws_help . emit ( )
878
907
} )
908
+
879
909
Commands . register ( 'aws.auth.signout' , ( ) => {
880
910
telemetry . ui_click . emit ( { elementId : 'devtools_signout' } )
881
-
882
911
return signout ( Auth . instance )
883
912
} )
884
913
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
-
901
914
const addConnection = Commands . register ( 'aws.auth.addConnection' , async ( ) => {
902
915
const c9IamItem = createIamItem ( )
903
916
c9IamItem . detail =
0 commit comments