Skip to content

gmail watch serve ignores --client flag for push handler API calls #410

@chrysb

Description

@chrysb

Bug

When running gmail watch serve --client personal --account user@gmail.com, the --client flag is correctly parsed and used to resolve the account in requireAccount(flags), but it is not propagated to the context used by the push handler. When a push notification arrives and the server calls newGmailService(ctx, account), the client override is missing from the context, causing authclient.ResolveClient() to fall back to "default".

This means multi-client setups (e.g., a company account on default and a personal account on personal) always fail for non-default clients:

watch: handle push failed: gmail options: token source: auth required for gmail user@gmail.com (client default)

Root cause

In root.go:150, the --client flag is injected into the context:

ctx = authclient.WithClient(ctx, cli.Client)

However, gmail_watch_server.go creates new contexts for incoming HTTP requests (via r.Context()), which don't inherit the root context's client override. The gmailWatchServer struct has no client field to carry this through.

Suggested fix

Store the client name in gmailWatchServerConfig and wrap each request context with authclient.WithClient() before calling newService:

// In gmail_watch_server.go, handlePush or wherever ctx is created from the request:
ctx = authclient.WithClient(r.Context(), s.cfg.Client)

Repro

# Register two accounts with different clients
gog auth add chrys@company.co --client default --services gmail
gog auth add user@gmail.com --client personal --services gmail

# Start watch serve for the personal account
gog gmail watch serve --client personal --account user@gmail.com --port 8802

# Send a push notification → fails with "auth required ... (client default)"

Version

gog v0.11.0 (91c4c15)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions