Skip to content

fix: preserve refresh token when server omits it from refresh response#47

Open
elijahr wants to merge 1 commit intoanomalyco:masterfrom
elijahr:fix/preserve-refresh-token
Open

fix: preserve refresh token when server omits it from refresh response#47
elijahr wants to merge 1 commit intoanomalyco:masterfrom
elijahr:fix/preserve-refresh-token

Conversation

@elijahr
Copy link

@elijahr elijahr commented Feb 9, 2026

Summary

Fixes the issue where users have to re-authenticate frequently (sometimes hourly) because the refresh token gets lost.

Fixes #12

Problem

When refreshing OAuth tokens, if the Anthropic server doesn't return a new refresh_token in the response (standard OAuth2 behavior - servers often only rotate refresh tokens periodically), the existing refresh token was being overwritten with undefined:

refresh: json.refresh_token,  // undefined if not in response

This caused:

  • TypeError: undefined is not an object (evaluating 'auth.type')
  • Users needing to re-authenticate every hour or so

Reported in #12 by @randomm:

"This is a new one: intermittently getting TypeError: undefined is not an object (evaluating 'auth.type') I have to oauth about once an hour and then it goes away."

Fix

Preserve the existing refresh token when the server doesn't return a new one:

- refresh: json.refresh_token,
+ refresh: json.refresh_token ?? auth.refresh,

Tests

Added test infrastructure (previously none existed):

  • 17 tests covering token refresh, headers, tool prefixing, system prompt sanitization
  • CI workflow for running tests on push/PR

When refreshing OAuth tokens, if the server doesn't return a new
refresh_token (standard OAuth2 behavior), preserve the existing one
instead of overwriting with undefined.

Also adds test infrastructure:
- 17 tests covering token refresh, headers, tool prefixing, sanitization
- CI workflow for running tests on push/PR
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.

The auth no longer works

1 participant