Skip to content

Show the server's OAuth error when sign-in is refused - #162

Open
ammartahamohamedy wants to merge 2 commits into
prooflinedev:mainfrom
ammar-taha-dev:fix/login-oauth-error
Open

ammartahamohamedy wants to merge 2 commits into
prooflinedev:mainfrom
ammar-taha-dev:fix/login-oauth-error

Conversation

@ammartahamohamedy

Copy link
Copy Markdown

Fixes #161

Problem

The sign-in endpoints refuse with an OAuth error body (error, error_description). device::start, and device::finish for codes it has no arm for, passed the reply to Http::problem, which reads only problem-details members. So a refused scope (--scope knowledge:read, a typo, more than ten scopes) printed HTTP 400: Bad Request, and the server's explanation was lost.

Fix

  • device.rs: OAuthError gains error_description. A refused reply that parses as an OAuth error becomes the existing ApiError::Problem, with its detail set to the description (through terminal_safe), or to the error code when the description is missing or blank, and its code set to the error code. When both are blank, and for a body that isn't an OAuth error, the reply goes through Http::problem as before, so the message never says less than main.
  • Used in start for every refused request, and in finish's catch-all arm.
  • Unchanged: Http::problem, ApiError, the four codes finish handles (access_denied keeps its text), and the exit code.
before: proofline: https://proofline.sh returned HTTP 400: Bad Request
after:  proofline: https://proofline.sh returned HTTP 400: Choose one to ten supported API permissions.

Tests (written first; failed before the change)

Test What it checks
a_refused_sign_in_shows_the_servers_oauth_error (new, tests/http.rs) Against a stand-in sign-in server: a refused start (invalid_scope) and a refused finish (invalid_grant) each print the server's description and keep the OAuth code; an ESC in the description comes out escaped. A body with no description, or a blank one, prints the code instead of "Bad Request"; with a blank code too, it prints "Bad Request" as before (round 1)

Mutation checks: reading start's refusal or finish's catch-all through Http::problem again, dropping terminal_safe, printing a blank description, or printing nothing when both fields are blank each fails the test.

Checks

  • cargo fmt --check: ✅
  • cargo clippy --locked -- -D warnings: clean on the lib, the bins and the integration tests. --all-targets stops at the 2 errors main already has on Windows (src/agent/tests.rs).
  • cargo test --locked: tests/http.rs passes (41 tests), and the rest of the suite has only the same 12 Windows failures as on main (tests/mcp.rs ×7, agent_install ×2, update, local_patch, hooks on a Windows push URL), none of them in this change.
  • cargo deny check: no dependency changes.
  • Fork CI: ✅ check and windows on both rounds

Overlaps: #82 and #118 also edit device::start and device::finish (an origin check, a poll deadline); the conflicts are textual only.

Proofline review log

Fork review PR: ammar-taha-dev/proofline-cli#8. Rounds capped at 2.

Round Finding What I made of it Outcome
1 Warning: OAuthError::refusal skips a blank error_description but not a blank error, so {"error": " "} prints HTTP 400: with nothing after it, less than main's "Bad Request" Right. A compliant server always sends a code, so it's rare, but the fix shouldn't print less than before Fixed as suggested: when both fields are blank, the reply goes through Http::problem. Two test cases added first (blank code; empty code with a blank description), failing before the change
2 Edge case: a blank error with a usable description is kept as Some(" ") in ApiError::Problem.code Right in principle, but nothing in the CLI reads a sign-in refusal's code (only scan.rs reads ApiError::code()), and a blank error breaks the OAuth error format. The printed message is already correct Not changed; noted here

The prompts below are the ones that drove this implementation; the investigation, reproduction and fix scope were done before them and aren't included.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

proofline login prints "Bad Request" instead of the server's OAuth error

1 participant