Class: FbGraph2::Auth::SignedRequest

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

Defined Under Namespace

Classes: VerificationFailed

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ SignedRequest

Returns a new instance of SignedRequest.



10
11
12
13
14
15
16
17
# File 'lib/fb_graph2/auth/signed_request.rb', line 10

def initialize(token)
  signature_str, @payload_str = token.split('.', 2)
  @signature = UrlSafeBase64.decode64 signature_str
  payload_json = UrlSafeBase64.decode64 @payload_str
  self.payload = MultiJson.load(payload_json).with_indifferent_access
rescue => e
  raise VerificationFailed.new 'Decode failed'
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



8
9
10
# File 'lib/fb_graph2/auth/signed_request.rb', line 8

def access_token
  @access_token
end

#payloadObject

Returns the value of attribute payload.



8
9
10
# File 'lib/fb_graph2/auth/signed_request.rb', line 8

def payload
  @payload
end

#userObject

Returns the value of attribute user.



8
9
10
# File 'lib/fb_graph2/auth/signed_request.rb', line 8

def user
  @user
end

Instance Method Details

#verify!(client) ⇒ Object

Raises:



19
20
21
22
23
# File 'lib/fb_graph2/auth/signed_request.rb', line 19

def verify!(client)
  signature = OpenSSL::HMAC.digest OpenSSL::Digest::SHA256.new, client.secret, @payload_str
  raise VerificationFailed.new('Verification failed') unless @signature == signature
  instantiate client
end