grpc-websocket-proxy icon indicating copy to clipboard operation
grpc-websocket-proxy copied to clipboard

Passing authentication from browser JS websocket

Open wbobeirne opened this issue 5 years ago • 2 comments

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?

wbobeirne avatar Mar 05 '20 08:03 wbobeirne

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

How it's work?

AKopytenko avatar Jun 19 '20 15:06 AKopytenko

It should be

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

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

Goobs avatar Nov 27 '20 06:11 Goobs