Question

I am working with faye messaging system and I want to add authentication! I worked my way through the website and followed the tutorial.

On the Client I have an extension for outgoing Messages:

var droneFaye = new faye.Client("/faye", {
            timeout: 120
        });
var USER_TOKEN = 'ifd63cylqwsyaq9c2ptzywjujgtfpxs';

    droneFaye.addExtension({
        outgoing: function(message, callback) {
            if (message.channel !== '/meta/subscribe')
                return callback(message);

            message.ext = message.ext || {};
            message.ext.token = USER_TOKEN;
            console.log(message);
            callback(message);
        }
    });

On the Server:

var token = 'ifd63cylqwsyaq9c2ptzywjujgtfpxs'

    var serverAuth = {
    incoming: function(message, callback) {
        // Let non-subscribe messages through

        if (message.channel !== '/meta/subscribe')
            return callback(message);

        // Get subscribed channel and auth token
        var msgToken = message.ext && message.ext.token;

        // Find the right token for the channel
        if (token !== msgToken) {
            message.error = 'Invalid subscription auth token';
        }
        console.log(message);
        callback(message);
    }
};

var adapter = new faye.NodeAdapter({
    mount:'/faye',
    timeout:45
});
adapter.addExtension(serverAuth);
adapter.attach(httpServer);

I have a subscription on the server like this:

adapter.getClient().subscribe("/drone/move", function(cmd) {});

Alright! So when I start the server and there is NO CLIENT it already calls the extension for the subscriptions and it will output on the console:

{ channel: '/meta/subscribe',
  clientId: '2isdeb0ds77zl0lh82ob1kqu29y1cajnv80',
  subscription: '/drone/move',
  id: '2',
  error: 'Invalid subscription auth token' }

Once a Client connects to the server it will again call the extension and it will output this:

{ channel: '/meta/subscribe',
  clientId: '3kechs0c7smpc05z5o7d0a8qcd301d8zi41',
  subscription: '/drone/move',
  id: '3',
  ext: { userId: 18787, token: 'ifd63cylqwsyaq9c2ptzywjujgtfpxs' } }

So this looks good! But no other messages are going to arrive on the server even though they have the correct token and there is no error message!

Just for information. If you add a error key with a value to the message object it will not pass the message to its subscription...its supposed to be like that!..

Also when I comment out the message.error in the extension it works fine but of course there is not authentication.

So does anyone know why the server calls the extension even though there is no client and second why does faye not give the message to its subscription even though there is no error in the message object?

thx!

Was it helpful?

Solution

Question was also asked, and answered here:

This is caused by the call to adapter.getClient().subscribe().

[...] the server-side client (<adapter>.getClient()) returns a connection to the server, thus walks through the same extensions (incoming, outgoing) as the client does.

[...] Attach an outgoing extension and you'll see it being responded to the server-client.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top