fix: use vscode.env.asExternalUri() for Claude Code OAuth in remote environments#10571
Closed
roomote-v0[bot] wants to merge 1 commit intomainfrom
Closed
fix: use vscode.env.asExternalUri() for Claude Code OAuth in remote environments#10571roomote-v0[bot] wants to merge 1 commit intomainfrom
roomote-v0[bot] wants to merge 1 commit intomainfrom
Conversation
…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
Contributor
Author
Review complete. No issues found. The implementation correctly uses Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.