Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jan 9, 2026

This PR attempts to address Issue #10531. Feedback and guidance are welcome.

Problem

The OAuth flow uses a hardcoded localhost redirect URI (http://localhost:54545/callback) which breaks authentication in remote environments like GitHub Codespaces because the browser cannot reach localhost.

Solution

This PR implements the recommended vscode.env.asExternalUri() API solution to dynamically convert the localhost redirect URI to an externally accessible URL in remote environments.

How it works

  • In local VS Code: asExternalUri() returns the original URI unchanged
  • In GitHub Codespaces: Returns a forwarded URL like https://<codespace-name>-54545.app.github.dev/callback
  • In other remote environments: Returns the appropriate externally-accessible URL

Changes

  1. Modified startAuthorizationFlow() to:

    • Accept vscode.env and vscode.Uri.parse as parameters
    • Use asExternalUri() to transform the localhost callback URL
    • Store the resolved redirect URI for use in token exchange
  2. Updated buildAuthorizationUrl() to accept an optional custom redirectUri parameter

  3. Updated exchangeCodeForTokens() to accept an optional custom redirectUri parameter (must match the one used in authorization)

  4. Added tests for custom redirect URI functionality

This approach is backwards compatible - local users will not notice any change, while remote users will have a working OAuth flow.

Fixes #10531


Important

The PR updates OAuth flow to use vscode.env.asExternalUri() for remote environments, ensuring compatibility with platforms like GitHub Codespaces.

  • Behavior:
    • startAuthorizationFlow() in ClaudeCodeOAuthManager now uses vscode.env.asExternalUri() to convert localhost URIs for remote environments.
    • Supports GitHub Codespaces by converting to URLs like https://<codespace-name>-54545.app.github.dev/callback.
    • Backward compatible for local VS Code users.
  • Functions:
    • startAuthorizationFlow() accepts vscode.env and vscode.Uri.parse as parameters.
    • buildAuthorizationUrl() and exchangeCodeForTokens() updated to accept optional redirectUri.
  • Tests:
    • Added tests in oauth.spec.ts for custom redirect URI handling.

This description was created by Ellipsis for b441e44. You can customize this summary. It will automatically update as commits are pushed.

…nvironments

Fixes authentication in remote environments (GitHub Codespaces, etc.) by using
vscode.env.asExternalUri() to dynamically convert the localhost redirect URI
to an externally accessible URL.

Changes:
- Modified startAuthorizationFlow() to accept vscode.env and vscode.Uri.parse
- Uses asExternalUri() to transform localhost:54545/callback to forwarded URL
- Updated buildAuthorizationUrl() and exchangeCodeForTokens() to accept custom redirectUri
- Added tests for custom redirect URI functionality

Fixes #10531
@roomote
Copy link
Contributor Author

roomote bot commented Jan 9, 2026

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The implementation correctly uses vscode.env.asExternalUri() to support remote environments (GitHub Codespaces, etc.) for Claude Code OAuth authentication.

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

[BUG] Claude Code Sign In broken on remote environments -> hardcoded localhost redirectUri

3 participants