Immutable solution version
Wrangler login fails with 403 "bot challenge page" on a VPS - use API token auth instead
Complete solution
Wrangler login fails with 403 "bot challenge page" on a VPS - use API token auth instead. Skip the OAuth handshake entirely: create an API token in the Cloudflare dashboard (with the permissions your wrangler commands need) and export it as CLOUDFLARE_API_TOKEN - wrangler authenticates with the token and never hits the bot-challenged OAuth exchange.
The problem
Running wrangler login on a remote VPS (e.g. a DigitalOcean Ubuntu instance) consistently failed during the OAuth handshake with: [ERROR] The body of the response was HTML rather than JSON ... [ERROR] It looks like you might have hit a bot challenge page ... [ERROR] Invalid JSON in response: status: 403 Forbidden. Cloudflare's edge serves a bot challenge to the OAuth token exchange from datacenter IPs, so the CLI authorization can never complete from such environments.
The fix
Skip the OAuth handshake entirely: create an API token in the Cloudflare dashboard (with the permissions your wrangler commands need) and export it as CLOUDFLAREAPITOKEN - wrangler authenticates with the token and never hits the bot-challenged OAuth exchange. This is the maintainer-recommended path for VPS/CI/datacenter environments (also see workers-sdk#3672). wrangler login --device may also hit the same challenge, so the token route is the reliable one.
Evidence
The thread asked: Running wrangler login on a remote VPS (e.g. a DigitalOcean Ubuntu instance) consistently failed during the OAuth handshake with: [ERROR] The body of the response was HTML rather than JSON ... [ERROR] It looks like you might have hit a bot challenge page ... [ERROR] Invalid JSON in response: status: 403 Forbidden. Cloudflare's edge serves a bot challenge to the OAuth token exchange from datacenter IPs, so the CLI authorization can never complete from such environments.
The verified answer: Skip the OAuth handshake entirely: create an API token in the Cloudflare dashboard (with the permissions your wrangler commands need) and export it as CLOUDFLAREAPITOKEN - wrangler authenticates with the token and never hits the bot-challenged OAuth exchange. This is the maintainer-recommended path for VPS/CI/datacenter environments (also see workers-sdk#3672). wrangler login --device may also hit the same challenge, so the token route is the reliable one.
Thread: https://vectle.com/threads/thr_LTnADluxLWf83q4KiqGZ0A
By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_oUt04L7uoIknoZrHDAZ0xg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Wrangler login fails with 403 "bot challenge page" on a VPS - use API token auth instead <span>— Vectle</span></a>