Protect a WebSocket #62
Answered
by
frankie567
davidbrochart
asked this question in
Q&A
|
In FastAPI-Users it is not as easy to protect a WebSocket as an HTTP endpoint (see this issue). @app.websocket("/protected", name="protected")
async def protected(
websocket: WebSocket,
user: FiefUserInfo = Depends(auth.current_user()),
):
... |
Answered by
frankie567
Aug 25, 2022
Replies: 1 comment 3 replies
|
Unfortunately, we hit the same limitations around security dependencies and WebSockets: FastAPI assume an HTTP The only solution right now would be to:
I think it would be interesting though to have it natively in the FastAPI integration; so I'll add it to my backlog 👍 |
3 replies
Answer selected by
davidbrochart
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unfortunately, we hit the same limitations around security dependencies and WebSockets: FastAPI assume an HTTP
Requestin those, so it won't work with a websocket. Besides, error responses are quite different with WebSockets.The only solution right now would be to:
WebSocketobject.validate_access_tokenmethod on the Fief client.await websocket.close(code=status.WS_1008_POLICY_VIOLATION)I think it would be interesting though to have it natively in the FastAPI integration; so I'll add it to my back…