Skip to content

Instantly share code, notes, and snippets.

@chimame
chimame / twilio_base_controller.rb
Created January 27, 2015 03:25
Twilio Request Validation for Rails
class TwilioBaseController < ActionController::Base
before_filter :authenticate_twilio_request
private
def authenticate_twilio_request
twilio_sig = request.headers['HTTP_X_TWILIO_SIGNATURE']
render :xml => (Twilio::TwiML::Response.new {|r| r.Hangup}).text and return if twilio_sig.blank?
twilio_validator = Twilio::Util::RequestValidator.new("YOUR TWILIO AUTH TOKEN")
params_for_auth = (request.post? ? env['rack.request.form_hash'] : {})