fix(core): dynamically resolve Cloud Workstations proxy redirect URI for OAuth flows - #28688
Conversation
|
📊 PR Size: size/L
|
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses authentication failures encountered when running OAuth 2.0 flows within Google Cloud Workstations. By replacing static 'localhost' redirect URIs with a dynamically resolved URL that accounts for the workstation's proxy gateway, the changes enable seamless authentication for remote development environments. The solution is applied selectively to ensure that sensitive flows, such as Google Code Assist, remain unaffected by these changes. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds support for Google Cloud Workstations by dynamically resolving the OAuth redirect URI to the workstation's proxy URL when running in a workstation environment. It introduces a helper function getRedirectUri and updates the OAuth provider and flow utilities to use it, accompanied by corresponding unit tests. The reviewer pointed out a critical edge case where an explicitly configured localhost or 127.0.0.1 redirect URI would bypass the workstation proxy resolution, leading to connection failures in the browser, and provided a robust code suggestion to handle this scenario.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a helper function getRedirectUri to handle OAuth redirect URIs when running inside Google Cloud Workstations, mapping local addresses to the Cloud Workstations proxy URL, and adds corresponding unit tests. The review feedback suggests improving getRedirectUri by mutating the URL object directly to preserve query parameters, hashes, and other URL components, as well as adding support for IPv6 loopback addresses.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds support for Google Cloud Workstations proxy redirect URIs during OAuth flows by introducing a getRedirectUri helper in packages/core/src/utils/oauth-flow.ts and updating MCPOAuthProvider and the OAuth utilities to use it. It also adds comprehensive tests and reformats some skill documentation files. The review feedback correctly identifies a critical issue where prioritizing the configured port over the active redirectPort in getRedirectUri can cause the workstation proxy to forward callbacks to an inactive port. The reviewer suggests always using the active redirectPort and updating the corresponding unit tests to expect this port.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for Google Cloud Workstations proxy redirect URIs during the OAuth flow. It adds a getRedirectUri helper function in oauth-flow.ts that automatically detects if the application is running inside Google Cloud Workstations and rewrites local loopback redirect URIs (localhost, 127.0.0.1, [::1]) to use the workstation's proxy URL format. The MCPOAuthProvider and OAuth flow utilities are updated to use this helper. Extensive unit tests are added to verify the URI conversion logic, and vi.unstubAllEnvs() is integrated into the test cleanup to prevent environment variable leakage. Additionally, minor formatting updates are applied to some built-in skill markdown files. I have no feedback to provide as there are no review comments.
|
@DavidAPierce This one is ready to review/merge, all comments and feedback has been addressed |
|
Summary
This PR resolves an issue where OAuth 2.0 authentication flows inside Google
Cloud Workstations VMs fail because they are statically configured to redirect
back to
localhost(e.g.,http://localhost:\${redirectPort}/oauth/callback).Since the developer's web browser runs locally on their physical laptop, the
browser cannot navigate the
localhostloopback back to the remote VM context,leading to connection refusal.
This fix dynamically detects the Google Cloud Workstations environment context
(via
GOOGLE_CLOUD_WORKSTATIONSandWEB_HOSTenvironment variables) andconstructs the correct authenticated reverse proxy callback URL format
(
https://\${redirectPort}-\${process.env['WEB_HOST']}/oauth/callback), routingthe authentication response securely back to the workstation VM.
Details
getRedirectUriinpackages/core/src/utils/oauth-flow.tsto encapsulate the environmentdetection and dynamic URL resolution logic.
(
packages/core/src/mcp/oauth-provider.tsandpackages/core/src/utils/oauth-flow.ts) where third-party IDPs (such asAuth0 configured by customers like CME Group) are used.
packages/core/src/code_assist/oauth2.ts) wasintentionally left unchanged. Google's official "Desktop App" client ID
strictly prohibits non-loopback redirect URIs and throws
redirect_uri_mismatchif dynamic proxy domains are supplied. The CodeAssist flow continues to safely utilize the manual code copy-paste
out-of-band (
authWithUserCode) flow in headless or remote VM environments.REDIRECT_PATHinoauth-provider.ts) to avoid compilation issues.Related Issues
Fixes #23711
How to Validate
Automated Unit Tests
Run the newly added unit tests that simulate and verify the Google Cloud
Workstations proxy callback resolution:
Manual Verification
8090).https://8090-<WEB_HOST>/oauth/callback) to your laptop browser.Workstation Gateway proxy, routing the request down to the workstation VM to
complete the login seamlessly.
Pre-Merge Checklist