Class: FBGraph::Authorization

Inherits:
Object
  • Object
show all
Defined in:
lib/fbgraph/authorization.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Authorization



5
6
7
# File 'lib/fbgraph/authorization.rb', line 5

def initialize(client)
  @client = client
end

Instance Method Details

#authorize_url(params = {}) ⇒ Object



9
10
11
12
# File 'lib/fbgraph/authorization.rb', line 9

def authorize_url(params = {})
  params = { :redirect_uri => FBGraph.config[:canvas_url] }.merge(params)
  @client.oauth_client.auth_code.authorize_url(params)
end

#process_callback(code, options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/fbgraph/authorization.rb', line 15

def process_callback(code, options = {})
  # HACK(pwnall): :parse => :query is added because Facebook's tarded OAuth
  #               endpoint returns ContentType: text/plain instead of
  #               application/x-www-form-urlencoded
  options = { :redirect_uri => FBGraph.config[:canvas_url],
              :parse => :query }.merge(options)
  @client.auth = @client.oauth_client.auth_code.get_token(code, options)
  @client.access_token = @client.auth.token
end

#upgrade_session!(key) ⇒ Object



25
26
27
28
# File 'lib/fbgraph/authorization.rb', line 25

def upgrade_session!(key)
  token = upgrade_session_keys(key).first
  @client.access_token = token
end

#upgrade_session_keys(*keys) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/fbgraph/authorization.rb', line 30

def upgrade_session_keys(*keys)
  tokens = @client.oauth_client.request(:get, '/oauth/exchange_sessions', {
    :client_id     => @client.client_id,
    :client_secret => @client.secret_id,
    :type          => 'client_cred',
    :sessions      => keys.flatten.join(',')
  })
  JSON.parse(tokens).map { |hash| hash['access_token'] if hash}
end