Datalayer VS Code Extension - v0.0.9
    Preparing search index...

    Manages OAuth authentication flows adapted for VS Code.

    Unlike browser-based OAuth flows, VS Code requires:

    • Opening system browser instead of popup window
    • Custom URI handler for OAuth callbacks
    • State-based CSRF protection
    • Timeout handling for abandoned flows
    const oauthManager = new OAuthFlowManager(context, logger);
    await oauthManager.initialize();

    try {
    const result = await oauthManager.startOAuthFlow('github');
    console.log('Authenticated with token:', result.token);
    } catch (error) {
    console.error('OAuth flow failed:', error);
    }

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    extensionId: string

    Extension identifier used for URI handler registration

    logger: ILogger

    Logger instance for this service

    name: string

    Service name for logging

    pendingFlows: Map<string, OAuthPendingFlow> = ...

    Map of pending OAuth flows indexed by state parameter. State provides CSRF protection and flow tracking.

    uriHandlerDisposable?: Disposable

    Disposable for URI handler

    FLOW_TIMEOUT_MS: number = ...

    Timeout duration for OAuth flows (5 minutes)

    Accessors

    Methods

    • Handle OAuth callback from URI handler.

      This method:

      1. Extracts state and token from callback URI
      2. Validates state parameter (CSRF protection)
      3. Resolves the pending OAuth flow promise

      Parameters

      • uri: Uri

        Callback URI from OAuth provider

      Returns Promise<void>

    • Start an OAuth authentication flow.

      This method:

      1. Generates a secure random state parameter (CSRF protection)
      2. Gets OAuth authorization URL from the platform API
      3. Opens system browser to the authorization URL
      4. Waits for OAuth callback via URI handler
      5. Returns the authentication token

      Parameters

      Returns Promise<OAuthResult>

      Promise that resolves with authentication token

      Error if flow times out, is cancelled, or fails

      try {
      const result = await oauthManager.startOAuthFlow('github');
      console.log('Token:', result.token);
      } catch (error) {
      if (error.message.includes('timeout')) {
      console.log('User did not complete authentication in time');
      }
      }
    • Validate OAuth state parameter and consume the pending flow.

      This method provides CSRF protection by:

      • Checking if state exists in pending flows
      • Verifying the flow hasn't expired (TTL check)
      • Removing state after validation (one-time use)

      Parameters

      • state: string

        State parameter from OAuth callback

      Returns OAuthPendingFlow

      Pending flow if valid, null otherwise