Skip to content

connect/auth: honor --org before the zero-orgs shortcut#182

Open
jetm wants to merge 1 commit into
mainfrom
fix/connect-login-org-hint
Open

connect/auth: honor --org before the zero-orgs shortcut#182
jetm wants to merge 1 commit into
mainfrom
fix/connect-login-org-hint

Conversation

@jetm

@jetm jetm commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Problem

avocado connect auth login --org <id> can report a successful login while silently ignoring the org the user asked for.

When the auth server's org list for the login code comes back empty, pick_org hits its orgs.is_empty() shortcut and returns OrgPick::None before it ever looks at the --org hint. The code exchange then runs with no organization_id, minting an unscoped token, and the CLI prints Logged in … / Created new profile. The user ends up with an "all orgs" profile scoped to nothing, for an org they explicitly named, with no error to signal it.

This is a real footgun: a --profile X --org <id> login "succeeds", but avocado connect auth status --profile X then reports Token scope: unscoped (all orgs), and every subsequent org-scoped call fails confusingly. It cost meaningful debugging time chasing a token-scope problem that was actually a silent no-op at login.

Fix

Resolve an explicit --org hint before the zero-orgs shortcut. A hint that matches nothing, including against an empty list, now fails loudly:

Error: organization '<id>' not found. Available: none

Everything else is unchanged: the no-hint zero-orgs path still returns OrgPick::None (server falls back to its default scoping), and single-org auto-select, multi-org JSON default, and multi-org human prompt all behave exactly as before.

Test

Added pick_org_explicit_hint_with_no_orgs_errors_not_dropped as a regression guard (written failing first, against the old behavior). Full pick_org suite green; cargo fmt --all -- --check and cargo clippy --all-targets --all-features -- -D warnings clean.

Validation

Built and run against connect.peridio.com:

  • Before: auth login --org <non-member-org> --profile XLogged in / Created new profile; auth status --profile XToken scope: unscoped (all orgs).
  • After: same command → Error: organization '<id>' not found. Available: none; the browser shows "CLI Login Failed"; no profile is written.
  • Member path still works: auth login --org <member-org> scopes the token correctly and projects list --org <member-org> returns the org's projects.

`avocado connect auth login --org <id>` silently dropped the requested
org whenever the auth server returned no organizations. pick_org tested
`orgs.is_empty()` first and returned None, so the code exchange minted an
unscoped token and the CLI reported a successful login for an org it
never scoped to, leaving a bogus "all orgs" profile behind with no error.

Resolve an explicit hint before the empty-list shortcut so a hint that
matches nothing, including an empty list, fails loudly. The no-hint
zero-orgs path still returns None unchanged.

Signed-off-by: Javier Tia <javier@peridio.com>
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.

1 participant