Merge branch 'ddamerell53-master'
This commit is contained in:
commit
9325691f29
39
lib/index.js
39
lib/index.js
@ -14,23 +14,40 @@ function noQsMethod(options) {
|
||||
}
|
||||
}
|
||||
|
||||
var auth_timeout = setTimeout(function () {
|
||||
socket.disconnect('unauthorized');
|
||||
}, options.timeout || 5000);
|
||||
if(options.required){
|
||||
var auth_timeout = setTimeout(function () {
|
||||
socket.disconnect('unauthorized');
|
||||
}, options.timeout || 5000);
|
||||
}
|
||||
|
||||
socket.on('authenticate', function (data) {
|
||||
clearTimeout(auth_timeout);
|
||||
if(options.required){
|
||||
clearTimeout(auth_timeout);
|
||||
}
|
||||
|
||||
jwt.verify(data.token, options.secret, options, function(err, decoded) {
|
||||
if (err) {
|
||||
var onError = function(){
|
||||
return socket.disconnect('unauthorized');
|
||||
};
|
||||
|
||||
if (err) {
|
||||
onError();
|
||||
}
|
||||
|
||||
socket.decoded_token = decoded;
|
||||
socket.emit('authenticated');
|
||||
if (server.$emit) {
|
||||
server.$emit('authenticated', socket);
|
||||
} else {
|
||||
server.server.sockets.emit('authenticated', socket);
|
||||
var onSuccess = function(){
|
||||
socket.decoded_token = decoded;
|
||||
socket.emit('authenticated');
|
||||
if (server.$emit) {
|
||||
server.$emit('authenticated', socket);
|
||||
} else {
|
||||
server.server.sockets.emit('authenticated', socket);
|
||||
}
|
||||
};
|
||||
|
||||
if(options.additional_auth){
|
||||
options.additional_auth(decoded, onSuccess, onError);
|
||||
}else{
|
||||
onSuccess();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user