Sha256: e3bc5673a5d7ac2068bf52750c0cf056957211ad2226ea4510a2cf392baf4edf

Contents?: true

Size: 510 Bytes

Versions: 3

Compression:

Stored size: 510 Bytes

Contents

module Twilio
  module Util
    class RequestValidator

      def initialize(auth_token)
        @auth_token = auth_token
      end

      def validate(url, params, signature)
        expected = build_signature_for url, params
        expected == signature
      end

      def build_signature_for(url, params)
        data = url + params.sort.to_s
        digest = OpenSSL::Digest::Digest.new('sha1')
        Base64.encode64(OpenSSL::HMAC.digest(digest, @auth_token, data)).strip
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
twilio-ruby-3.1.1 lib/twilio-ruby/util/request_validator.rb
twilio-ruby-3.1.0 lib/twilio-ruby/util/request_validator.rb
twilio-ruby-3.0.0 lib/twilio-ruby/util/request_validator.rb