Coder Social home page Coder Social logo

adcentury / socketio-jwt-auth Goto Github PK

View Code? Open in Web Editor NEW
90.0 6.0 16.0 46 KB

Socket.io authentication middleware using Json Web Token

License: MIT License

JavaScript 100.00%
socket-io socket-io-middleware authenticate authentication auth jwt json-web-token socketio-jwt socketio-jwt-auth

socketio-jwt-auth's People

Contributors

adcentury avatar chapmanc avatar davesag avatar federkun avatar grufft avatar leilei-tsmount avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

socketio-jwt-auth's Issues

Success event not firing on client

I'm using Angulra 2 as client and Nodejs as backend.

The issue is that error event is firing on the client side but the success event is not firing.

Install from npm no "succeedWithoutToken"

I Install the module from the npm and it's seems like the 0.0.5 version, but the succeedWithoutToken parameter is not working.
I look in to the code, ands it's look like something old. There is no handling of the succeedWithoutToken parameter.

Not enough or too many segments

Have Problem, its good for you to make a simple test on a place like stackblitz.
because i try anyway and this package not work !

// Server Side
const express = require('express');
const server = express();
const app = require('http').createServer(server);
const io = require('socket.io')(app);
var jwtAuth = require('socketio-jwt-auth');

io.use(jwtAuth.authenticate({
  secret: 'your_secret',
  algorithm: 'HS256',
  succeedWithoutToken: true
}, function(payload, done){
// This part is never work
  console.log('work')
}
));

io.on('connection', function(socket) {
  socket.emit('success', {
    message: 'success logged in!',
    user: socket.request.user
  });
});

//Client Side

const socket = io('ws://127.0.0.1:3002', { query: `auth_token=x`});
`
  socket.on('error', function(err) {
    console.log(err)
  });

  socket.on('success', function(data) {
    console.log(data);
  })

Response

image

Connecting as a guest, how to supply login credentials to socketio, after login?

My case is the following

When a user connects as a guest, before supplying login credentials. He gets connected thats nice!

On the client side when I successfully login to the application. The returned JWT is being saved in localStorage. But the socket doesn't know anything about that.

In order to fix this I need to refresh the page to use the token from localStorage from my login to send to the socket server.

I hacked the code a little in my authentication function... to let the socket know that the user is connected

socket.request.user = {...person, logged_in: true };

Do you have a better method or a real world example for this?

Thanks.

Not handling token expiration

In my token, I set the expiration to be 60 minutes. However, the authenticate() method continues to treat the token as valid after expiration. Is there something I am doing wrong, or does this library not support token expiration?

Mutiple Auth

is it possible to use multiple authentications for multiple namespaces?

error event event outputs undefined on client

io.use(jwtAuth.authenticate({ secret: config.jwtSecret }, async (payload, done) => {
  if (!payload && !payload.sub) return done(null, false, "invalid token");
  try {
    const user = await User.findOne({uniqueID: payload.sub});
    if (!user) {
      return done(null, false, 'user not found.');
    } 
    return done(null, user);
  } catch (error) {
    return done(error);
  }
}))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.