-
Notifications
You must be signed in to change notification settings - Fork 622
CLI emdash login fails against remote instances #54
Description
The CLI emdash login command fails against remote EmDash instances due to two distinct issues.
Issue 1: Response envelope mismatch (device flow)
The server's OAuth device flow endpoints wrap responses in {"data": {...}}, but the CLI expects the fields at the top level.
Affected endpoints:
POST /_emdash/api/oauth/device/code— returns{"data": {"device_code": ..., "verification_uri": ..., "user_code": ...}}POST /_emdash/api/oauth/device/token— returns{"data": {"access_token": ..., "expires_in": ...}}
Symptoms:
verification_urianduser_codedisplay asundefinedduring login- After authorizing in the browser, login fails with
ERROR Invalid time value(becauseexpires_inisundefined)
These were verified independently — patching only the device code response allowed login to proceed to the token exchange, which then failed with the same wrapping issue.
Fix: Unwrap the .data property when parsing these responses in the CLI
Issue 2: Device flow token lacks admin scope
Separately from the envelope issue, the CLI's device code request does not include a scope parameter:
{"client_id": "emdash-cli"}The resulting token is issued without admin scope, so all subsequent CLI commands fail with INSUFFICIENT_SCOPE / Token lacks required scope: admin — even when the authorizing user is an admin.
This was verified by patching issue 1, completing a successful login, then running emdash whoami which returned a 403.
Fix: Adding "scope": "admin" to the device code request resolved this for me.
Steps to reproduce
- Deploy an EmDash site to Cloudflare (with or without Cloudflare Access)
- Run
npx emdash login --url https://<your-site> - Observe
undefinedfor the verification URL and user code (issue 1) - If issue 1 is patched locally, complete the browser authorization
- Observe
ERROR Invalid time value(issue 1, token endpoint) - If both envelope issues are patched, complete login and run
npx emdash whoami - Observe
Failed to fetch user info: 403/INSUFFICIENT_SCOPE(issue 2)
Environment
- EmDash v0.1.0 (both server and CLI)
- Deployed to Cloudflare Workers with D1
- Tested with and without Cloudflare Access (Access auth itself works correctly; the issues are in the subsequent EmDash device flow)
Workaround
I patchednode_modules/emdash/dist/cli/index.mjs with the unwrap fix and scope addition described above. Patches need to be re-applied after any npm install.