4

I was wondering what are the best practices for socket.IO authentication.

Alice emits event 'message' with parameters including Bobs unique identifier etc. Bob receives the message while listening to socket.on('message') event.

How do I prevent unauthenticated users from ever connecting to the server using Socket.IO and how do I emit event to only specific user?

Thank you very much in advance for all suggestions and answers. Peter

Peter Bielak
  • 643
  • 2
  • 12
  • 24

1 Answers1

5

Socket.IO allows you to set up authentication for new sessions. You could do this with cookies or using JSON web tokens for example. The authentication mechanism did change from 0.9 to 1.0, so just be aware of that when googling.

As far as encryption goes, as long as you're using https you should be fine. Trying to implement your own encryption scheme instead of using https is more risky and more work anyway.

Community
  • 1
  • 1
mscdex
  • 104,356
  • 15
  • 192
  • 153