From d2cc8fb51406af646b03ce6e62613b200b885178 Mon Sep 17 00:00:00 2001 From: Root-Core Date: Tue, 18 Apr 2017 23:26:47 +0200 Subject: [PATCH 1/3] Renamed "data" to "socket", updated deps --- lib/index.js | 24 ++++++++++++------------ package.json | 21 ++++++++++----------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/lib/index.js b/lib/index.js index bfcb715..4aa18ad 100644 --- a/lib/index.js +++ b/lib/index.js @@ -112,15 +112,15 @@ function authorize(options, onConnection) { } var defaults = { - success: function(data, accept){ - if (data.request) { + success: function(socket, accept){ + if (socket.request) { accept(); } else { accept(null, true); } }, - fail: function(error, data, accept){ - if (data.request) { + fail: function(error, socket, accept){ + if (socket.request) { accept(error); } else { accept(null, false); @@ -130,9 +130,9 @@ function authorize(options, onConnection) { var auth = xtend(defaults, options); - return function(data, accept){ + return function(socket, accept){ var token, error; - var req = data.request || data; + var req = socket.request || socket; var authorization_header = (req.headers || {}).authorization; if (authorization_header) { @@ -148,7 +148,7 @@ function authorize(options, onConnection) { error = new UnauthorizedError('credentials_bad_format', { message: 'Format is Authorization: Bearer [token]' }); - return auth.fail(error, data, accept); + return auth.fail(error, socket, accept); } } @@ -164,25 +164,25 @@ function authorize(options, onConnection) { error = new UnauthorizedError('credentials_required', { message: 'No Authorization header was found' }); - return auth.fail(error, data, accept); + return auth.fail(error, socket, accept); } var onJwtVerificationReady = function(err, decoded) { if (err) { error = new UnauthorizedError(err.code || 'invalid_token', err); - return auth.fail(error, data, accept); + return auth.fail(error, socket, accept); } - data[options.decodedPropertyName] = decoded; + socket[options.decodedPropertyName] = decoded; - return auth.success(data, accept); + return auth.success(socket, accept); }; var onSecretReady = function(err, secret) { if (err) { error = new UnauthorizedError(err.code || 'invalid_secret', err); - return auth.fail(error, data, accept); + return auth.fail(error, socket, accept); } jwt.verify(token, secret, options, onJwtVerificationReady); diff --git a/package.json b/package.json index ba5258a..bd0589a 100644 --- a/package.json +++ b/package.json @@ -22,19 +22,18 @@ }, "license": "MIT", "dependencies": { - "jsonwebtoken": "^5.0.0", - "xtend": "~2.1.2" + "jsonwebtoken": "^7.3.0", + "xtend": "~4.0.1" }, "devDependencies": { - "body-parser": "~1.13.3", - "express": "~4.10.6", - "mocha": "~1.17.0", - "passport-local": "~0.1.6", - "request": "~2.19.0", - "serve-static": "^1.7.1", + "body-parser": "~1.17.1", + "express": "~4.15.2", + "mocha": "~3.2.0", + "request": "~2.81.0", + "serve-static": "^1.12.1", "server-destroy": "~1.0.1", - "should": "~1.2.2", - "socket.io": "^1.0.4", - "socket.io-client": "^1.0.4" + "should": "~11.2.1", + "socket.io": "^1.7.3", + "socket.io-client": "^1.7.3" } } From 40334831548dd376071269ea051461088a55cdc0 Mon Sep 17 00:00:00 2001 From: Root-Core Date: Wed, 19 Apr 2017 00:23:05 +0200 Subject: [PATCH 2/3] Fixed mocha tests by downgrading "jsonwebtoken" Version 5.7.0 is the last working. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bd0589a..6aedca6 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ }, "license": "MIT", "dependencies": { - "jsonwebtoken": "^7.3.0", + "jsonwebtoken": "^5.7.0", "xtend": "~4.0.1" }, "devDependencies": { From 250312152a85282edd9064b468a94d62853cffc4 Mon Sep 17 00:00:00 2001 From: Root-Core Date: Wed, 19 Apr 2017 00:33:26 +0200 Subject: [PATCH 3/3] Fixed mocha tests by not using `expiresInMinutes` Using `expiresInMinutes` leads to errors, as it was deprecated in `jsonwebtoken` > 5.7.0. We should use `expiresIn` instead. --- package.json | 2 +- test/fixture/index.js | 2 +- test/fixture/namespace.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 6aedca6..bd0589a 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ }, "license": "MIT", "dependencies": { - "jsonwebtoken": "^5.7.0", + "jsonwebtoken": "^7.3.0", "xtend": "~4.0.1" }, "devDependencies": { diff --git a/test/fixture/index.js b/test/fixture/index.js index 432c474..f897021 100644 --- a/test/fixture/index.js +++ b/test/fixture/index.js @@ -38,7 +38,7 @@ exports.start = function (options, callback) { }; // We are sending the profile inside the token - var token = jwt.sign(profile, options.secret, { expiresInMinutes: 60*5 }); + var token = jwt.sign(profile, options.secret, { expiresIn: 60*60*5 }); res.json({token: token}); }); diff --git a/test/fixture/namespace.js b/test/fixture/namespace.js index d3de1f5..eff8223 100644 --- a/test/fixture/namespace.js +++ b/test/fixture/namespace.js @@ -38,7 +38,7 @@ exports.start = function (callback) { }; // We are sending the profile inside the token - var token = jwt.sign(profile, options.secret, { expiresInMinutes: 60*5 }); + var token = jwt.sign(profile, options.secret, { expiresIn: 60*60*5 }); res.json({token: token}); });