title: Securing Socket.io
body: <p>I am using a Node.js based https server that authenticates using HTTP Basic (which is fine as the data are sent over the SSL encrypted connection).</p>
  
  <p>Now I want to provide a Socket.io connection which should be</p>
  
  <ol>
  <li>encrypted and</li>
  <li>for authenticated users only.</li>
  </ol>
  
  <p>The question is how to do this. I already found out that I need to specify <code>{ secure: true }</code> in the client JavaScript code when connecting to the socket, but how do I force on the server-side that socket connections can only be run over SSL, and that it works only for authenticated users?</p>
  
  <p>I guess that the SSL thing is the easy part, as the Socket.io server is bound to the https server only, so it should run using SSL only, and there should be no possibility to run it over an (additionally) running http server, right?</p>
  
  <p>Regarding the other thing I have not the slightest idea of how to ensure that socket connections can only be established once the user successfully authenticated using HTTP Basic.</p>
  
  <p>Any ideas?</p>