2
1
mirror of https://github.com/Thream/socketio-jwt.git synced 2024-07-21 09:38:31 +02:00

Merge branch 'ddamerell53-master'

This commit is contained in:
José F. Romaniello 2015-05-29 08:51:53 -03:00
commit 9325691f29

View File

@ -14,17 +14,27 @@ function noQsMethod(options) {
} }
} }
if(options.required){
var auth_timeout = setTimeout(function () { var auth_timeout = setTimeout(function () {
socket.disconnect('unauthorized'); socket.disconnect('unauthorized');
}, options.timeout || 5000); }, options.timeout || 5000);
socket.on('authenticate', function (data) {
clearTimeout(auth_timeout);
jwt.verify(data.token, options.secret, options, function(err, decoded) {
if (err) {
return socket.disconnect('unauthorized');
} }
socket.on('authenticate', function (data) {
if(options.required){
clearTimeout(auth_timeout);
}
jwt.verify(data.token, options.secret, options, function(err, decoded) {
var onError = function(){
return socket.disconnect('unauthorized');
};
if (err) {
onError();
}
var onSuccess = function(){
socket.decoded_token = decoded; socket.decoded_token = decoded;
socket.emit('authenticated'); socket.emit('authenticated');
if (server.$emit) { if (server.$emit) {
@ -32,6 +42,13 @@ function noQsMethod(options) {
} else { } else {
server.server.sockets.emit('authenticated', socket); server.server.sockets.emit('authenticated', socket);
} }
};
if(options.additional_auth){
options.additional_auth(decoded, onSuccess, onError);
}else{
onSuccess();
}
}); });
}); });