Class: FbGraph2::Auth::SignedRequest
- Inherits:
-
Object
- Object
- FbGraph2::Auth::SignedRequest
- Defined in:
- lib/fb_graph2/auth/signed_request.rb
Defined Under Namespace
Classes: VerificationFailed
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(token) ⇒ SignedRequest
constructor
A new instance of SignedRequest.
- #verify!(client) ⇒ Object
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_token ⇒ Object
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 |
#payload ⇒ Object
Returns the value of attribute payload.
8 9 10 |
# File 'lib/fb_graph2/auth/signed_request.rb', line 8 def payload @payload end |
#user ⇒ Object
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
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 |