Repository navigation
fix(auth): name invalid OAuth scopes and re-authenticate when scopes change (#552) - #659
Conversation
|
Hi @TheVicky1. Thanks for contributing to During the release candidate phase, we’re being very intentional about the changes we accept so that we can prioritise stability for GA. We’re limiting pull requests to contributions coordinated with the team in advance, so this PR has been automatically closed. We’d still love to hear about your use case, so please make sure it’s captured in a |
|
Hi @petebacondarwin! I saw the auto-close notice regarding the RC phase. I've prepared a clean, focused fix for #552:
The branch and tests are ready. Could you please take a look when you have a moment and vouch for me or reopen the PR? Thank you! |
|
This pull request's reviews are posted as pull request reviews: see the review of |
|
clanker review |
There was a problem hiding this comment.
Superseded by the review of
710f03f5.
This review, of 6a934329
💬 Approved with comments — One WARNING: the new error message recommends --profile <name>, which cf auth login rejects. One SUGGESTION about checking scope names before the already-logged-in check.
Findings: 1 warning · 1 suggestion (2 are inline comments on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
🔧 Fix with your agent
Paste the following into your coding agent to investigate and fix these issues.
Fix the following code review issues found in pull request #659.
Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order
## WARNING (1)
### [Code Quality] The error hint recommends `--profile <name>`, but `cf auth login` rejects `--profile` (`assertNoProfileFlag` at login.ts:74); point to `cf auth create <name>` instead.
- **File:** packages/cli/src/commands/auth/login.ts:122
## SUGGESTION (1)
### [Code Quality] Scope names are checked only inside `login()`, after this check, so a mistyped scope on an existing login is reported as missing and the user is told to use `--force`.
- **File:** packages/cli/src/commands/auth/login.ts:117
📋 Code Quality: ⚠️ 1 warning · 1 suggestion
The new error hint recommends a flag the command rejects, and a mistyped scope is reported as missing when the user is already logged in.
Recommendation: 📝 Minor Comments
- [WARNING] The error hint recommends
--profile <name>, butcf auth loginrejects--profile(assertNoProfileFlagat login.ts:74); point tocf auth create <name>instead. (packages/cli/src/commands/auth/login.ts:122) - [SUGGESTION] Scope names are checked only inside
login(), after this check, so a mistyped scope on an existing login is reported as missing and the user is told to use--force. (packages/cli/src/commands/auth/login.ts:117)
View full review
--profilehint is wrong (packages/cli/src/commands/auth/login.ts:122). The handler starts withassertNoProfileFlag(argv, "login", ...)at line 74. That call rejects--profileoncf auth loginand points tocf auth create <name>, so following the new hint leads straight to another error.- Invalid scopes are reported as missing (
login.ts:115-125). The already-logged-in check runs beforelogin()checks scope names. A typo such as--scopes workerz:writefirst gives "run--force". The--forcerun then fails withInvalid cf OAuth scope(s). Checking scope names before the already-logged-in check would give the correct error in one step.
✅ All other checks passed
🚀 Release: ✅ LGTM
The patch changeset describes both behavior changes in cf auth login: invalid scopes are named, and requesting new scopes on an existing login now requires --force. Release risk is moderate because the change is limited to scope handling in the login flow.
🔒 Security: ✅ LGTM
No security concerns in the scope check or error-message changes.
📖 AGENTS.md: ✅ LGTM
The changes follow the repository conventions, and a changeset is included.
⚡ Performance: ✅ LGTM
No performance concerns.
📝 Documentation: ✅ LGTM
No documentation issues.
Reviewed commit: 6a934329
|
Addressed both findings in commit 710f03f: early scope validation ensures invalid scope names fail before checking existing credentials. Please review it, Thanks! |
|
clanker review |
There was a problem hiding this comment.
⚠️ Out of date: this review is of710f03f5; the pull request is now at456e88dd. Someone with write access can commentclanky review(orclanker reviewor@clanky-the-clanker review) to review the new commits.
💬 Approved with comments — Both earlier findings are fixed. The only remaining note is an INFO about changeset wording.
Findings: 1 info (1 is an inline comment on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📝 Documentation: 💬 1 info
The changeset describes an error message as a prompt.
Recommendation: 💬 Optional Nits
- [INFO] The changeset says the command will "prompt for
--force", but it exits with an error telling the user to rerun with--force. (.changeset/oauth-scope-validation.md:9)
View full review
The changeset says the command will "prompt for --force". It actually exits with an error that tells the user to rerun with --force.
✅ All other checks passed
🚀 Release: ✅ LGTM
The patch changeset documents both changes: invalid scope names are now listed in the error, and requesting new scopes on an existing login now requires --force. The change is limited to scope handling in the login flow.
🔒 Security: ✅ LGTM
Scope names are checked against a fixed allowlist. The error messages echo only the user's own CLI input, to the local terminal. Requiring --force for new scopes makes the CLI stricter, not looser.
📖 AGENTS.md: ✅ LGTM
The change follows the repository conventions and includes a changeset.
📋 Code Quality: ✅ LGTM
- The
--profilehint is fixed: the error atlogin.ts:125-128now points tocf auth create <name>, which matches theassertNoProfileFlagmessage. - The scope check order is fixed:
assertValidScopeKeysruns atlogin.ts:81-83, before the already-logged-in branch, and a test covers it. login()still checks the scope names too. Checking them twice is harmless and keepslogin()safe for other callers.
⚡ Performance: ✅ LGTM
No performance concerns.
Reviewed commit: 710f03f5
Rather than requiring the user to run again with |
petebacondarwin
left a comment
There was a problem hiding this comment.
Rather than requiring the user to run again with --force we should just trigger a new login flow (an implicit force) since we know the user is requesting new scopes.
710f03f to
3988b9c
Compare
commit: |
|
Thanks for the feedback, @petebacondarwin! I've updated the implementation: Requesting new scopes now directly initiates a new OAuth login flow (implicit --force) instead of halting. Ready for another look when you have time! |
petebacondarwin
left a comment
There was a problem hiding this comment.
All looks great except for the subset check.
Why
Fixes #552.
When requesting custom scopes during
cf auth login:cfpreviously threw a generic message:One or more of the requested scopes are not valid cf OAuth scopes.without naming which scope failed validation.cf auth login --scopes <new_scopes>without--force,cfpreviously ignored--scopes, printedYou are already logged in, and exited 0. This silently dropped the requested permissions.What changed
src/lib/oauth/index.ts,login()now checks individual scopes againstvalidateScopeKeys()and names all invalid scopes in the error message (e.g.Invalid cf OAuth scope(s): foo, bar.).src/commands/auth/login.ts, validate explicit scopes before checking the current login. When the requested and stored scope sets differ, including when requesting fewer scopes, start a fresh OAuth login without requiring--force. Equivalent sets reuse the current credentials, ignoring order, duplicates, and automatically addedoffline_access.auth.test.tsanddevice-login.test.ts.Blast Radius
Only
cf auth loginwith--scopesis affected. Login without--scopesand login with an equivalent scope set behave unchanged.Verification
pnpm --filter cf exec vp test run src/__tests__/lib/auth.test.tspassed (19 tests).pnpm --filter cf exec vp test run -t "requesting new scopes|holds the requested scopes" src/__tests__/commands/auth/device-login.test.tspassed.pnpm checkpassed.