Class: OmniAuth::Strategies::Tqq

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

Overview

Authenticate to Tqq via OAuth and retrieve basic user information.

Usage:

use OmniAuth::Strategies::Tqq, 'APIKey', 'APIKeySecret'

Instance Method Summary collapse

Constructor Details

#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ Tqq

Returns a new instance of Tqq.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/omniauth_china/strategies/tqq.rb', line 16

def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
  @api_key = consumer_key
  
  client_options = {
    :site               => 'https://open.t.qq.com',
    :request_token_path => '/cgi-bin/request_token',
    :access_token_path  => '/cgi-bin/access_token',
    :authorize_path     => '/cgi-bin/authorize',
    :realm              => 'OmniAuth',
    :scheme             => :query_string,
    :nonce              => nonce,
    :http_method        => :get,
  }

  super(app, :tqq, consumer_key, consumer_secret, client_options, options, &block)
end

Instance Method Details

#auth_hashObject



37
38
39
40
41
42
43
44
# File 'lib/omniauth_china/strategies/tqq.rb', line 37

def auth_hash
				# NOTE: Tencent not give uid current, use username instead.
  OmniAuth::Utils.deep_merge(super, {
    'uid' => user_hash["data"]['name'],
    'user_info' => ,
    'extra' => {'user_hash' => user_hash}
  })
end

#nonceObject



33
34
35
# File 'lib/omniauth_china/strategies/tqq.rb', line 33

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

#user_hashObject



60
61
62
# File 'lib/omniauth_china/strategies/tqq.rb', line 60

def user_hash
  @user_hash ||= MultiJson.decode(@access_token.get("http://open.t.qq.com/api/user/info?format=json").body)
end

#user_infoObject



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/omniauth_china/strategies/tqq.rb', line 46

def 
  user_hash = self.user_hash
  {
    'username' => user_hash["data"]['name'],
    'name' => user_hash["data"]['nick'],
    'location' => user_hash["data"]['location'],
    'image' => user_hash["data"]['head'],
    'description' => user_hash['data']['introduction'],
    'urls' => {
      'Tqq' => 't.qq.com'
    }
  }
end