VS Code API

VS Code API is a set of JavaScript APIs that you can invoke in your Visual Studio Code extension. This page lists all VS Code APIs available to extension authors.

API namespaces and classes

This listing is compiled from the vscode.d.ts file from the VS Code repository.

authentication

Namespace for authentication.

Events

An Event which fires when the authentication sessions of an authentication provider have been added, removed, or changed.

Functions

Get all accounts that the user is logged in to for the specified provider. Use this paired with getSession in order to get an authentication session for a specific account.

Currently, there are only two authentication providers that are contributed from built in extensions to the editor that implement GitHub and Microsoft authentication: their providerId's are 'github' and 'microsoft'.

Note: Getting accounts does not imply that your extension has access to that account or its authentication sessions. You can verify access to the account by calling getSession.

ParameterDescription
providerId: string

The id of the provider to use

ReturnsDescription
Thenable<readonly AuthenticationSessionAccountInformation[]>

A thenable that resolves to a readonly array of authentication accounts.

Get an authentication session matching the desired scopes or satisfying the WWW-Authenticate request. 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.

Built-in auth providers include:

  • 'github' - For GitHub.com
  • 'microsoft' For both personal & organizational Microsoft accounts
  • (less common) 'github-enterprise' - for alternative GitHub hostings, GHE.com, GitHub Enterprise Server
  • (less common) 'microsoft-sovereign-cloud' - for alternative Microsoft clouds
ParameterDescription
providerId: string

The id of the provider to use

scopeListOrRequest: readonly string[] | AuthenticationWwwAuthenticateRequest

A scope list of permissions requested or a WWW-Authenticate request. These are dependent on the authentication provider.

options: AuthenticationGetSessionOptions & {createIfNone: true | AuthenticationGetSessionPresentationOptions}
ReturnsDescription
Thenable<AuthenticationSession>

A thenable that resolves to an authentication session

Get an authentication session matching the desired scopes or request. 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.

Built-in auth providers include:

  • 'github' - For GitHub.com
  • 'microsoft' For both personal & organizational Microsoft accounts
  • (less common) 'github-enterprise' - for alternative GitHub hostings, GHE.com, GitHub Enterprise Server
  • (less common) 'microsoft-sovereign-cloud' - for alternative Microsoft clouds
ParameterDescription
providerId: string

The id of the provider to use

scopeListOrRequest: readonly string[] | AuthenticationWwwAuthenticateRequest

A scope list of permissions requested or a WWW-Authenticate request. These are dependent on the authentication provider.

options: AuthenticationGetSessionOptions & {forceNewSession: true | AuthenticationGetSessionPresentationOptions}
ReturnsDescription
Thenable<AuthenticationSession>

A thenable that resolves to an authentication session

Get an authentication session matching the desired scopes or request. 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.

Built-in auth providers include:

  • 'github' - For GitHub.com
  • 'microsoft' For both personal & organizational Microsoft accounts
  • (less common) 'github-enterprise' - for alternative GitHub hostings, GHE.com, GitHub Enterprise Server
  • (less common) 'microsoft-sovereign-cloud' - for alternative Microsoft clouds
ParameterDescription
providerId: string

The id of the provider to use

scopeListOrRequest: readonly string[] | AuthenticationWwwAuthenticateRequest

A scope list of permissions requested or a WWW-Authenticate request. These are dependent on the authentication provider.

options?: AuthenticationGetSessionOptions
ReturnsDescription
Thenable<AuthenticationSession | undefined>

A thenable that resolves to an authentication session or undefined if a silent flow was used and no session was found

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.

ParameterDescription
id: string

The unique identifier of the provider.

label: string

The human-readable name of the provider.

provider: AuthenticationProvider

The authentication provider provider.

options