Blog

Websocket basic Authorisation in Node.js

By:
on:

Secure websockets, authenticated with Basic http authentication.

On the client-side they throw a popup and you provide it with an username and a password to authenticate yourself and gain access.

On the server-side you have to add this to your request headers.

There are a lot of websocket client packages available on npm, but they don't have easy access to the request headers.

We extended the nodejs-websocket package with this extra feature.

This way, we could add Basic access authentication headers to our project through the extraHeaders property in options.

Example

var ws = require('nodejs-websocket')

var name = 'test'

var password = 'test123'

var options = {

	extraHeaders: {

  // implementation of Basic access authentication 

		Authorization: 'Basic ' + new Buffer(name+ ':' + password).toString('base64')

	}

}

var conn = ws.connect('wss://data.appsaloon.io/socket',options)



conn.on('connect',function(){

    conn.sendText('data')

})

KOEN IS HAPPY TO INTRODUCE APPSALOON
APPSALOON BV
Bampslaan 21 box 3.01
3500 Hasselt
Belgium
VAT: BE08 4029 5063
2021 © AppSaloon All Rights Reserved
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram