node.js and wordpress sessions

February 2, 2017 on 11:27 am | In geeky | No Comments

For a leetle project, I needed a way to validate a wordpress session from node.js. WordPress uses a somewhat complicated session system, with HMACs and using part of password salt, and was unable to find a ready puzzle piece for the purpose. So I wrote my own.

The result is a javascript module. Sample usage:

var wps = require('wpsess');
var vdtor = new wps.Validator('/path/to/my/wp-config.php');
vdtor.validate('value_of_my_logged_in_cookie', function (err, username) {
    if (err)
        console.log('Authentication failed: ' + err);
        console.log('Logged in user: ' + username);

It is way from perfect, but it works well enough for me.

Powered by WordPress.
Entries and comments feeds. Valid XHTML and CSS. ^Top^