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:
commit
9325691f29
45
lib/index.js
45
lib/index.js
@ -13,24 +13,41 @@ function noQsMethod(options) {
|
|||||||
Namespace.events.push('authenticated');
|
Namespace.events.push('authenticated');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var auth_timeout = setTimeout(function () {
|
if(options.required){
|
||||||
socket.disconnect('unauthorized');
|
var auth_timeout = setTimeout(function () {
|
||||||
}, options.timeout || 5000);
|
socket.disconnect('unauthorized');
|
||||||
|
}, options.timeout || 5000);
|
||||||
|
}
|
||||||
|
|
||||||
socket.on('authenticate', function (data) {
|
socket.on('authenticate', function (data) {
|
||||||
clearTimeout(auth_timeout);
|
if(options.required){
|
||||||
|
clearTimeout(auth_timeout);
|
||||||
|
}
|
||||||
|
|
||||||
jwt.verify(data.token, options.secret, options, function(err, decoded) {
|
jwt.verify(data.token, options.secret, options, function(err, decoded) {
|
||||||
if (err) {
|
var onError = function(){
|
||||||
return socket.disconnect('unauthorized');
|
return socket.disconnect('unauthorized');
|
||||||
|
};
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
onError();
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.decoded_token = decoded;
|
var onSuccess = function(){
|
||||||
socket.emit('authenticated');
|
socket.decoded_token = decoded;
|
||||||
if (server.$emit) {
|
socket.emit('authenticated');
|
||||||
server.$emit('authenticated', socket);
|
if (server.$emit) {
|
||||||
} else {
|
server.$emit('authenticated', socket);
|
||||||
server.server.sockets.emit('authenticated', socket);
|
} else {
|
||||||
|
server.server.sockets.emit('authenticated', socket);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if(options.additional_auth){
|
||||||
|
options.additional_auth(decoded, onSuccess, onError);
|
||||||
|
}else{
|
||||||
|
onSuccess();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user