RuView icon indicating copy to clipboard operation
RuView copied to clipboard

fix(python): authenticate SensingClient WebSocket connections

Open pengqima opened this issue 4 months ago • 1 comments

Summary

  • Add bearer-token authentication to the Python SensingClient.
  • Read the token from RUVIEW_API_TOKEN by default.
  • Allow callers to override the token through the constructor.
  • Support both WebSocket header APIs used across the declared websockets>=12 dependency range.

Details

SensingClient now sends:

Authorization: Bearer <token>

during the WebSocket upgrade.

websockets renamed extra_headers to additional_headers in version 14. The client inspects the installed connect() API and deliberately selects the supported argument, preserving compatibility with versions 12, 13, 14, and later.

Passing token="" explicitly disables authentication even when RUVIEW_API_TOKEN is set.

Validation

Client test suite with websockets==12.0: 11 passed Client test suite with websockets==15.0.1: 11 passed Python compile check passed Targeted Ruff checks passed

Closes #1395

pengqima avatar Jul 22 '26 15:07 pengqima

Heads-up: #1396 and #1400 implement the same feature — bearer-token auth on the SensingClient WebSocket upgrade — and edit the same lines of python/wifi_densepose/client/ws.py and python/tests/test_client_ws.py (both close #1395). So only one can merge; the other will conflict.

Both look sound. A small point in this one's (#1396) favor: it adds a dedicated unit test that monkeypatches websockets.connect's signature to verify the additional_headers (websockets ≥14) vs extra_headers (<14) branch — the one non-trivial piece here. Worth picking one and closing the other.

PrinceAudre avatar Jul 25 '26 12:07 PrinceAudre