title: Flask SocketIO authenticate on connect event by sending token
body: <p>Currently after a <code>user</code> logs in, I return a <code>token</code> using <code>JSON</code>. Subsequently they must make a request to the <code>index</code> page  and pass the <code>token</code> in the <code>HTTP Authorisation header</code>.</p>
  
  <p>The <code>index.html</code> page contains the following:</p>
  
  <pre><code>var socket = io.connect('http://' + document.domain + ':' + location.port + namespace);
  
  socket.on('connect', function() {          
            socket.emit('join', {room: 'venue_1'}); 
  });  
  </code></pre>
  
  <p>If the <code>user</code> follows this process of events then connection to <code>socket</code> is only possible after they <code>login</code>. However, I am trying to prevent against the situation where someone may just create a <code>html</code> file containing the above code and not first go through the <code>login</code> step.</p>
  
  <p><strong>Server Code</strong></p>
  
  <pre><code>@socketio.on('connect', namespace='/test')
  def test_connect():
  
      # Can anything be done here to verify a user?
  
      emit('my response', {'data': 'Connected'})
  </code></pre>
  
  <p>Is there a way I can pass a <code>token</code> to the above <code>connect</code> event so that I can verify the user there. If the <code>token</code> ended up being invalid, I could maybe run a <code>disconnect</code> call.</p>
  
  <p>Or does this need to occur when I do the following call?</p>
  
  <pre><code>socket.emit('join', {room: 'venue_1', token:'token1234'}); 
  </code></pre>
  
  <p>Thanks for your help.</p>