Skip to content

Commit 12f63d9

Browse files
author
Rachel Macfarlane
committed
Stabilize authentication consumer side, fixes microsoft#100993
1 parent 51cdb49 commit 12f63d9

4 files changed

Lines changed: 120 additions & 111 deletions

File tree

extensions/github-authentication/src/github.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { keychain } from './common/keychain';
99
import { GitHubServer, NETWORK_ERROR } from './githubServer';
1010
import Logger from './common/logger';
1111

12-
export const onDidChangeSessions = new vscode.EventEmitter<vscode.AuthenticationSessionsChangeEvent>();
12+
export const onDidChangeSessions = new vscode.EventEmitter<vscode.AuthenticationProviderAuthenticationSessionsChangeEvent>();
1313

1414
interface SessionData {
1515
id: string;

extensions/microsoft-authentication/src/AADHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function parseQuery(uri: vscode.Uri) {
7373
}, {});
7474
}
7575

76-
export const onDidChangeSessions = new vscode.EventEmitter<vscode.AuthenticationSessionsChangeEvent>();
76+
export const onDidChangeSessions = new vscode.EventEmitter<vscode.AuthenticationProviderAuthenticationSessionsChangeEvent>();
7777

7878
export const REFRESH_NETWORK_FAILURE = 'Network failure';
7979

src/vs/vscode.d.ts

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11521,6 +11521,122 @@ declare module 'vscode' {
1152111521
}
1152211522

1152311523
//#endregion
11524+
11525+
/**
11526+
* Represents a session of a currently logged in user.
11527+
*/
11528+
export interface AuthenticationSession {
11529+
/**
11530+
* The identifier of the authentication session.
11531+
*/
11532+
readonly id: string;
11533+
11534+
/**
11535+
* The access token.
11536+
*/
11537+
readonly accessToken: string;
11538+
11539+
/**
11540+
* The account associated with the session.
11541+
*/
11542+
readonly account: AuthenticationSessionAccountInformation;
11543+
11544+
/**
11545+
* The permissions granted by the session's access token. Available scopes
11546+
* are defined by the [AuthenticationProvider](#AuthenticationProvider).
11547+
*/
11548+
readonly scopes: ReadonlyArray<string>;
11549+
}
11550+
11551+
/**
11552+
* The information of an account associated with an [AuthenticationSession](#AuthenticationSession).
11553+
*/
11554+
export interface AuthenticationSessionAccountInformation {
11555+
/**
11556+
* The unique identifier of the account.
11557+
*/
11558+
readonly id: string;
11559+
11560+
/**
11561+
* The human-readable name of the account.
11562+
*/
11563+
readonly label: string;
11564+
}
11565+
11566+
11567+
/**
11568+
* Options to be used when getting an [AuthenticationSession](#AuthenticationSession) from an [AuthenticationProvider](#AuthenticationProvider).
11569+
*/
11570+
export interface AuthenticationGetSessionOptions {
11571+
/**
11572+
* Whether login should be performed if there is no matching session. Defaults to false.
11573+
*/
11574+
createIfNone?: boolean;
11575+
11576+
/**
11577+
* Whether the existing user session preference should be cleared. Set to allow the user to switch accounts.
11578+
* Defaults to false.
11579+
*/
11580+
clearSessionPreference?: boolean;
11581+
}
11582+
11583+
/**
11584+
* Basic information about an[authenticationProvider](#AuthenticationProvider)
11585+
*/
11586+
export interface AuthenticationProviderInformation {
11587+
/**
11588+
* The unique identifier of the authentication provider.
11589+
*/
11590+
readonly id: string;
11591+
11592+
/**
11593+
* The human-readable name of the authentication provider.
11594+
*/
11595+
readonly label: string;
11596+
}
11597+
11598+
/**
11599+
* An [event](#Event) which fires when an [AuthenticationSession](#AuthenticationSession) is added, removed, or changed.
11600+
*/
11601+
export interface AuthenticationSessionsChangeEvent {
11602+
/**
11603+
* The [authenticationProvider](#AuthenticationProvider) that has had its sessions change.
11604+
*/
11605+
readonly provider: AuthenticationProviderInformation;
11606+
}
11607+
11608+
export namespace authentication {
11609+
/**
11610+
* Get an authentication session matching the desired scopes. Rejects if a provider with providerId is not
11611+
* registered, or if the user does not consent to sharing authentication information with
11612+
* the extension. If there are multiple sessions with the same scopes, the user will be shown a
11613+
* quickpick to select which account they would like to use.
11614+
* @param providerId The id of the provider to use
11615+
* @param scopes A list of scopes representing the permissions requested. These are dependent on the authentication provider
11616+
* @param options The [getSessionOptions](#GetSessionOptions) to use
11617+
* @returns A thenable that resolves to an authentication session
11618+
*/
11619+
export function getSession(providerId: string, scopes: string[], options: AuthenticationGetSessionOptions & { createIfNone: true }): Thenable<AuthenticationSession>;
11620+
11621+
/**
11622+
* Get an authentication session matching the desired scopes. Rejects if a provider with providerId is not
11623+
* registered, or if the user does not consent to sharing authentication information with
11624+
* the extension. If there are multiple sessions with the same scopes, the user will be shown a
11625+
* quickpick to select which account they would like to use.
11626+
* @param providerId The id of the provider to use
11627+
* @param scopes A list of scopes representing the permissions requested. These are dependent on the authentication provider
11628+
* @param options The [getSessionOptions](#GetSessionOptions) to use
11629+
* @returns A thenable that resolves to an authentication session if available, or undefined if there are no sessions
11630+
*/
11631+
export function getSession(providerId: string, scopes: string[], options: AuthenticationGetSessionOptions): Thenable<AuthenticationSession | undefined>;
11632+
11633+
/**
11634+
* An [event](#Event) which fires when the array of sessions has changed, or data
11635+
* within a session has changed for a provider. Fires with the ids of the providers
11636+
* that have had session data change.
11637+
*/
11638+
export const onDidChangeSessions: Event<AuthenticationProviderAuthenticationSessionsChangeEvent>;
11639+
}
1152411640
}
1152511641

