Module: Passport::Oauth::Authorizable::ClassMethods

Defined in:
lib/passport/oauth/client/authorizable.rb

Instance Method Summary collapse

Instance Method Details

#access(options) ⇒ Object

get the access token



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/passport/oauth/client/authorizable.rb', line 35

def access(options)
  if version == 1.0
    access_token = OAuth::RequestToken.new(consumer, options[:token], options[:secret]).get_access_token(:oauth_verifier => options[:oauth_verifier])
    result = {:token => access_token.token.to_s, :secret => access_token.secret.to_s}
  else
    access_token = consumer.web_server.get_access_token(options[:secret], :redirect_uri => options[:callback_url])
    result = {:token => access_token.token.to_s, :secret => options[:secret].to_s}
  end
  
  result[:key] = identify(access_token) unless options[:identify] == false
  
  result
end

#authorize(callback_url, options = {}) ⇒ Object

first part in the sequece. returns a <Hash>:

{:url => "x", :token => "y", :secret => "z"}

if it’s using Oauth 1.0, token and secret will be present. if it’s using Oauth 2.0, token and secret are not present. for Oauth 1.0, save the token/secret in the session to use after the redirect.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/passport/oauth/client/authorizable.rb', line 17

def authorize(callback_url, options = {})
  result = {}

  if version == 1.0
    options.reverse_merge!(:scope => consumer_settings[:scope]) if consumer_settings[:scope]
    request = consumer.get_request_token({:oauth_callback => callback_url}, options)
    result[:token] = request.token
    result[:secret] = request.secret
    result[:url] = request.authorize_url
  else
    options.merge!(:redirect_uri => callback_url)
    result[:url] = consumer.web_server.authorize_url(options)
  end
  
  result
end

#credentialsObject



49
50
51
# File 'lib/passport/oauth/client/authorizable.rb', line 49

def credentials
  @credentials ||= Passport.credentials(service)
end