@@ -387,7 +387,7 @@ export class AuthenticationService extends Disposable implements IAuthentication
387
387
return undefined ;
388
388
}
389
389
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 {
391
391
const allowList = readAllowedExtensions ( this . storageService , providerId , accountName ) ;
392
392
const index = allowList . findIndex ( extension => extension . id === extensionId ) ;
393
393
if ( index === - 1 ) {
@@ -396,9 +396,29 @@ export class AuthenticationService extends Disposable implements IAuthentication
396
396
allowList [ index ] . allowed = isAllowed ;
397
397
}
398
398
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 ) ;
400
400
}
401
401
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
+
402
422
async showGetSessionPrompt ( providerId : string , accountName : string , extensionId : string , extensionName : string ) : Promise < boolean > {
403
423
const providerName = this . getLabel ( providerId ) ;
404
424
const { choice } = await this . dialogService . show (
@@ -413,7 +433,7 @@ export class AuthenticationService extends Disposable implements IAuthentication
413
433
const cancelled = choice === 2 ;
414
434
const allowed = choice === 0 ;
415
435
if ( ! cancelled ) {
416
- this . updatedAllowedExtension ( providerId , accountName , extensionId , extensionName , allowed ) ;
436
+ this . updateAllowedExtension ( providerId , accountName , extensionId , extensionName , allowed ) ;
417
437
this . removeAccessRequest ( providerId , extensionId ) ;
418
438
}
419
439
@@ -458,10 +478,9 @@ export class AuthenticationService extends Disposable implements IAuthentication
458
478
const session = quickPick . selectedItems [ 0 ] . session ?? await this . createSession ( providerId , scopes ) ;
459
479
const accountName = session . account . label ;
460
480
461
- this . updatedAllowedExtension ( providerId , accountName , extensionId , extensionName , true ) ;
462
-
481
+ this . updateAllowedExtension ( providerId , accountName , extensionId , extensionName , true ) ;
482
+ this . updateSessionPreference ( providerId , extensionId , session ) ;
463
483
this . removeAccessRequest ( providerId , extensionId ) ;
464
- this . storageService . store ( `${ extensionName } -${ providerId } ` , session . id , StorageScope . APPLICATION , StorageTarget . MACHINE ) ;
465
484
466
485
quickPick . dispose ( ) ;
467
486
resolve ( session ) ;
@@ -551,9 +570,10 @@ export class AuthenticationService extends Disposable implements IAuthentication
551
570
// since this is sync and returns a disposable. So, wait for registration event to fire that indicates the
552
571
// provider is now in the map.
553
572
await new Promise < void > ( ( resolve , _ ) => {
554
- this . onDidRegisterAuthenticationProvider ( e => {
573
+ const dispose = this . onDidRegisterAuthenticationProvider ( e => {
555
574
if ( e . id === providerId ) {
556
575
provider = this . _authenticationProviders . get ( providerId ) ;
576
+ dispose . dispose ( ) ;
557
577
resolve ( ) ;
558
578
}
559
579
} ) ;
@@ -594,14 +614,10 @@ export class AuthenticationService extends Disposable implements IAuthentication
594
614
id : commandId ,
595
615
handler : async ( accessor ) => {
596
616
const authenticationService = accessor . get ( IAuthenticationService ) ;
597
- const storageService = accessor . get ( IStorageService ) ;
598
617
const session = await authenticationService . createSession ( providerId , scopes ) ;
599
618
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 ) ;
605
621
}
606
622
} ) ;
607
623
0 commit comments