Skip to content

Show native OAuth project limits in auth status - #325

Open
masnwilliams wants to merge 3 commits into
mainfrom
hypeship/auth-status-native-projects
Open

masnwilliams wants to merge 3 commits into
mainfrom
hypeship/auth-status-native-projects

Conversation

@masnwilliams

@masnwilliams masnwilliams commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

kernel auth status decides its "Access scope" line from the token response's access_scope and project_id. Tokens from the native authorization server limit a grant to chosen projects through its policy and list them in a separate projects field, with access_scope: organization and no project_id. The CLI ignored that field, so a sign-in limited to one project showed "organization-wide". Enforcement was already correct; only the display was wrong.

  • Store projects from the token response on login, and keep it across refreshes that omit it.
  • auth status shows project <id> for one project, projects <id>, <id> for several, and organization-wide only when the grant isn't limited.
  • Legacy project-scoped tokens (access_scope: project) display as before.

Testing

  • go test ./pkg/auth/ ./cmd/: new tests for storing projects on exchange and keeping them on refresh, and for the scope label.
  • Not run against a live sign-in.

Note

Medium Risk
Changes OAuth token persistence and credential load/save behavior; display-only scope risk is low but wrong merge of keyring/file could surface stale tokens.

Overview
kernel auth status now reports access scope from stored projects and ScopeRecorded, not only legacy access_scope / project_id. Native org-scoped grants limited to specific projects show project <id> or projects <id>, …> instead of always organization-wide; older credentials without recorded scope show an unknown message prompting kernel login --force.

On login and refresh, the CLI persists projects from the token response, sets ScopeRecorded when access_scope is present, and keeps project lists when refresh responses omit projects.

Token storage adds SavedAt, resolves keyring vs. credentials file by picking the newer copy (expiry fallback for older saves), clears stale keyring entries on file fallback, and removes the file when keyring saves succeed again—supporting larger payloads (e.g. project lists) when the OS keychain refuses them.

Reviewed by Cursor Bugbot for commit 08ad67f. Bugbot is set up for automated code reviews on this repo. Configure here.

@yummybomb yummybomb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two credential issues to address:

  • pkg/auth/storage.go:28 — projects can push credentials past the windows keyring's 2,560-byte limit. login reports success after saving to disk, but the next command still reads the old keyring entry. make the successful fallback authoritative.
  • cmd/auth.go:181 — project-limited native logins saved by older cli versions still show organization-wide until refresh. show the scope as unknown when it wasn't recorded, and point users to kernel login --force.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 26a80d1. Configure here.

Comment thread pkg/auth/oauth.go Resolved
@masnwilliams

Copy link
Copy Markdown
Contributor Author

@yummybomb thanks, both addressed (26a80d1, 08ad67f):

  • Stale keychain entry after a disk fallback (pkg/auth/storage.go): when the keychain refuses the credentials and the file write succeeds, SaveTokens now deletes the old keychain entry. A successful keychain save removes a leftover credentials file. LoadTokens reads both stores and returns the newer copy (a new saved_at stamp, falling back to expiry for credentials saved by older CLIs), so the right copy wins even if that delete fails. Tests: TestSaveTokensFallbackReplacesStaleKeyring (keychain fails the way Windows does above 2,560 bytes) and TestLoadTokensPrefersNewerCopy.
  • Older logins showing organization-wide (cmd/auth.go): credentials now record scope_recorded when a login or refresh response states the access scope. Without it, auth status shows "unknown (saved by an older CLI version; run 'kernel login --force' to record it)". The first refresh by this CLI records it. Tests: TestAccessScopeLabel, TestRefreshRecordsScopeForOlderCredentials, TestRefreshLegacyTokensRemainOrganizationWide.

go test ./... passes; CI and BugBot are green on 08ad67f.

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.

2 participants