From 640e8d0ef065a3a8e8aa2e9e8ceabd95e2f72208 Mon Sep 17 00:00:00 2001 From: Root-Core Date: Tue, 22 Nov 2016 14:27:04 +0100 Subject: [PATCH] Fix authentication for namespaces #95 Try to get the token from query string, which is stored in the sockets "handshake" object. This should fix #95 and be a more elegant (say valid) approach. --- lib/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index bfcb715..a34bb88 100644 --- a/lib/index.js +++ b/lib/index.js @@ -133,6 +133,7 @@ function authorize(options, onConnection) { return function(data, accept){ var token, error; var req = data.request || data; + var handshake = data.handshake; var authorization_header = (req.headers || {}).authorization; if (authorization_header) { @@ -152,8 +153,11 @@ function authorize(options, onConnection) { } } - //get the token from query string - if (req._query && req._query.token) { + //get the token from handshake or query string + if (handshake && handshake.query.token){ + token = handshake.query.token; + } + else if (req._query && req._query.token) { token = req._query.token; } else if (req.query && req.query.token) {