@@ -9,7 +9,6 @@ import { Emitter, Event } from 'vs/base/common/event';
99import { IMainContext , MainContext , MainThreadAuthenticationShape , ExtHostAuthenticationShape } from 'vs/workbench/api/common/extHost.protocol' ;
1010import { Disposable } from 'vs/workbench/api/common/extHostTypes' ;
1111import { IExtensionDescription , ExtensionIdentifier } from 'vs/platform/extensions/common/extensions' ;
12- import { IExtHostStorage } from 'vs/workbench/api/common/extHostStorage' ;
1312
1413export class ExtHostAuthentication implements ExtHostAuthenticationShape {
1514 private _proxy : MainThreadAuthenticationShape ;
@@ -21,8 +20,7 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
2120 private _onDidChangeSessions = new Emitter < { [ providerId : string ] : vscode . AuthenticationSessionsChangeEvent } > ( ) ;
2221 readonly onDidChangeSessions : Event < { [ providerId : string ] : vscode . AuthenticationSessionsChangeEvent } > = this . _onDidChangeSessions . event ;
2322
24- constructor ( mainContext : IMainContext ,
25- @IExtHostStorage private readonly storageService : IExtHostStorage ) {
23+ constructor ( mainContext : IMainContext ) {
2624 this . _proxy = mainContext . getProxy ( MainContext . MainThreadAuthentication ) ;
2725 }
2826
@@ -35,34 +33,15 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
3533 return ids ;
3634 }
3735
38- private async hasNotBeenReadByOtherExtension ( providerId : string , session : vscode . AuthenticationSession , extensionId : string ) : Promise < boolean > {
39- const readerId = await this . storageService . getValue ( true , `${ providerId } -${ session . accountName } -${ session . id } ` ) ;
40- if ( ! readerId ) {
41- await this . storageService . setValue ( true , `${ providerId } -${ session . accountName } -${ session . id } ` , extensionId as any ) ;
42- return true ;
43- }
44-
45- return readerId === extensionId ;
46- }
47-
48- private async isMatchingSession ( session : vscode . AuthenticationSession , scopes : string , providerId : string , extensionId : string ) : Promise < boolean > {
49- return session . scopes . sort ( ) . join ( ' ' ) === scopes && ( await this . hasNotBeenReadByOtherExtension ( providerId , session , extensionId ) ) ;
50- }
51-
5236 async getSessions ( requestingExtension : IExtensionDescription , providerId : string , scopes : string [ ] ) : Promise < readonly vscode . AuthenticationSession [ ] > {
5337 const provider = this . _authenticationProviders . get ( providerId ) ;
5438 if ( ! provider ) {
5539 throw new Error ( `No authentication provider with id '${ providerId } ' is currently registered.` ) ;
5640 }
5741
58- const extensionId = ExtensionIdentifier . toKey ( requestingExtension . identifier ) ;
5942 const orderedScopes = scopes . sort ( ) . join ( ' ' ) ;
60-
61- const sessions = await provider . getSessions ( ) ;
62- const filteredSessions = await Promise . all ( sessions . map ( session => this . isMatchingSession ( session , orderedScopes , providerId , extensionId ) ) ) ;
63-
64- return sessions
65- . filter ( ( _ , i ) => { return filteredSessions [ i ] ; } )
43+ return ( await provider . getSessions ( ) )
44+ . filter ( session => session . scopes . sort ( ) . join ( ' ' ) === orderedScopes )
6645 . map ( session => {
6746 return {
6847 id : session . id ,
@@ -72,9 +51,8 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
7251 const isAllowed = await this . _proxy . $getSessionsPrompt (
7352 provider . id ,
7453 session . accountName ,
75- session . id ,
7654 provider . displayName ,
77- extensionId ,
55+ ExtensionIdentifier . toKey ( requestingExtension . identifier ) ,
7856 requestingExtension . displayName || requestingExtension . name ) ;
7957
8058 if ( ! isAllowed ) {
@@ -99,28 +77,9 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
9977 throw new Error ( 'User did not consent to login.' ) ;
10078 }
10179
102- const session = await provider . login ( scopes ) ;
103- await this . _proxy . $setTrustedExtension ( provider . id , session . accountName , ExtensionIdentifier . toKey ( requestingExtension . identifier ) , extensionName ) ;
104- return {
105- id : session . id ,
106- accountName : session . accountName ,
107- scopes : session . scopes ,
108- getAccessToken : async ( ) => {
109- const isAllowed = await this . _proxy . $getSessionsPrompt (
110- provider . id ,
111- session . accountName ,
112- session . id ,
113- provider . displayName ,
114- ExtensionIdentifier . toKey ( requestingExtension . identifier ) ,
115- requestingExtension . displayName || requestingExtension . name ) ;
116-
117- if ( ! isAllowed ) {
118- throw new Error ( 'User did not consent to token access.' ) ;
119- }
120-
121- return session . getAccessToken ( ) ;
122- }
123- } ;
80+ const newSession = await provider . login ( scopes ) ;
81+ await this . _proxy . $setTrustedExtension ( provider . id , newSession . accountName , ExtensionIdentifier . toKey ( requestingExtension . identifier ) , extensionName ) ;
82+ return newSession ;
12483 }
12584
12685 registerAuthenticationProvider ( provider : vscode . AuthenticationProvider ) : vscode . Disposable {
0 commit comments