Hello!

After upgrading to the latest dev release of August the 1st, or from git today, I get these errors when using nodejs with the chatroom module:

Failed to parse authentication message: { arguments: [ 'ILLEGAL' ],
  type: 'unexpected_token',
  message: [Getter/Setter],
  stack: [Getter/Setter] }
Failed to parse authentication message: { arguments: [ 'ILLEGAL' ],
  type: 'unexpected_token',
  message: [Getter/Setter],
  stack: [Getter/Setter] }

The result is a non-working realtime chat.

Best regards,
Ao

Comments

pavlosdan’s picture

Also getting this issue:
Failed to parse authentication message: {}
I am not using chatroom module currently.

My current nodejs.config file looks like this:
backendSettings = {
'scheme': 'http',
'host': 'hostname',
'port': 9080,
'key': '',
'cert': '',
'resource': '/socket.io',
'publishUrl': '/nodejs/publish',
'serviceKey': '',
'backend': {
'port': 8080,
'host': 'hostname',
'authPath': '/nodejs/auth/'
},
'extensions': [],
'clientsCanWriteToChannels': false,
'clientsCanWriteToClients': false,
'clientsCanWriteToClients': false,
'transports': ['websocket', 'flashsocket', 'htmlfile', 'xhr-polling', 'jsonp-polling'],
'jsMinification': true,
'jsEtag': true,
'logLevel': 1
};

The file I had previously didn't seem to work anymore after the upgrade so I created a new one using the example.

Gray Fox’s picture

Finally got to the bottom of it.
You will have to edit your nodejs.config.js file, as there are few undocumented changes. First the authPath inside backendSettings.backend is no longer used. You can delete that line and put this one (inside backendSettings.backend):
'messagePath': '/nodejs/message/'

