@@ -387,7 +387,7 @@ export class AuthenticationService extends Disposable implements IAuthentication
387387 return undefined ;
388388 }
389389
390- async updatedAllowedExtension ( providerId : string , accountName : string , extensionId : string , extensionName : string , isAllowed : boolean ) : Promise < void > {
390+ updateAllowedExtension ( providerId : string , accountName : string , extensionId : string , extensionName : string , isAllowed : boolean ) : void {
391391 const allowList = readAllowedExtensions ( this . storageService , providerId , accountName ) ;
392392 const index = allowList . findIndex ( extension => extension . id === extensionId ) ;
393393 if ( index === - 1 ) {
@@ -396,9 +396,29 @@ export class AuthenticationService extends Disposable implements IAuthentication
396396 allowList [ index ] . allowed = isAllowed ;
397397 }
398398
399- await this . storageService . store ( `${ providerId } -${ accountName } ` , JSON . stringify ( allowList ) , StorageScope . APPLICATION , StorageTarget . USER ) ;
399+ this . storageService . store ( `${ providerId } -${ accountName } ` , JSON . stringify ( allowList ) , StorageScope . APPLICATION , StorageTarget . USER ) ;
400400 }
401401
402+ //#region Session Preference
403+
404+ updateSessionPreference ( providerId : string , extensionId : string , session : AuthenticationSession ) : void {
405+ // The 3 parts of this key are important:
406+ // * Extension id: The extension that has a preference
407+ // * Provider id: The provider that the preference is for
408+ // * The scopes: The subset of sessions that the preference applies to
409+ this . storageService . store ( `${ extensionId } -${ providerId } -${ session . scopes . join ( ' ' ) } ` , session . id , StorageScope . APPLICATION , StorageTarget . MACHINE ) ;
410+ }
411+
412+ getSessionPreference ( providerId : string , extensionId : string , scopes : string [ ] ) : string | undefined {
413+ return this . storageService . get ( `${ extensionId } -${ providerId } -${ scopes . join ( ' ' ) } ` , StorageScope . APPLICATION , undefined ) ;
414+ }
415+
416+ removeSessionPreference ( providerId : string , extensionId : string , scopes : string [ ] ) : void {
417+ this . storageService . remove ( `${ extensionId } -${ providerId } -${ scopes . join ( ' ' ) } ` , StorageScope . APPLICATION ) ;
418+ }
419+
420+ //#endregion
421+
402422 async showGetSessionPrompt ( providerId : string , accountName : string , extensionId : string , extensionName : string ) : Promise < boolean > {
403423 const providerName = this . getLabel ( providerId ) ;
404424 const { choice } = await this . dialogService . show (
@@ -413,7 +433,7 @@ export class AuthenticationService extends Disposable implements IAuthentication
413433 const cancelled = choice === 2 ;
414434 const allowed = choice === 0 ;
415435 if ( ! cancelled ) {
416- this . updatedAllowedExtension ( providerId , accountName , extensionId , extensionName , allowed ) ;
436+ this . updateAllowedExtension ( providerId , accountName , extensionId , extensionName , allowed ) ;
417437 this . removeAccessRequest ( providerId , extensionId ) ;
418438 }
419439
@@ -458,10 +478,9 @@ export class AuthenticationService extends Disposable implements IAuthentication
458478 const session = quickPick . selectedItems [ 0 ] . session ?? await this . createSession ( providerId , scopes ) ;
459479 const accountName = session . account . label ;
460480
461- this . updatedAllowedExtension ( providerId , accountName , extensionId , extensionName , true ) ;
462-
481+ this . updateAllowedExtension ( providerId , accountName , extensionId , extensionName , true ) ;
482+ this . updateSessionPreference ( providerId , extensionId , session ) ;
463483 this . removeAccessRequest ( providerId , extensionId ) ;
464- this . storageService . store ( `${ extensionName } -${ providerId } ` , session . id , StorageScope . APPLICATION , StorageTarget . MACHINE ) ;
465484
466485 quickPick . dispose ( ) ;
467486 resolve ( session ) ;
@@ -551,9 +570,10 @@ export class AuthenticationService extends Disposable implements IAuthentication
551570 // since this is sync and returns a disposable. So, wait for registration event to fire that indicates the
552571 // provider is now in the map.
553572 await new Promise < void > ( ( resolve , _ ) => {
554- this . onDidRegisterAuthenticationProvider ( e => {
573+ const dispose = this . onDidRegisterAuthenticationProvider ( e => {
555574 if ( e . id === providerId ) {
556575 provider = this . _authenticationProviders . get ( providerId ) ;
576+ dispose . dispose ( ) ;
557577 resolve ( ) ;
558578 }
559579 } ) ;
@@ -594,14 +614,10 @@ export class AuthenticationService extends Disposable implements IAuthentication
594614 id : commandId ,
595615 handler : async ( accessor ) => {
596616 const authenticationService = accessor . get ( IAuthenticationService ) ;
597- const storageService = accessor . get ( IStorageService ) ;
598617 const session = await authenticationService . createSession ( providerId , scopes ) ;
599618
600- // Add extension to allow list since user explicitly signed in on behalf of it
601- this . updatedAllowedExtension ( providerId , session . account . label , extensionId , extensionName , true ) ;
602-
603- // And also set it as the preferred account for the extension
604- storageService . store ( `${ extensionName } -${ providerId } ` , session . id , StorageScope . APPLICATION , StorageTarget . MACHINE ) ;
619+ this . updateAllowedExtension ( providerId , session . account . label , extensionId , extensionName , true ) ;
620+ this . updateSessionPreference ( providerId , extensionId , session ) ;
605621 }
606622 } ) ;
607623
0 commit comments