Merge pull request #117 from Root-Core/misc
Renamed "data" to "socket", updated deps
This commit is contained in:
commit
e4c5b973f4
24
lib/index.js
24
lib/index.js
@ -117,15 +117,15 @@ function authorize(options, onConnection) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
success: function(data, accept){
|
success: function(socket, accept){
|
||||||
if (data.request) {
|
if (socket.request) {
|
||||||
accept();
|
accept();
|
||||||
} else {
|
} else {
|
||||||
accept(null, true);
|
accept(null, true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: function(error, data, accept){
|
fail: function(error, socket, accept){
|
||||||
if (data.request) {
|
if (socket.request) {
|
||||||
accept(error);
|
accept(error);
|
||||||
} else {
|
} else {
|
||||||
accept(null, false);
|
accept(null, false);
|
||||||
@ -135,9 +135,9 @@ function authorize(options, onConnection) {
|
|||||||
|
|
||||||
var auth = xtend(defaults, options);
|
var auth = xtend(defaults, options);
|
||||||
|
|
||||||
return function(data, accept){
|
return function(socket, accept){
|
||||||
var token, error;
|
var token, error;
|
||||||
var req = data.request || data;
|
var req = socket.request || socket;
|
||||||
var authorization_header = (req.headers || {}).authorization;
|
var authorization_header = (req.headers || {}).authorization;
|
||||||
|
|
||||||
if (authorization_header) {
|
if (authorization_header) {
|
||||||
@ -153,7 +153,7 @@ function authorize(options, onConnection) {
|
|||||||
error = new UnauthorizedError('credentials_bad_format', {
|
error = new UnauthorizedError('credentials_bad_format', {
|
||||||
message: 'Format is Authorization: Bearer [token]'
|
message: 'Format is Authorization: Bearer [token]'
|
||||||
});
|
});
|
||||||
return auth.fail(error, data, accept);
|
return auth.fail(error, socket, accept);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +169,7 @@ function authorize(options, onConnection) {
|
|||||||
error = new UnauthorizedError('credentials_required', {
|
error = new UnauthorizedError('credentials_required', {
|
||||||
message: 'No Authorization header was found'
|
message: 'No Authorization header was found'
|
||||||
});
|
});
|
||||||
return auth.fail(error, data, accept);
|
return auth.fail(error, socket, accept);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store encoded JWT
|
// Store encoded JWT
|
||||||
@ -179,18 +179,18 @@ function authorize(options, onConnection) {
|
|||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
error = new UnauthorizedError(err.code || 'invalid_token', 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) {
|
var onSecretReady = function(err, secret) {
|
||||||
if (err) {
|
if (err) {
|
||||||
error = new UnauthorizedError(err.code || 'invalid_secret', 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);
|
jwt.verify(token, secret, options, onJwtVerificationReady);
|
||||||
|
25
package.json
25
package.json
@ -22,19 +22,20 @@
|
|||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"jsonwebtoken": "^8.3.0",
|
"jsonwebtoken": "^7.3.0",
|
||||||
"xtend": "~2.1.2"
|
"xtend": "~4.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"body-parser": "~1.13.3",
|
"body-parser": "~1.17.1",
|
||||||
"express": "~4.10.6",
|
"express": "~4.15.2",
|
||||||
"mocha": "~1.17.0",
|
"mocha": "~3.2.0",
|
||||||
"passport-local": "~0.1.6",
|
"request": "~2.81.0",
|
||||||
"request": "2.68.0",
|
"serve-static": "^1.12.1",
|
||||||
"serve-static": "^1.7.1",
|
"jsonwebtoken": "^8.3.0",
|
||||||
|
"xtend": "~2.1.2",
|
||||||
"server-destroy": "~1.0.1",
|
"server-destroy": "~1.0.1",
|
||||||
"should": "~1.2.2",
|
"should": "~11.2.1",
|
||||||
"socket.io": "^1.0.4",
|
"socket.io": "^1.7.3",
|
||||||
"socket.io-client": "^1.0.4"
|
"socket.io-client": "^1.7.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -38,7 +38,7 @@ exports.start = function (options, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// We are sending the profile inside the token
|
// 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});
|
res.json({token: token});
|
||||||
});
|
});
|
||||||
|
@ -38,7 +38,7 @@ exports.start = function (callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// We are sending the profile inside the token
|
// 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});
|
res.json({token: token});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user