socializr
Advanced tools
Comparing version 0.0.3 to 0.0.4
var stream = require('stream') | ||
, util = require('util') | ||
, crypto = require('crypto') | ||
, request = require('superagent') | ||
@@ -19,17 +20,19 @@ , oauth1a = require('../auth/oauth1a') | ||
function PubSubConnection(){ | ||
function PubSubConnection(secret){ | ||
this.appSecret = secret; | ||
}; | ||
PubSubConnection.prototype.verifyToken = function(){ | ||
return this.verifyToken = oauth1a.makeNonce(); | ||
}; | ||
PubSubConnection.prototype.verify = function(){ | ||
PubSubConnection.prototype.validateSignature = function(data){ | ||
var decipher = crypto.createDecipher('AES-128-CBC-HMAC-SHA1', this.appSecret); | ||
decipher.update('sha1='+data, 'hex'); | ||
return decipher.final('utf8'); | ||
}; | ||
PubSubConnection.prototype.verify = function(){ | ||
}; | ||
function Facebook(opts){ | ||
@@ -47,2 +50,4 @@ | ||
this.subscribedFields = FB_DEFAULT_PAGE_SUBSCRIBED_FIELDS; | ||
this._pubsubConnections = {}; | ||
}; | ||
@@ -92,2 +97,8 @@ util.inherits(Facebook, Transform); | ||
Facebook.prototype.subscribe = function(token,cb){ | ||
var conn = new PubSubConnection( this.appSecret) | ||
, verify_token = conn.verifyToken() | ||
; | ||
this._pubsubConnections[ verify_token] = conn; | ||
this._graphRequest( this.appId + '/subscriptions', 'POST', { | ||
@@ -97,3 +108,3 @@ object: 'page', | ||
fields: this.subscribedFields.join(','), | ||
verify_token: oauth1a.makeNonce(), | ||
verify_token: verify_token, | ||
access_token: this.appAccessToken | ||
@@ -109,2 +120,3 @@ },function(res){ | ||
return function(req, res, next){ | ||
console.log(res.get('X-Hub-Signature')); | ||
res.pipe( this); | ||
@@ -115,2 +127,6 @@ next(); | ||
Facebook.prototype.isVerifyToken = function(token){ | ||
return this._pubsubConnections.hasOwnProperty( token); | ||
}; | ||
Facebook.prototype.verify = function(){ | ||
@@ -122,3 +138,7 @@ var _this = this; | ||
res.send(); | ||
if( _this.isVerifyToken( req.query['hub.verify_token'])){ | ||
res.send(req.query['hub.challenge']); | ||
}else { | ||
res.send('false'); | ||
} | ||
next(); | ||
@@ -125,0 +145,0 @@ }; |
{ | ||
"name": "socializr", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Read data streams from several social networks.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
26459
1084