Sha256: 3e8c6d8cda9ec12f5cacc4a5ad7ebbe93755b308ff1b92e8cd8637f9d7c9f8fa

Contents?: true

Size: 788 Bytes

Versions: 5

Compression:

Stored size: 788 Bytes

Contents

module FBGraph
  
  class Canvas
    
    class << self
      def parse_signed_request(secret_id,request)
        encoded_sig, payload = request.split('.', 2)
        sig = urldecode64(encoded_sig)
        data = JSON.parse(urldecode64(payload))
        if data['algorithm'].to_s.upcase != 'HMAC-SHA256'
          raise "Bad signature algorithm: %s" % data['algorithm']
        end
        expected_sig = OpenSSL::HMAC.digest('sha256', secret_id, payload)
        if expected_sig != sig
          raise "Bad signature"
        end
        data
      end
      
      private
      
      def urldecode64(str)
        encoded_str = str.tr('-_', '+/')
        encoded_str += '=' while !(encoded_str.size % 4).zero?
        Base64.decode64(encoded_str)
      end
    end  
    
  end
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fbgraph-1.10.1 lib/fbgraph/canvas.rb
fbgraph-1.10.0 lib/fbgraph/canvas.rb
fbgraph-1.9.0 lib/fbgraph/canvas.rb
fbgraph-1.8.4 lib/fbgraph/canvas.rb
fbgraph-1.8.3 lib/fbgraph/canvas.rb