Next, if your serviceKey is empty (ie. if you're on a development machine), you'll have to edit your nodejs.module file's line 427 and replace

if (isset($_POST['messageJson']) && $_POST['authKey']) {

with

if (isset($_POST['messageJson']) && isset($_POST['authKey'])) {
Anonymous’s picture

both of those look like bugs, on it.

taz3r’s picture

Yeah I'm having the same problem.

Running latest dev release from August 1st on Ubuntu with nginx.
After following Gray Fox's instructions, I'm getting the message:

Started http server.
   info  - socket.io started
   debug - client authorized
   info  - handshake authorized 7832807241390730251
   debug - client authorized
   info  - handshake authorized 516167741612417551
   debug - setting request GET /socket.io/1/flashsocket/7832807241390730251
   debug - set heartbeat interval for client 7832807241390730251
   debug - client authorized for
   debug - flashsocket writing 1::
   debug - flashsocket received data packet 5:::{"name":"authenticate","args":[{                                                                         "authToken":"588882b34361fc51cd3f24c297ae0c94"}]}
Backend authentication url not found.
Backend authentication url not found.

My nodejs.config.js:

backendSettings = {
  'scheme': 'http',
  'host': 'mydomain.com',
  'port': 9000,
  'key': '/path/to/key/file',
  'cert': '/path/to/cert/file',
  'resource': '/socket.io',
  'publishUrl': '/nodejs/publish',
  'serviceKey': 'myservicekey',
  'backend': {
    'port': 80,
    'host': 'mydomain.com',
    'authPath': '/nodejs/auth/',
	'messagePath': '/nodejs/message/'
  },
  'extensions': [],
  'clientsCanWriteToChannels': false,
  'clientsCanWriteToClients': false,
  'clientsCanWriteToClients': false,
  'transports': ['websocket', 'flashsocket', 'htmlfile', 'xhr-polling', 'jsonp-polling'],
  'jsMinification': true,
  'jsEtag': true,
  'logLevel': 3
};

And if anyone cares, my NPM list:

---¬ connect@0.5.10
 --- qs@0.3.0
---¬ express@1.0.7
 --- qs@0.3.0
--- policyfile@0.0.3
---¬ socket.io@0.7.7
  --- bison@1.1.1  extraneous
  --- redis@0.6.0
  ---¬ socket.io-client@0.7.4
    --- uglify-js@1.0.3
Anonymous’s picture

taz3r, can you update your nodejs.config.js and set backendSettings.debug to true, then report back.

Gray Fox, thanks for the report, the example config issue is fixed with this commit:

http://drupalcode.org/project/nodejs.git/commit/1159da6

and the authKey bug is fixed with:

http://drupalcode.org/project/nodejs.git/commit/4efe47f

taz3r’s picture

Ok, I updated to latest commit.

My backend settings:

backendSettings = {
  'scheme': 'http',
  'host': 'mydomain.com',
  'port': 9000,
  'key': '/path/to/key/file',
  'cert': '/path/to/cert/file',
  'resource': '/socket.io',
  'publishUrl': '/nodejs/publish',
  'serviceKey': 'myservicekey',
  'backend': {
    'port': 80,
    'host': 'mydomain.com',
    'messagePath': '/nodejs/message'
  },
  'extensions': [],
  'clientsCanWriteToChannels': false,
  'clientsCanWriteToClients': false,
  'clientsCanWriteToClients': false,
  'transports': ['websocket', 'flashsocket', 'htmlfile', 'xhr-polling', 'jsonp-polling'],
  'jsMinification': true,
  'jsEtag': true,
  'debug': true,
  'logLevel': 1
};

A new error pops up when trying to start server:

Started http server.
   info  - socket.io started
Authenticating client with key "588882b34361fc51cd3f24c297ae0c94"
Sending message to backend { authToken: '588882b34361fc51cd3f24c297ae0c94',
  messageType: 'authenticate',
  clientId: '1049677100181977363' } { port: 80,
  host: 'mydomain.com',
  headers:
   { 'Content-Length': 172,
     'Content-Type': 'application/x-www-form-urlencoded' },
  agent:
   { options: { host: 'mydomain.com', port: 80 },
     host: 'mydomain.com',
     port: 80,
     socketPath: undefined,
     queue: [],
     sockets: [],
     maxSockets: 5 },
  method: 'POST',
  path: '/nodejs/message' }
Backend authentication url not found, tried using these options:

/var/www/mydomain.com/sites/all/modules/nodejs/server.js:172
        console.log(options);
                    ^
ReferenceError: options is not defined
    at IncomingMessage.<anonymous> (/var/www/mydomain.com/sites/all/modules/nodejs/server.js:172:21)
    at IncomingMessage.emit (events.js:67:17)
    at HTTPParser.onBody (http.js:121:23)
    at Socket.ondata (http.js:1224:22)
    at Socket._onReadable (net_legacy.js:689:27)
    at IOWatcher.onReadable [as callback] (net_legacy.js:177:10)
Anonymous’s picture

righto, another bug, fixed here:

http://drupalcode.org/project/nodejs.git/commit/3f29a66

thanks for the report.

taz3r’s picture

Thanks! Nodejs running without hitch now.

Anonymous’s picture

Status: Active » Fixed

yay! closing, please repopen/open other issues if you hit other problems.

Aonoa’s picture

Status: Fixed » Active

After updating to the latest from git or dev snapshot, I am getting:

Backend authentication url not found.

The config is pretty much default:

backendSettings = {
  'scheme': 'http',
  'host': 'example.com',
  'port': 9090,
  'key': '/path/to/key/file',
  'cert': '/path/to/cert/file',
  'resource': '/socket.io',
  'publishUrl': '/nodejs/publish',
  'serviceKey': '',
  'backend': {
    'port': 80,
    'host': 'example.com',
    'messagePath': '/nodejs/message/'
  },
  'extensions': [],
  'clientsCanWriteToChannels': false,
  'clientsCanWriteToClients': false,
  'clientsCanWriteToClients': false,
  'transports': ['websocket', 'flashsocket', 'htmlfile', 'xhr-polling', 'jsonp-polling'],
  'jsMinification': true,
  'jsEtag': true,
  'logLevel': 1
};

Best regards,
Ao

Anonymous’s picture

have you cleared the menu cache?

what happens if you just go to 'http://example.com/nodejs/message/' in your browser? you should see

{"error":"Invalid service key."}

Aonoa’s picture

Ah, clearing the cache did the trick. Apparently I forgot that bit.. :)
I'd like to ask if I should use some kind of service key, though?

EDIT: It seems something is still wrong, going to the server stats page, I get this: Error reading Node.js server stats.

Best regards,
Ao

Anonymous’s picture

oh, yep, i forgot to rip out the drupal side of the half-baked stats code. fixed here:

http://drupalcode.org/project/nodejs.git/commit/0629c58

i'm open to the stats stuff coming back, but i'd like it to be a) a sub-module and b) a server extension on the node.js side.

