Comparing version 1.4.0 to 1.5.0
@@ -10,2 +10,3 @@ /** | ||
var crypto = require('crypto'), | ||
_ = require('underscore'), | ||
RestClient = require('./RestClient'); | ||
@@ -35,2 +36,3 @@ | ||
}); | ||
var computed = crypto.createHmac('sha1', authToken).update(url).digest('Base64'); | ||
return twilioHeader === crypto.createHmac('sha1', authToken).update(url).digest('Base64'); | ||
@@ -47,7 +49,93 @@ }; | ||
initializer.validateExpressRequest = function(request, authToken) { | ||
var url = request.protocol + '://' + request.headers.host + request.url; | ||
var url = request.protocol + '://' + request.headers.host + request.originalUrl; | ||
return initializer.validateRequest(authToken, request.header('X-Twilio-Signature'), url, request.body||{}); | ||
}; | ||
/** | ||
Express middleware to accompany a Twilio webhook. Provides Twilio | ||
request validation, and makes the response a little more friendly for our | ||
TwiML generator. Request validation requires the express.urlencoded middleware | ||
to have been applied (e.g. app.use(express.urlencoded()); in your app config). | ||
Options: | ||
- validate: {Boolean} whether or not the middleware should validate the request | ||
came from Twilio. Default true. If the request does not originate from | ||
Twilio, we will return a text body and a 403. If there is no configured | ||
auth token and validate=true, this is an error condition, so we will return | ||
a 500. | ||
- includeHelpers: {Boolean} add helpers to the response object to improve support | ||
for XML (TwiML) rendering. Default true. | ||
Returns a middleware function. | ||
Examples: | ||
var webhookMiddleware = twilio.webhook(); | ||
var webhookMiddleware = twilio.webhook('asdha9dhjasd'); //init with auth token | ||
var webhookMiddleware = twilio.webhook({ | ||
validate:false // don't attempt request validation | ||
}); | ||
*/ | ||
initializer.webhook = function() { | ||
var opts = { | ||
validate:true, | ||
includeHelpers:true | ||
}; | ||
// Process arguments | ||
var tokenString; | ||
for (var i = 0, l = arguments.length; i<l; i++) { | ||
var arg = arguments[i]; | ||
if (typeof arg === 'string') { | ||
tokenString = arg; | ||
} else { | ||
opts = _.extend(opts, arg); | ||
} | ||
} | ||
// set auth token from input or environment variable | ||
opts.authToken = tokenString ? tokenString : process.env.TWILIO_AUTH_TOKEN; | ||
// Create middleware function | ||
return function hook(request, response, next) { | ||
// Add helpers, unless disabled | ||
if (opts.includeHelpers) { | ||
var oldSend = response.send; | ||
response.send = function() { | ||
// This is a special TwiML-aware version of send. If we detect | ||
// A twiml response object, we'll set the content-type and | ||
// automatically call .toString() | ||
if (arguments.length == 1 && arguments[0].legalNodes) { | ||
response.type('text/xml'); | ||
oldSend.call(response,arguments[0].toString()); | ||
} else { | ||
// Continue with old version of send | ||
oldSend.apply(response,arguments); | ||
} | ||
}; | ||
} | ||
// Do validation if requested | ||
if (opts.validate) { | ||
// Check for a valid auth token | ||
if (!opts.authToken) { | ||
console.error('[Twilio]: Error - Twilio auth token is required for webhook request validation.'); | ||
response.type('text/plain'); | ||
response.send(500, 'Webhook Error - we attempted to validate this request without first configuring our auth token.'); | ||
} else { | ||
// Check that the request originated from Twilio | ||
valid = initializer.validateExpressRequest(request,opts.authToken); | ||
if (valid) { | ||
next(); | ||
} else { | ||
response.type('text/plain'); | ||
return response.send(403, 'Twilio Request Validation Failed.'); | ||
} | ||
} | ||
} else { | ||
next(); | ||
} | ||
}; | ||
}; | ||
//public module interface is a function, which passes through to RestClient constructor | ||
module.exports = initializer; |
@@ -110,4 +110,6 @@ /** | ||
'Accept':'application/json', | ||
'Accept-Charset': 'utf-8', | ||
'User-Agent':'twilio-node/' + moduleinfo.version | ||
}; | ||
options.timeout = 31000; | ||
@@ -114,0 +116,0 @@ // Manually create POST body if there's a form object. Sadly, request |
@@ -23,7 +23,5 @@ var _ = require('underscore'); | ||
text = arg; | ||
} | ||
else if (typeof arg === 'function') { | ||
} else if (typeof arg === 'function') { | ||
builder = arg; | ||
} | ||
else { | ||
} else { | ||
attributes = arg; | ||
@@ -107,4 +105,3 @@ } | ||
buffer.push(esc(this.text)); | ||
} | ||
else { | ||
} else { | ||
//process child tags | ||
@@ -111,0 +108,0 @@ for (var i = 0, l = this.children.length; i < l; i++) { |
{ | ||
"name": "twilio", | ||
"description": "A Twilio helper library", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"author": "Kevin Whinnery <kevin.whinnery@gmail.com>", | ||
@@ -21,3 +21,3 @@ "contributors": [ | ||
"dependencies": { | ||
"request": "2.x", | ||
"request": "2.27.x", | ||
"underscore": "1.x", | ||
@@ -28,5 +28,3 @@ "jwt-simple": "0.1.x", | ||
"devDependencies": { | ||
"express": "2.x", | ||
"connect": "2.x", | ||
"ejs": "0.8.x" | ||
"express": "3.x" | ||
}, | ||
@@ -33,0 +31,0 @@ "scripts": { |
# twilio-node | ||
[![NPM](https://nodei.co/npm/twilio.png?downloads=true&stars=true)](https://nodei.co/npm/twilio/) | ||
[![Build Status](https://travis-ci.org/twilio/twilio-node.png?branch=master)](https://travis-ci.org/twilio/twilio-node) | ||
@@ -8,1 +10,33 @@ | ||
[http://twilio.github.com/twilio-node/](http://twilio.github.com/twilio-node/) | ||
## Contributing | ||
Bug fixes, docs, and enhancements welcome! If you're not familiar with the GitHub pull request/contribution process, [this is a nice tutorial](http://gun.io/blog/how-to-github-fork-branch-and-pull-request/). | ||
#### Getting Started | ||
Fork and clone the repository. Install dependencies with: | ||
npm install | ||
Run the existing test spec with `npm test`. This requires `jasmine-node` to be installed globally via npm: | ||
[sudo] npm install -g jasmine-node | ||
To run just one specific test file instead of the whole suite, provide a JavaScript regular expression that will match your spec file's name, like: | ||
jasmine-node spec -m .\*accounts.\* | ||
To run live tests (such as `client.live.spec.js`) against your [Twilio account](https://www.twilio.com/user/account), you will need to create a local configuration file. In the project root directory, do the following: | ||
* `cp config.sample.js config.js` | ||
* Edit `config.js` with your account information, a Twilio number, and your own mobile number | ||
* Run the live tests | ||
#### Contributing Code | ||
In your fork, create a new feature/bug fix branch, [per the guide listed above](http://gun.io/blog/how-to-github-fork-branch-and-pull-request/). Write a Jasmine test spec for your new feature or bug fix, and hack until it passes! Submit a pull request, and it will be reviewed as soon as possible. | ||
#### Contributing Docs | ||
Right now, the docs are maintained in static HTML in the `gh-pages` branch of this repository. We hope to switch to a more robust documentation system soon, but for the time being, you can make documentation changes by editing [index.html](https://github.com/twilio/twilio-node/blob/gh-pages/index.html) directly. | ||
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
55120
1
29
1047
42
9
+ Addedasn1@0.1.11(transitive)
+ Addedassert-plus@0.1.5(transitive)
+ Addedasync@0.9.2(transitive)
+ Addedaws-sign@0.3.0(transitive)
+ Addedboom@0.4.2(transitive)
+ Addedcombined-stream@0.0.7(transitive)
+ Addedcookie-jar@0.3.0(transitive)
+ Addedcryptiles@0.2.2(transitive)
+ Addedctype@0.5.3(transitive)
+ Addeddelayed-stream@0.0.5(transitive)
+ Addedforever-agent@0.5.2(transitive)
+ Addedform-data@0.1.4(transitive)
+ Addedhawk@1.0.0(transitive)
+ Addedhoek@0.9.1(transitive)
+ Addedhttp-signature@0.10.1(transitive)
+ Addedmime@1.2.11(transitive)
+ Addednode-uuid@1.4.8(transitive)
+ Addedoauth-sign@0.3.0(transitive)
+ Addedqs@0.6.6(transitive)
+ Addedrequest@2.27.0(transitive)
+ Addedsntp@0.2.4(transitive)
+ Addedtunnel-agent@0.3.0(transitive)
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.9.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)
Updatedrequest@2.27.x