@@ -199,10 +199,6 @@ export class ProfileStore {
199
199
public async addProfile ( id : string , profile : SsoProfile ) : Promise < StoredProfile < SsoProfile > >
200
200
public async addProfile ( id : string , profile : IamProfile ) : Promise < StoredProfile < IamProfile > >
201
201
public async addProfile ( id : string , profile : Profile ) : Promise < StoredProfile > {
202
- if ( this . getProfile ( id ) !== undefined ) {
203
- throw new Error ( `Profile already exists: ${ id } ` )
204
- }
205
-
206
202
return this . putProfile ( id , this . initMetadata ( profile ) )
207
203
}
208
204
@@ -770,9 +766,7 @@ const switchConnections = Commands.register('aws.auth.switchConnections', (auth:
770
766
}
771
767
} )
772
768
773
- async function signout ( auth : Auth ) {
774
- const conn = auth . activeConnection
775
-
769
+ async function signout ( auth : Auth , conn : Connection | undefined = auth . activeConnection ) {
776
770
if ( conn ?. type === 'sso' ) {
777
771
// TODO: does deleting the connection make sense UX-wise?
778
772
// this makes it disappear from the list of available connections
@@ -865,39 +859,54 @@ export async function createStartUrlPrompter(title: string, ignoreScopes = true)
865
859
export async function createBuilderIdConnection ( auth : Auth ) {
866
860
const newProfile = createBuilderIdProfile ( )
867
861
const existingConn = ( await auth . listConnections ( ) ) . find ( isBuilderIdConnection )
868
- if ( existingConn && ! hasScopes ( existingConn , newProfile . scopes ) ) {
869
- return migrateBuilderId ( auth , existingConn , newProfile )
862
+ if ( ! existingConn ) {
863
+ return auth . createConnection ( newProfile )
864
+ }
865
+
866
+ const userResponse = await promptLogoutExistingBuilderIdConnection ( )
867
+ if ( userResponse !== 'signout' ) {
868
+ throw new CancellationError ( 'user' )
870
869
}
871
870
872
- return existingConn ?? ( await auth . createConnection ( newProfile ) )
871
+ await signout ( auth , existingConn )
872
+
873
+ return auth . createConnection ( newProfile )
874
+ }
875
+
876
+ /**
877
+ * Prompts the user to log out of an existing Builder ID connection.
878
+ *
879
+ * @returns The name of the action performed by the user
880
+ */
881
+ async function promptLogoutExistingBuilderIdConnection ( ) : Promise < 'signout' | 'cancel' > {
882
+ const items : DataQuickPickItem < 'signout' | 'cancel' > [ ] = [
883
+ {
884
+ data : 'signout' ,
885
+ label : `Currently signed in with ${ getIdeProperties ( ) . company } Builder ID. Sign out to add another?` ,
886
+ detail : `This will sign out of your current ${
887
+ getIdeProperties ( ) . company
888
+ } Builder ID and open the sign-in page in browser.`,
889
+ } ,
890
+ { data : 'cancel' , label : 'Cancel' } ,
891
+ ]
892
+ const resp = await showQuickPick ( items , {
893
+ title : `Sign in to different ${ getIdeProperties ( ) . company } Builder ID` ,
894
+ buttons : createCommonButtons ( ) as vscode . QuickInputButton [ ] ,
895
+ } )
896
+
897
+ return resp === undefined ? 'cancel' : resp
873
898
}
874
899
875
900
Commands . register ( 'aws.auth.help' , async ( ) => {
876
901
vscode . env . openExternal ( vscode . Uri . parse ( authHelpUrl ) )
877
902
telemetry . aws_help . emit ( )
878
903
} )
904
+
879
905
Commands . register ( 'aws.auth.signout' , ( ) => {
880
906
telemetry . ui_click . emit ( { elementId : 'devtools_signout' } )
881
-
882
907
return signout ( Auth . instance )
883
908
} )
884
909
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
910
const addConnection = Commands . register ( 'aws.auth.addConnection' , async ( ) => {
902
911
const c9IamItem = createIamItem ( )
903
912
c9IamItem . detail =
0 commit comments