Class: FbGraph::Auth

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

Defined Under Namespace

Classes: Cookie, SignedRequest, 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
15
16
# 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 => ROOT_URL
  ))
  if options[:cookie]
    from_cookie options[:cookie]
  elsif options[:signed_request]
    from_signed_request options[:signed_request]
  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

#dataObject

Returns the value of attribute data.



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

def data
  @data
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

#authorize_uri(canvas_uri, options = {}) ⇒ Object



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

def authorize_uri(canvas_uri, options = {})
  endpoint = URI.parse SignedRequest::OAUTH_DIALOG_ENDPOINT
  params = options.merge(
    :client_id => self.client.id,
    :redirect_uri => canvas_uri
  )
  params[:scope] = Array(params[:scope]).join(',') if params[:scope].present?
  endpoint.query = params.to_query
  endpoint.to_s
end

#authorized?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/fb_graph/auth.rb', line 18

def authorized?
  self.access_token.present?
end


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

def from_cookie(cookie)
  data = Cookie.parse(self.client, cookie)
  self.access_token = build_access_token(data)
  self.user = User.new(data[:uid], :access_token => self.access_token)
  self.data = data
  self
end

#from_signed_request(signed_request) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/fb_graph/auth.rb', line 41

def from_signed_request(signed_request)
  data = SignedRequest.verify(self.client, signed_request)
  if data[:oauth_token]
    self.access_token = build_access_token(data)
    self.user = User.new(data[:user_id], :access_token => self.access_token)
  end
  self.data = data
  self
end