Skip to content

Authenticate Socket.IO Connection using JSON Web Tokens (jwt) and the node-jwt-simple library

License

Notifications You must be signed in to change notification settings

iamakimmer/jwtauth-socket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jwtauth-socket

Authenticate Socket.IO Connection using JSON Web Tokens (jwt) and the node-jwt-simple library

Client Side:

Connect socket with adding a token as a query parameter:

var socket = io.connect('http://localhost', {
  query: 'token=abcdefghijklmnopqrstuvwxyz
});

Server Side:

var server = http.createServer(app);
var io = require('socket.io').listen(server);
io.configure(function() {        
    io.set('authorization', jwtAuth.auth('your jwt secret'));
});    


io.sockets.on('connection', function(socket) {
    console.log('decoded', socket.handshake.decoded); // decoded is your decided token
});

About

Authenticate Socket.IO Connection using JSON Web Tokens (jwt) and the node-jwt-simple library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published