angular2-websocket icon indicating copy to clipboard operation
angular2-websocket copied to clipboard

How can I pass Authorization Header?

Open just4give opened this issue 7 years ago • 3 comments

Hi there, Is there any way to pass Authorization header? My backend is secured by OAuth2 and Socket connection failing with 401.

just4give avatar Sep 18 '17 21:09 just4give

+1

jSchez avatar Oct 22 '17 11:10 jSchez

For anyone interested, looking on the source, there is a second parameter protocols? which allows sending information. This information will be passed as a header Sec-WebSocket-Protocol with the values needed.

Then, you only need to pass the second parameter in the constructor like this: new $WebSocket( url, [ access_token, refresh_token ] );

jSchez avatar Oct 22 '17 12:10 jSchez

This will cause the connection to fail on "Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received", if the server does not respond back with the same protocols. Details: stackoverflow.com

NadavK avatar Oct 15 '19 23:10 NadavK