1152611642
/**

src/vs/vscode.proposed.d.ts

Lines changed: 2 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -18,59 +18,6 @@ declare module 'vscode' {
1818

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

21-
export interface AuthenticationSession {
22-
/**
23-
* The identifier of the authentication session.
24-
*/
25-
readonly id: string;
26-
27-
/**
28-
* The access token.
29-
*/
30-
readonly accessToken: string;
31-
32-
/**
33-
* The account associated with the session.
34-
*/
35-
readonly account: AuthenticationSessionAccountInformation;
36-
37-
/**
38-
* The permissions granted by the session's access token. Available scopes
39-
* are defined by the authentication provider.
40-
*/
41-
readonly scopes: ReadonlyArray<string>;
42-
}
43-
44-
/**
45-
* The information of an account associated with an authentication session.
46-
*/
47-
export interface AuthenticationSessionAccountInformation {
48-
/**
49-
* The unique identifier of the account.
50-
*/
51-
readonly id: string;
52-
53-
/**
54-
* The human-readable name of the account.
55-
*/
56-
readonly label: string;
57-
}
58-
59-
/**
60-
* Basic information about an[authenticationProvider](#AuthenticationProvider)
61-
*/
62-
export interface AuthenticationProviderInformation {
63-
/**
64-
* The unique identifier of the authentication provider.
65-
*/
66-
readonly id: string;
67-
68-
/**
69-
* The human-readable name of the authentication provider.
70-
*/
71-
readonly label: string;
72-
}
73-
7421
/**
7522
* An [event](#Event) which fires when an [AuthenticationProvider](#AuthenticationProvider) is added or removed.
7623
*/
@@ -86,33 +33,10 @@ declare module 'vscode' {
8633
readonly removed: ReadonlyArray<AuthenticationProviderInformation>;
8734
}
8835