Aonoa’s picture

That fixed it. =)

What about:

   warn  - flashsocket connection invalid
   warn  - client not handshaken client should reconnect

Is this a bug or a fault in my configuration? There is a huge amount of the flash socket connection invalid messages.

Best regards,
Ao

Anonymous’s picture

Status: Active » Fixed

those messages are straight from socket.io code, nothing to do with the node.js module.

i'd look at the socket.io bug reports on github, see if you can find anything.

oh, and make sure you have the lasted stable release of socket.io.

i'm going to close this issue now, please open other specific issues if you hit them.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

inolen’s picture

Just installed the integration module with the notify module, and while it works, node is spitting out the same errors as the OPs:

Started http server.
   info  - socket.io started
Failed to parse authentication message: { stack: [Getter/Setter],
  arguments: [ 'ILLEGAL' ],
  type: 'unexpected_token',
  message: [Getter/Setter] }
Failed to parse authentication message: { stack: [Getter/Setter],
  arguments: [ 'ILLEGAL' ],
  type: 'unexpected_token',
  message: [Getter/Setter] }

I'm running node.js 4.10 and using the versions of connect and express as mentioned in the readme.

My nodejs.config.js is practically default, with 'your.nodejs.server.hostname' changed to 'localhost'.

What exactly do these messages mean?

inolen’s picture

It turns out my problem was due to the BOM not being stripped out of the JSON reply in authenticateClientCallback(). Evidently this if fixed as of node 0.5.4, but for 0.4.x users you may need to strip it out like so:

      var buffer = chunk.toString();      
      if (buffer.charCodeAt(0) === 0xFEFF) {
        buffer = buffer.slice(1);
      }
rootrau’s picture

Version: 7.x-1.x-dev » 7.x-1.0-beta5
rootrau’s picture

Help me Error nodejs beta6
Failed to parse authentication message: { stack: [Getter/Setter],
arguments: [ 'ILLEGAL' ],
type: 'unexpected_token',
message: [Getter/Setter] }
Failed message string:

404 Not Found

Not Found

The requested URL /index.php was not found on this server.

Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.


Apache/2.2.15 (CentOS) Server at 127.0.0.1 Port 80


Thanks

inolen’s picture

What version of node are you using?

rootrau’s picture

I using node version 0.4.10.

inolen’s picture

It's probably due to what I mentioned in #18.

The code has changed slightly, but look in authenticateClientCallback in server.js where it calls:

authData = JSON.parse(requestBody);

Right before that, try stripping out the byte order marker if it exists:

if (requestBody.charCodeAt(0) === 0xFEFF) {
  requestBody = requestBody.slice(1);
}
rootrau’s picture

Thanks inolen.But after I add code
if (requestBody.charCodeAt(0) === 0xFEFF) {
requestBody = requestBody.slice(1);
}
there is this error.

Failed to parse authentication message: { stack: [Getter/Setter],
arguments: [],
type: 'unexpected_eos',
message: [Getter/Setter] }
this code Handle authentication call response.
/**
* Handle authentication call response.
*/
var authenticateClientCallback = function (response) {
var requestBody = '';
response.setEncoding('utf8');
response.on('data', function (chunk) {
var requestBody = chunk.toString();
if (requestBody.charCodeAt(0) === 0xFEFF) {
requestBody = requestBody.slice(1);
}
//requestBody += chunk;
});

response.on('end', function () {
if (response.statusCode == 404) {
if (backendSettings.debug) {
console.log('Backend authentication url not found, full response info:', response);
}
else {
console.log('Backend authentication url not found.');
}
// return;
}
var authData = false;

try {
authData = JSON.parse(requestBody);
}
catch (exception) {
console.log('Failed to parse authentication message:', exception);
if (backendSettings.debug) {
console.log('Failed message string: ' + requestBody);
}
// return;
}
console.log('authData = ' , authData);
if (!checkServiceKey(authData.serviceKey)) {
console.log('Invalid service key "', authData.serviceKey, '"');
return;
}
if (authData.nodejsValidAuthToken) {
if (backendSettings.debug) {
console.log('Valid login for uid "', authData.uid, '"');
}
setupClientConnection(authData.clientId, authData, authData.contentTokens);
//console.log('co chay 1 lan roi');
authenticatedClients[authData.authToken] = authData;
}
else {
console.log('Invalid login for uid "', authData.uid, '"');
delete authenticatedClients[authData.authToken];
}
});
}
thanks.

