Class: FBGraph::Authorization
- Inherits:
-
Object
- Object
- FBGraph::Authorization
- Defined in:
- lib/fbgraph/authorization.rb
Instance Method Summary collapse
- #authorize_url(params = {}) ⇒ Object
-
#initialize(client) ⇒ Authorization
constructor
A new instance of Authorization.
- #process_callback(code, options = {}) ⇒ Object
- #upgrade_session!(key) ⇒ Object
- #upgrade_session_keys(*keys) ⇒ Object
Constructor Details
#initialize(client) ⇒ Authorization
Returns a new instance of 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 (params = {}) params = { :redirect_uri => FBGraph.config[:canvas_url] }.merge(params) @client.oauth_client.auth_code.(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, = {}) # HACK(pwnall): :parse => :query is added because Facebook's tarded OAuth # endpoint returns ContentType: text/plain instead of # application/x-www-form-urlencoded = { :redirect_uri => FBGraph.config[:canvas_url], :parse => :query }.merge() @client.auth = @client.oauth_client.auth_code.get_token(code, ) @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 |