fix(desktop): use camelCase-aware parser for persisted native OAuth tokens (#73271) - #73437
Closed
JonthanaHanh wants to merge 1 commit into
Closed
fix(desktop): use camelCase-aware parser for persisted native OAuth tokens (#73271)#73437JonthanaHanh wants to merge 1 commit into
JonthanaHanh wants to merge 1 commit into
Conversation
…okens Persisted NativeTokenSet uses camelCase keys (accessToken, refreshToken, expiresAt, userId) while parseTokenResponse() expects snake_case from raw gateway responses (access_token, refresh_token, expires_at, user_id). When _loadNativeTokens() passes decrypted persisted JSON through parseTokenResponse(), it always fails with "Gateway token response missing access_token" because the camelCase keys don't match — forcing the user to re-authenticate after every Desktop restart. Add rehydratePersistedTokens() that accepts camelCase with snake_case fallback, and use it in _loadNativeTokens() instead of parseTokenResponse(). Raw OAuth responses from the gateway still use parseTokenResponse(). Fixes NousResearch#73271
1 task
Collaborator
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
Desktop native OAuth sign-in works during the initial process lifetime, but after a cold restart the persisted token set cannot be rehydrated — the user is forced to re-authenticate.
Root cause:
_loadNativeTokens()passes the decrypted persistedNativeTokenSet(camelCase:accessToken,refreshToken,expiresAt) throughparseTokenResponse(), which expects raw gateway OAuth response format (snake_case:access_token,refresh_token,expires_at). The camelCase keys don't match, so the parser throws "Gateway token response missing access_token" and returnsnull— the stored tokens are silently discarded.Changes
apps/desktop/electron/native-oauth.ts— AddrehydratePersistedTokens():accessToken), falls back to snake_case (access_token) for belt-and-suspenders compatibilityparseTokenResponse()(throws on missing access token)parseTokenResponse()apps/desktop/electron/main.ts— UserehydratePersistedTokens()in_loadNativeTokens():parseTokenResponse()→rehydratePersistedTokens()parseTokenResponse()is still used at line 6169 for raw gateway token exchange responses (correct usage)apps/desktop/electron/native-oauth.test.ts— 4 new tests:accessTokenTest Plan
rehydratePersistedTokenstests passFixes #73271