Skip to content

Instantly share code, notes, and snippets.

@uvshah
Last active August 29, 2015 14:06
Show Gist options
  • Save uvshah/0ac82a3e43c7297ebd20 to your computer and use it in GitHub Desktop.
Save uvshah/0ac82a3e43c7297ebd20 to your computer and use it in GitHub Desktop.
Socket.IO authentication method
//Server side
var express = require('express');
var app = express();
var http = require('http');
var server = http.createServer(app);
var io = require('socket.io').listen(server);
io.set('authorization', function (req, callback) {
if (req.query.token)
{
//checking token key.If true then return
return callback(null, true);
}
else
{
return callback(null, false);
}
});
//Browser side(client side)
socket = io.connect('http://localhost/', {
'port': 8088,
query: "token=" + Key,
});
//Server side
var express = require('express');
var app = express();
var http = require('http');
var server = http.createServer(app);
var io = require('socket.io').listen(server);
io.set('authorization', function (req, callback) {
if (req._query.token)//then only diffrence i found from 0.9(_query)
{
//checking token key.If true then return
return callback(null, true);
}
else
{
return callback(null, false);
}
});
//Browser side(client side)
socket = io.connect('http://localhost:8088/', { // can't connect if i initialize as 'port':8088, like 0.9
query: "token=" + Key,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment