Authentication Providers
Relevant source files
The following files were used as context for generating this wiki page:
Authentication Providers are a core extensibility feature in Visual Studio Code that allows extensions to provide authentication services for various platforms, such as GitHub and Microsoft accounts. This system enables other extensions to request and use authentication tokens securely, facilitating integration with external services.
Extensions can declare themselves as Authentication Providers through the contributes.authentication section in their package.json manifest. VS Code includes built-in providers for common services, and this mechanism allows for a decoupled architecture where consumer extensions do not need to implement authentication flows themselves.
Contribution Point
The primary way an extension registers as an authentication provider is through the authentication contribution point in its package.json file. This is an array of objects, where each object defines a distinct authentication provider.
This diagram illustrates the basic registration flow for an authentication provider.
Provider Properties
The following properties are used to define an authentication provider:
| Property | Type | Description | Example |
|---|---|---|---|
label | string | A user-facing name for the authentication provider. | "GitHub" |
id | string | A unique identifier for the provider. | "github" |
authorizationServerGlobs | string[] | An optional array of glob patterns for matching authorization server URLs associated with this provider. | ["https://github.com/login/oauth"] |
Sources: extensions/github-authentication/package.json:30-42, extensions/microsoft-authentication/package.json:29-35
Core Authentication Providers
VS Code ships with two primary built-in authentication provider extensions: github-authentication and microsoft-authentication.
GitHub Authentication
The github-authentication extension provides authentication for both GitHub.com and GitHub Enterprise Server.
Sources: extensions/github-authentication/package.json
Contributed Providers
| ID | Label | Authorization Server Globs |
|---|---|---|
github | GitHub | ["https://github.com/login/oauth"] |
github-enterprise | GitHub Enterprise Server | ["*"] |
Sources: extensions/github-authentication/package.json:30-42
Configuration
This provider can be configured through user settings:
| Setting | Type | Default | Description |
|---|---|---|---|
github-enterprise.uri | string | null | The URI for the GitHub Enterprise server. Must match the pattern `^(?:$ |
github-authentication.useElectronFetch | boolean | true | A setting to control the use of Electron's fetch API. |
Sources: extensions/github-authentication/package.json:46-57
The following JSON snippet shows how these providers are defined:
"contributes": {
"authentication": [
{
"label": "GitHub",
"id": "github",
"authorizationServerGlobs": [
"https://github.com/login/oauth"
]
},
{
"label": "GitHub Enterprise Server",
"id": "github-enterprise",
"authorizationServerGlobs": [
"*"
]
}
]
}
Sources: extensions/github-authentication/package.json:29-43
Microsoft Authentication
The microsoft-authentication extension provides authentication for Microsoft accounts, including support for sovereign clouds.
Sources: extensions/microsoft-authentication/package.json
Contributed Providers
| ID | Label | Authorization Server Globs |
|---|---|---|
microsoft | Microsoft | ["https://login.microsoftonline.com/*/v2.0"] |
microsoft-sovereign-cloud | Microsoft Sovereign Cloud | Not specified. |
Sources: extensions/microsoft-authentication/package.json:29-38
Configuration
This provider offers extensive configuration, especially for connecting to different sovereign cloud environments.
| Setting | Type | Default | Description |
|---|---|---|---|
microsoft-sovereign-cloud.environment | string | null | Specifies the sovereign cloud environment. Can be ChinaCloud, USGovernment, or custom. |
microsoft-sovereign-cloud.customEnvironment | object | null | An object to define a custom cloud environment when environment is set to custom. Requires properties like name, portalUrl, activeDirectoryEndpointUrl, etc. |
microsoft-authentication.implementation | string | "msal" | Allows switching the underlying implementation between msal and classic. |
Sources: extensions/microsoft-authentication/package.json:43-107
API Proposals
The authentication provider extensions make use of several API proposals, indicating that the authentication framework is an evolving part of the VS Code API. These proposals enable more advanced authentication scenarios.
github-authenticationproposals:authIssuers,authProviderSpecificmicrosoft-authenticationproposals:idToken,nativeWindowHandle,authIssuers,authenticationChallenges
This suggests a rich set of capabilities being developed for authentication.
Sources: extensions/github-authentication/package.json:20-23, extensions/microsoft-authentication/package.json:20-25
Consuming Authentication
Other extensions can consume the services provided by these authentication providers. The github extension, for example, provides a setting to control its use of the authentication provider for Git operations.
This diagram shows the interaction between a consumer extension, the VS Code API, and an authentication provider.
This flow is a conceptual representation based on the provider/consumer model.
The github extension includes a configuration setting github.gitAuthentication which defaults to true, enabling the use of the GitHub authentication provider for Git network operations.
Sources: extensions/github/package.json:173-178
Workspace Security
Authentication providers are designed to work within VS Code's security model, including support for untrusted workspaces.
github-authentication: Haslimitedsupport in untrusted workspaces, with thegithub-enterprise.uriconfiguration being restricted.microsoft-authentication: Has full (true) support in untrusted workspaces.markdown-language-features: Also demonstrateslimitedsupport, restrictingmarkdown.styles. This shows a common pattern for extensions handling sensitive configurations.
This capability ensures that authentication operations are handled safely, preventing potentially malicious workspace configurations from hijacking credentials.
Sources: extensions/github-authentication/package.json:24-30, extensions/microsoft-authentication/package.json:26-30, extensions/markdown-language-features/package.json:20-26