When trying to see the server stats, I noticed my server.js was writing into console:
Invalid service key "", expecting "GXZAYZjR7iDKzw4CcV9ZLYJQfDgWz8PQ"

My configuration was set to use service key of "GXZAYZjR7iDKzw4CcV9ZLYJQfDgWz8PQ". It was configured in UI provided by nodejs_config module.

I found out that the service key was saved into variable 'nodejs_config_serviceKey', not into variable 'nodejs_service_key' as nodejs_get_config() and nodejs_is_valid_service_key() expects.

However, after fixing that I found out also that nodejs server expect the service key to be provided in HTTP headers. Server stats callback function nodejs_get_server_stats() calls for nodejs server without headers at all leaving the service key not be provided at all to nodejs server.

CommentFileSizeAuthor
#9 nodejs-server-vars-1260974-9.patch715 bytescarnau

Comments

Anonymous’s picture

Status: Active » Fixed

closing, the server stats code has been removed, and bugs in the config UI module fixed during the code sprint at drupalcon london.

Status: Fixed » Closed (fixed)

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

imiksu’s picture

Status: Closed (fixed) » Active

I installed once again (7.x-1.0-beta6) and still having same issue (getting console.log about service key). Is it related to my Node.js version? I'm using v0.4.11.

imiksu’s picture

Title: Invalid service key "", expecting "..." » Server keeps saying: Invalid service key "", expecting "..."
Version: 7.x-1.0-beta3 » 7.x-1.0-beta6
Anonymous’s picture

Version: 7.x-1.0-beta6 » 7.x-1.x-dev
Status: Active » Fixed

yep, confirmed, fixed with this commit:

http://drupalcode.org/project/nodejs.git/commit/952f867

danielm’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev

Can be put also in the version 6X

carnau’s picture

Status: Fixed » Active

Changed status, 'because for 6.x version it's not fixed.

Also, changing these lines don't affect the bug and is still reproducible(in D6). I think JSON is empty.

julien’s picture

Just commited on the 6.x branch. #0ac5049
@carnau after this commit i'm not able to reproduce this issue, but after reading up @ #1, can you confirm me that it's fixed?

carnau’s picture

StatusFileSize
new715 bytes

Yes, I'm still having this issue. I'll try to trace it.

Also, I provide a patch because in the last version, host and port nodejs variables in nodejs_get_config() are wrong, and always is using default values.

carnau’s picture

Well, I see the problem here.

In nodejs.module we get the serviceKey value like this:

'serviceKey' => variable_get('nodejs_config_serviceKey', ''),

This variable isn't from this module, but nodejs_config. So, if you don't enable this extra module and also fill the admin form, it always return blank because the variable not exists.

Also, I found another bug in nodejs_config admin form. The first value says:

Specify the host name or IP address that the node.js server should listen on. Leave blank to listen for any host name. Otherwise, the server will only respond to names that match the IP address given (or resolved from the given name).

So, if you want to leave this field blank you can't, because the required option is TRUE. Should be FALSE.

carnau’s picture

One question about this. I'm getting this error on nodejs side :

Backend authentication url not found.

If I enter the url nodejs/message with my browser, it shows:

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

I found that nodejs_message_handler() function is who returns this message:

  if (!isset($_POST['serviceKey']) || !nodejs_is_valid_service_key($_POST['serviceKey'])) {
    drupal_json(array('error' => 'Invalid service key.'));
    exit();
  }

So, the question is, ¿Where $_POST['serviceKey'] is initialized? I dumped it but returns NULL.

julien’s picture

Are you using the 6.x-1.x-dev branch or the 6.x-1.0 ?
I confirm that to use the service key feature, you need to set it correctly in both the js config file and also in the Drupal backend settings form.
if you get this error from the server:

Backend authentication url not found.

It may come from a wrong config file, like your drupal hostname.

julien’s picture

Assigned: Unassigned » julien
carnau’s picture

Yes, it was a bad configuration file, damn virtualhosts... It's working now.

Now I'm using the dev version, and I can't reproduce the 'Invalid service key' message on the nodejs side, so I assume it's working now.

I'm still working on find why I recive the "{ "error": "Invalid service key." }" if I enter directly from the browser to the 'nodejs/message' path.

Anonymous’s picture

Status: Active » Closed (works as designed)

the reason you recieve that if you got to 'nodejs/message' is because things are working as designed.

the point of the service key is to secure the back-channel between the drupal server and node.js server process.

sahithya06’s picture

Hello Carnauro

What steps did you take to resolve the Invalid Service Key issue? I am able to see the messages being pushed to the server in the logs, but am unable to see them inside the chatroom and I am wondering if it is because of this error.

I have maintained the same service key in the nodejs config file and in drupal backend settings.

Would appreciate a quick reply!

Thanks,
Sahithya

sahithya06’s picture

Hi beejeebus

I am getting the "Invalid Service Key" error and have been unable to resolve it. I have maintained the service key in settings.php as well.
My configurations are as below :

settings = {
scheme: 'http',
port: 5000,
host: '127.0.0.1',
resource: '/socket.io',
serviceKey: 'xyz',
backend: {
port: 80,
host: '127.0.0.1',
scheme: 'http',
basePath: '',
messagePath: '/nodejs/message/'
},
debug: false,
sslKeyPath: '',
sslCertPath: '',
sslCAPath: '',
baseAuthPath: '/nodejs/',
publishUrl: 'publish',
kickUserUrl: 'user/kick/:uid',
logoutUserUrl: 'user/logout/:authtoken',
addUserToChannelUrl: 'user/channel/add/:channel/:uid',
removeUserFromChannelUrl: 'user/channel/remove/:channel/:uid',
addChannelUrl: 'channel/add/:channel',
removeChannelUrl: 'channel/remove/:channel',
setUserPresenceListUrl: 'user/presence-list/:uid/:uidList',
addAuthTokenToChannelUrl: 'authtoken/channel/add/:channel/:uid',
removeAuthTokenFromChannelUrl: 'authtoken/channel/remove/:channel/:uid',
toggleDebugUrl: 'debug/toggle',
contentTokenUrl: 'content/token',
publishMessageToContentChannelUrl: 'content/token/message',
extensions: [],
clientsCanWriteToChannels: false,
clientsCanWriteToClients: false,
transports: ['websocket', 'flashsocket', 'htmlfile', 'xhr-polling', 'jsonp-polling'],
jsMinification: true,
jsEtag: true,
logLevel: 1
};

It would be great if you could let me know what exactly could be causing this issue. I am able to see that the messages are being pushed correctly through the logs, however, I am unable to view the messages inside the chatroom. Are the issues tied?

Would really appreciate a quick reply!

Thanks,
Sahithya

Ari Gold’s picture

Issue summary: View changes

I needed to use quotes:

"serviceKey":"my service key",

  • Commit 952f867 on 7.x-1.x, auth-refactor, 8.x-1.x, 8.x-1.x-head by beejeebus:
    #1260974: fix invalid service key bug.