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
Events
onDidChangeSessions: Event<AuthenticationSessionsChangeEvent>
An Event which fires when the authentication sessions of an authentication provider have been added, removed, or changed.
Functions
getAccounts(providerId: string): Thenable<readonly AuthenticationSessionAccountInformation[]>
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.
| Parameter | Description |
|---|---|
| providerId: string | The id of the provider to use |
| Returns | Description |
| Thenable<readonly AuthenticationSessionAccountInformation[]> | A thenable that resolves to a readonly array of authentication accounts. |
getSession(providerId: string, scopeListOrRequest: readonly string[] | AuthenticationWwwAuthenticateRequest, options: AuthenticationGetSessionOptions & {createIfNone: true | AuthenticationGetSessionPresentationOptions}): Thenable<AuthenticationSession>
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
| Parameter | Description |
|---|---|
| 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} | The AuthenticationGetSessionOptions to use |
| Returns | Description |
| Thenable<AuthenticationSession> | A thenable that resolves to an authentication session |
getSession(providerId: string, scopeListOrRequest: readonly string[] | AuthenticationWwwAuthenticateRequest, options: AuthenticationGetSessionOptions & {forceNewSession: true | AuthenticationGetSessionPresentationOptions}): Thenable<AuthenticationSession>
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
| Parameter | Description |
|---|---|
| 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} | The AuthenticationGetSessionOptions to use |
| Returns | Description |
| Thenable<AuthenticationSession> | A thenable that resolves to an authentication session |
getSession(providerId: string, scopeListOrRequest: readonly string[] | AuthenticationWwwAuthenticateRequest, options?: AuthenticationGetSessionOptions): Thenable<AuthenticationSession | undefined>
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
| Parameter | Description |
|---|---|
| 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 | The AuthenticationGetSessionOptions to use |
| Returns | Description |
| Thenable<AuthenticationSession | undefined> | A thenable that resolves to an authentication session or undefined if a silent flow was used and no session was found |
registerAuthenticationProvider(id: string, label: string, provider: AuthenticationProvider, options?: AuthenticationProviderOptions): Disposable
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.
| Parameter | Description |
|---|---|
| id: string | The unique identifier of the provider. |
| label: string | The human-readable name of the provider. |
| provider: AuthenticationProvider | The authentication provider provider. |
| options |
Namespace for authentication.