Skip to content

A Socket.IO middleware for authenticating with a JSON Web Token based on passport-jwt.

License

Notifications You must be signed in to change notification settings

erreina/passport-jwt.socketio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

passport-jwt.socketio

Build Status npm dependency status js-standard-style

A Socket.IO middleware for authenticating with a JSON Web Token based on passport-jwt.

This module lets you authenticate socket.io endpoints using a JSON web token. It is intended to be used to secure endpoints without sessions.

Example usage

// Initialize our modules
const io = require('socket.io')(server)
const passportJwtSocketIo = require('passport-jwt.socketio')

// set the passport-jwt options
const options = {
  jwtFromRequest: ExtractJwt.fromUrlQueryParameter('token'),
  secretOrKey: secret
}

// define the verify callback
function verify(jwtPayload, done) {
  // token is valid 
  // we still can verify the token

  // the user passed is set to socket.request.user
  done(null, user)
}


// set the authorization middleware
io.use(passportJwtSocketIo.authorize(options, verify))

Tests

npm install
npm test

Inspiration

Contribute

You are always welcome to open an issue or provide a pull-request!

License

The MIT License

About

A Socket.IO middleware for authenticating with a JSON Web Token based on passport-jwt.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published