inolen’s picture

It's now throwing an error because you mutilated the code.

Revert your changes and do exactly what I said in #23 :)

Anonymous’s picture

I am getting a similar error:

Failed to parse authentication message: { stack: [Getter/Setter],
  arguments: [ 'ILLEGAL' ],
  type: 'unexpected_token',
  message: [Getter/Setter] }

My settings:
nodejs v0.4.12
connect v1.1.4
express v2.4.3
nodejs-7.x-1.0-beta6
Site Root: localhost/drupal_sites/enspire_geo_mobile/

nodejs.config.js:

backendSettings = {
  "scheme":"http",
  "host":"localhost",
  "port":8080,
  "key":"/path/to/key/file",
  "cert":"/path/to/cert/file",
  "resource":"/socket.io",
  "publishUrl":"/drupal_sites/enspire_geo_mobile/nodejs/publish",
  "serviceKey":"",
  "backend":{
  "port":80,
  "host":"localhost",
  "messagePath":"/drupal_sites/enspire_geo_mobile/nodejs/message"},
  "clientsCanWriteToChannels":false,
  "clientsCanWriteToClients":false,
  "extensions":"",
  "debug":true,
  "transports":["websocket",
  "flashsocket",
  "htmlfile",
  "xhr-polling",
  "jsonp-polling"],
  "jsMinification":true,
  "jsEtag":true,
  "logLevel":1};

I have also applied the change suggested in #23 to server.js:

var authenticateClientCallback = function (response) {
  var requestBody = '';
  response.setEncoding('utf8');
  response.on('data', function (chunk) {
    requestBody += chunk;
  });
  response.on('end', function () {
    if (response.statusCode == 404) {
      if (backendSettings.debug) {
        console.log('Backend authentication url not found, full response info:', response);
      }
      else {
        console.log('Backend authentication url not found.');
      }
      return;
    }
    var authData = false;
    try {
      if (requestBody.charCodeAt(0) === 0xFEFF) {
	requestBody = requestBody.slice(1);
      }
      authData = JSON.parse(requestBody);
    }
    catch (exception) {
      console.log('Failed to parse authentication message:', exception);
      if (backendSettings.debug) {
        console.log('Failed message string: ' + requestBody);
      }
      return;
    }.......
Anonymous’s picture

Status: Closed (fixed) » Active

Newb here. Just noticed this issue had been fixed but I am experiencing it using the most recent beta. Please see post #26 for my details.

Anonymous’s picture

I was finally able to get past this by changing to different versions of some of the required node_modules, etc. The version list that finally worked for me:
nodejs v0.4.7
express v2.4.3
connect v1.1.4
socket.io v0.8.7
nodejs-7.x-1.x-dev

robertdouglass’s picture

Version: 7.x-1.0-beta5 » 7.x-1.x-dev

This seems to be still present in the latest .dev version.

Here's my node console output:

Authenticating client with key "2d2b74986ea7318872c82b11ef99ba2d"
Sending message to backend { authToken: '2d2b74986ea7318872c82b11ef99ba2d',
  messageType: 'authenticate',
  clientId: '15230871291326689086' } { uri: 'http://localhost:8082/nodejs/message',
  body: 'messageJson=%7B%22authToken%22%3A%222d2b74986ea7318872c82b11ef99ba2d%22%2C%22messageType%22%3A%22authenticate%22%2C%22clientId%22%3A%2215230871291326689086%22%7D&serviceKey=foobar',
  headers: 
   { 'Content-Length': 179,
     'Content-Type': 'application/x-www-form-urlencoded' } }
Failed to parse authentication message: { stack: [Getter/Setter],
  arguments: [ 'ILLEGAL' ],
  type: 'unexpected_token',
  message: [Getter/Setter] }
Failed message string: undefined
getNodejsSessionIdsFromUid { uid: undefined,
  sessionIds: [ '993864384112155517', '15230871291326689086' ] }

Here's my config, generated by the included tool:

backendSettings = {
  "scheme":"http",
   "host":"localhost",
   "port":8080,
   "key":"\u002Fpath\u002Fto\u002Fkey\u002Ffile",
   "cert":"\u002Fpath\u002Fto\u002Fcert\u002Ffile",
   "resource":"\u002Fsocket.io",
   "publishUrl":"\u002Fnodejs\u002Fpublish",
   "serviceKey":"foobar",
   "backend":{
  "port":8082,
   "host":"localhost",
   "messagePath":"\u002Fnodejs\u002Fmessage"},
   "clientsCanWriteToChannels":false,
   "clientsCanWriteToClients":false,
   "extensions":"",
   "debug":true,
   "transports":[ "websocket",
   "flashsocket",
   "htmlfile",
   "xhr-polling",
   "jsonp-polling" ],
   "jsMinification":true,
   "jsEtag":true,
   "logLevel":1};

I'm using node -v
v0.4.11

robertdouglass’s picture

Status: Active » Fixed

I now believe that this is not a problem in the current .dev release. I had made a mistake in my configuration, putting wrong value for "host" for the Drupal site.

Perhaps there should be some targeted error reporting in the node console if it is calling out to a non-existent server?

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

slv_’s picture

Having a similar problem than the ones reported previously. Have tried everything I can think of right now, but no joy so far.

Authenticating client with key "d0139c6171652381382a5f78c795d659"
Sending message to backend { authToken: 'd0139c6171652381382a5f78c795d659',
  messageType: 'authenticate',
  clientId: '1461508548898200644' } { uri: 'http://drupal7.local:80/nodejs/message',
  body: 'messageJson=%7B%22authToken%22%3A%22d0139c6171652381382a5f78c795d659%22%2C%22messageType%22%3A%22authenticate%22%2C%22clientId%22%3A%221461508548898200644%22%7D&serviceKey=pass',
  headers: 
   { 'Content-Length': 176,
     'Content-Type': 'application/x-www-form-urlencoded' } }
Failed to parse authentication message: [SyntaxError: Unexpected token u]
Failed message string: undefined

Configuration file:

backendSettings = {
  "scheme":"http",
  "host":"127.0.0.1",
  "port":8080,
  "key":"/path/to/key/file",
  "cert":"/path/to/cert/file",
  "resource":"/socket.io",
  "publishUrl":"/nodejs/publish",
  "serviceKey":"pass",
  "backend":{
  "port":80,
  "host":"drupal7.local",
  "messagePath":"/nodejs/message"},
  "clientsCanWriteToChannels":false,
  "clientsCanWriteToClients":false,
  "extensions":"",
  "debug":true,
  "transports":["websocket",
  "flashsocket",
  "htmlfile",
  "xhr-polling",
  "jsonp-polling"],
  "jsMinification":true,
  "jsEtag":true,
  "logLevel":1};

Node -v:
v0.6.17

Any help would be really appreciated. Thanks!

slv_’s picture

Status: Closed (fixed) » Active
slv_’s picture

Status: Active » Closed (fixed)

Didn't find the actual problem, but redoing everything from scratch in a new site and a new nodejs server solved the issue, even though the configuration was exactly the same.

I change the status of the issue back to close(fixed)

codesidekick’s picture

Keeping the issue closed but if anybody else runs into this issue:

Make sure any modules you have that control user access using redirects don't run on the path nodejs/message.

  • Commit 1159da6 on 7.x-1.x, drupalconlondon, auth-refactor, 8.x-1.x, 8.x-1.x-head by beejeebus:
    #1236162: update example node.js config, s/authPath/messagePath/, thanks...
  • Commit 4efe47f on 7.x-1.x, drupalconlondon, auth-refactor, 8.x-1.x, 8.x-1.x-head by beejeebus:
    #1236162: fix authKey bug, we should be using serviceKey, thanks Gray...
  • Commit 3f29a66 on 7.x-1.x, drupalconlondon, auth-refactor, 8.x-1.x, 8.x-1.x-head by beejeebus:
    #1236162: don't try to use options in debug, use response instead,...
socialnicheguru’s picture

Issue summary: View changes

@interactivejunky are you saying that modules like redirect or global_redirect should always exclude 'nodejs/message'?

codesidekick’s picture

No idea, sorry, post was from too long ago.