Class: OmniAuth::Strategies::Tqq

Inherits:
OAuth
  • Object
show all
Defined in:
lib/omniauth/strategies/tqq.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Tqq

Returns a new instance of Tqq.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/omniauth/strategies/tqq.rb', line 9

def initialize(*args)
  super
  # taken from https://github.com/intridea/omniauth/blob/0-3-stable/oa-oauth/lib/omniauth/strategies/oauth/tqq.rb#L15-24
  options.client_options = {
    :access_token_path => '/cgi-bin/access_token',
    :authorize_path => '/cgi-bin/authorize',
    :http_method => :get,
    :nonce => nonce,
    :realm => 'OmniAuth',
    :request_token_path => '/cgi-bin/request_token',
    :scheme => :query_string,
    :site => 'https://open.t.qq.com',
  }
end

Instance Method Details

#consumerObject



29
30
31
32
# File 'lib/omniauth/strategies/tqq.rb', line 29

def consumer
  consumer = ::OAuth::Consumer.new(options.consumer_key, options.consumer_secret, options.client_options)
  consumer
end

#nonceObject



25
26
27
# File 'lib/omniauth/strategies/tqq.rb', line 25

def nonce
  Base64.encode64(OpenSSL::Random.random_bytes(32)).gsub(/\W/, '')[0, 32]
end

#raw_infoObject



76
77
78
79
80
# File 'lib/omniauth/strategies/tqq.rb', line 76

def raw_info
  @raw_info ||= MultiJson.decode(access_token.get('http://open.t.qq.com/api/user/info?format=json').body)
rescue ::Errno::ETIMEDOUT
  raise ::Timeout::Error
end

#request_phaseObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/omniauth/strategies/tqq.rb', line 59

def request_phase
  request_token = consumer.get_request_token(:oauth_callback => callback_url)
  session['oauth'] ||= {}
  session['oauth'][name.to_s] = {'callback_confirmed' => true, 'request_token' => request_token.token, 'request_secret' => request_token.secret}

  if request_token.callback_confirmed?
    redirect request_token.authorize_url(options[:authorize_params])
  else
    redirect request_token.authorize_url(options[:authorize_params].merge(:oauth_callback => callback_url))
  end

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