WebSocket-Node
WebSocket-Node copied to clipboard
How to do basic authentication [Documentation]
Hello,
I'm trying to connect to a device that runs a websocket server but it requires a username and password. It's basic auth but ws://user@pw:192.169.10.10 doesn't work... Any suggestions?
WebSocket-Node doesn't have specific support for basic auth. I suppose that's something that could be added, but nobody has asked for it before?
Sent from my iPhone
On Jan 26, 2015, at 6:00 AM, sk1tt1sh [email protected] wrote:
Hello,
I'm trying to connect to a device that runs a websocket server but it requires a username and password. It's basic auth but ws://user@pw:192.169.10.10 doesn't work... Any suggestions?
— Reply to this email directly or view it on GitHub.
Do you have possible workaround I could try? I've tried adding it in headers and request options with no luck.. I just get a 401 and no luck. If it's not a common thing I'd feel bad for you to have to work hard to implement something 1 person is going to use lol.
Please close this. I feel sheepish.... client.connect('ws://123.45.67.8', null, null, {'Authorization' : 'Basic QWRtaW46QWRtaW4='}, null);
Regardless of how many people request the feature, it is absolutely a valid feature request. It ought to be supported. Just because I haven't had a reason to implement it before now doesn't mean it shouldn't be done.
I'm glad you found a way to handle the auth manually! Still, one shouldn't have to generate their own authorization header, ideally.
Indeed. It's not incredibly difficult to do but is a bit tedious. The WebSocket-Sharp implementation is pretty good if you would like something to model yours off of.
client = new WebSocket(uri); client.SetCredentials("Admin", "Admin", true); // (user, pw, preauth) client.Connect();
There is also the other way around. I mean having WebSocketServer implementing basic and digest authentication, or am I missing something?