Skip to content

Commit a155fcf

Browse files
author
Rachel Macfarlane
committed
Address feedback on auth provider API
1 parent 0d1933a commit a155fcf

6 files changed

Lines changed: 14 additions & 47 deletions

File tree

extensions/github-authentication/src/github.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,12 @@ export class GitHubAuthenticationProvider {
141141

142142
private async tokenToSession(token: string, scopes: string[]): Promise<vscode.AuthenticationSession> {
143143
const userInfo = await this._githubServer.getUserInfo(token);
144-
return new vscode.AuthenticationSession(uuid(), token, { label: userInfo.accountName, id: userInfo.id }, scopes);
144+
return {
145+
id: uuid(),
146+
accessToken: token,
147+
account: { label: userInfo.accountName, id: userInfo.id },
148+
scopes
149+
};
145150
}
146151

147152
private async setToken(session: vscode.AuthenticationSession): Promise<void> {

extensions/microsoft-authentication/src/AADHelper.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,12 @@ export class AzureActiveDirectoryService {
219219

220220
private async convertToSession(token: IToken): Promise<vscode.AuthenticationSession> {
221221
const resolvedToken = await this.resolveAccessToken(token);
222-
return new vscode.AuthenticationSession(token.sessionId, resolvedToken, token.account, token.scope.split(' '));
222+
return {
223+
id: token.sessionId,
224+
accessToken: resolvedToken,
225+
account: token.account,
226+
scopes: token.scope.split(' ')
227+
};
223228
}
224229

225230
private async resolveAccessToken(token: IToken): Promise<string> {

src/vs/vscode.proposed.d.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ declare module 'vscode' {
1818

1919
// #region auth provider: https://github.com/microsoft/vscode/issues/88309
2020

21-
export class AuthenticationSession {
21+
export interface AuthenticationSession {
2222
/**
2323
* The identifier of the authentication session.
2424
*/
@@ -39,8 +39,6 @@ declare module 'vscode' {
3939
* are defined by the authentication provider.
4040
*/
4141
readonly scopes: ReadonlyArray<string>;
42-
43-
constructor(id: string, accessToken: string, account: AuthenticationSessionAccountInformation, scopes: string[]);
4442
}
4543

4644
/**
@@ -212,17 +210,6 @@ declare module 'vscode' {
212210
*/
213211
export const providers: ReadonlyArray<AuthenticationProviderInformation>;
214212

215-
/**
216-
* Returns whether a provider has any sessions matching the requested scopes. This request
217-
* is transparent to the user, no UI is shown. Rejects if a provider with providerId is not
218-
* registered.
219-
* @param providerId The id of the provider
220-
* @param scopes A list of scopes representing the permissions requested. These are dependent on the authentication
221-
* provider
222-
* @returns A thenable that resolve to whether the provider has sessions with the requested scopes.
223-
*/
224-
export function hasSessions(providerId: string, scopes: string[]): Thenable<boolean>;
225-
226213
/**
227214
* Get an authentication session matching the desired scopes. Rejects if a provider with providerId is not
228215
* registered, or if the user does not consent to sharing authentication information with

src/vs/workbench/api/common/extHost.api.impl.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
205205
get providers(): ReadonlyArray<vscode.AuthenticationProviderInformation> {
206206
return extHostAuthentication.providers;
207207
},
208-
hasSessions(providerId: string, scopes: string[]): Thenable<boolean> {
209-
return extHostAuthentication.hasSessions(providerId, scopes);
210-
},
211208
getSession(providerId: string, scopes: string[], options: vscode.AuthenticationGetSessionOptions) {
212209
return extHostAuthentication.getSession(extension, providerId, scopes, options as any);
213210
},
@@ -1103,8 +1100,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
11031100
TimelineItem: extHostTypes.TimelineItem,
11041101
CellKind: extHostTypes.CellKind,
11051102
CellOutputKind: extHostTypes.CellOutputKind,
1106-
NotebookCellRunState: extHostTypes.NotebookCellRunState,
1107-
AuthenticationSession: extHostTypes.AuthenticationSession
1103+
NotebookCellRunState: extHostTypes.NotebookCellRunState
11081104
};
11091105
};
11101106
}

src/vs/workbench/api/common/extHostAuthentication.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,6 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
4040
return Object.freeze(this._providers);
4141
}
4242

43-
private async resolveSessions(providerId: string): Promise<ReadonlyArray<modes.AuthenticationSession>> {
44-
const provider = this._authenticationProviders.get(providerId);
45-
46-
let sessions;
47-
if (!provider) {
48-
sessions = await this._proxy.$getSessions(providerId);
49-
} else {
50-
sessions = await provider.getSessions();
51-
}
52-
53-
return sessions;
54-
}
55-
56-
async hasSessions(providerId: string, scopes: string[]): Promise<boolean> {
57-
const orderedScopes = scopes.sort().join(' ');
58-
const sessions = await this.resolveSessions(providerId);
59-
return !!(sessions.filter(session => session.scopes.slice().sort().join(' ') === orderedScopes).length);
60-
}
61-
6243
async getSession(requestingExtension: IExtensionDescription, providerId: string, scopes: string[], options: vscode.AuthenticationGetSessionOptions & { createIfNone: true }): Promise<vscode.AuthenticationSession>;
6344
async getSession(requestingExtension: IExtensionDescription, providerId: string, scopes: string[], options: vscode.AuthenticationGetSessionOptions): Promise<vscode.AuthenticationSession | undefined> {
6445
const provider = this._authenticationProviders.get(providerId);

src/vs/workbench/api/common/extHostTypes.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2774,13 +2774,6 @@ export enum ExtensionMode {
27742774

27752775
//#endregion ExtensionContext
27762776

2777-
2778-
//#region Authentication
2779-
export class AuthenticationSession implements vscode.AuthenticationSession {
2780-
constructor(public id: string, public accessToken: string, public account: { label: string, id: string }, public scopes: string[]) { }
2781-
}
2782-
2783-
//#endregion Authentication
27842777
export enum StandardTokenType {
27852778
Other = 0,
27862779
Comment = 1,

0 commit comments

Comments
 (0)