89-
/**
90-
* Options to be used when getting a session from an [AuthenticationProvider](#AuthenticationProvider).
91-
*/
92-
export interface AuthenticationGetSessionOptions {
93-
/**
94-
* Whether login should be performed if there is no matching session. Defaults to false.
95-
*/
96-
createIfNone?: boolean;
97-
98-
/**
99-
* Whether the existing user session preference should be cleared. Set to allow the user to switch accounts.
100-
* Defaults to false.
101-
*/
102-
clearSessionPreference?: boolean;
103-
}
104-
105-
export interface AuthenticationProviderAuthenticationSessionsChangeEvent {
106-
/**
107-
* The [authenticationProvider](#AuthenticationProvider) that has had its sessions change.
108-
*/
109-
readonly provider: AuthenticationProviderInformation;
110-
}
111-
11236
/**
11337
* An [event](#Event) which fires when an [AuthenticationSession](#AuthenticationSession) is added, removed, or changed.
11438
*/
115-
export interface AuthenticationSessionsChangeEvent {
39+
export interface AuthenticationProviderAuthenticationSessionsChangeEvent {
11640
/**
11741
* The ids of the [AuthenticationSession](#AuthenticationSession)s that have been added.
11842
*/
@@ -156,7 +80,7 @@ declare module 'vscode' {
15680
* An [event](#Event) which fires when the array of sessions has changed, or data
15781
* within a session has changed.
15882
*/
159-
readonly onDidChangeSessions: Event<AuthenticationSessionsChangeEvent>;
83+
readonly onDidChangeSessions: Event<AuthenticationProviderAuthenticationSessionsChangeEvent>;
16084

16185
/**
16286
* Returns an array of current sessions.
@@ -210,30 +134,6 @@ declare module 'vscode' {
210134
*/
211135
export const providers: ReadonlyArray<AuthenticationProviderInformation>;
212136

213-
/**
214-
* Get an authentication session matching the desired scopes. Rejects if a provider with providerId is not
215-
* registered, or if the user does not consent to sharing authentication information with
216-
* the extension. If there are multiple sessions with the same scopes, the user will be shown a
217-
* quickpick to select which account they would like to use.
218-
* @param providerId The id of the provider to use
219-
* @param scopes A list of scopes representing the permissions requested. These are dependent on the authentication provider
220-
* @param options The [getSessionOptions](#GetSessionOptions) to use
221-
* @returns A thenable that resolves to an authentication session
222-
*/
223-
export function getSession(providerId: string, scopes: string[], options: AuthenticationGetSessionOptions & { createIfNone: true }): Thenable<AuthenticationSession>;
224-
225-
/**
226-
* Get an authentication session matching the desired scopes. Rejects if a provider with providerId is not
227-
* registered, or if the user does not consent to sharing authentication information with
228-
* the extension. If there are multiple sessions with the same scopes, the user will be shown a
229-
* quickpick to select which account they would like to use.
230-
* @param providerId The id of the provider to use
231-
* @param scopes A list of scopes representing the permissions requested. These are dependent on the authentication provider
232-
* @param options The [getSessionOptions](#GetSessionOptions) to use
233-
* @returns A thenable that resolves to an authentication session if available, or undefined if there are no sessions
234-
*/
235-
export function getSession(providerId: string, scopes: string[], options: AuthenticationGetSessionOptions): Thenable<AuthenticationSession | undefined>;
236-
237137
/**
238138
* @deprecated
239139
* Logout of a specific session.
@@ -242,13 +142,6 @@ declare module 'vscode' {
242142
* provider
243143
*/
244144
export function logout(providerId: string, sessionId: string): Thenable<void>;
245-
246-
/**
247-
* An [event](#Event) which fires when the array of sessions has changed, or data
248-
* within a session has changed for a provider. Fires with the ids of the providers
249-
* that have had session data change.
250-
*/
251-
export const onDidChangeSessions: Event<AuthenticationProviderAuthenticationSessionsChangeEvent>;
252145
}
253146

254147
//#endregion

0 commit comments

Comments
 (0)