3

I am working with Socket IO in Node JS. I want to authenticate each event emitted by my client i.e If i have following events :

socket.emit("1"); socket.emit("2"); : : socket.emit("n");

Now I want to authenticate each of them individually when they are emitted by JWT token.

Is it possible with JWT, Sockets IO in Node JS or another way?

  • Check this - https://stackoverflow.com/questions/36788831/authenticating-socket-io-connections-using-jwt/36821359#36821359 i think it is exactly what are you looking for – Nikolay Aug 14 '20 at 10:29
  • Actually I want the authentication on lower level, by lower level i mean at each event my client emits, I don't want to authenticate just once at the time of connection but I want to take authentication to each event when it is emitted. I simple words I mean "Each of event emitted from my client should be responsible of its own authentication ". – Choudary Usama Abbas Aug 14 '20 at 10:59
  • You could send the JWT along with each request and parse it on the server e.g. client: `socket.emit('hello', {jwt: '...'});` and on the server: `socket.on('hello', ({jwt}) => {...});` – Nikolay Aug 14 '20 at 11:16
  • @ChoudaryUsamaAbbas have you found a way to do it? – Huzaifa Mar 17 '21 at 14:47

0 Answers0