Skip to main content
The Authentication API allows extensions to request authentication sessions from authentication providers. This enables extensions to securely authenticate users and access protected resources on their behalf.

Overview

VS Code’s Authentication API supports:
  • Multiple authentication providers (GitHub, Microsoft, custom providers)
  • OAuth and OpenID Connect flows
  • Secure token management
  • Account switching and multiple sessions
  • Silent authentication flows

Authentication Namespace

The vscode.authentication namespace provides methods for working with authentication:

Core Interfaces

AuthenticationSession

Represents an authentication session with an access token and associated account information:

AuthenticationSessionAccountInformation

Information about the account associated with a session:

Getting Authentication Sessions

Use authentication.getSession() to request an authentication session from a provider.

Basic Usage

Authentication Options

Whether login should be performed if there is no matching session. If true, a modal dialog will be shown. If false, a numbered badge will be shown on the accounts menu.
Whether to reauthenticate even if there is already a session available. Useful for scenarios where the token needs to be re-minted.
Whether to show the indication to sign in. If true, no UI will be shown.
Whether to clear the existing session preference. Useful when you want the user to be able to choose a different account.

Using Authentication in Extensions

Example: GitHub API Access

Example: Microsoft Graph API

Handling Session Changes

Listen to session changes to update your extension’s state:

Creating Custom Authentication Providers

Extensions can register custom authentication providers to support custom OAuth flows or enterprise authentication systems.

AuthenticationProvider Interface

Registering a Provider

Authentication Scopes

Different providers support different scopes:

GitHub Scopes

Common GitHub scopes:
  • repo - Full control of private repositories
  • user - Read/write access to profile info
  • user:email - Access to email addresses
  • read:user - Read access to profile info
  • gist - Create gists
  • workflow - Update GitHub Actions workflows

Microsoft Scopes

Common Microsoft Graph scopes:
  • User.Read - Read user profile
  • User.ReadWrite - Read and write user profile
  • Mail.Read - Read user mail
  • Mail.Send - Send mail as the user
  • Files.Read - Read user files

Best Practices

Only request the scopes your extension actually needs. Users are more likely to grant narrower permissions.
Users may deny authentication or close the dialog. Always check for undefined sessions.
When checking for existing sessions in the background, use silent mode to avoid disturbing the user.
Cache the session in your extension to avoid repeated authentication calls.

Security Considerations

Always follow these security best practices when working with authentication:
  1. Never log access tokens - Access tokens are sensitive credentials
  2. Use HTTPS for API calls - Always use secure connections when using tokens
  3. Validate token responses - Check API responses for authentication errors
  4. Handle token expiration - Some tokens expire and need refresh
  5. Clear tokens on sign out - Remove cached tokens when users sign out
  6. Respect token scopes - Don’t attempt operations outside granted scopes

Commands API

Register commands for authentication actions

Workspace API

Store authentication state in workspace settings