Repository navigation
fix(ai): renew Cursor logins through the IDE refresh grant (#2919) - #6155
Open
surlymochan wants to merge 2 commits into
Open
surlymochan wants to merge 2 commits into
surlymochan wants to merge 2 commits into
Conversation
Owner
|
Thanks @surlymochan. One thing to settle before merge, plus two smaller notes:
Minor: the |
Owner
|
@surlymochan, a maintainer ruling on the client identity question: an OAuth refresh must present the same
Please show, with the login code path, which |
This branch has not been deployed
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.
Fixes #2919
What
Every Cursor refresh sent the stored session token as a
Bearerto/auth/exchange_user_api_key, an endpoint that trades dashboard user API keys — Cursor answers "Invalid User API Key" every time, so each login was going to lapse about 60 days after/login cursorwhile its row stayed active and retried with no hint to log in again.This ports upstream oh-my-pi #14753 to senpi's fork-shaped
cursor.ts:POST https://api2.cursor.sh/oauth/tokenwith{ grant_type: "refresh_token", client_id: <the IDE's public client id>, refresh_token }and noAuthorizationheader. The renewed session token is stored as both access and refresh (unless the response rotates the refresh token).200andshouldLogout: true; that now throwsOAuthReauthorizationRequiredError("invalid_grant")(credentialRefused: true, so the credential pool disables the row as a verdict on the login) instead of being retried as a transient failure.crsr_...) is a different credential and still trades atauth/exchange_user_api_keywith the previous Bearer exchange and camelCase response. Senpi stores no other marker distinguishing a dashboard key from a login session, so thecrsr_prefix is the discriminator.OAuthTokenEndpointErrorwith the status, whichclassifyOAuthRefreshFailurekeeps transient.Tests
packages/ai/test/cursor-oauth.test.ts: the refresh block was rewritten for the new endpoint and gained three cases (refresh-grant request shape,shouldLogoutmapping, dashboard-key exchange).accessTokenfrom a snake_caseaccess_tokenresponse, andshouldLogoutwas not mapped to a reauthorization error.bun run --cwd packages/ai test test/cursor-oauth.test.ts→ 22 passed / 0 failed.models-refresh-joins-token-refresh→ 10 files, 106 tests, all passed.bun run check(oxlint, format, lint ratchet,tsc --noEmitover 8,789 + 3,192 files, browser smoke, lock checks) → exit 0.Notes
changes/unreleased/<this PR number>.md, tracker block forpackages/ai/src/auth/changes.mdplus thepackages/ai/CHANGELOG.mdentry) follows in a second commit once this PR has its number.Summary by cubic
Fixes Cursor login renewal so sessions no longer lapse about 60 days after
/login cursor.Uses the same
refresh_tokengrant as the Cursor IDE instead of sending the session token as a Bearer to the dashboard API key exchange, which rejected it every time. AshouldLogout: trueresponse now marks the credential as permanently refused (invalid_grant) instead of retrying it as transient, and dashboard user API keys (crsr_...) still trade through the original key exchange. Adds a user-facing changelog entry for the fix.Written for commit cc3e48a. Summary will update on new commits.