Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headers emulation #440

Merged
merged 1 commit into from
Dec 22, 2024
Merged

Headers emulation #440

merged 1 commit into from
Dec 22, 2024

Conversation

FZambia
Copy link
Member

@FZambia FZambia commented Dec 22, 2024

This feature allows implementing mechanics described in centrifugal/centrifugo#832 (comment)

WebSocket browser API does not allow setting custom HTTP headers which makes implementing authentication for browser WebSocket connections harder. With Centrifugo JWT authentication it works pretty good, but proxy still requires careful thinking each time.

Centrifugo can help here by providing a feature called headers emulation. Centrifugo users can provide a custom headers map to the browser SDK (centrifuge-js) constructor, these headers are then sent in the first message to Centrifugo, and Centrifugo has an option to translate it to the outgoing proxy request native HTTP headers – abstracting away the specifics of WebSocket protocol in a secure way. This can drastically simplify the integration from the auth perspective since the backend may re-use existing code.

I already have MVP, so maybe (I will still evaluate for some time) it will be possible to do sth like this soon in centrifuge-js:

const centrifuge = new Centrifuge(
    "ws://host/connection/websocket",
    {"headers": {"Authorization": "Bearer XXX"}})

And Centrifugo will deliver Authorization as an HTTP header in connect proxy request, and in can deliver in all other proxy request types too.

@FZambia FZambia merged commit 3a3fceb into v0.34.0_dev Dec 22, 2024
8 checks passed
@FZambia FZambia deleted the cfg_v6 branch December 22, 2024 09:07
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