Looks like it\'s easy to add custom HTTP headers to your websocket client with any HTTP header client which supports this, but I can\'t find how to do it with the JSON API.
HTTP Authorization header problem can be addressed with the following:
var ws = new WebSocket("ws://username:password@example.com/service");
Then, a proper Basic Authorization HTTP header will be set with the provided username
and password
. If you need Basic Authorization, then you're all set.
I want to use Bearer
however, and I resorted to the following trick: I connect to the server as follows:
var ws = new WebSocket("ws://my_token@example.com/service");
And when my code at the server side receives Basic Authorization header with non-empty username and empty password, then it interprets the username as a token.