google-gemini / google-gemini/gemini-cli

OAuth login fails on headless VPS: "Premature close" fetching oauth2.googleapis.com/token (CLI HTTP stack only)

Open
#28,440 4 comments 0 reactions 0 assignees View on GitHub
area/security kind/bug priority/p1 status/bot-triaged
Dominant language
TypeScript
Stars
107k
Forks
14.6k
Avg merge
2d 3h
Merged PRs (30d)
45

Description

**Environment:** gemini-cli v0.51.0, Node v22.23.0, Ubuntu 24.04 VPS (Contabo, no proxy), headless via SSH/tmux.

**Bug:** `gemini` login (both browser fallback and NO_BROWSER=true user-code flow) always fails at token exchange with:

```
Invalid response body while trying to fetch https://oauth2.googleapis.com/token: Premature close
```

(FatalAuthenticationError, exitCode 41).

**Evidence it's the bundled HTTP stack, not the network:** on the SAME machine/user, the token endpoint works via curl (HTTP 400 on probe), Python urllib (full manual PKCE exchange succeeded — got access+refresh token), and raw Node fetch (HTTP 400 on probe). Only the CLI bundle fails.

**Tried:** NODE_OPTIONS=--dns-result-order=ipv4first, clean ~/.gemini, fresh flows — same result. Manually written oauth_creds.json is ignored (CLI re-validates via same failing stack and loops back to auth).

**Expected:** token exchange succeeds, or CLI honors valid cached oauth_creds.json.

Contributor guide

Open the contributing guide

Research direction

Reproduce the OAuth token exchange on the headless VPS and compare the CLI's bundled HTTP stack with curl, Python urllib, and raw Node fetch. Trace the CLI authentication request path; done means browser and NO_BROWSER=true flows complete successfully, or a valid cached oauth_creds.json is honored without re-authentication.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
authentication, cli, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.