diff --git a/README.md b/README.md index e7b7737..87c50be 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# socketio-auth [![Build Status](https://secure.travis-ci.org/invisiblejs/socketio-auth.png)](http://travis-ci.org/invisiblejs/socketio-auth) +# socketio-auth [![Build Status](https://secure.travis-ci.org/facundoolano/socketio-auth.png)](http://travis-ci.org/facundoolano/socketio-auth) This module provides hooks to implement authentication in [socket.io](https://github.com/Automattic/socket.io) without using querystrings to send credentials, which is not a good security practice. @@ -76,7 +76,7 @@ function postAuthenticate(socket, data) { } ``` -* `timeout`: The amount of millisenconds to wait for a client to authenticate before disconnecting it. Defaults to 1000. +* `timeout`: The amount of millisenconds to wait for a client to authenticate before disconnecting it. Defaults to 1000. The value 'none' disables the timeout feature. ## Auth error messages diff --git a/lib/socketio-auth.js b/lib/socketio-auth.js index 3e386d0..72e7646 100644 --- a/lib/socketio-auth.js +++ b/lib/socketio-auth.js @@ -13,7 +13,7 @@ var debug = require('debug')('socketio-auth'); * @param {Function} config.authenticate - indicates if authentication was successfull * @param {Function} config.postAuthenticate=noop - called after the client is authenticated * @param {Number} [config.timeout=1000] - amount of millisenconds to wait for a client to - * authenticate before disconnecting it + * authenticate before disconnecting it. A value of 'none' means no connection timeout. */ module.exports = function socketIOAuth(io, config) { config = config || {}; @@ -53,13 +53,15 @@ module.exports = function socketIOAuth(io, config) { }); - setTimeout(function() { - // If the socket didn't authenticate after connection, disconnect it - if (!socket.auth) { - debug('Disconnecting socket %s', socket.id); - socket.disconnect('unauthorized'); - } - }, timeout); + if (timeout !== 'none') { + setTimeout(function() { + // If the socket didn't authenticate after connection, disconnect it + if (!socket.auth) { + debug('Disconnecting socket %s', socket.id); + socket.disconnect('unauthorized'); + } + }, timeout); + } }); }; diff --git a/package.json b/package.json index a42a14c..d8432ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "socketio-auth", - "version": "0.0.4", + "version": "0.0.5", "description": "Authentication for socket.io", "main": "index.js", "directories": {