Class: FacebookRegistration::SignedRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/signed_request.rb

Class Method Summary collapse

Class Method Details

.parse(params, secret_key = nil) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rails/signed_request.rb', line 8

def self.parse(params, secret_key=nil)
  if params.is_a?(Hash)
    signed_request = (params.delete('signed_request') || params.delete(:signed_request))
  else
    signed_request  = params
  end
  unless signed_request
    raise "Missing signed_request param"
  end
			unless secret_key
raise "Missing Facebook secret key"
			end
  signature, signed_params = signed_request.split('.')
  unless signed_request_is_valid?(secret_key, signature, signed_params)
    raise "Invalid signature"
  end
  signed_params = Yajl::Parser.new.parse(base64_url_decode(signed_params))
  return signed_params
end