Skip to content

Instantly share code, notes, and snippets.

@chrisenytc
Created September 15, 2014 03:03
Show Gist options
  • Save chrisenytc/323fa3fce012ea24f252 to your computer and use it in GitHub Desktop.
Save chrisenytc/323fa3fce012ea24f252 to your computer and use it in GitHub Desktop.
Socket.io 1.0.x Authentication example
'use strict';
var socket = io.connect('http://localhost:3000', { query: 'token=12345'});
'use strict';
/*
* Module dependencies
*/
var io = require('socket.io');
//Auth middleware
io.use(function(socket, next) {
if (socket.handshake.query.token === '12344') {
return next();
} else {
return next(new Error('Access Denied!'));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment