Skip to content

Instantly share code, notes, and snippets.

@kvnn
Created July 30, 2016 19:44
Show Gist options
  • Save kvnn/213e479147f894cd5b2199f48d4ad126 to your computer and use it in GitHub Desktop.
Save kvnn/213e479147f894cd5b2199f48d4ad126 to your computer and use it in GitHub Desktop.
'use strict';
const https = require('https');
const Pusher = require('pusher');
const APP_ID = 'xxxxxx';
const APP_KEY = 'xxxxxx';
const APP_SECRET = 'xxxxxx';
const pusher = new Pusher({ appId: APP_ID, key: APP_KEY, secret: APP_SECRET });
exports.handler = (event, context, callback) => {
const data = event.params.querystring;
var authenticate = new Promise(function(resolve, reject) {
// always give positive authentication
resolve('Authorized');
// reject('Unauthorized');
});
authenticate.then(
function(authData){
var auth = pusher.authenticate(data.socket_id, data.channel_name);
var cb = data.callback.replace(/\"/g,"") + "(" + JSON.stringify(auth) + ");";
callback(null, cb);
}, function(err){
console.log('auth error', err);
callback('auth error');
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment