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

Passing authentication from browser JS websocket #20

Open
wbobeirne opened this issue Mar 5, 2020 · 2 comments
Open

Passing authentication from browser JS websocket #20

wbobeirne opened this issue Mar 5, 2020 · 2 comments

Comments

@wbobeirne
Copy link

Hey there, I see there are some docs about passing authorization using the Sec-Websocket-Protocol header. While this is a clever workaround, it doesn't appear as though it'll actually work for websockets started from the browser. From the MDN article on websockets, only registered IANA subprotocols can be passed. Attempting to pass Bearer, 123 results in

VM3291:1 Uncaught DOMException: Failed to construct 'WebSocket': The subprotocol 'Bearer, 123' is invalid.

Was this implemented with browser compatibility in mind? Or was the idea that cookies would be the only browser-friendly authorization method?

@AKopytenko
Copy link

AKopytenko commented Jun 19, 2020

+1
new WebSocket(address, 'Bearer,' + token )
Subprotocol is invalid.

How it's work?

@Goobs
Copy link

Goobs commented Nov 27, 2020

It should be

ws = new WebSocket(address, ['Bearer', token])

Browser concatenates subprotocol header by itself. No spaces or commas are allowed in header values.

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

No branches or pull requests

3 participants