Skip to content

Fix token refresh: accept numeric userid from Withings#3

Merged
DTTerastar merged 1 commit into
mainfrom
fix/token-refresh-userid-number
Apr 20, 2026
Merged

Fix token refresh: accept numeric userid from Withings#3
DTTerastar merged 1 commit into
mainfrom
fix/token-refresh-userid-number

Conversation

@DTTerastar
Copy link
Copy Markdown
Contributor

Summary

  • Withings /v2/oauth2 returns userid as a JSON string on the authorization_code grant but as a JSON number on the refresh_token grant. tokenResponse.UserID was typed string, so every refresh failed with cannot unmarshal number into Go struct field tokenResponse.userid of type string, locking users out ~3h after login until they re-ran auth login.
  • Switch the field to json.Number (unmarshals from either form); call .String() at the two assign sites.
  • TokenStore.UserID remains string on disk — existing auth.json files stay valid.
  • Adds a regression test covering both wire forms.

Test plan

  • go build ./... clean
  • go vet ./... clean
  • go test ./internal/auth/... — both subtests pass
  • Manual: force-expire token (expires_at → 2020), run measurements --since 1d --json, confirm refresh succeeds and new expires_at is ~3h out

🤖 Generated with Claude Code

The /v2/oauth2 endpoint returns userid as a JSON string on the
initial authorization_code grant but as a JSON number on the
refresh_token grant. tokenResponse.UserID was typed as string,
so every refresh failed with:

  cannot unmarshal number into Go struct field tokenResponse.userid
  of type string

leaving users locked out after the ~3h access token expiry until
they re-ran auth login. Switch the field to json.Number, which
unmarshals from either form, and call .String() at the two assign
sites. TokenStore.UserID stays string on disk, so existing
auth.json files remain valid.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@DTTerastar DTTerastar merged commit 7c347c4 into main Apr 20, 2026
1 check passed
@DTTerastar DTTerastar deleted the fix/token-refresh-userid-number branch April 20, 2026 20:00
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.

1 participant