Skip to content

fix(longbridge): send expired_at and fail-closed on refresh errors - #653

Merged
Pigbibi merged 1 commit into
mainfrom
fix/longport-refresh-expired-at-fail-closed
Oct 9, 2026
Merged

Pigbibi merged 1 commit into
mainfrom
fix/longport-refresh-expired-at-fail-closed

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • refresh_token_if_needed now sends vendor-required expired_at (default +90d, RFC3339 Z) on GET /v1/token/refresh, and includes that query string in the HMAC params slot.
  • Fail-closed: non-zero LongPort refresh responses raise even when the current JWT is still within its expiry window (no more soft-return of the stale token).
  • Empty token payloads also raise. Probe/snapshot callers are unchanged (they do not call this helper).

Why

LongBridgePlatform path A: pre-expiry Legacy refresh must be reliable before a scheduled refresh job. Soft-fail + missing expired_at historically allowed tokens to rot until portal reset (HK incident).

Test plan

  • PYTHONPATH=src python3 -m unittest tests.test_longbridge_auth -v (7 OK)
  • CI green
  • Downstream pin bump + refresh job remain separate (paper→SG→HK last)

Refs: https://open.longportapp.com/docs/refresh-token-api.md · LongBridgePlatform #585 runbook

Legacy /v1/token/refresh requires expired_at; omit it and soft-return the
stale token let pre-expiry failures sit silent until 401003. Include the
query in the HMAC params slot, default new-token lifetime to 90 days, and
raise on any non-zero refresh response while the token is still valid.
@Pigbibi
Pigbibi merged commit b8d8827 into main Oct 9, 2026
@Pigbibi
Pigbibi deleted the fix/longport-refresh-expired-at-fail-closed branch October 9, 2026 06:19
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