Instantly share code, notes, and snippets.

Embed
What would you like to do?
'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