feat(auth): add --scope/-s and --read-only flags to login and refresh#1032
Merged
Conversation
db35ed3 to
17fd04c
Compare
17fd04c to
98bc598
Compare
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 98bc598. Configure here.
Add explicit OAuth scope selection following `gh` CLI conventions: - `auth login --scope/-s`: variadic, comma-separated scope flag - `auth login --read-only`: sugar for the read-only subset - `auth refresh --scope/-s` and `--read-only`: re-run device flow with new scopes (like `gh auth refresh -s`), bypassing the 'already authenticated' gate - 403 enrichment: when specific missing scopes are detected, suggest the exact `sentry auth refresh --scope X` command - Interactive 403 recovery middleware: in TTYs, prompt to re-authenticate with missing scopes (merged with default set) and retry the command Scopes are validated against the canonical SENTRY_SCOPES set from getsentry/sentry. The plumbing passes a resolved scope string (not a boolean) through performDeviceFlow, avoiding positional-boolean creep. Refs #1031.
98bc598 to
d768af3
Compare
Member
|
Thanks for the initial implementation @RaeesBhatti! Your PR was the foundation for the scope selection feature. We expanded it to include explicit |
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.

Summary
Adds explicit OAuth scope selection to
auth loginandauth refresh,following
ghCLI conventions. Also adds scope-aware 403 error recovery.Fixes #1031.
Motivation
issues for debugging context. A read-only OAuth path means "let the
agent investigate" doesn't also mean "let the agent accidentally
change production state."
only read shouldn't hold tokens that can also write or delete.
ghparity:gh auth login/gh auth refreshsupport--scopes/-sfor explicit scope selection and interactive 403recovery. This PR brings the same ergonomics to the Sentry CLI.
Features
auth login --scope/-sand--read-onlyScopes are validated against the canonical
SENTRY_SCOPESset fromgetsentry/sentry. Conflict guards reject
--token+ scope flags and--read-only+--scope.auth refresh --scope/-sand--read-onlyLike
gh auth refresh -s <scope>— re-runs the OAuth device flow withthe requested scopes, bypassing the "already authenticated" gate:
Scope-aware 403 error hints
When the API returns 403 with specific missing scopes, the error now
suggests the exact fix command:
Interactive 403 scope recovery (TTY only)
In interactive terminals, catches 403 missing-scope errors for OAuth
tokens and prompts:
On confirmation, re-authenticates via the device flow (merging missing
scopes with the default set) and retries the command automatically.
Implementation
src/lib/oauth.ts—resolveOAuthScopeString()resolver;requestDeviceCode(scope)andperformDeviceFlow(..., scope)take aresolved scope string (not a boolean)
src/lib/api-scope.ts— export canonicalSENTRY_SCOPESfor validationsrc/lib/api/infrastructure.ts— scope-aware 403 enrichment hintssrc/cli.ts—scopeRecoveryMiddlewarefor interactive 403 auto-fixsrc/commands/auth/login.ts—--read-only+--scope/-sflagssrc/commands/auth/refresh.ts—--read-only+--scope/-sflagsTest plan
resolveOAuthScopeString(fast-check)Credits
Based on the initial
--read-onlyimplementation by @RaeesBhatti in theoriginal PR. Extended with
--scope/-s,auth refreshsupport,scope-aware 403 hints, and interactive recovery middleware.