The authentication code example for node.js on pusher.com does not work.
var express = require( 'express' );
var Pusher = require( 'pusher' );
var app = express( express.logger() );
app.use( express.bodyParser() );
var pusher = new Pusher( { appId: APP_ID, key: APP_KEY, secret: APP_SECRET } );
app.post( '/pusher/auth', function( req, res ) {
var socketId = req.body.socket_id;
var channel = req.body.channel_name;
var auth = pusher.auth( socketId, channel );
res.send( auth );
} );
var port = process.env.PORT || 5000;
app.listen( port );
I get the following error returned. How do I resolve this?
TypeError: Object #<Pusher> has no method 'auth'
Ah, for whatever reason they must have changed the method name from auth to authenticate.
Here is my fixed version of their example. Note line 4 pusher.authenticate
app.post( '/pusher/auth', function( req, res ) {
var socketId = req.body.socket_id;
var channel = req.body.channel_name;
var auth = pusher.authenticate( socketId, channel );
res.send( auth );
} );
Here's what I see in my pusher.js file. Locally, in my node_modules:
/** Returns a signature for given socket id, channel and socket data.
*
* @param {String} socketId socket id
* @param {String} channel channel name
* @param {Object} [data] additional socket data
* @returns {String} authentication signature
*/
Pusher.prototype.authenticate = function(socketId, channel, data) {
return auth.getSocketSignature(this.config.token, channel, socketId, data);
};
Pusher.js package.json
{
"name": "pusher",
"description": "Node.js client to interact with the Pusher REST API",
"version": "1.0.0",
"author": {
"name": "Pusher",
"email": "support@pusher.com"
},