Merge branch 'master' into misc

This commit is contained in:
Conrad Sopala
2019-07-23 15:20:05 +02:00
committed by GitHub
14 changed files with 247 additions and 238 deletions

View File

@ -35,7 +35,7 @@ function noQsMethod(options) {
message: (Object.prototype.toString.call(err) === '[object Object]' && err.message) ? err.message : err
});
var callback_timeout;
// If callback explicitely set to false, start timeout to disconnect socket
// If callback explicitely set to false, start timeout to disconnect socket
if (options.callback === false || typeof options.callback === "number") {
if (typeof options.callback === "number") {
if (options.callback < 0) {
@ -57,10 +57,15 @@ function noQsMethod(options) {
}
};
if(!data || typeof data.token !== "string") {
var token = options.cookie ? socket.request.cookies[options.cookie] : (data ? data.token : undefined);
if(!token || typeof token !== "string") {
return onError({message: 'invalid token datatype'}, 'invalid_token');
}
// Store encoded JWT
socket[options.encodedPropertyName] = data.token;
var onJwtVerificationReady = function(err, decoded) {
if (err) {
@ -96,16 +101,16 @@ function noQsMethod(options) {
return onError(err, 'invalid_secret');
}
jwt.verify(data.token, secret, options, onJwtVerificationReady);
jwt.verify(token, secret, options, onJwtVerificationReady);
};
getSecret(socket.request, options.secret, data.token, onSecretReady);
getSecret(socket.request, options.secret, token, onSecretReady);
});
};
}
function authorize(options, onConnection) {
options = xtend({ decodedPropertyName: 'decoded_token' }, options);
options = xtend({ decodedPropertyName: 'decoded_token', encodedPropertyName: 'encoded_token' }, options);
if (!options.handshake) {
return noQsMethod(options);
@ -167,6 +172,9 @@ function authorize(options, onConnection) {
return auth.fail(error, socket, accept);
}
// Store encoded JWT
data[options.encodedPropertyName] = token;
var onJwtVerificationReady = function(err, decoded) {
if (err) {