feat(login): log in by pasting browser-exported cookies (--cookies)#31
Open
SipengXie2024 wants to merge 1 commit into
Open
feat(login): log in by pasting browser-exported cookies (--cookies)#31SipengXie2024 wants to merge 1 commit into
SipengXie2024 wants to merge 1 commit into
Conversation
Headless servers (and machines where the site blocks DevTools/QR login)
have no way to feed cookies to boss-cli except the BOSS_COOKIES env var,
which only accepts a 'k=v; k=v' string. Add a first-class --cookies option
to 'boss login' that accepts a Cookie-Editor/EditThisCookie JSON export, a
plain {name: value} object, or a Cookie header string — from an inline
value, a file, stdin ('-'), or $EDITOR (no value).
Parsing is factored into auth.parse_cookie_blob / credential_from_cookie_blob
and reused by load_from_env, so BOSS_COOKIES now accepts JSON exports too.
The command validates required cookies (clear error naming the missing
HttpOnly ones) and verifies against the live API before saving.
Tests: parse_cookie_blob across all formats, JSON-export env loading, and
CLI flows (success, stdin, missing-cookie, unparseable, verify-failure).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On a headless server (or any machine where the browser lives elsewhere), there's no practical way to get cookies into boss-cli:
--qrcode) is unreliable: the terminal half-block QR is often unscannable, and even when it scans, the App opens the encodedqrcode/scan?uuid=…URL as a plain webpage (shows{"msg":"timeout"}) instead of treating it as a login intent, so it never completes. The real web login QR is generated by a lazy-loaded chunk and uses a different, App-recognized format.BOSS_COOKIESis the only manual path, but it only accepts ak=v; k=vstring — awkward to assemble by hand, and it silently drops anything that isn't that exact shape.Meanwhile the browser on your own laptop logs in fine. The missing piece is a clean way to carry those cookies over.
What this adds
A first-class
--cookiesoption onboss loginthat accepts cookies pasted straight from a browser export:It accepts three formats so users can paste whatever their browser hands them:
{"url":…, "cookies":[{"name","value"},…]}or a bare[{…}]array{"name": "value"}JSON object"key1=val1; key2=val2"Cookie header stringParsing is factored into
auth.parse_cookie_blob/credential_from_cookie_bloband reused byload_from_env, soBOSS_COOKIESnow accepts JSON exports too (previously string-only). The command validates required cookies — naming the missing HttpOnly ones (__zp_stoken__,zp_at) so users knowdocument.cookiewon't cut it — and verifies against the live API before reporting success.The Cookie-Editor route also sidesteps sites that block DevTools: the extension reads HttpOnly cookies via the browser cookie API, no F12 needed.
Tests
parse_cookie_blobacross all formats (Cookie-Editor export, bare array, plain object, header string,=-in-value, empty/malformed)load_from_envwith a JSON export--cookies: success, stdin, missing-required-cookie, unparseable, and verify-failure-clears-credentialpytest -m "not smoke"→ 124 passed.ruff checkclean. Verified end to end against the live API with a real Cookie-Editor export on a headless box.Docs
README updated: quickstart examples (EN + 中文), an Authentication "Headless / remote servers" section, and a troubleshooting entry.