Class: FbGraph::Auth

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

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.



7
8
9
10
11
12
13
14
# File 'lib/fb_graph/auth.rb', line 7

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.



5
6
7
# File 'lib/fb_graph/auth.rb', line 5

def access_token
  @access_token
end

#clientObject

Returns the value of attribute client.



5
6
7
# File 'lib/fb_graph/auth.rb', line 5

def client
  @client
end

#userObject

Returns the value of attribute user.



5
6
7
# File 'lib/fb_graph/auth.rb', line 5

def user
  @user
end

Instance Method Details



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fb_graph/auth.rb', line 16

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