I have a setup where we are using Redis for persistent session caching using the session_proxy module. We have tested this and works fine.

Now, when using nodejs with this setup the authentication seems to be a problem.

/**
 * Default Node.js auth check callback implementation.
 */
function nodejs_auth_check_callback($auth_token) {
  $sql = "SELECT uid FROM {sessions} WHERE MD5(sid) = :auth_key OR MD5(ssid) = :auth_key";
  return db_query($sql, array(':auth_key' => $auth_token))->fetchField();
}

Here we are fetching the uid from sessions table and then subsequent code loads the user object via user_load and magic happens. I can confirm that this works fine when I dont use Redis for sessions and instead use Drupal's default sessions table for sessions.

But in case Redis is caching sessions, this query obviously fails and the subsequent code works as if the user id 0 and this messes up everything.

While I dont expect every Contrib module which queries session table to factor this case, I would really appreciate some help here. Is there a way I can query redis directly for fetching the uid based on auth token ?

Thanks,
Swarad

Comments

swarad07 created an issue. See original summary.

swarad07’s picture

Issue summary: View changes
raj.chourasia’s picture

Anonymous’s picture

Status: Active » Closed (works as designed)

have a look at the start of nodejs_authcheck() function:

/**
 * Checks the given key to see if it matches a valid session.
 */
function nodejs_auth_check($message) {
  $nodejs_auth_check_callback = variable_get('nodejs_auth_check_callback', 'nodejs_auth_check_callback');
  if (!function_exists($nodejs_auth_check_callback)) {
    throw new Exception("No nodejs_auth_check callback found - looked for '$nodejs_auth_check_callback'.");
  }
  $uid = $nodejs_auth_check_callback($message['authToken']);

you should be able to override the session behaviour by putting this in settings.php:

$conf['nodejs_auth_check_callback'] = 'my_redis_auth_callback';

reopen this issue if that doesn't work for you.