Repository navigation
Conversation
The refresh flow used the JWT returned by exchange_user_api_key as the stored refresh credential, but that endpoint only accepts a crsr_ API key (or the original stored refresh value). Subsequent refreshes then failed with 401 / "Invalid User API Key" every time the access token expired, leaving pi unable to recover the cursor-agent credentials. Preserve the original refresh credential when returning refreshed tokens so refresh keeps working across expirations. Add unit tests covering the happy path, the access-only fallback, and the failure path.
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.
Problem
With
pi-cursor-agent, the OAuth refresh flow breaks permanently after the first access-token expiry:AuthManager.refreshcallsexchange_user_api_keywith the stored refresh credential and receives a new JWT access + refresh pair.exchange_user_api_keyis called with that JWT, but the endpoint only accepts acrsr_API key (or the original stored value). It returns401 Invalid User API Key.OAuth refresh failed for cursor-agent.Verified against
https://api2.cursor.sh/auth/exchange_user_api_key:crsr_...API key200401 Invalid User API Key401 Invalid User API KeyFix
Preserve the original refresh credential when returning refreshed tokens instead of replacing it with the JWT returned by the exchange. A stored
crsr_API key stays valid across refreshes, so the flow recovers automatically after each access-token expiry.Tests
Added
test/lib/auth.test.tscovering:crsr_refresh credential (and asserts the exchange is invoked with it)Verification
npm run lint✅npm run typecheck✅npm test✅ (37 pass, including the 3 new tests)cursor-agent/composer-2.5succeeded andauth.jsonwas refreshed (expiresupdated, refresh credential unchanged).