Add authentication provider registration to stable API, closes #88309

This commit is contained in:
Rachel Macfarlane 2021-02-22 15:14:14 -08:00
parent b6377b8e71
commit 67ded11020
2 changed files with 88 additions and 85 deletions

81
src/vs/vscode.d.ts vendored
View file

@ -12331,6 +12331,73 @@ declare module 'vscode' {
readonly provider: AuthenticationProviderInformation;
}
/**
* Options for creating an [AuthenticationProvider](#AuthenticationProvider).
*/
export interface AuthenticationProviderOptions {
/**
* Whether it is possible to be signed into multiple accounts at once with this provider.
* If not specified, will default to false.
*/
readonly supportsMultipleAccounts?: boolean;
}
/**
* An [event](#Event) which fires when an [AuthenticationSession](#AuthenticationSession) is added, removed, or changed.
*/
export interface AuthenticationProviderAuthenticationSessionsChangeEvent {
/**
* The [AuthenticationSession](#AuthenticationSession)s of the [AuthenticationProvider](#AuthentiationProvider) that have been added.
*/
readonly added: ReadonlyArray<AuthenticationSession>;
/**
* The [AuthenticationSession](#AuthenticationSession)s of the [AuthenticationProvider](#AuthentiationProvider) that have been removed.
*/
readonly removed: ReadonlyArray<AuthenticationSession>;
/**
* The [AuthenticationSession](#AuthenticationSession)s of the [AuthenticationProvider](#AuthentiationProvider) that have been changed.
*/
readonly changed: ReadonlyArray<AuthenticationSession>;
}
/**
* A provider for performing authentication to a service.
*/
export interface AuthenticationProvider {
/**
* An [event](#Event) which fires when the array of sessions has changed, or data
* within a session has changed.
*/
readonly onDidChangeSessions: Event<AuthenticationProviderAuthenticationSessionsChangeEvent>;
/**
* Get a list of sessions.
* @param scopes An optional list of scopes. If provided, the sessions returned should match
* these permissions, otherwise all sessions should be returned.
* @returns A promise that resolves to an array of authentication sessions.
*/
// eslint-disable-next-line vscode-dts-provider-naming
getSessions(scopes?: string[]): Thenable<ReadonlyArray<AuthenticationSession>>;
/**
* Prompts a user to login.
* @param scopes A list of scopes, permissions, that the new session should be created with.
* @returns A promise that resolves to an authentication session.
*/
// eslint-disable-next-line vscode-dts-provider-naming
createSession(scopes: string[]): Thenable<AuthenticationSession>;
/**
* Removes the session corresponding to session id.
* @param sessionId The id of the session to remove.
*/
// eslint-disable-next-line vscode-dts-provider-naming
removeSession(sessionId: string): Thenable<void>;
}
/**
* Namespace for authentication.
*/
@ -12370,6 +12437,20 @@ declare module 'vscode' {
* been added, removed, or changed.
*/
export const onDidChangeSessions: Event<AuthenticationSessionsChangeEvent>;
/**
* Register an authentication provider.
*
* There can only be one provider per id and an error is being thrown when an id
* has already been used by another provider. Ids are case-sensitive.
*
* @param id The unique identifier of the provider.
* @param label The human-readable name of the provider.
* @param provider The authentication provider provider.
* @params options Additional options for the provider.
* @return A [disposable](#Disposable) that unregisters this provider when being disposed.
*/
export function registerAuthenticationProvider(id: string, label: string, provider: AuthenticationProvider, options?: AuthenticationProviderOptions): Disposable;
}
}

View file

@ -33,87 +33,7 @@ declare module 'vscode' {
readonly removed: ReadonlyArray<AuthenticationProviderInformation>;
}
/**
* An [event](#Event) which fires when an [AuthenticationSession](#AuthenticationSession) is added, removed, or changed.
*/
export interface AuthenticationProviderAuthenticationSessionsChangeEvent {
/**
* The [AuthenticationSession](#AuthenticationSession)s of the [AuthenticationProvider](#AuthentiationProvider) that have been added.
*/
readonly added: ReadonlyArray<AuthenticationSession>;
/**
* The [AuthenticationSession](#AuthenticationSession)s of the [AuthenticationProvider](#AuthentiationProvider) that have been removed.
*/
readonly removed: ReadonlyArray<AuthenticationSession>;
/**
* The [AuthenticationSession](#AuthenticationSession)s of the [AuthenticationProvider](#AuthentiationProvider) that have been changed.
*/
readonly changed: ReadonlyArray<AuthenticationSession>;
}
/**
* A provider for performing authentication to a service.
*/
export interface AuthenticationProvider {
/**
* An [event](#Event) which fires when the array of sessions has changed, or data
* within a session has changed.
*/
readonly onDidChangeSessions: Event<AuthenticationProviderAuthenticationSessionsChangeEvent>;
/**
* Get a list of sessions.
* @param scopes An optional list of scopes. If provided, the sessions returned should match
* these permissions, otherwise all sessions should be returned.
* @returns A promise that resolves to an array of authentication sessions.
*/
// eslint-disable-next-line vscode-dts-provider-naming
getSessions(scopes?: string[]): Thenable<ReadonlyArray<AuthenticationSession>>;
/**
* Prompts a user to login.
* @param scopes A list of scopes, permissions, that the new session should be created with.
* @returns A promise that resolves to an authentication session.
*/
// eslint-disable-next-line vscode-dts-provider-naming
createSession(scopes: string[]): Thenable<AuthenticationSession>;
/**
* Removes the session corresponding to session id.
* @param sessionId The id of the session to remove.
*/
// eslint-disable-next-line vscode-dts-provider-naming
removeSession(sessionId: string): Thenable<void>;
}
/**
* Options for creating an [AuthenticationProvider](#AuthentcationProvider).
*/
export interface AuthenticationProviderOptions {
/**
* Whether it is possible to be signed into multiple accounts at once with this provider.
* If not specified, will default to false.
*/
readonly supportsMultipleAccounts?: boolean;
}
export namespace authentication {
/**
* Register an authentication provider.
*
* There can only be one provider per id and an error is being thrown when an id
* has already been used by another provider. Ids are case-sensitive.
*
* @param id The unique identifier of the provider.
* @param label The human-readable name of the provider.
* @param provider The authentication provider provider.
* @params options Additional options for the provider.
* @return A [disposable](#Disposable) that unregisters this provider when being disposed.
*/
export function registerAuthenticationProvider(id: string, label: string, provider: AuthenticationProvider, options?: AuthenticationProviderOptions): Disposable;
/**
* @deprecated - getSession should now trigger extension activation.
* Fires with the provider id that was registered or unregistered.
@ -121,16 +41,18 @@ declare module 'vscode' {
export const onDidChangeAuthenticationProviders: Event<AuthenticationProvidersChangeEvent>;
/**
* @deprecated
* An array of the information of authentication providers that are currently registered.
*/
export const providers: ReadonlyArray<AuthenticationProviderInformation>;
/**
* Logout of a specific session.
* @param providerId The id of the provider to use
* @param sessionId The session id to remove
* provider
*/
* @deprecated
* Logout of a specific session.
* @param providerId The id of the provider to use
* @param sessionId The session id to remove
* provider
*/
export function logout(providerId: string, sessionId: string): Thenable<void>;
}