Architecture: How to implement OAuth authentication for a VSCode extension...

Documentation for Sessions

🏗️ Architecture: How to implement OAuth authentication for a VSCode extension...

Date: 2026-02-05
Time: 04:38:46 UTC
Session: editor2-89.6
Agent: backend
Confidence: 95%
Status: ✅ Documented


📋 Decision Context

Question:

How to implement OAuth authentication for a VSCode extension that connects to a web backend?

Task: VSCode Extension OAuth Authentication Flow


🎯 Decision Made

Chosen:

Open browser with localhost callback server

Options Considered:

  1. Redirect to browser with custom protocol handler (mcp://)
  2. Open browser with localhost callback server
  3. Use VSCode's built-in authentication provider API
  4. Manual token entry only

💭 Reasoning

VSCode extensions can start a local HTTP server to receive OAuth callbacks. The flow: 1) Extension generates random state for CSRF protection, 2) Finds available port and starts temp HTTP server, 3) Opens browser to backend /auth/mcp/authorize with redirect_uri=http://localhost:{port}/auth/callback, 4) Backend redirects to frontend auth page, 5) User authorizes, 6) Frontend calls backend POST /auth/mcp/callback, 7) Backend returns token, 8) Frontend redirects to extension's localhost server with token, 9) Extension saves token and closes server. This approach works cross-platform and doesn't require custom protocol handlers.


📁 Files Involved


🔗 Related


Auto-generated by MCP Smart Consolidation