Class: FbGraph::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/fb_graph/auth.rb,
lib/fb_graph/auth/cookie.rb

Overview

Parse & verify facebook auth cookie

Used with Facebook JavaScript SDK

app = FbGraph::Auth.new(APP_ID, APP_SECRET)
app.from_cookie(cookie_hash)
auth.access_token
# => OAuth2::AccessToken (not String!)
auth.user # only initialized
auth.user.fetch # fetch whole profile

This method is called automatically if cookie is given when initializing

auth = FbGraph::Auth.new(APP_ID, APP_SECRET, :cookie => {..})
auth.access_token # already parsed

Defined Under Namespace

Classes: Cookie, VerificationFailed

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id, client_secret, options = {}) ⇒ Auth

Returns a new instance of Auth.



22
23
24
25
26
27
28
29
# File 'lib/fb_graph/auth.rb', line 22

def initialize(client_id, client_secret, options = {})
  @client = OAuth2::Client.new(client_id, client_secret, options.merge(
    :site => FbGraph::ROOT_URL
  ))
  if options[:cookie].present?
    from_cookie(options[:cookie])
  end
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



20
21
22
# File 'lib/fb_graph/auth.rb', line 20

def access_token
  @access_token
end

#clientObject

Returns the value of attribute client.



20
21
22
# File 'lib/fb_graph/auth.rb', line 20

def client
  @client
end

#userObject

Returns the value of attribute user.



20
21
22
# File 'lib/fb_graph/auth.rb', line 20

def user
  @user
end

Instance Method Details



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fb_graph/auth.rb', line 31

def from_cookie(cookie)
  cookie = FbGraph::Auth::Cookie.parse(self.client, cookie)
  self.access_token = OAuth2::AccessToken.new(
    self.client,
    cookie[:access_token],
    cookie[:refresh_token],
    cookie[:expires]
  )
  self.user = FbGraph::User.new(cookie[:uid], :access_token => self.access_token)
  self
end