fix: use vscode.env.asExternalUri() for Claude Code OAuth in remote environments #10571
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
asExternalUri()returns the original URI unchangedhttps://<codespace-name>-54545.app.github.dev/callbackChanges
Modified
startAuthorizationFlow()to:vscode.envandvscode.Uri.parseas parametersasExternalUri()to transform the localhost callback URLUpdated
buildAuthorizationUrl()to accept an optional customredirectUriparameterUpdated
exchangeCodeForTokens()to accept an optional customredirectUriparameter (must match the one used in authorization)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.startAuthorizationFlow()inClaudeCodeOAuthManagernow usesvscode.env.asExternalUri()to convert localhost URIs for remote environments.https://<codespace-name>-54545.app.github.dev/callback.startAuthorizationFlow()acceptsvscode.envandvscode.Uri.parseas parameters.buildAuthorizationUrl()andexchangeCodeForTokens()updated to accept optionalredirectUri.oauth.spec.tsfor custom redirect URI handling.This description was created by
for b441e44. You can customize this summary. It will automatically update as commits are pushed.