Created
September 15, 2014 03:03
-
-
Save chrisenytc/323fa3fce012ea24f252 to your computer and use it in GitHub Desktop.
Socket.io 1.0.x Authentication example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var socket = io.connect('http://localhost:3000', { query: 'token=12345'}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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