Skip to content

fix(management): support external base url for webui oauth callbacks#2605

Open
cikichen wants to merge 1 commit intorouter-for-me:devfrom
cikichen:fix/external-base-url-oauth-callbacks
Open

fix(management): support external base url for webui oauth callbacks#2605
cikichen wants to merge 1 commit intorouter-for-me:devfrom
cikichen:fix/external-base-url-oauth-callbacks

Conversation

@cikichen
Copy link
Copy Markdown
Contributor

@cikichen cikichen commented Apr 8, 2026

Summary

  • add remote-management.external-base-url so webui oauth callbacks can use a configured public base URL
  • route Codex, Claude, Gemini CLI, and Antigravity webui oauth flows through provider-specific external callback paths when configured
  • add config and management handler tests to cover external callback resolution and preserve localhost fallback behavior

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

This pull request targeted main.

The base branch has been automatically changed to dev.

@github-actions github-actions bot changed the base branch from main to dev April 8, 2026 06:07
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds an "external-base-url" configuration to allow remote management clients to use public callback URLs instead of local forwarders for OAuth authentication across multiple providers. While the logic is implemented for several services, the PR is currently incomplete as it references a missing "ExchangeCodeForTokensWithRedirect" method for the Codex provider, which will prevent the code from compiling. Additionally, the feedback highlights an architectural inconsistency in how the Codex redirect URI is managed compared to other providers, recommending a more standardized approach within the authentication packages to eliminate manual URL manipulation.

log.Debug("Authorization code received, exchanging for tokens...")
// Exchange code for tokens using internal auth service
bundle, errExchange := openaiAuth.ExchangeCodeForTokens(ctx, code, pkceCodes)
bundle, errExchange := openaiAuth.ExchangeCodeForTokensWithRedirect(ctx, code, redirectURI, pkceCodes)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The method openaiAuth.ExchangeCodeForTokensWithRedirect is called here, but its definition is missing from the pull request. It appears that the necessary changes to internal/auth/codex/codex_auth.go (similar to those made for claude in internal/auth/claude/anthropic_auth.go) were not included in the patch set. This will result in a compilation error.

} else if ok {
redirectURI = externalCallbackURL
useLocalForwarder = false
updatedURL, errReplace := replaceURLQueryValue(authURL, "redirect_uri", redirectURI)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There is an inconsistency in how the redirect_uri is updated for the codex provider compared to claude. While claude uses a new GenerateAuthURLWithRedirect method (added in this PR), codex relies on a manual query string replacement via replaceURLQueryValue. For better maintainability and consistency, the codex package should be updated with a similar WithRedirect method for URL generation, avoiding the need for manual URL manipulation in the handler.

Comment on lines +247 to +256
func replaceURLQueryValue(rawURL, key, value string) (string, error) {
parsed, err := url.Parse(strings.TrimSpace(rawURL))
if err != nil {
return "", fmt.Errorf("parse url: %w", err)
}
query := parsed.Query()
query.Set(key, value)
parsed.RawQuery = query.Encode()
return parsed.String(), nil
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The replaceURLQueryValue function is only used as a workaround for the codex provider's API inconsistency. If the codex package is updated to support a redirect URI during URL generation (as suggested in the other comment), this utility function becomes unnecessary and should be removed to keep the codebase clean.

Copy link
Copy Markdown
Collaborator

@luispater luispater left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

  • Adds remote-management.external-base-url to support externally reachable OAuth callback URLs for WebUI flows.
  • Routes Codex/Claude/Gemini CLI/Antigravity WebUI OAuth through provider-specific external callback paths when configured, and skips localhost callback forwarders in that case.
  • Adds tests to cover external callback URL resolution and preserve localhost fallback behavior.

Key findings

  • Blocking: None.
  • Non-blocking:
    • Consider validating external-base-url scheme to http/https only to prevent accidental misconfiguration.
    • Tests currently rely on time.Sleep(600ms); polling with a timeout could reduce flakiness on slow runners.

Test plan

  • go test ./internal/api/handlers/management ./internal/config ./internal/auth/claude

This is an automated Codex review result and still requires manual verification by a human reviewer.

@luispater luispater added the codex label Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants