Error when using ?api_key=test param in a websocket request. The api key gets through, but then the move_api_key function wants to call cookies_to_set which fails. Seems that the issue is you can't set cookies with the websocket.
File "/Users/seij/Repos/bluesky-httpserver/.venv/lib/python3.12/site-packages/fastapi/routing.py", line 184, in app
await wrap_app_handling_exceptions(app, session)(scope, receive, send)
File "/Users/seij/Repos/bluesky-httpserver/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
raise exc
File "/Users/seij/Repos/bluesky-httpserver/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "/Users/seij/Repos/bluesky-httpserver/.venv/lib/python3.12/site-packages/fastapi/routing.py", line 181, in app
await func(session)
File "/Users/seij/Repos/bluesky-httpserver/.venv/lib/python3.12/site-packages/fastapi/routing.py", line 796, in app
await dependant.call(**solved_result.values)
File "/Users/seij/Repos/bluesky-httpserver/src/bluesky_httpserver/routers/core_api.py", line 1215, in console_output_ws
principal, accepted = await _authenticate_websocket(websocket, scopes)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/seij/Repos/bluesky-httpserver/src/bluesky_httpserver/routers/core_api.py", line 1184, in _authenticate_websocket
principal = get_current_principal_websocket(websocket=websocket, scopes=scopes)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/seij/Repos/bluesky-httpserver/src/bluesky_httpserver/authentication.py", line 516, in get_current_principal_websocket
File "/Users/seij/Repos/bluesky-httpserver/src/bluesky_httpserver/authentication.py", line 298, in get_current_principal
)
File "/Users/seij/Repos/bluesky-httpserver/src/bluesky_httpserver/authentication.py", line 256, in move_api_key
# The `set_cookies` HTTP middleware initializes `request.state.cookies_to_set`.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/seij/Repos/bluesky-httpserver/.venv/lib/python3.12/site-packages/starlette/datastructures.py", line 686, in __getattr__
raise AttributeError(message.format(self.__class__.__name__, key))
AttributeError: 'State' object has no attribute 'cookies_to_set'
Replacing line 256 with the above worked for me. I tested through a browser client and through Postman.
bluesky-httpserver/src/bluesky_httpserver/authentication.py
Line 256 in a8093be
Error when using ?api_key=test param in a websocket request. The api key gets through, but then the
move_api_keyfunction wants to callcookies_to_setwhich fails. Seems that the issue is you can't set cookies with the websocket.Replacing line 256 with the above worked for me. I tested through a browser client and through Postman.
Proposed fix: