twilio/twilio-salesforce — pull request #7 by metadaddy-sfdc (2012-03-01 01:31:25+00:00)
Title: Added signature validation

Sample usage:

@RestResource(urlMapping='/twiliosms')
global class TwilioEndpoint {
@HttpPost
global static void incomingSMS() {
String expectedSignature =
RestContext.request.headers.get('X-Twilio-Signature');
String url = 'https://' + RestContext.request.headers.get('Host') +
'/services/apexrest' + RestContext.request.requestURI;
Map params = RestContext.request.params;

// Validate sender
if (!TwilioAPI.getDefaultClient().validateRequest(expectedSignature, url, params)) {
RestContext.response.statusCode = 403;
return;
}

insert new SMS__c(Body__c = params.get('Body'),
From__c = params.get('From'),
To__c = params.get('To'));
}
}