Fix: verify gist scope on connect (#195 bug 4)#201
Conversation
#195) If a user authenticated gh for Git only, connect_cloud_sync accepted the token and every subsequent Gist API call returned 403 with a generic failure. Verify the 'gist' scope via the X-OAuth-Scopes header on /user before storing credentials, so the error names the exact fix: gh auth refresh -h github.com -s gist. Fine-grained PATs don't emit X-OAuth-Scopes, so their absence falls through (no upfront verification possible — API-level errors still surface later). Added 4 tests covering scope present, scope missing, header absent (fine-grained PAT), and 401. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Second-pass review (independent agent)Verdict: good to merge as-is. No high-confidence issues flagged. Header-absent fall-through is correct. Classic OAuth/PAT tokens always emit Error message reaches the user verbatim. The call site maps No security concerns. Token flows via existing Test coverage sufficient. 4 tests cover scope-present, scope-missing (asserts both message fragments), header-absent (fine-grained PAT), and 401. No gaps worth closing. Style consistent. Minor note (not blocking)Both service calls in |
Summary
Closes the last remaining bug from #195:
connect_cloud_syncaccepted any tokengh auth tokenreturned, so users without thegistscope got a generic 403 on first push instead of a helpful message at connect time.Now verifies the
gistscope via theX-OAuth-Scopesresponse header onGET /userbefore storing credentials. If the scope is absent, the error names the exact remediation: `gh auth refresh -h github.com -s gist`.Fine-grained PATs don't emit
X-OAuth-Scopes, so in that case we fall through (the API-level error will still surface later on the actual gist call).What changed
services/gist_sync.rs— addedverify_gist_scope(token)+ 4 tests (scope present / scope missing / header absent / 401).commands/cloud_sync.rs— callverify_gist_scopeinconnect_cloud_syncafterget_authenticated_user, beforefind_or_create_gist.Cargo.lock— refresh to matchCargo.tomlversion (was stale at 3.8.1, now 3.8.3).Test plan
Bugs 1–3 from #195 already landed
Once this merges, #195 can close.
🤖 Generated with Claude Code