Comparing version 0.7.0 to 0.7.1
@@ -9,4 +9,6 @@ /** | ||
var RestClient = require('./RestClient'); | ||
var crypto = require('crypto'), | ||
RestClient = require('./RestClient'); | ||
//Shorthand to automatically create a RestClient | ||
function initializer(sid,tkn) { | ||
@@ -16,2 +18,3 @@ return new RestClient(sid, tkn); | ||
//Main functional components of the Twilio module | ||
initializer.RestClient = RestClient; | ||
@@ -21,3 +24,30 @@ initializer.Capability = require('./Capability'); | ||
/** | ||
Utility function to validate an incoming request is indeed from Twilio | ||
@param {string} authToken - The auth token, as seen in the Twilio portal | ||
@param {string} twilioHeader - The value of the X-Twilio-Signature header from the request | ||
@param {string} url - The full URL (with query string) you configured to handle this request | ||
@param {object} params - the parameters sent with this request | ||
*/ | ||
initializer.validateRequest = function(authToken, twilioHeader, url, params) { | ||
Object.keys(params).sort().forEach(function(key, i) { | ||
url = url + key + params[key]; | ||
}); | ||
return twilioHeader === crypto.createHmac('sha1', authToken).update(url).digest('Base64'); | ||
}; | ||
/** | ||
Utility function to validate an incoming request is indeed from Twilio (for use with express). | ||
adapted from https://github.com/crabasa/twiliosig | ||
@param {object} request - An expressjs request object (http://expressjs.com/api.html#req.params) | ||
@param {string} authToken - The auth token, as seen in the Twilio portal | ||
*/ | ||
initializer.validateExpressRequest = function(request, authToken) { | ||
var url = request.protocol + '://' + request.headers.host + request.url; | ||
return initializer.validateRequest(authToken, request.header('X-Twilio-Signature'), url, request.body); | ||
}; | ||
//public module interface is a function, which passes through to RestClient constructor | ||
module.exports = initializer; |
{ | ||
"name":"twilio", | ||
"description":"A Twilio helper library", | ||
"version":"0.7.0", | ||
"version":"0.7.1", | ||
"author":"Kevin Whinnery <kevin.whinnery@gmail.com>", | ||
@@ -6,0 +6,0 @@ "contributors":[ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63643
33
1237