Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As a lot of comments have pointed out below the Socket.IO API changed in their <code>1.0</code> release. Authentication should now be done via a middleware function, see 'Authentication differences' @ <a href="http://socket.io/docs/migrating-from-0-9/#authentication-differences">http://socket.io/docs/migrating-from-0-9/#authentication-differences</a>. I'll include my orginal answer for anyone stuck on &lt;1.0 as the old docs seem to be gone.</p> <h1>1.0 and later:</h1> <p>Client Side:</p> <pre><code>//The query member of the options object is passed to the server on connection and parsed as a CGI style Querystring. var socket = io("http://127.0.0.1:3000/", { query: "foo=bar" }); </code></pre> <p>Server Side:</p> <pre><code>io.use(function(socket, next){ console.log("Query: ", socket.handshake.query); // return the result of next() to accept the connection. if (socket.handshake.query.foo == "bar") { return next(); } // call next() with an Error if you need to reject the connection. next(new Error('Authentication error')); }); </code></pre> <h1>Pre 1.0</h1> <p>You can pass a query: param in the second argument to connect() on the client side which will be available on the server in the authorization method. </p> <p>I've just been testing it. On the client I have:</p> <pre><code>var c = io.connect('http://127.0.0.1:3000/', { query: "foo=bar" }); </code></pre> <p>On the server:</p> <pre><code>io.set('authorization', function (handshakeData, cb) { console.log('Auth: ', handshakeData.query); cb(null, true); }); </code></pre> <p>The output on the server then looked like:</p> <pre><code>:!node node_app/main.js info - socket.io started Auth: { foo: 'bar', t: '1355859917678' } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload