From 12f63d9c66b8a4bc9efca936d174184893f652a2 Mon Sep 17 00:00:00 2001 From: Rachel Macfarlane Date: Tue, 28 Jul 2020 09:58:01 -0700 Subject: [PATCH] Stabilize authentication consumer side, fixes #100993 --- .../github-authentication/src/github.ts | 2 +- .../microsoft-authentication/src/AADHelper.ts | 2 +- src/vs/vscode.d.ts | 116 ++++++++++++++++++ src/vs/vscode.proposed.d.ts | 111 +---------------- 4 files changed, 120 insertions(+), 111 deletions(-) diff --git a/extensions/github-authentication/src/github.ts b/extensions/github-authentication/src/github.ts index 0f9284bbecf..a042ebe2a36 100644 --- a/extensions/github-authentication/src/github.ts +++ b/extensions/github-authentication/src/github.ts @@ -9,7 +9,7 @@ import { keychain } from './common/keychain'; import { GitHubServer, NETWORK_ERROR } from './githubServer'; import Logger from './common/logger'; -export const onDidChangeSessions = new vscode.EventEmitter(); +export const onDidChangeSessions = new vscode.EventEmitter(); interface SessionData { id: string; diff --git a/extensions/microsoft-authentication/src/AADHelper.ts b/extensions/microsoft-authentication/src/AADHelper.ts index f548b2ba528..035c5af7350 100644 --- a/extensions/microsoft-authentication/src/AADHelper.ts +++ b/extensions/microsoft-authentication/src/AADHelper.ts @@ -73,7 +73,7 @@ function parseQuery(uri: vscode.Uri) { }, {}); } -export const onDidChangeSessions = new vscode.EventEmitter(); +export const onDidChangeSessions = new vscode.EventEmitter(); export const REFRESH_NETWORK_FAILURE = 'Network failure'; diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index efd2b3b06e4..edcfd4db4a1 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -11521,6 +11521,122 @@ declare module 'vscode' { } //#endregion + + /** + * Represents a session of a currently logged in user. + */ + export interface AuthenticationSession { + /** + * The identifier of the authentication session. + */ + readonly id: string; + + /** + * The access token. + */ + readonly accessToken: string; + + /** + * The account associated with the session. + */ + readonly account: AuthenticationSessionAccountInformation; + + /** + * The permissions granted by the session's access token. Available scopes + * are defined by the [AuthenticationProvider](#AuthenticationProvider). + */ + readonly scopes: ReadonlyArray; + } + + /** + * The information of an account associated with an [AuthenticationSession](#AuthenticationSession). + */ + export interface AuthenticationSessionAccountInformation { + /** + * The unique identifier of the account. + */ + readonly id: string; + + /** + * The human-readable name of the account. + */ + readonly label: string; + } + + + /** + * Options to be used when getting an [AuthenticationSession](#AuthenticationSession) from an [AuthenticationProvider](#AuthenticationProvider). + */ + export interface AuthenticationGetSessionOptions { + /** + * Whether login should be performed if there is no matching session. Defaults to false. + */ + createIfNone?: boolean; + + /** + * Whether the existing user session preference should be cleared. Set to allow the user to switch accounts. + * Defaults to false. + */ + clearSessionPreference?: boolean; + } + + /** + * Basic information about an[authenticationProvider](#AuthenticationProvider) + */ + export interface AuthenticationProviderInformation { + /** + * The unique identifier of the authentication provider. + */ + readonly id: string; + + /** + * The human-readable name of the authentication provider. + */ + readonly label: string; + } + + /** + * An [event](#Event) which fires when an [AuthenticationSession](#AuthenticationSession) is added, removed, or changed. + */ + export interface AuthenticationSessionsChangeEvent { + /** + * The [authenticationProvider](#AuthenticationProvider) that has had its sessions change. + */ + readonly provider: AuthenticationProviderInformation; + } + + export namespace authentication { + /** + * Get an authentication session matching the desired scopes. Rejects if a provider with providerId is not + * registered, or if the user does not consent to sharing authentication information with + * the extension. If there are multiple sessions with the same scopes, the user will be shown a + * quickpick to select which account they would like to use. + * @param providerId The id of the provider to use + * @param scopes A list of scopes representing the permissions requested. These are dependent on the authentication provider + * @param options The [getSessionOptions](#GetSessionOptions) to use + * @returns A thenable that resolves to an authentication session + */ + export function getSession(providerId: string, scopes: string[], options: AuthenticationGetSessionOptions & { createIfNone: true }): Thenable; + + /** + * Get an authentication session matching the desired scopes. Rejects if a provider with providerId is not + * registered, or if the user does not consent to sharing authentication information with + * the extension. If there are multiple sessions with the same scopes, the user will be shown a + * quickpick to select which account they would like to use. + * @param providerId The id of the provider to use + * @param scopes A list of scopes representing the permissions requested. These are dependent on the authentication provider + * @param options The [getSessionOptions](#GetSessionOptions) to use + * @returns A thenable that resolves to an authentication session if available, or undefined if there are no sessions + */ + export function getSession(providerId: string, scopes: string[], options: AuthenticationGetSessionOptions): Thenable; + + /** + * An [event](#Event) which fires when the array of sessions has changed, or data + * within a session has changed for a provider. Fires with the ids of the providers + * that have had session data change. + */ + export const onDidChangeSessions: Event; + } } /** diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 876ae7adc90..54c28ce4a12 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -18,59 +18,6 @@ declare module 'vscode' { // #region auth provider: https://github.com/microsoft/vscode/issues/88309 - export interface AuthenticationSession { - /** - * The identifier of the authentication session. - */ - readonly id: string; - - /** - * The access token. - */ - readonly accessToken: string; - - /** - * The account associated with the session. - */ - readonly account: AuthenticationSessionAccountInformation; - - /** - * The permissions granted by the session's access token. Available scopes - * are defined by the authentication provider. - */ - readonly scopes: ReadonlyArray; - } - - /** - * The information of an account associated with an authentication session. - */ - export interface AuthenticationSessionAccountInformation { - /** - * The unique identifier of the account. - */ - readonly id: string; - - /** - * The human-readable name of the account. - */ - readonly label: string; - } - - /** - * Basic information about an[authenticationProvider](#AuthenticationProvider) - */ - export interface AuthenticationProviderInformation { - /** - * The unique identifier of the authentication provider. - */ - readonly id: string; - - /** - * The human-readable name of the authentication provider. - */ - readonly label: string; - } - /** * An [event](#Event) which fires when an [AuthenticationProvider](#AuthenticationProvider) is added or removed. */ @@ -86,33 +33,10 @@ declare module 'vscode' { readonly removed: ReadonlyArray; } - /** - * Options to be used when getting a session from an [AuthenticationProvider](#AuthenticationProvider). - */ - export interface AuthenticationGetSessionOptions { - /** - * Whether login should be performed if there is no matching session. Defaults to false. - */ - createIfNone?: boolean; - - /** - * Whether the existing user session preference should be cleared. Set to allow the user to switch accounts. - * Defaults to false. - */ - clearSessionPreference?: boolean; - } - - export interface AuthenticationProviderAuthenticationSessionsChangeEvent { - /** - * The [authenticationProvider](#AuthenticationProvider) that has had its sessions change. - */ - readonly provider: AuthenticationProviderInformation; - } - /** * An [event](#Event) which fires when an [AuthenticationSession](#AuthenticationSession) is added, removed, or changed. */ - export interface AuthenticationSessionsChangeEvent { + export interface AuthenticationProviderAuthenticationSessionsChangeEvent { /** * The ids of the [AuthenticationSession](#AuthenticationSession)s that have been added. */ @@ -156,7 +80,7 @@ declare module 'vscode' { * An [event](#Event) which fires when the array of sessions has changed, or data * within a session has changed. */ - readonly onDidChangeSessions: Event; + readonly onDidChangeSessions: Event; /** * Returns an array of current sessions. @@ -210,30 +134,6 @@ declare module 'vscode' { */ export const providers: ReadonlyArray; - /** - * Get an authentication session matching the desired scopes. Rejects if a provider with providerId is not - * registered, or if the user does not consent to sharing authentication information with - * the extension. If there are multiple sessions with the same scopes, the user will be shown a - * quickpick to select which account they would like to use. - * @param providerId The id of the provider to use - * @param scopes A list of scopes representing the permissions requested. These are dependent on the authentication provider - * @param options The [getSessionOptions](#GetSessionOptions) to use - * @returns A thenable that resolves to an authentication session - */ - export function getSession(providerId: string, scopes: string[], options: AuthenticationGetSessionOptions & { createIfNone: true }): Thenable; - - /** - * Get an authentication session matching the desired scopes. Rejects if a provider with providerId is not - * registered, or if the user does not consent to sharing authentication information with - * the extension. If there are multiple sessions with the same scopes, the user will be shown a - * quickpick to select which account they would like to use. - * @param providerId The id of the provider to use - * @param scopes A list of scopes representing the permissions requested. These are dependent on the authentication provider - * @param options The [getSessionOptions](#GetSessionOptions) to use - * @returns A thenable that resolves to an authentication session if available, or undefined if there are no sessions - */ - export function getSession(providerId: string, scopes: string[], options: AuthenticationGetSessionOptions): Thenable; - /** * @deprecated * Logout of a specific session. @@ -242,13 +142,6 @@ declare module 'vscode' { * provider */ export function logout(providerId: string, sessionId: string): Thenable; - - /** - * An [event](#Event) which fires when the array of sessions has changed, or data - * within a session has changed for a provider. Fires with the ids of the providers - * that have had session data change. - */ - export const onDidChangeSessions: Event; } //#endregion