Sha256: 4c8c075f92a9f1851abd1171f2e921fefc4ba600f25cc2087b2269d4b1ee8836

Contents?: true

Size: 719 Bytes

Versions: 17

Compression:

Stored size: 719 Bytes

Contents

# FROM https://github.com/nsanta/fbgraph/blob/master/lib/fbgraph/canvas.rb

def parse_signed_request(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', FB[:secret], payload)
        if expected_sig != sig
          raise "Bad signature"
        end
        data
      end
      
    
def urldecode64(str)
  encoded_str = str.tr('-_', '+/')
  encoded_str += '=' while !(encoded_str.size % 4).zero?
  Base64.decode64(encoded_str)
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
fbdoorman-0.9.3 lib/request_parser.rb
fbdoorman-0.9.2 lib/request_parser.rb
fbdoorman-0.9.1 lib/request_parser.rb
fbdoorman-0.9.0 lib/request_parser.rb
fbdoorman-0.8.0.98 lib/request_parser.rb
fbdoorman-0.8.0.97 lib/request_parser.rb
fbdoorman-0.8.0.95 lib/request_parser.rb
fbdoorman-0.8.0.94 lib/request_parser.rb
fbdoorman-0.8.0.93 lib/request_parser.rb
fbdoorman-0.8.0.92 lib/request_parser.rb
fbdoorman-0.8.0.91 lib/request_parser.rb
fbdoorman-0.8.0.9 lib/request_parser.rb
fbdoorman-0.8.0.8 lib/request_parser.rb
fbdoorman-0.8.0.7 lib/request_parser.rb
fbdoorman-0.8.0.6 lib/request_parser.rb
fbdoorman-0.8.0.5 lib/request_parser.rb
fbdoorman-0.8.0.4 lib/request_parser.rb