DigiLord
DigiLord

Reputation: 1014

Pusher Authentication with Meteor

Is there a way to setup pusher authentication for private channels using Meteor? I looked in Atmosphere for a pusher package and didn't see one.

Upvotes: 1

Views: 359

Answers (1)

DigiLord
DigiLord

Reputation: 1014

After some digging the solution I found was not very difficult to implement. Here are the steps.

  1. mrt add npm
  2. Add "pusher": "0.1.3" to packages.json
  3. Add the following code block to a file INSIDE the server directory of your project. Be sure to change the appId, key, and secret to be the correct ones for your app.

if (Meteor.isServer) {
  var Pusher = Meteor.require('pusher');
  var pusher = new Pusher( { appId: '12345', key: 'keytext', secret: 'secrettext' } );
  Meteor.Router.add('/pusher/auth','POST', function(){
    var req = this.request;
    var res = this.response;
    var socketId = req.body.socket_id;
    var channel = req.body.channel_name;
    var auth = pusher.auth( socketId, channel );
    res.write(JSON.stringify(auth));
  })
}

Upvotes: 2

Related Questions