Skip to content

Commit b32ea51

Browse files
Dumbrisclaude
andauthored
fix(oauth): open browser window for 'auth login' command (smart-mcp-proxy#155) (smart-mcp-proxy#241)
The 'mcpproxy auth login' command was not opening browser windows for OAuth authentication. This was caused by isDeferOAuthForTray() always returning true when the daemon is running, even for manual OAuth flows. The manualOAuthKey context value was already being set in ForceOAuthFlow but isDeferOAuthForTray() never checked for it. Fix: - Add context parameter to isDeferOAuthForTray() - Check isManualOAuthFlow(ctx) first - if true, don't defer - Update caller to pass context Fixes smart-mcp-proxy#155 Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent b6e3253 commit b32ea51

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

internal/upstream/core/connection.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ func (c *Client) tryOAuthAuth(ctx context.Context) error {
13471347
// For daemon mode, defer OAuth to prevent UI blocking
13481348
// The connection will be retried by the managed client retry logic
13491349
// which will eventually complete OAuth in the background
1350-
if c.isDeferOAuthForTray() {
1350+
if c.isDeferOAuthForTray(ctx) {
13511351
c.logger.Info("⏳ Deferring OAuth to prevent UI blocking - will retry in background",
13521352
zap.String("server", c.config.Name))
13531353

@@ -1811,6 +1811,8 @@ func (c *Client) isOAuthError(err error) bool {
18111811
"OAuth authentication failed",
18121812
"oauth timeout",
18131813
"oauth error",
1814+
"no valid token available", // Transport layer token check
1815+
"authorization required", // Generic authorization needed
18141816
}
18151817

18161818
for _, oauthErr := range oauthErrors {
@@ -2541,8 +2543,11 @@ func (c *Client) forceHTTPOAuthFlow(ctx context.Context) error {
25412543
err = c.initialize(ctx)
25422544
if err != nil {
25432545
// Check if this is an OAuth authorization error that we need to handle manually
2544-
if client.IsOAuthAuthorizationRequiredError(err) {
2545-
c.logger.Info("✅ OAuth authorization requirement triggered - starting manual OAuth flow")
2546+
// Also check for transport-level OAuth errors (e.g., "no valid token available")
2547+
if client.IsOAuthAuthorizationRequiredError(err) || c.isOAuthError(err) {
2548+
c.logger.Info("✅ OAuth authorization requirement triggered - starting manual OAuth flow",
2549+
zap.String("error_type", fmt.Sprintf("%T", err)),
2550+
zap.String("error", err.Error()))
25462551

25472552
// Handle OAuth authorization manually using the example pattern
25482553
if oauthErr := c.handleOAuthAuthorization(ctx, err, oauthConfig, extraParams); oauthErr != nil {
@@ -2716,8 +2721,17 @@ func (c *Client) hasGUIEnvironment() bool {
27162721
return false
27172722
}
27182723

2719-
// isDeferOAuthForTray checks if OAuth should be deferred to prevent tray UI blocking
2720-
func (c *Client) isDeferOAuthForTray() bool {
2724+
// isDeferOAuthForTray checks if OAuth should be deferred to prevent tray UI blocking.
2725+
// It accepts a context to check if this is a manual OAuth flow triggered by 'auth login' CLI command.
2726+
func (c *Client) isDeferOAuthForTray(ctx context.Context) bool {
2727+
// CRITICAL FIX: Never defer manual OAuth flows triggered by 'auth login' CLI command
2728+
// This fixes issue #155 where 'mcpproxy auth login' doesn't open browser windows
2729+
if c.isManualOAuthFlow(ctx) {
2730+
c.logger.Info("🎯 Manual OAuth flow detected (auth login command) - NOT deferring",
2731+
zap.String("server", c.config.Name))
2732+
return false
2733+
}
2734+
27212735
// Check if we're in tray mode by looking for tray-specific environment or configuration
27222736
// During initial server startup, we should defer OAuth to prevent blocking the tray UI
27232737

0 commit comments

Comments
 (0)