Class: OmniAuth::Strategies::Launchpad

Inherits:
OAuth
  • Object
show all
Includes:
OmniAuth::Strategy
Defined in:
lib/omniauth/strategies/launchpad.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, consumer_key = "babun", options = {}, &block) ⇒ Launchpad

Returns a new instance of Launchpad.



25
26
27
28
29
# File 'lib/omniauth/strategies/launchpad.rb', line 25

def initialize(app, consumer_key="babun", options={}, &block)
  options[:oauth_consumer_key] = consumer_key
  options[:oauth_consumer_secret] = consumer_secret
  super(app, consumer_key, nil, options, &block)
end

Instance Method Details

#raw_user_infoObject



31
32
33
34
35
36
37
38
39
# File 'lib/omniauth/strategies/launchpad.rb', line 31

def 
    puts "before: #{@access_token.inspect}"
    request_options = {:oauth_consumer_key => options[:oauth_consumer_key], :realm => "https://api.launchpad.net/"}
    request_options.merge!(options[:authorize_params])
    @access_token.consumer.options[:scheme] = :header
    info = @access_token.get('https://api.launchpad.net/devel/people/+me', {'Accept' => 'application/json'})
    info = @access_token.get(info["location"], {'Accept' => 'application/json'})
    @raw_user_info ||= MultiJson.load info.body
end

#request_phaseObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/omniauth/strategies/launchpad.rb', line 54

def request_phase
        puts "Request info: #{options.request_param}"
request_options = {:oauth_consumer_key => options[:oauth_consumer_key], :realm => "https://api.launchpad.net/"}
  request_options.merge!(options[:authorize_params])

  request_token = consumer.get_request_token({:oauth_callback => callback_url}, request_options)
  session['oauth'] ||= {}
  session['oauth'][name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
  r = Rack::Response.new

  if request_token.callback_confirmed?
    r.redirect(request_token.authorize_url)
  else
    r.redirect(request_token.authorize_url(:oauth_callback => callback_url))
  end
  @request_token = request_token
  r.finish

  rescue ::Timeout::Error => e
    fail!(:timeout, e)
  rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e
    fail!(:service_unavailable, e)
end