-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Closed
Description
It's now possible to define middleware per namespace, but when this is used for authorization there is an issue. The issue is that the root namespace authorization is always called first, when this fails the namespace specific authorization isn't called. This makes it "impossible" to send the client an error from the namespace it was connecting to.
Not sure what would be the best solution here...
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var socketClient = require('socket.io-client');
var debug = require('debug')('nspAuthorization');
var port = 5000;
// SERVER
http.listen(port, function(){
debug('server listening on *:'+port);
});
var rootNSP = io.of('/');
var subNSP = io.of('/namespace');
rootNSP.use(authorization); // when enabled, the user won't get a error
subNSP.use(authorization);
function authorization(socket, next) {
debug('authorization: to nsp: ',socket.nsp.name);
var query = socket.handshake.query;
if (query.secret === 'abc') {
debug(" valid secret");
next();
} else{
debug(" invalid secret");
next(new Error('invalid secret'));
}
}
// CLIENT
var url = 'http://localhost:'+port;
debug('namespace: connecting');
var socket = socketClient.connect(url+'/namespace?secret=fake');
socket.on('error',function(err) { // not received when root authorization middleware is enabled
debug('namespace: error: ',arguments);
});
socket.on('connection',function() {
debug('namespace: connected');
});Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels